@@ -122,14 +122,15 @@ def random_circuits(
122
122
inverse_layer = True ,
123
123
single_qubit = True ,
124
124
file_inv = pathlib .Path (),
125
+ interleave = None ,
125
126
) -> Iterable :
126
127
"""Returns random (self-inverting) Clifford circuits."""
127
128
128
129
circuits = []
129
130
indexes = defaultdict (list )
130
131
for _ in range (niter ):
131
132
for target in targets :
132
- circuit , random_index = layer_circuit (rb_gen , depth , target )
133
+ circuit , random_index = layer_circuit (rb_gen , depth , target , interleave )
133
134
if inverse_layer :
134
135
add_inverse_layer (circuit , rb_gen , single_qubit , file_inv )
135
136
add_measurement_layer (circuit )
@@ -307,6 +308,14 @@ def extract_probabilities(self, qubits):
307
308
return probs
308
309
309
310
311
+ @dataclass
312
+ class RB2QInterData (RB2QData ):
313
+ """The output of the acquisition function."""
314
+
315
+ fidelity : dict [QubitPairId , list ] = field (default_factory = dict )
316
+ """The interleaved fidelity of this qubit."""
317
+
318
+
310
319
@dataclass
311
320
class StandardRBResult (Results ):
312
321
"""Standard RB outputs."""
@@ -319,26 +328,32 @@ class StandardRBResult(Results):
319
328
"""Raw fitting parameters."""
320
329
fit_uncertainties : dict [QubitId , list [float ]]
321
330
"""Fitting parameters uncertainties."""
322
- error_bars : dict [QubitId , Optional [Union [float , list [float ]]]] = None
331
+ error_bars : dict [QubitId , Optional [Union [float , list [float ]]]] = field (
332
+ default_factory = dict
333
+ )
323
334
"""Error bars for y."""
324
335
325
336
326
337
def setup (
327
338
params : Parameters ,
339
+ platform : Platform ,
328
340
single_qubit : bool = True ,
341
+ interleave : Optional [str ] = None ,
329
342
):
330
343
"""
331
344
Set up the randomized benchmarking experiment backend, noise model and data class.
332
345
333
346
Args:
334
347
params (Parameters): The parameters for the experiment.
335
348
single_qubit (bool, optional): Flag indicating whether the experiment is for a single qubit or two qubits. Defaults to True.
349
+ interleave: (str, optional): The type of interleaving to apply. Defaults to None.
336
350
337
351
Returns:
338
352
tuple: A tuple containing the experiment data, noise model, and backend.
339
353
"""
340
354
341
355
backend = GlobalBackend ()
356
+ backend .platform = platform
342
357
# For simulations, a noise model can be added.
343
358
noise_model = None
344
359
if params .noise_model is not None :
@@ -351,7 +366,12 @@ def setup(
351
366
noise_model = getattr (noisemodels , params .noise_model )(params .noise_params )
352
367
params .noise_params = noise_model .params .tolist ()
353
368
# Set up the scan (here an iterator of circuits of random clifford gates with an inverse).
354
- cls = RBData if single_qubit else RB2QData
369
+ if single_qubit :
370
+ cls = RBData
371
+ elif interleave is not None :
372
+ cls = RB2QInterData
373
+ else :
374
+ cls = RB2QData
355
375
data = cls (
356
376
depths = params .depths ,
357
377
uncertainties = params .uncertainties ,
@@ -405,6 +425,7 @@ def get_circuits(
405
425
add_inverse_layer ,
406
426
single_qubit ,
407
427
inv_file ,
428
+ interleave ,
408
429
)
409
430
410
431
circuits .extend (circuits_depth )
@@ -464,8 +485,8 @@ def execute_circuits(circuits, targets, params, backend, single_qubit=True):
464
485
465
486
def rb_acquisition (
466
487
params : Parameters ,
467
- targets : list [QubitId ],
468
488
platform : Platform ,
489
+ targets : list [QubitId ],
469
490
add_inverse_layer : bool = True ,
470
491
interleave : str = None ,
471
492
) -> RBData :
@@ -482,8 +503,7 @@ def rb_acquisition(
482
503
Returns:
483
504
RBData: The depths, samples, and ground state probability of each experiment in the scan.
484
505
"""
485
- data , noise_model , backend = setup (params , single_qubit = True )
486
- backend .platform = platform
506
+ data , noise_model , backend = setup (params , platform , single_qubit = True )
487
507
circuits , indexes , npulses_per_clifford = get_circuits (
488
508
params , targets , add_inverse_layer , interleave , noise_model , single_qubit = True
489
509
)
@@ -512,11 +532,11 @@ def rb_acquisition(
512
532
513
533
def twoq_rb_acquisition (
514
534
params : Parameters ,
515
- targets : list [QubitPairId ],
516
535
platform : Platform ,
536
+ targets : list [QubitPairId ],
517
537
add_inverse_layer : bool = True ,
518
538
interleave : str = None ,
519
- ) -> RB2QData :
539
+ ) -> Union [ RB2QData , RB2QInterData ] :
520
540
"""
521
541
The data acquisition stage of two qubit Standard Randomized Benchmarking.
522
542
@@ -530,8 +550,7 @@ def twoq_rb_acquisition(
530
550
RB2QData: The acquired data for two qubit randomized benchmarking.
531
551
"""
532
552
533
- data , noise_model , backend = setup (params , single_qubit = False )
534
- backend .platform = platform
553
+ data , noise_model , backend = setup (params , platform , single_qubit = False )
535
554
circuits , indexes , npulses_per_clifford = get_circuits (
536
555
params , targets , add_inverse_layer , interleave , noise_model , single_qubit = False
537
556
)
@@ -564,13 +583,16 @@ def twoq_rb_acquisition(
564
583
return data
565
584
566
585
567
- def layer_circuit (rb_gen : Callable , depth : int , target ) -> tuple [Circuit , dict ]:
586
+ def layer_circuit (
587
+ rb_gen : Callable , depth : int , target , interleave : str = None
588
+ ) -> tuple [Circuit , dict ]:
568
589
"""Creates a circuit of `depth` layers from a generator `layer_gen` yielding `Circuit` or `Gate`
569
590
and a dictionary with random indexes used to select the clifford gates.
570
591
571
592
Args:
572
593
layer_gen (Callable): Should return gates or a full circuit specifying a layer.
573
594
depth (int): Number of layers.
595
+ interleave (str, optional): Interleaving pattern for the circuits. Defaults to None.
574
596
575
597
Returns:
576
598
Circuit: with `depth` many layers.
@@ -587,14 +609,19 @@ def layer_circuit(rb_gen: Callable, depth: int, target) -> tuple[Circuit, dict]:
587
609
for _ in range (depth ):
588
610
# Generate a layer.
589
611
new_layer , random_index = rb_gen_layer
612
+ random_indexes .append (random_index )
590
613
new_circuit = Circuit (nqubits )
591
614
if nqubits == 1 :
592
615
new_circuit .add (new_layer )
593
616
elif nqubits == 2 :
594
617
for gate in new_layer :
595
618
new_circuit .add (gate )
596
-
597
- random_indexes .append (random_index )
619
+ # FIXME: General interleave
620
+ if interleave == "CZ" :
621
+ interleaved_clifford = rb_gen .two_qubit_cliffords ["13" ]
622
+ interleaved_clifford_gate = clifford2gates (interleaved_clifford )
623
+ new_circuit .add (interleaved_clifford_gate )
624
+ random_indexes .append ("13" )
598
625
599
626
if full_circuit is None : # instantiate in first loop
600
627
full_circuit = Circuit (new_circuit .nqubits )
0 commit comments