-
-
Notifications
You must be signed in to change notification settings - Fork 166
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
Noise Scaling for LRE #2347
Noise Scaling for LRE #2347
Conversation
c40d58d
to
63297af
Compare
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #2347 +/- ##
==========================================
+ Coverage 98.22% 98.34% +0.11%
==========================================
Files 87 89 +2
Lines 4056 4105 +49
==========================================
+ Hits 3984 4037 +53
+ Misses 72 68 -4 ☔ View full report in Codecov by Sentry. |
|
||
def _get_chunks( | ||
input_circuit: Circuit, num_chunks: Optional[int] = None | ||
) -> List[Circuit]: |
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.
Side note: Are we still supporting versions of Python that wouldn't allow -> list[Circuit]
vs. List[Circuit]
?
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 is a good question. Which versions of python did you have in mind? I know there's an open issue to drop 3.9 once we add support for 3.12.
The validate workflow only runs for python 3.11 which is used for type checking by mypy.
mitiq/.github/workflows/build.yml
Lines 25 to 32 in 837ea83
python-version: "3.11" | |
- name: Install Python dependencies | |
run: | | |
python -m pip install --upgrade pip | |
make install requirements | |
- name: Check types with mypy | |
run: make check-types |
From what I could find, 3.9 uses list[Circuit]
as a type alias and List[Circuit]
for type annotations. Same with 3.10.
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.
TIL that type aliases List
and Dict
are deprecated starting from Python 3.9 https://docs.python.org/3/library/typing.html#deprecated-aliases
I think it's better to limit this PR to Cirq circuits only because I need to spend some more time understanding how the Mitiq interface decorators work. I have used the default args for the decorators in the past without any issues. This PR requires using the optional arguments. Two different ways to implement the optional args led to errors. Either the @accept_qprogram_and_validate
def multivariate_layer_scaling( input_circuit, degree, ............, one_to_many = True) Similar to how the optional arg is used in PEC, I also tried changing noise_scaling_func = accept_qprogram_and_validate(
_cirq_multivariate_layer_scaling,
one_to_many=True,
)
scaled_circuits = noise_scaling_func(
input_circuit, degree, fold_multiplier, num_chunks, folding_method
)
return scaled_circuits |
Sounds good Purva, we can limit this PR for Cirq for now. |
Except for 1 unresolved comment #2347 (comment), this PR is ready for another review. |
|
||
def _get_chunks( | ||
input_circuit: Circuit, num_chunks: Optional[int] = None | ||
) -> List[Circuit]: |
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.
TIL that type aliases List
and Dict
are deprecated starting from Python 3.9 https://docs.python.org/3/library/typing.html#deprecated-aliases
terminal measurements | ||
""" | ||
|
||
_check_foldable(input_circuit) |
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 can raise an UnfoldableCircuitError, it should be documented in the docstring of this caller function as well.
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 had included it previously. #2347 (comment)
We should agree on style guidelines for this project and update the docs style guidelines section on docstrings.
Couple of things that confused me:
- Since I am relying on private functions, a user won't be able to read the source of the error in the API. Which is why I felt it's better to document the raised errors in the public function.
- Referring to Vincent's comment on raising errors from a function in a different module, the API-doc page only mentions
UnfoldableCircuitError
once as a defined exception. Since_check_foldable
is a private function, the error raised by the function does not show up publicly. - Most of the raised errors in the public-facing function are specified in a paragraph.
As we rely on google-style docstrings, there is no convention to allow lists in the description of the different sections of a docstring. Portions of our API-doc have run-on sentences because someone used a list in the section description which appear as badly formatted sentences publicly.
Intended | in API-doc |
---|---|
This PR is ready to be merged once all checks pass. As of 1:45 pm CST, not all checks are being run after I pushed the latest commit to this PR. Looks like Github is aware of the issues and they are working on fixing it. https://www.githubstatus.com/ |
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.
LGTM
To re-run all checks, you will have to push another commit (even an empty one). I re-run it manually here and everything looks fine.
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.
LGTM
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.
(Minor comments only--but aside from those, LGTM!)
Fixes #2307
Description
License
Before opening the PR, please ensure you have completed the following where appropriate.