Skip to content
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

LGST doesn't work with TP-parameterized target models #366

Closed
coreyostrove opened this issue Nov 8, 2023 · 0 comments
Closed

LGST doesn't work with TP-parameterized target models #366

coreyostrove opened this issue Nov 8, 2023 · 0 comments
Assignees
Labels
bug A bug or regression
Milestone

Comments

@coreyostrove
Copy link
Contributor

I ran into this while refactoring some unit tests to shift away from using legacy modelpacks. As part of that change I also for different reasons thought it would be good to switch to a 'full TP' parameterized model for the target models used in some of the unit tests. In doing so I discovered that LGST (which is tested in test_core.py) doesn't actually work when using a 'full TP' parameterized model as the target model. Here is a minimal working example:

from pygsti.modelpacks import smq1Q_XY
test_model = smq1Q_XY.target_model('full TP')
ds = pygsti.data.datasetconstruction.simulate_data(test_model, smq1Q_XY.create_gst_experiment_design(1).all_circuits_needing_data, num_samples=100)
pygsti.algorithms.core.run_lgst(ds, smq1Q_XY.prep_fiducials(), smq1Q_XY.meas_fiducials(), target_model=test_model)

This produces the traceback:

---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
Cell In[18], line 1
----> 1 pygsti.algorithms.core.run_lgst(ds, smq1Q_XY.prep_fiducials(), smq1Q_XY.meas_fiducials(), target_model=test_model)

File ~\Documents\pyGSTi_new_FPR_method\pygsti\algorithms\core.py:282, in run_lgst(dataset, prep_fiducials, effect_fiducials, target_model, op_labels, op_label_aliases, guess_model_for_gauge, svd_truncate_to, verbosity)
    279 for i in range(guessTrunc): guessPj[i, i] = 1.0
    280 # guessPjt = _np.transpose(guessPj)         # shape = (guessTrunc, K)
--> 282 AMat = _construct_a(effect_fiducials, guess_model_for_gauge)    # shape = (nESpecs, gsDim)
    283 # AMat_p = _np.dot( guessPjt, _np.dot(Ud, AMat)) #truncate Evec => Evec', shape (guessTrunc,gsDim) (square!)
    285 BMat = _construct_b(prep_fiducials, guess_model_for_gauge)  # shape = (gsDim, nRhoSpecs)

File ~\Documents\pyGSTi_new_FPR_method\pygsti\algorithms\core.py:455, in _construct_a(effect_fiducials, model)
    453 for i in range(dim):  # propagate each basis initial state
    454     basis_st[i] = 1.0
--> 455     model.preps['rho_LGST_tmp'] = basis_st
    456     probs = model.probabilities(_circuits.Circuit(('rho_LGST_tmp',), line_labels=estr.line_labels) + estr)
    457     A[eoff:eoff + povmLen, i] = [probs[(ol,)] for ol in model.povms[povmLbl]]  # CHECK will this work?

File ~\Documents\pyGSTi_new_FPR_method\pygsti\models\memberdict.py:334, in OrderedMemberDict.__setitem__(self, key, value)
    329     new_item = None  # keep track of newly set item for later
    331 else:
    332     #otherwise, we've been given a non-ModelMember-object that doesn't
    333     # exist yet, so use default creation flags to make one:
--> 334     obj = self.cast_to_model_member(value)
    336     if obj is None:
    337         raise ValueError("Cannot set a value of type: ", type(value))

File ~\Documents\pyGSTi_new_FPR_method\pygsti\models\memberdict.py:264, in OrderedMemberDict.cast_to_model_member(self, value)
    262 if self.flags['cast_to_type'] == "state":
    263     obj = _state.StaticState(value, basis, evotype, state_space)
--> 264     obj = _state.convert(obj, self.default_param, basis)
    265 elif self.flags['cast_to_type'] == "operation":
    266     obj = _op.StaticArbitraryOp(value, None, evotype, state_space)

File ~\Documents\pyGSTi_new_FPR_method\pygsti\modelmembers\states\__init__.py:291, in convert(state, to_type, basis, ideal_state, flatten_structure)
    287     except ValueError as e:
    288         #_warnings.warn('Failed to convert state to type %s with error: %s' % (to_type, e))
    289         error_msgs[to_type] = str(e)  # try next to_type
--> 291 raise ValueError("Could not convert state to to type(s): %s\n%s" % (str(to_types), str(error_msgs)))

ValueError: Could not convert state to to type(s): ['full TP']
{'full TP': 'Could not create a state of type(s) full TP from the given superket vector!'}

As indicated in the traceback the issue looks to be in the function _construct_a which does a propagation of basis vectors, but appears to do so in such a way that it also propagates the basis element for the identity, which the conversion code for switching to TP states doesn't like. This should be fixable with some appropriate logic for detecting when we have a TP model and avoiding the propagation of the identity element in those cases.

This is a bit of a rabbit hole with respect to the refactor and fixes to the unit tests which led to discovering this, and those are higher priority at the moment so bookmarking this for the future.

Environment (please complete the following information):

  • pyGSTi version: develop
  • python version 3.9
  • OS Windows 11
@coreyostrove coreyostrove added the bug A bug or regression label Nov 8, 2023
@coreyostrove coreyostrove self-assigned this Nov 8, 2023
@sserita sserita added this to the 0.9.12.1 milestone Nov 29, 2023
sserita added a commit that referenced this issue Jan 30, 2024
@sserita sserita added the fixed-but-not-in-release-yet Bug has been fixed, but isn't in an official release yet (just exists on a development branch) label Jan 30, 2024
@sserita sserita closed this as completed Jan 31, 2024
@sserita sserita removed the fixed-but-not-in-release-yet Bug has been fixed, but isn't in an official release yet (just exists on a development branch) label Feb 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug A bug or regression
Projects
None yet
Development

No branches or pull requests

2 participants