-
Notifications
You must be signed in to change notification settings - Fork 58
New Feature: GST iteration-specific optimizers #690
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
base: develop
Are you sure you want to change the base?
Changes from 15 commits
f559b35
ff14dd5
1107ee3
eaa1e7f
5bd509f
c50127c
67045dc
1706895
2a9f5ed
b3b59f7
d0504ee
b5dbcde
d7c5257
f9cc02f
6389e3a
d62e886
d6d0500
4e3fa03
88440f0
b1d269b
85fc08a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -13,6 +13,7 @@ | |
| from pygsti.tools import two_delta_logl | ||
| from ..util import BaseCase | ||
| import pytest | ||
| import numpy as _np | ||
|
|
||
|
|
||
| class GSTUtilTester(BaseCase): | ||
|
|
@@ -232,7 +233,7 @@ def _bulk_fill_probs_atom(self, array_to_fill, layout_atom, resource_alloc): | |
| super(MapForwardSimulatorWrapper, self)._bulk_fill_probs_atom(array_to_fill, layout_atom, resource_alloc) | ||
|
|
||
|
|
||
| class TestGateSetTomography(BaseProtocolData): | ||
| class GateSetTomographyTester(BaseProtocolData): | ||
| """ | ||
| Tests for methods in the GateSetTomography class. | ||
|
|
||
|
|
@@ -248,6 +249,27 @@ def test_run(self): | |
| twoDLogL = two_delta_logl(mdl_result, self.gst_data.dataset) | ||
| assert twoDLogL <= 1.0 # should be near 0 for perfect data | ||
|
|
||
| def test_optimizer_list_run(self): | ||
| self.setUpClass() | ||
|
|
||
| optimizer = {'tol':1e-5} | ||
|
|
||
| proto1 = gst.GateSetTomography(smq1Q_XYI.target_model("CPTPLND"), 'stdgaugeopt', name="testGST", optimizer=optimizer) | ||
| results1 = proto1.run(self.gst_data) | ||
| results2 = proto1.run(self.gst_data, optimizers=optimizer) | ||
|
|
||
| mdl_result1 = results1.estimates["testGST"].models['stdgaugeopt'] | ||
| mdl_result2 = results2.estimates["testGST"].models['stdgaugeopt'] | ||
|
|
||
| assert _np.allclose(mdl_result1.to_vector() , mdl_result2.to_vector()) | ||
|
|
||
| #Test that we can pass a list | ||
| optimizers = [optimizer]*len(self.gst_data.edesign.circuit_lists) | ||
| results3 = proto1.run(self.gst_data, optimizers=optimizers) | ||
| mdl_result3 = results3.estimates["testGST"].models['stdgaugeopt'] | ||
| assert _np.allclose(mdl_result3.to_vector() , mdl_result1.to_vector()) | ||
|
|
||
|
|
||
| def test_run_custom_sim(self, capfd: pytest.LogCaptureFixture): | ||
| self.setUpClass() | ||
| proto = gst.GateSetTomography(smq1Q_XYI.target_model("CPTPLND"), 'stdgaugeopt', name="testGST") | ||
|
|
@@ -317,7 +339,7 @@ def test_write_and_read_to_dir(self): | |
| assert proto_read.name == proto.name | ||
| assert proto_read.badfit_options.actions == proto.badfit_options.actions | ||
|
|
||
| class TestStandardGST(BaseProtocolData): | ||
| class StandardGSTTester(BaseProtocolData): | ||
| """ | ||
| Tests for methods in the StandardGST class. | ||
|
|
||
|
|
@@ -357,6 +379,26 @@ def _test_run_custom_sim(self, mode, parent_capfd, check_output): | |
| for model in estimate.models.values(): | ||
| assert isinstance(model, MapForwardSimulatorWrapper) | ||
juangmendoza19 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| pass | ||
|
|
||
| def test_optimizer_list_run(self): | ||
| self.setUpClass() | ||
|
|
||
| optimizer = {'tol':1e-5} | ||
|
|
||
| proto1 = gst.StandardGST(modes=["full TP","CPTPLND","Target"]) | ||
| results1 = proto1.run(self.gst_data) | ||
| results2 = proto1.run(self.gst_data, optimizers=optimizer) | ||
| #Test that we can pass a list | ||
| optimizers = [optimizer]*len(self.gst_data.edesign.circuit_lists) | ||
| results3 = proto1.run(self.gst_data, optimizers=optimizers) | ||
| for mode in ["full TP","CPTPLND","Target"]: | ||
| mdl_result1 = results1.estimates[mode].models['stdgaugeopt'] | ||
| mdl_result2 = results2.estimates[mode].models['stdgaugeopt'] | ||
| mdl_result3 = results3.estimates[mode].models['stdgaugeopt'] | ||
|
|
||
| assert _np.allclose(mdl_result1.to_vector() , mdl_result2.to_vector()) | ||
| assert _np.allclose(mdl_result3.to_vector() , mdl_result1.to_vector()) | ||
|
|
||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Did you also want to test if we can have different optimizer settings for each iteration of the
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I can add a test to check if it runs, but I don't see an easy way to test its valid. At that point it might not have any more value than the results3 = proto1.run(self.gst_data, optimizers=optimizers) test. |
||
|
|
||
| def test_write_and_read_to_dir(self): | ||
| #integration test to at least confirm we are writing and reading | ||
|
|
||
juangmendoza19 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| { | ||
| "module": "pygsti.protocols.gst", | ||
| "class": "GSTBadFitOptions", | ||
| "version": 0, | ||
| "threshold": 2.0, | ||
| "actions": [], | ||
| "wildcard": { | ||
| "budget_includes_spam": true, | ||
| "L1_weights": null, | ||
| "primitive_op_labels": null, | ||
| "initial_budget": null, | ||
| "methods": [ | ||
| "neldermead" | ||
| ], | ||
| "indadmissable_action": "print" | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| { | ||
| "module": "pygsti.protocols.gst", | ||
| "class": "GSTGaugeOptSuite", | ||
| "version": 0, | ||
| "gaugeopt_suite_names": [ | ||
| "stdgaugeopt" | ||
| ], | ||
| "gaugeopt_argument_dicts": {}, | ||
| "gaugeopt_target": null | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This logic is repeated from the
algorithms/core.iterative_gst_generatorfunction. I think we should refactor to call the same utility helper function in both cases. That way if we update the allowed types to pass in we will only need to update the logic in one location.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll take this as an opportunity to soap box against DRY in this particular instance, and instead advocate for LoB (https://htmx.org/essays/locality-of-behaviour/).