Skip to content

Bugfixes for PGG FPR and Germ Selection #545

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Mar 14, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions pygsti/algorithms/fiducialpairreduction.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,22 +19,20 @@
import scipy.linalg as _sla

from math import ceil
import time

from pygsti import baseobjs as _baseobjs
from pygsti import circuits as _circuits

from pygsti.circuits import circuitconstruction as _gsc
from pygsti.modelmembers.operations import EigenvalueParamDenseOp as _EigenvalueParamDenseOp
from pygsti.tools import apply_aliases_to_circuits as _apply_aliases_to_circuits
from pygsti.tools import remove_duplicates as _remove_duplicates
from pygsti.tools import slicetools as _slct
from pygsti.tools.legacytools import deprecate as _deprecated_fn
from pygsti.forwardsims import MatrixForwardSimulator as _MatrixForwardSimulator

from pygsti.algorithms.germselection import construct_update_cache, minamide_style_inverse_trace, compact_EVD, compact_EVD_via_SVD, germ_set_spanning_vectors
from pygsti.algorithms.germselection import construct_update_cache, minamide_style_inverse_trace, compact_EVD, germ_set_spanning_vectors
from pygsti.algorithms import scoring as _scoring

from pygsti.tools.matrixtools import print_mx

import warnings

Expand Down Expand Up @@ -1658,6 +1656,10 @@ def find_sufficient_fiducial_pairs_per_germ_global(target_model, prep_fiducials,
`prep_fiducials` and `meas_fiducials`).
"""

if not isinstance(target_model.sim, _MatrixForwardSimulator):
target_model = target_model.copy()
target_model.sim = 'matrix'

printer = _baseobjs.VerbosityPrinter.create_printer(verbosity)

#if no germ_vector_spanning_set is passed in compute it here.
Expand All @@ -1674,7 +1676,7 @@ def find_sufficient_fiducial_pairs_per_germ_global(target_model, prep_fiducials,
if germ_set_spanning_kwargs is not None:
used_kwargs.update(germ_set_spanning_kwargs)

germ_vector_spanning_set = germ_set_spanning_vectors(target_model, germs,
germ_vector_spanning_set, _ = germ_set_spanning_vectors(target_model, germs,
float_type=float_type,
evd_tol = evd_tol,
verbosity=verbosity,
Expand Down
24 changes: 15 additions & 9 deletions pygsti/algorithms/germselection.py
Original file line number Diff line number Diff line change
Expand Up @@ -409,15 +409,17 @@ def find_germs(target_model, randomize=True, randomization_strength=1e-2,
#force the line labels on each circuit to match the state space labels for the target model.
#this is suboptimal for many-qubit models, so will probably want to revisit this. #TODO
finalGermList = []
for ckt in germList:
if ckt._static:
new_ckt = ckt.copy(editable=True)
new_ckt.line_labels = target_model.state_space.state_space_labels
new_ckt.done_editing()
finalGermList.append(new_ckt)
else:
ckt.line_labels = target_model.state_space.state_space_labels
finalGermList.append(ckt)
if germList is not None:
for ckt in germList:
if ckt._static:
new_ckt = ckt.copy(editable=True)
new_ckt.line_labels = target_model.state_space.state_space_labels
new_ckt.done_editing()
finalGermList.append(new_ckt)
else:
ckt.line_labels = target_model.state_space.state_space_labels
finalGermList.append(ckt)

return finalGermList


Expand Down Expand Up @@ -4531,6 +4533,10 @@ def germ_set_spanning_vectors(target_model, germ_list, assume_real=False, float_
amplificational properties of the reduced vector set.
"""
printer = _baseobjs.VerbosityPrinter.create_printer(verbosity)

if not isinstance(target_model.sim, _MatrixForwardSimulator):
target_model = target_model.copy()
target_model.sim = 'matrix'

#Add some checks related to the option to switch up data types:
if not assume_real:
Expand Down
16 changes: 11 additions & 5 deletions pygsti/modelmembers/operations/lindbladcoefficients.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,23 @@
import collections as _collections
import copy as _copy
import warnings as _warnings

from pygsti.tools import lindbladtools as _lt
from pygsti.tools import matrixtools as _mt
from pygsti.tools import optools as _ot
from pygsti.tools import fastcalc as _fc
from pygsti.baseobjs.basis import Basis as _Basis, BuiltinBasis as _BuiltinBasis
from pygsti.modelmembers import term as _term
from pygsti.baseobjs.polynomial import Polynomial as _Polynomial
from pygsti.baseobjs.nicelyserializable import NicelySerializable as _NicelySerializable

from functools import lru_cache
try:
from pygsti.tools import fastcalc as _fc
triu_indices = _fc.fast_triu_indices
except ImportError:
msg = 'Could not import cython module `fastcalc`. This may indicate that your cython extensions for pyGSTi failed to.'\
+'properly build. Lack of cython extensions can result in significant performance degredation so we recommend trying to rebuild them.'\
'Falling back to numpy implementation for triu_indices.'
_warnings.warn(msg)
triu_indices = _np.triu_indices

IMAG_TOL = 1e-7 # tolerance for imaginary part being considered zero

Expand Down Expand Up @@ -814,7 +820,7 @@ def from_vector(self, v):

cache_mx = self._cache_mx

params_upper_indices = _fc.fast_triu_indices(num_bels)
params_upper_indices = triu_indices(num_bels)
params_upper = 1j*params[params_upper_indices]
params_lower = (params.T)[params_upper_indices]

Expand All @@ -837,7 +843,7 @@ def from_vector(self, v):

elif self._param_mode == "elements": # params mx stores block_data (hermitian) directly
#params holds block_data real and imaginary parts directly
params_upper_indices = _fc.fast_triu_indices(num_bels)
params_upper_indices = triu_indices(num_bels)
params_upper = -1j*params[params_upper_indices]
params_lower = (params.T)[params_upper_indices]

Expand Down
3 changes: 2 additions & 1 deletion test/unit/algorithms/test_germselection.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,8 @@ class GenerateGermsTester(GermSelectionData, BaseCase):
def test_generate_germs_with_candidate_germ_counts(self):
germs = germsel.find_germs(
self.mdl_target_noisy, randomize=False,
candidate_germ_counts={3: 'all upto', 4: 10, 5: 10, 6: 10}
candidate_germ_counts={3: 'all upto', 4: 10, 5: 10, 6: 10},
candidate_seed=1234
)
# TODO assert correctness

Expand Down