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
Update code of local folding functions #649
Conversation
Codecov Report
@@ Coverage Diff @@
## master #649 +/- ##
==========================================
+ Coverage 97.30% 97.38% +0.07%
==========================================
Files 35 39 +4
Lines 1821 1986 +165
==========================================
+ Hits 1772 1934 +162
- Misses 49 52 +3
Continue to review full report at Codecov.
|
@rmlarose , this is now ready for review. Main change 1: re-written local folding functions with via folding masks. This also fixes #650. Minor note 1: I made Minor note 2: you don't need to review |
@@ -124,7 +116,7 @@ def _check_foldable(circuit: Circuit) -> None: | |||
) | |||
|
|||
|
|||
def squash_moments(circuit: Circuit) -> Circuit: | |||
def _squash_moments(circuit: Circuit) -> 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.
No change needed, but we really need to make submodule structure consistent. Here, squash_moments
is never imported in zne.scaling.__init__.py
, so it is private and the underscore is extraneous. In other places though (zne/inference.py
) the underscore is needed because the module structure is different.
mitiq/zne/scaling/folding.py
Outdated
# TODO: decide if removing next else case to get better approximations | ||
else: | ||
break |
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.
Any updates here @andreamari? What will it take to decide 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.
I removed the TODO (bc75b9f). It was just an idea to improve the scale factor approximation but I think it is better to keep the behavior of the function as simple and predictable as possible to avoid confusing the user.
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 very nice, thanks @andreamari. I'm happy to see 300 fewer lines of code here. See inline comments before merging.
Can be merged without remaining comments, but food for thought and perhaps future work:
- Should the masks be two-dimensional instead of one-dimensional to match circuit structure? It's easy enough to
np.reshape
between these, 2d seems a little more natural to me. - Should
_apply_fold_mask
be user-facing? (Involves above comment.) This is quite general and perhaps useful. - Should we recommend that custom folding methods be written using
_apply_fold_mask
? - I'm not the biggest fan of
folding_method
being a string in_create_fold_mask
, but I guess it's ok.
Co-authored-by: Ryan LaRose <rlarose@umich.edu>
About your general comments:
I see your point but I am not sure about it, I think we can discuss about a 2D mask in the future. My fear is that it could make
I think it is possible. However, before doing this, it would be good to clearly separate "standard" scaling functions (where scale_factor is an argument) from other anomalous functions like this one. Maybe using different files.
It can be a suggestion but not a requirement. Sometimes it is not appropriate e.g.
As long as it is private I think it is probably fine. If we need something more flexible in the future, we could use a list of indices instead of a string to identify a generic folding order. |
Description
Draft PR to:
Simplify the code of folding functions.
fixes Make folding at_random and from_right and from_left consistent with odd scale factors #650
Checklist
Check off the following once complete (or if not applicable) after opening the PR. The PR will be reviewed once this checklist is complete and all tests are passing.
If some items remain, you can mark this a draft pull request.
Tips
If the validation check fails:
Run
make check-style
(from the root directoryof the repository) and fix any flake8 errors.
Run
make format
to format your code with the blackautoformatter.
For more information, check the style guidelines for Mitiq.
Write "Fixes #XYZ" in the description if this PR fixes Issue #XYZ.