-
-
Notifications
You must be signed in to change notification settings - Fork 163
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
LRE Executors #2499
LRE Executors #2499
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #2499 +/- ##
=======================================
Coverage 98.71% 98.72%
=======================================
Files 89 90 +1
Lines 4131 4156 +25
=======================================
+ Hits 4078 4103 +25
Misses 53 53 ☔ View full report in Codecov by Sentry. |
e328b9d
to
52e0812
Compare
52e0812
to
3db2817
Compare
This test does not fail locally: https://github.com/unitaryfund/mitiq/actions/runs/10847148259/job/30101612145?pr=2499#step:6:4556 Will dig into this. |
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.
Nice work Purva! All your hard work makes this a nice and simple PR :)
Maybe we can do some debugging as to the num_chunks
issue in tomorrows coding session.
mitiq/lre/lre.py
Outdated
folding_method: Callable[ | ||
[Union[Any], float], Union[Any] | ||
] = fold_gates_at_random, |
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.
Let's follow what happens in ZNE here for consistency.
Line 70 in 6f912f6
scale_noise: Callable[[QPROGRAM, float], QPROGRAM] = fold_gates_at_random, # type: ignore [has-type] |
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 don't use the num_to_average
param in LRE.
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.
Sorry, I'm missing how num_to_average
is related here. I'm just suggesting we typehint the folding method differently.
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.
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.
Have you modified code above these lines? If so then it will probably change the location of the suggestion.
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 hadn't modified anything in ZNE which is why it's weird that when you linked L70 in zne.py
, L71 also showed up.
The location of the suggestion was not changed.
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 left two comments, not blockers.
"""Verify LRE decorators work as expected.""" | ||
|
||
@lre_decorator(degree=2, fold_multiplier=2) | ||
def execute(circuit, noise_level=0.025): |
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.
Something more in the spirit of unit tests (and more future-proof) would be a test that only checks whether the correct functions are called, and doesn't actually run the circuit through the simulator. Here you are testing lots of things at the same time (including a Google's simulator), all of which could go wrong without giving much insights on the unit you are testing here, which is the behaviour of the new decorator.
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.
@cosenal @natestemen Are either of you available for a quick call on Friday (excluding the community call)? I have been unsuccessful in trying to write a unit test that utilizes mock objects.
It's unclear to me what needs to be a mock object and what must have a pre-defined value.
mitiq/lre/tests/test_lre.py
Outdated
ideal_val = execute(test_cirq * 200, noise_level=0) | ||
assert abs(ideal_val - noisy_val) > 0 | ||
lre_exp_val = execute_with_lre( | ||
test_cirq * 200, execute, degree=2, fold_multiplier=2, num_chunks=5 |
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 misled you by not creating a variable for test_cirq * 200
in y'day live coding*, but we do want one in the pull request.
*As @natestemen was bugging me about while I tried to hack things around as quick as possible 😅
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 am going to use the mock testing module for this. As Nate noticed yesterday, test_cirq * 200
will increase the time taken by unit tests.
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.
Discussed with Nate and Alessandro to skip this unit for when we get to #2512 in the future.
The code block that misbehaves when we have really large circuits is in one of the inference functions.
mitiq/mitiq/lre/inference/multivariate_richardson.py
Lines 165 to 182 in 6f912f6
except RuntimeWarning: # pragma: no cover | |
# taken from https://stackoverflow.com/a/19317237 | |
warnings.warn( # pragma: no cover | |
"To account for overflow error, required determinant of " | |
+ "large sample matrix is calculated through " | |
+ "`np.linalg.slogdet`." | |
) | |
sign, logdet = np.linalg.slogdet( # pragma: no cover | |
input_sample_matrix | |
) | |
det = sign * np.exp(logdet) # pragma: no cover | |
if np.isinf(det): | |
raise ValueError( # pragma: no cover | |
"Determinant of sample matrix cannot be calculated as " | |
+ "the matrix is too large. Consider chunking your" | |
+ " input circuit. " | |
) |
ae2f4fe
to
3d25cd2
Compare
I don't know why some of the tests are failing right now. Will rerun them in a couple of hours. |
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.
A few minor changes requested, but looking good once those are addressed.
How long does it take to run the tests in test_lre.py
?
I used Chunking test where it is not expected to fail takes the longest. |
Description
Fixes #2370
List of todos:
License
Before opening the PR, please ensure you have completed the following where appropriate.