From 5b6d1b5919083d3ee1755abf4538f7996ff95082 Mon Sep 17 00:00:00 2001 From: Corey Ostrove Date: Sun, 2 Mar 2025 23:03:20 -0700 Subject: [PATCH 1/2] Fiducial Selection Bugfix Fix a quite old bug in the fiducial selection code. This bug (related to incorrectly skipping complement POVM effects) looks to be the reason why fiducial selection would never find the MIC fiducial set for measurements when you wanted it to. --- pygsti/algorithms/fiducialselection.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/pygsti/algorithms/fiducialselection.py b/pygsti/algorithms/fiducialselection.py index 6f75275ed..4a63f0bc6 100644 --- a/pygsti/algorithms/fiducialselection.py +++ b/pygsti/algorithms/fiducialselection.py @@ -712,8 +712,8 @@ def create_meas_cache(model, available_meas_fid_list, circuit_cache=None): if circuit_cache is not None: for povm in model.povms.values(): for E in povm.values(): - if isinstance(E, _ComplementPOVMEffect): continue # complement is dependent on others - new_povm_effect_key_pair= (povm.to_vector().tobytes(), E.to_vector().tobytes()) + #if isinstance(E, _ComplementPOVMEffect): continue # complement is dependent on others + new_povm_effect_key_pair= (povm.to_vector().tobytes(), E.to_dense().tobytes()) keypairlist.append(new_povm_effect_key_pair) for measFid in available_meas_fid_list: meas_cache[(new_povm_effect_key_pair[0],new_povm_effect_key_pair[1],measFid.str)] = _np.dot(E.to_dense(), circuit_cache[measFid.str]) @@ -721,8 +721,8 @@ def create_meas_cache(model, available_meas_fid_list, circuit_cache=None): else: for povm in model.povms.values(): for E in povm.values(): - if isinstance(E, _ComplementPOVMEffect): continue # complement is dependent on others - new_povm_effect_key_pair= (povm.to_vector().tobytes(), E.to_vector().tobytes()) + #if isinstance(E, _ComplementPOVMEffect): continue # complement is dependent on others + new_povm_effect_key_pair= (povm.to_vector().tobytes(), E.to_dense().tobytes()) keypairlist.append(new_povm_effect_key_pair) for measFid in available_meas_fid_list: meas_cache[(new_povm_effect_key_pair[0],new_povm_effect_key_pair[1],measFid.str)] = _np.dot(E.to_dense(), model.sim.product(measFid)) @@ -832,9 +832,9 @@ def create_meas_mxs(model, meas_fid_list, meas_cache=None): #Actually, this is slowing things down a good amount, let's just print a #descriptive error message if the key is missing try: - outputMat[:, i] = meas_cache[0][(povm_key, E_key,measFid.str)] + outputMat[:, i] = meas_cache[0][(povm_key, E_key, measFid.str)] except KeyError as err: - print('A (POVM, Effect, Circuit) pair is missing from the cache, all such pairs should be available is using the caching option.') + print('A (POVM, Effect, Circuit) pair is missing from the cache, all such pairs should be available if using the caching option.') raise err #outputMat[:, i] = _np.dot(E.to_dense(), model.sim.product(measFid)) outputMatList.append(outputMat) @@ -842,7 +842,7 @@ def create_meas_mxs(model, meas_fid_list, meas_cache=None): else: for povm in model.povms.values(): for E in povm.values(): - if isinstance(E, _ComplementPOVMEffect): continue # complement is dependent on others + #if isinstance(E, _ComplementPOVMEffect): continue # complement is dependent on others outputMat = _np.zeros([dimE, numFid], float) for i, measFid in enumerate(meas_fid_list): outputMat[:, i] = _np.dot(E.to_dense(), model.sim.product(measFid)) From 9b3862bda4c9e21bec8de0423698c24ec6aa5c6d Mon Sep 17 00:00:00 2001 From: Corey Ostrove Date: Tue, 25 Mar 2025 19:10:30 -0600 Subject: [PATCH 2/2] Finish removal of problematic line Remove the commented out lines related to the (erroneous) ComplementPOVMEffect check. Also clean up a few misc commented out bits of code. --- pygsti/algorithms/fiducialselection.py | 9 --------- 1 file changed, 9 deletions(-) diff --git a/pygsti/algorithms/fiducialselection.py b/pygsti/algorithms/fiducialselection.py index fb7fc622a..5bac3d711 100644 --- a/pygsti/algorithms/fiducialselection.py +++ b/pygsti/algorithms/fiducialselection.py @@ -712,7 +712,6 @@ def create_meas_cache(model, available_meas_fid_list, circuit_cache=None): if circuit_cache is not None: for povm in model.povms.values(): for E in povm.values(): - #if isinstance(E, _ComplementPOVMEffect): continue # complement is dependent on others new_povm_effect_key_pair= (povm.to_vector().tobytes(), E.to_dense().tobytes()) keypairlist.append(new_povm_effect_key_pair) for measFid in available_meas_fid_list: @@ -721,7 +720,6 @@ def create_meas_cache(model, available_meas_fid_list, circuit_cache=None): else: for povm in model.povms.values(): for E in povm.values(): - #if isinstance(E, _ComplementPOVMEffect): continue # complement is dependent on others new_povm_effect_key_pair= (povm.to_vector().tobytes(), E.to_dense().tobytes()) keypairlist.append(new_povm_effect_key_pair) for measFid in available_meas_fid_list: @@ -777,7 +775,6 @@ def create_prep_mxs(model, prep_fid_list, prep_cache=None): except KeyError as err: print('A (Rho, Circuit) pair is missing from the cache, all such pairs should be available is using the caching option.') raise err - #outputMat[:, i] = _np.dot(model.sim.product(prepFid), rho.to_dense()) outputMatList.append(outputMat) else: @@ -836,13 +833,11 @@ def create_meas_mxs(model, meas_fid_list, meas_cache=None): except KeyError as err: print('A (POVM, Effect, Circuit) pair is missing from the cache, all such pairs should be available if using the caching option.') raise err - #outputMat[:, i] = _np.dot(E.to_dense(), model.sim.product(measFid)) outputMatList.append(outputMat) else: for povm in model.povms.values(): for E in povm.values(): - #if isinstance(E, _ComplementPOVMEffect): continue # complement is dependent on others outputMat = _np.zeros([dimE, numFid], float) for i, measFid in enumerate(meas_fid_list): outputMat[:, i] = _np.dot(E.to_dense(), model.sim.product(measFid)) @@ -1774,10 +1769,6 @@ def _find_fiducials_greedy(model, fids_list, prep_or_meas, op_penalty=0.0, else: for fiducial in fids_list: #calculate the score matrix - #if prep_or_meas == 'prep': - # fidArrayList = create_prep_mxs(model, [fiducial], fid_cache) - #elif prep_or_meas == 'meas': - # fidArrayList = create_meas_mxs(model, [fiducial], fid_cache) current_score_mx= fiducial_compact_EVD_cache[fiducial] current_score_gramian= fiducial_compact_EVD_cache[fiducial]@fiducial_compact_EVD_cache[fiducial].T current_inv_trace = _np.trace(_np.linalg.pinv(current_score_gramian, hermitian=True))