Skip to content

WIP: leakage-aware GST #410

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

Draft
wants to merge 88 commits into
base: develop
Choose a base branch
from
Draft

WIP: leakage-aware GST #410

wants to merge 88 commits into from

Conversation

rileyjmurray
Copy link
Contributor

@rileyjmurray rileyjmurray commented Mar 19, 2024

TODOs

  • Justify or revert the change in bc7cb8b. (Justified.)
  • Write explanations of report metrics; see this comment.
  • Discuss what to do with my changes to report table captions; see this comment and this comment.
  • Move various helper functions from my notebooks (i.e., the ones I make static functions of an Infrastructure class) into appropriate places within pyGSTi. Examples from Leakage_Analysis/2025-06-24/a.ipynb:
    • leaky_qubit_model_from_pspec (definitely)
    • changebasis_3level_model and changebasis_3level_results (maybe)
    • std_lago_gopsuite and lago_gaugeopt_params. (definitely)
    • transform_composed_model (definitely)
    • param_preserving_gauge_opt (definitely)
  • Decide on a real solution to my changes and comment in _add_gauge_opt.
  • Make a leakage-friendly built-in basis. Right now it's just a factory function sitting in basistools.py.
  • An example notebook.

Leakage analysis that's important, but out of scope for this PR.

  • systems with > 1 qubit.
  • systems with > 1 leakage level.
  • CPTP kite models

@rileyjmurray rileyjmurray changed the title WIP: leakage-aware gauge optimization WIP: leakage-aware gauge optimization -- bad commit history Sep 24, 2024
@rileyjmurray rileyjmurray changed the base branch from master to develop September 24, 2024 21:15
@rileyjmurray rileyjmurray changed the title WIP: leakage-aware gauge optimization -- bad commit history WIP: leakage-aware gauge optimization Sep 24, 2024
@rileyjmurray rileyjmurray changed the title WIP: leakage-aware gauge optimization WIP: leakage-aware GST Mar 25, 2025
@rileyjmurray
Copy link
Contributor Author

Text from an email Piper sent (not showing plots since they contained real data):

I was looking at the model violation tab, trying to work out why the smaller L models weren’t fitting the data as well as might be expected as quantified by Nsigma. I think this maybe be a function of how we calculate Nsigma = (2delta logl -k)/sqrt(2k). The number of non-gauge model parameters N_p is reported as 351 in the leakage-enhanced GST report (I don’t have any particular sense of whether this is correct). The number of data points N_s is 193 for L=1. This means that k (the degrees of freedom) is negative if you just calculate it as N_s-N_p. In cases like this, pyGSTi chooses k=1. k remains small until L is fairly large, which means two delta logl must be quite small for Nsigma to be small. This explains why we don’t see any red boxes in the per sequence detail for the L=1 iteration (and Nsigma is large enough that I would expect to see some or at least more dark gray squares than can be seen).

If you directly compare two delta logl between the two fits, you can see that the two delta logl is in fact smaller in the leakage-enhanced report than in the standard report.

I think the solution here is just to make sure that the first iteration of leakage-aware GST uses L=2 instead of L=1. (Or, more generally, we use the smallest L where N_s > N_p.)

Copy link
Contributor Author

@rileyjmurray rileyjmurray left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Leaving file-level comments so @coreyostrove and I can figure out what to split out from this PR.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changes here ARE leakage-specific and CANNOT be moved to another PR.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change is needed for correctness; it's not leakage-specific.

Copy link
Contributor Author

@rileyjmurray rileyjmurray Jul 24, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The change in 42f0cf3 (the date is misleading because I force-pushed) is not leakage-specific and seems worth keeping.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Type annotations; not leakage-specific.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Type annotations; not leakage-specific.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not leakage-specific, but necessary for leakage analysis.

Copy link
Contributor Author

@rileyjmurray rileyjmurray Jul 24, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changes needed for leakage analysis, plus a handful for non-leakage-specific changes.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changes needed for leakage analysis, and useful more broadly

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not leakage-specific

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Modest tests for code used in leakage analysis

…inearOperator (not just plain numpy ndarrays)
…frobenius norm computation. Bugfix in test_optools.py.
…lots of in-line comments explaining the logic.
…anch that omitted jac as a keyword argument to scipy.minimize, even if jac was None.
…nt fidelity from the calculation of that metric itself. This makes it easier to reuse the setup code in other metrics. While making this change, also make the setup more efficient by using TensorProduct bases from the beginning.
…imizers. Right now only entanglement fidelity and jtracedist have implementations that can consider leakage. (So there are no leakage-aware metrics for SPAM.)
…dded annotations to all gauage optimization objectives used in the non-LS optimizer, indicating if that particular objective has support for leakage-aware metrics.
… while. The tests only consider when no leakage is modeled. New tests wil be needed for when theres a leakage dimension
… that various gauge optimization functions don`t raise errors.
rileyjmurray and others added 20 commits July 25, 2025 11:46
…. Correct bug in sdptools.py::cptp_superop_variable that showed up when using bases whose first element was the identity (not the case in the leakage-friendly basis)
…eterizations on non-qubit spaces (for example, qutrit spaces) by changing the default error generator basis.
…n from ConfidenceRegionFactoryView.compute_confidence_interval(...) function, moving it to its own public instance method.
Comment on lines 1180 to +1187
"""
povm_mx = compute_povm_map(model, povmlbl)
target_povm_mx = compute_povm_map(target_model, povmlbl)
return diamonddist(povm_mx, target_povm_mx, target_model.basis)
try:
povm_mx = compute_povm_map(model, povmlbl)
target_povm_mx = compute_povm_map(target_model, povmlbl)
return diamonddist(povm_mx, target_povm_mx, target_model.basis)
except AssertionError as e:
assert '`dim` must be a perfect square' in str(e)
return _np.NaN
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should have been included in PR #615

Comment on lines -166 to -172
tr = _np.sum(evals)
if abs(tr - 1) > __VECTOR_TOL__:
message = f"""
The PSD part of the input matrix is not trace-1 up to tolerance {__VECTOR_TOL__}.
Beware result!
"""
_warnings.warn(message)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should have been included in PR #615

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are no subclasses of ModelMemberGraph, so the classmethod should be a staticmethod.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

readability

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Figuring this one out was a doozy. I'm certain that I could make a test which caused the existing code to break without doing anything leakage-specific.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants