-
Notifications
You must be signed in to change notification settings - Fork 603
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
Add exponential fitting for ZNE #5972
Add exponential fitting for ZNE #5972
Conversation
Thanks for this PR @natestemen!
Feel free to tag us directly on the PR, or alternatively let us know if you want anyone to go through the PR. |
Guidance would be appreciated on resolving the CI error raised here. |
@josh146 ready for the first look! |
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.
Thanks @natestemen, it looks great! I suggest you use the math module from PennyLane then the function is compatible with all frameworks and add some tests for the different ML frameworks. Otherwise make sure to parametize the unit test for the fit.
test both increasing and decreasing exponentials
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.
It looks good to me! The failure seems unrelated. We need two approvals, I will tag someone from the core team.
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #5972 +/- ##
==========================================
- Coverage 99.66% 99.65% -0.01%
==========================================
Files 427 427
Lines 41059 40776 -283
==========================================
- Hits 40920 40636 -284
- Misses 139 140 +1 ☔ View full report in Codecov by Sentry. |
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.
Great addition 🤩 ! Just left some comments regarding typos/cosmetics.
Is there a reason why we are not checking differentiability for other backends besides pennylane/tests/transforms/test_mitigate.py Lines 646 to 647 in 169d53e
why didn't we add @pytest.mark.parametrize("extrapolate", [richardson_extrapolate, exponential_extrapolate]) like we did with JAX and JAX-JIT? |
Co-Authored-By: Cristian Emiliano Godinez Ramirez <[email protected]>
Thanks for the docstring suggestions! Addressed in e0815da.
The goal of this PR was to get an exponential fit function in that would be compatible with Happy to add your suggestion. Let me know. Footnotes
|
Good question @natestemen 🤔 Strictly speaking, the other interfaces are not needed for this functionality to work with Catalyst. However, since this will be part of the Pennylane features (even without Jitting our workflows), it should be compatible with the interfaces supported by Pennylane - this includes being able to differentiate it. The good thing is that since you are using @pytest.mark.parametrize("extrapolate", [richardson_extrapolate, exponential_extrapolate]) wherever only |
@natestemen The requirement for it to work with Catalyst is to be Jax-jittable. I have asked for other interfaces because in PL we always make things compatible for the different frameworks. |
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.
Looks good to me! 😄
**Context:** The last PR ([first](#806), [second](PennyLaneAI/pennylane#5972)) to add exponential extrapolation capabilities to catalyst. **Description of the Change:** This PR ensures that `pennylane.transforms.exponential_extrapolate` works inside catalyst's `mitigate_with_zne` function. **Benefits:** ZNE has increased functionality. **Possible Drawbacks:** As part of the testing, I've removed 0.1 and 0.2 from the list of values being used to create different circuits. This is because exponential extrapolation is not necessarily as stable as polynomial fitting. For example, when extrapolating near constant values exponential extrapolation can struggle due to the fact that a linear fit is first performed to understand the "direction" (or `sign`) of the exponential. If the slope is positive, the data is flipped to fit something that looks like $A\mathrm{e}^{-Bx} + C$ where $B\in\mathbb{R}_{> 0}$. An example of this happening can be seen here. ```py >>> exponential_extrapolate([1,2,3], [0.3894, 0.3894183, 0.38941]) -1.0000000000000059e-06 >>> richardson_extrapolate([1,2,3], [0.3894, 0.3894183, 0.38941]) 0.3893551000000072 ``` If we want to ensure to continue testing values 0.1 and 0.2 for polynomial extrapolation, we can create separate tests. Let me know what would be best. **Related GitHub Issues:** fixes #754
Context: As part of increasing the utility of ZNE within Catalyst, we'd like to add the option to use exponential fitting with ZNE. The issue
Description of the Change: A function which is written using JAX is added which performs an exponential fit of data, and evaluates said fit at 0.
Benefits: Increased capabilities for users to play with. This is especially important given the benefits of tuning ZNE to the problem and backend at hand.
Possible Drawbacks: The current implementation transforms data using the natural logarithm$\ln$ to linearize the data so that a linear fit can be applied to learn the necessary parameters (see section below on the exponential model). Once they transformed parameters are learned, they can be converted back into those from the exponential model quite simply. The major drawback of this approach is that they expectation values have to be shifted to be in the domain of $\ln$ (i.e. $> 0$ ), or thrown away if small enough (see $\varepsilon$
eps
parameter introduced inexpontial_extrapolate
).Related GitHub Issues: PennyLaneAI/catalyst#754
Exponential model: Assuming an exponential model with asymptote$y(x) = A\mathrm{e}^{Bx} + C$ we must first turn this into a linear equation to be able to apply a linear fit.
Once$\tilde{A}$ is learned, the hard part is over as the ZNE value is "simply" $y(0) = A + C$ .