Skip to content
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

Draft
wants to merge 14 commits into
base: main
Choose a base branch
from
Draft

Noise Scaling for LRE #2347

wants to merge 14 commits into from

Conversation

purva-thakre
Copy link
Contributor

Fixes #2307

Description


License

  • I license this contribution under the terms of the GNU GPL, version 3 and grant Unitary Fund the right to provide additional permissions as described in section 7 of the GNU GPL, version 3.

Before opening the PR, please ensure you have completed the following where appropriate.

Copy link

codecov bot commented May 4, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 98.34%. Comparing base (b58f029) to head (94b46d2).
Report is 24 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2347      +/-   ##
==========================================
+ Coverage   98.22%   98.34%   +0.11%     
==========================================
  Files          87       89       +2     
  Lines        4056     4099      +43     
==========================================
+ Hits         3984     4031      +47     
+ Misses         72       68       -4     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Comment on lines 158 to 166
ValueError:
When the degree for the multinomial is not >= to 1.
ValueError:
When the fold multiplier to scale the circuit is not >= to 1.
ValueError:
When the number of chunks for a large circuit is 0.
ValueError:
When the number of chunks in a circuit is greater than the number
of layers in the input circuit.
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All of these ValueError messages could be listed as a bullet list. Attempts to do so resulted in build errors.

@purva-thakre
Copy link
Contributor Author

@cosenal @vprusso This is ready for a review up to using layerwise folding on cirq circuits.

I am working on figuring out why layerwise folding on a pyquil circuit raises errors. Once this is fixed, laywerise folding for non-cirq circuits will be added.

mitiq/lre/multivariate_scaling/layerwise_folding.py Outdated Show resolved Hide resolved

Raises:
UnfoldableCircuitError:
* If the circuit has intermediate measurements.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does it make sense to put the Raises content here? My impression is that these comments should be local to the function in which they are originally being raised from (in this case, _check_foldable.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll search around for what the usual convention for this is.

Anyway, I need to figure out how to raise errors for a public function when private functions also raise other errors. #2347 (comment)


def _get_chunks(
input_circuit: Circuit, num_chunks: Optional[int] = None
) -> List[Circuit]:
Copy link
Contributor

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]?

Copy link
Contributor Author

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.

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.

mitiq/lre/multivariate_scaling/layerwise_folding.py Outdated Show resolved Hide resolved
mitiq/lre/multivariate_scaling/layerwise_folding.py Outdated Show resolved Hide resolved
mitiq/lre/multivariate_scaling/layerwise_folding.py Outdated Show resolved Hide resolved
mitiq/lre/multivariate_scaling/layerwise_folding.py Outdated Show resolved Hide resolved

"""
if degree < 1:
raise ValueError("Multinomial degree not >= to 1.")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would word these conditions in a way that makes parsing the error a bit easier for the user. For instance:

raise ValueError("Multinomial degree must be greater than 1.")

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We do want to allow degree = 1 as well.

mitiq/zne/scaling/layer_scaling.py Outdated Show resolved Hide resolved
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

LRE Functions: Noise Scaling
3 participants