Skip to content

Bugfix reparameterize #480

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 36 commits into from
May 29, 2025
Merged

Bugfix reparameterize #480

merged 36 commits into from
May 29, 2025

Conversation

juangmendoza19
Copy link

Addressing issue #425.

convert() function has been changed for POVM elements and state preparation. They now support proper conversion from full TP to GLND parameterization. The optimization is now done over non-gauge directions, which are found through Jacobians.

This function still needs to be changed to appropriately handle other reparameterizations.

Lastly, this is not guaranteed to work for POVMs, just because the number of degrees of freedom of a POVM can be greater than the number of error generators that span TP maps for a given number of qubits. By pigeon hole principle, we may not be able to find a description for a POVM consisting of Ideal_POVM + error generators. There is an assertion to try to catch this.

@juangmendoza19 juangmendoza19 requested review from rileyjmurray and a team as code owners August 23, 2024 18:12
@juangmendoza19 juangmendoza19 requested a review from sserita August 23, 2024 18:12
Copy link
Contributor

@sserita sserita left a comment

Choose a reason for hiding this comment

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

Just bookkeeping: Not ready for review, rerequest from me when ready.

TODO: 2 qubit labels returning None when label does exist in self.labels.
'(support, left_support) not in self._offsets[eetype]' returning True incorrectly


Copy link
Author

@juangmendoza19 juangmendoza19 Feb 20, 2025

Choose a reason for hiding this comment

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

The fancy code below (now commented out) to find the index of a label was not working for 2 qubits. Temporary easy solution implemented by just calling index(). This was creating problems during the creation of 2 qubit FOGI models

Copy link
Contributor

Choose a reason for hiding this comment

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

Pretty sure that I implemented a similar fix for this on PR #538. Making note of this in case there are merge conflicts that need to eventually get resolved here.

if ideal_effect is not None:
base_items.append((lbl, convert_effect(ideal_effect, 'static', basis, ideal_effect, flatten_structure)))
else:
base_items.append((lbl, convert_effect(vec, 'static', basis, idl.get(lbl, None), flatten_structure)))
Copy link
Author

Choose a reason for hiding this comment

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

This is code to properly collect the ideal POVM effects. Before, the ideal_effect passed in was being ignored

raise ValueError("Failed to find an errorgen such that <ideal|exp(errorgen) = <effect|")
errgen_vec = _np.linalg.pinv(phys_directions) @ soln.x
errorgen.from_vector(errgen_vec)

Copy link
Author

Choose a reason for hiding this comment

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

Code added to find errgen parameterization for POVMs based on optimization, just like state prep was being done before, but for some reason was never implemented on POVMs. Note that the optimization variations are done over a POVM space that lacks the dumb-gauge/metagauge. To find that space we wrote the function calc_physical_subspace which does a numerical calculation of the Jacobian with respect to POVM parameters.

phys_directions = calc_physical_subspace(dense_state)

#We use optimization to find the best error generator representation
#we only vary physical directions, not independent error generators
Copy link
Author

Choose a reason for hiding this comment

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

Just as explained in the POVM init file, we added a function to identify the dumb-gauge/metagauge and move orthogonally to it. This allows for better optimization.

@@ -340,7 +340,7 @@ def __getitem__(self, label):
raise KeyError("Key %s has an invalid prefix" % label)

def convert_members_inplace(self, to_type, categories_to_convert='all', labels_to_convert='all',
ideal_model=None, flatten_structure=False, set_default_gauge_group=False, cptp_truncation_tol= 1e-6):
ideal_model=None, flatten_structure=False, set_default_gauge_group=False, cptp_truncation_tol= 1e-7, spam_cptp_penalty = 1e-6):
Copy link
Author

Choose a reason for hiding this comment

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

added piping for the cptp penalty factor to be used in the optimization within the SPAM convert functions discussed above

Copy link
Contributor

@sserita sserita left a comment

Choose a reason for hiding this comment

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

One refactor requested, and a few minor fixes while you are at it.

Copy link
Contributor

@sserita sserita left a comment

Choose a reason for hiding this comment

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

Forgot to hit Enter on my refactor request...

@coreyostrove
Copy link
Contributor

@juangmendoza19 and @sserita : Do either of you recall what still needs to get sorted out on this PR? I see that there is at least one merge conflict (probably from merging in develop recently) and some unresolved discussion threads above.

@juangmendoza19
Copy link
Author

@juangmendoza19 and @sserita : Do either of you recall what still needs to get sorted out on this PR? I see that there is at least one merge conflict (probably from merging in develop recently) and some unresolved discussion threads above.

Stefan’s requests above have not been implemented yet.

Copy link
Contributor

@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.

Left a few comments. Happy to iterate quickly to see them resolved!

@rileyjmurray
Copy link
Contributor

@coreyostrove this looks good to me. Other than resolving any merge conflicts or failing tests, do you still have unaddressed comments?

I see that Stefan has unresolved comments. Rather than try to resolve those I suggest we dismiss Stefan's review (see screenshot below) and make a GitHub issue about following up on Stefan's unresolved points later.
image

@coreyostrove
Copy link
Contributor

@coreyostrove this looks good to me. Other than resolving any merge conflicts or failing tests, do you still have unaddressed comments?

I see that Stefan has unresolved comments. Rather than try to resolve those I suggest we dismiss Stefan's review (see screenshot below) and make a GitHub issue about following up on Stefan's unresolved points later. image

One more minor change related to an errant file on my end, but after that I'm satisfied with all of this. I'll approve once that last change is made and we have confirmation that tests are still passing.

@rileyjmurray
Copy link
Contributor

The failing tests seem related to the proposed changes:

FAILED test/unit/objects/test_model.py::TPModelTester::test_set_all_parameterizations_GLND - ValueError: Failed to convert members. If converting to CPTP-based models, try providing an ideal_model to avoid possible branch cuts.
FAILED test/unit/objects/test_model.py::FullModelTester::test_set_all_parameterizations_GLND - ValueError: Failed to convert members. If converting to CPTP-based models, try providing an ideal_model to avoid possible branch cuts.
FAILED test/unit/objects/test_model.py::StaticModelTester::test_set_all_parameterizations_GLND - ValueError: Failed to convert members. If converting to CPTP-based models, try providing an ideal_model to avoid possible branch cuts.
FAILED test/unit/objects/test_model.py::LindbladModelTester::test_set_all_parameterizations_GLND - ValueError: Failed to convert members. If converting to CPTP-based models, try providing an ideal_model to avoid possible branch cuts.
FAILED test/unit/drivers/test_longsequence.py::StdPracticeGSTTester::test_stdpractice_gst_CPTP - ValueError: Could not interpret 'CPTPLND' mode as a parameterization! Details:
Failed to convert members. If converting to CPTP-based models, try providing an ideal_model to avoid possible branch cuts.
FAILED test/unit/objects/test_errorgenpropagation.py::ErrorgenPropTester::test_explicit_model - ValueError: Failed to convert members. If converting to CPTP-based models, try providing an ideal_model to avoid possible branch cuts.
FAILED test/unit/drivers/test_longsequence.py::CPTPGatesTester::test_long_sequence_gst - ValueError: Failed to convert members. If converting to CPTP-based models, try providing an ideal_model to avoid possible branch cuts.
ERROR test/unit/objects/test_forwardsim.py::CPTPMatrixForwardSimTester::test_bulk_fill_dprobs - ValueError: Failed to convert members. If converting to CPTP-based models, try providing an ideal_model to avoid possible branch cuts.
ERROR test/unit/objects/test_forwardsim.py::CPTPMatrixForwardSimTester::test_bulk_fill_dprobs_with_block_size - ValueError: Failed to convert members. If converting to CPTP-based models, try providing an ideal_model to avoid possible branch cuts.
ERROR test/unit/objects/test_forwardsim.py::CPTPMatrixForwardSimTester::test_bulk_fill_hprobs - ValueError: Failed to convert members. If converting to CPTP-based models, try providing an ideal_model to avoid possible branch cuts.
ERROR test/unit/objects/test_forwardsim.py::CPTPMatrixForwardSimTester::test_bulk_fill_probs - ValueError: Failed to convert members. If converting to CPTP-based models, try providing an ideal_model to avoid possible branch cuts.
ERROR test/unit/objects/test_forwardsim.py::CPTPMatrixForwardSimTester::test_doperation - ValueError: Failed to convert members. If converting to CPTP-based models, try providing an ideal_model to avoid possible branch cuts.
ERROR test/unit/objects/test_forwardsim.py::CPTPMatrixForwardSimTester::test_hoperation - ValueError: Failed to convert members. If converting to CPTP-based models, try providing an ideal_model to avoid possible branch cuts.
ERROR test/unit/objects/test_forwardsim.py::CPTPMatrixForwardSimTester::test_iter_hprobs_by_rectangle - ValueError: Failed to convert members. If converting to CPTP-based models, try providing an ideal_model to avoid possible branch cuts.
= 7 failed, 1934 passed, 64 skipped, 8103 warnings, 7 errors in 1757.83s (0:29:17) =
Error: Process completed with exit code 1.

Fixes are hopefully straightforward. @juangmendoza19, can you investigate?

@rileyjmurray rileyjmurray dismissed sserita’s stale review May 27, 2025 20:45

Per the pyGSTi dev call today, we believe Juan has addressed all of Stefan's comments. All tests pass as of this moment, so I'm formally dismissing Stefan's review to remove the block from merging.

@rileyjmurray
Copy link
Contributor

@coreyostrove all tests pass. If you approve then we can merge.

Copy link
Contributor

@coreyostrove coreyostrove left a comment

Choose a reason for hiding this comment

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

Great work, @juangmendoza19! And thanks for bearing with the many changes requested during the review process.

@coreyostrove coreyostrove merged commit 3944ca5 into develop May 29, 2025
4 checks passed
@coreyostrove coreyostrove deleted the bugfix-reparameterize branch May 29, 2025 00:59
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.

4 participants