-
Notifications
You must be signed in to change notification settings - Fork 1k
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
Optimize Clifford.__pow__ by using binary exponentiation #6581
Optimize Clifford.__pow__ by using binary exponentiation #6581
Conversation
Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). View this failed invocation of the CLA check for more information. For the most up to date status, view the checks section at the bottom of the pull request. |
@NoureldinYosri as this is my 1st contribution, I had to add the CLA. I have added it now, however I don't think I can retrigger the GitHub action to run the 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.
please refer to docs/dev/development.md for creating a dev environmental. personally I create a virtual env and then pip install -r dev_tools/requirements/dev.env.txt
also prefer a simpler implementation
I do the same, the issue is that my Python env defaults to the latest ( Python 3.12 ), and I think cirq's dev environment is not compatible with Python 3.12 due to the PyLaTeX dependency ( it hasn't been updated in 7 months and it breaks in Python 3.12 ) I got around it by doing Thank you for the guidance @NoureldinYosri |
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.
for your convience, you can choose the python version when you create a venv (e.g. python3.11 -m ven "env_name"or
conda create -n en_name python=3.11`)
to pass the format CI you can run ./check/format-incremental --apply
@@ -129,7 +129,8 @@ def apply_global_phase(self, coefficient: linear_dict.Scalar): | |||
|
|||
class CliffordTableau(StabilizerState): | |||
"""Tableau representation of a stabilizer state | |||
(based on Aaronson and Gottesman 2006). |
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.
References:
- [Aaronson and Gottesman](https://arxiv.org/pdf/quant-ph/0406196)
cirq-core/cirq/ops/clifford_gate.py
Outdated
base_tableau = self.clifford_tableau.copy() | ||
if exponent < 0: | ||
base_tableau = base_tableau.inverse() | ||
exponent = int(abs(exponent)) |
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.
nit: no need to case again to int
since we already checked that exponent is int
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #6581 +/- ##
=======================================
Coverage 97.79% 97.79%
=======================================
Files 1124 1124
Lines 95699 95703 +4
=======================================
+ Hits 93589 93593 +4
Misses 2110 2110 ☔ View full report in Codecov by Sentry. |
cirq-core/cirq/ops/clifford_gate.py
Outdated
@@ -400,7 +400,10 @@ def _has_stabilizer_effect_(self) -> Optional[bool]: | |||
# By definition, Clifford Gate should always return True. | |||
return True | |||
|
|||
def __pow__(self, exponent) -> 'CliffordGate': | |||
def __pow__(self, exponent: int) -> 'CliffordGate': |
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.
to pass the type check CI make the type of exponent Union[int, float]
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 did not work, as mypy complained about the type Union[int, float]
. Instead using float
works: int
s are accepted as float
. I had to include a exponent = int(exponent)
, after the initial assertion, to make mypy
happy.
(based on Aaronson and Gottesman 2006). | ||
|
||
References: | ||
- [Aaronson and Gottesman](https://arxiv.org/pdf/quant-ph/0406196) |
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.
nit: instead of pdf
make it abs
Is there a way to run the entire CI/CD locally? |
@migueltorrescosta please refer to https://github.com/quantumlib/Cirq/blob/main/docs/dev/development.md#continuous-integration-and-local-testing for running locally, note that we currently support only py3.10 & py3.11 so work in a venv/conda env with one of them |
I have submitted the fixed mypy |
@migueltorrescosta from the changed files it doesn't look like your last commit was pushed |
Done. Sorry for the confusion 🤦 |
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.
@migueltorrescosta Thanks for your help with this issue
Implements binary exponentiation as described in #6327$\frac{5}{2}$ might be supported ( i.e. the square root is clear ), but other values might not. Knowing which non-integers to support needs to be discussed
This change does not include the feature of exponentiation for non-integer exponents. This still needs to be discussed, since