26
26
from pygsti .tools import listtools as _lt
27
27
from pygsti .tools .legacytools import deprecate as _deprecated_fn
28
28
29
+ from typing import Dict
30
+ ordereddict = Dict
31
+
29
32
30
33
def _create_raw_lsgst_lists (op_label_src , prep_strs , effect_strs , germ_list , max_length_list ,
31
34
fid_pairs = None , trunc_scheme = "whole germ powers" , nest = True ,
@@ -325,7 +328,8 @@ def create_lsgst_circuit_lists(op_label_src, prep_fiducials, meas_fiducials, ger
325
328
indexing a string within prep_strs and effect_strs, respectively, so
326
329
that prepStr = prep_strs[iPrepStr] and effectStr =
327
330
effect_strs[iEffectStr]. If a dictionary, keys are germs (elements
328
- of germ_list) and values are lists of 2-tuples specifying the pairs
331
+ of germ_list) or tuples of germs and length values
332
+ and values are lists of 2-tuples specifying the pairs
329
333
to use for that germ.
330
334
331
335
trunc_scheme : str, optional
@@ -414,9 +418,8 @@ def create_lsgst_circuit_lists(op_label_src, prep_fiducials, meas_fiducials, ger
414
418
[c .str for c in prep_fiducials ]
415
419
[c .str for c in meas_fiducials ]
416
420
417
- #print('Germs: ', germs)
418
-
419
421
def filter_ds (circuits , ds , missing_lgst ):
422
+ """Filter a list of circuits so that only those appearing in dataset are included."""
420
423
if ds is None : return circuits [:]
421
424
filtered_circuits = []
422
425
for opstr in circuits :
@@ -444,8 +447,7 @@ def add_to_plaquettes(pkey_dict, plaquette_dict, base_circuit, maxlen, germ, pow
444
447
for i in reversed (inds_to_remove ):
445
448
del fidpair_indices [i ]
446
449
447
- fidpairs = _collections .OrderedDict ([((j , i ), (prep_fiducials [i ], meas_fiducials [j ]))
448
- for i , j in fidpair_indices ])
450
+ fidpairs : ordereddict = {(j , i ): (prep_fiducials [i ], meas_fiducials [j ]) for i , j in fidpair_indices }
449
451
450
452
if base_circuit not in plaquette_dict :
451
453
pkey_dict [base_circuit ] = (maxlen , germ )
@@ -528,7 +530,7 @@ def add_to_plaquettes(pkey_dict, plaquette_dict, base_circuit, maxlen, germ, pow
528
530
if nest :
529
531
#keep track of running quantities used to build circuit structures
530
532
running_plaquette_keys = {} # base-circuit => (maxlength, germ) key for final plaquette dict
531
- running_plaquettes = _collections . OrderedDict () # keep consistent ordering in produced circuit list.
533
+ running_plaquettes : ordereddict = dict () # keep consistent ordering in produced circuit list.
532
534
running_unindexed = []
533
535
running_maxLens = []
534
536
@@ -554,7 +556,7 @@ def add_to_plaquettes(pkey_dict, plaquette_dict, base_circuit, maxlen, germ, pow
554
556
unindexed = running_unindexed
555
557
else : # create a new cs for just this maxLen
556
558
pkey = {} # base-circuit => (maxlength, germ) key for final plaquette dict
557
- plaquettes = _collections . OrderedDict ()
559
+ plaquettes : ordereddict = dict ()
558
560
maxLens = [maxLen ]
559
561
unindexed = []
560
562
@@ -586,39 +588,39 @@ def add_to_plaquettes(pkey_dict, plaquette_dict, base_circuit, maxlen, germ, pow
586
588
if power == 0 and len (germ ) != 0 :
587
589
continue
588
590
589
- # Switch on fidpair dicts with germ or (germ, L) keys
590
- key = germ
591
- if fidpair_germ_power_keys :
592
- key = (germ , maxLen_thisgerm )
593
-
594
- if rndm is None :
595
- fiducialPairsThisIter = fidPairDict . get ( key , allPossiblePairs ) \
596
- if fidPairDict is not None else allPossiblePairs
597
- # if fiducialPairsThisIter==allPossiblePairs :
598
- # print('Couldn\'t find ', key, ' using allPossiblePairs')
599
- #print('FiducialPairsThisIter: ', fiducialPairsThisIter)
600
- elif fidPairDict is not None :
601
- pair_indx_tups = fidPairDict .get (key , allPossiblePairs )
602
- remainingPairs = [(i , j )
603
- for i in range (len (prep_fiducials ))
604
- for j in range (len (meas_fiducials ))
605
- if (i , j ) not in pair_indx_tups ]
606
- nPairsRemaining = len (remainingPairs )
607
- nPairsToChoose = nPairsToKeep - len (pair_indx_tups )
608
- nPairsToChoose = max (0 , min (nPairsToChoose , nPairsRemaining ))
609
- assert (0 <= nPairsToChoose <= nPairsRemaining )
610
- # FUTURE: issue warnings when clipping nPairsToChoose?
611
-
612
- fiducialPairsThisIter = fidPairDict [key ] + \
613
- [remainingPairs [k ] for k in
614
- sorted (rndm .choice (nPairsRemaining , nPairsToChoose ,
615
- replace = False ))]
616
-
617
- else : # rndm is not None and fidPairDict is None
618
- assert (nPairsToKeep <= nPairs ) # keep_fraction must be <= 1.0
619
- fiducialPairsThisIter = \
620
- [allPossiblePairs [k ] for k in
621
- sorted (rndm .choice (nPairs , nPairsToKeep , replace = False ))]
591
+ if include_lgst and i == 0 :
592
+ fiducialPairsThisIter = allPossiblePairs
593
+ else :
594
+ # Switch on fidpair dicts with germ or (germ, L) keys
595
+ key = germ
596
+ if fidpair_germ_power_keys :
597
+ key = ( germ , maxLen_thisgerm )
598
+
599
+ if rndm is None :
600
+ fiducialPairsThisIter = fidPairDict . get ( key , allPossiblePairs ) \
601
+ if fidPairDict is not None else allPossiblePairs
602
+ elif fidPairDict is not None :
603
+ pair_indx_tups = fidPairDict .get (key , allPossiblePairs )
604
+ remainingPairs = [(i , j )
605
+ for i in range (len (prep_fiducials ))
606
+ for j in range (len (meas_fiducials ))
607
+ if (i , j ) not in pair_indx_tups ]
608
+ nPairsRemaining = len (remainingPairs )
609
+ nPairsToChoose = nPairsToKeep - len (pair_indx_tups )
610
+ nPairsToChoose = max (0 , min (nPairsToChoose , nPairsRemaining ))
611
+ assert (0 <= nPairsToChoose <= nPairsRemaining )
612
+ # FUTURE: issue warnings when clipping nPairsToChoose?
613
+
614
+ fiducialPairsThisIter = fidPairDict [key ] + \
615
+ [remainingPairs [k ] for k in
616
+ sorted (rndm .choice (nPairsRemaining , nPairsToChoose ,
617
+ replace = False ))]
618
+
619
+ else : # rndm is not None and fidPairDict is None
620
+ assert (nPairsToKeep <= nPairs ) # keep_fraction must be <= 1.0
621
+ fiducialPairsThisIter = \
622
+ [allPossiblePairs [k ] for k in
623
+ sorted (rndm .choice (nPairs , nPairsToKeep , replace = False ))]
622
624
623
625
add_to_plaquettes (pkey , plaquettes , germ_power , maxLen , germ , power ,
624
626
fiducialPairsThisIter , dscheck , missing_list )
@@ -630,8 +632,7 @@ def add_to_plaquettes(pkey_dict, plaquette_dict, base_circuit, maxlen, germ, pow
630
632
unindexed = unindexed [:]
631
633
632
634
lsgst_structs .append (
633
- _PlaquetteGridCircuitStructure (_collections .OrderedDict ([(pkey [base ], plaq )
634
- for base , plaq in plaquettes .items ()]),
635
+ _PlaquetteGridCircuitStructure ({pkey [base ]:plaq for base , plaq in plaquettes .items ()},
635
636
maxLens , germs , "L" , "germ" , unindexed , op_label_aliases ,
636
637
circuit_weights_dict = None , additional_circuits_location = 'start' , name = None ))
637
638
tot_circuits += len (lsgst_structs [- 1 ]) # only relevant for non-nested case
@@ -641,11 +642,9 @@ def add_to_plaquettes(pkey_dict, plaquette_dict, base_circuit, maxlen, germ, pow
641
642
642
643
printer .log ("--- Circuit Creation ---" , 1 )
643
644
printer .log (" %d circuits created" % tot_circuits , 2 )
644
- #print("Total Number of Circuits: ", tot_circuits)
645
645
if dscheck :
646
646
printer .log (" Dataset has %d entries: %d utilized, %d requested circuits were missing"
647
647
% (len (dscheck ), tot_circuits , len (missing_list )), 2 )
648
- #print(len(missing_lgst))
649
648
if len (missing_list ) > 0 or len (missing_lgst ) > 0 :
650
649
MAX = 10 # Maximum missing-seq messages to display
651
650
missing_msgs = [("Prep: %s, Germ: %s, L: %d, Meas: %s, Circuit: %s" % tup ) for tup in missing_list [0 :MAX + 1 ]] \
0 commit comments