-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Pauli gate initialization is slower than other gates #6274
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
Comments
I'd like to take this up as my first investigative issue. Thanks! |
Hey @suyashdamle, I'd be interested in collaborating on this with you if possible, also new to contributing haha? |
I think this is due to validation during the construction of GateOperation. you can turn off validation to boost performance In [3]: %timeit cirq.I(q)
1.63 µs ± 33.3 ns per loop (mean ± std. dev. of 7 runs, 1,000,000 loops each)
In [4]: cirq.__cirq_debug__.set(False)
Out[4]: <Token var=<ContextVar name='__cirq_debug__' default=True at 0x7f723657d8a0> at 0x7f71e9e25a80>
In [5]: %timeit cirq.I(q)
629 ns ± 8.14 ns per loop (mean ± std. dev. of 7 runs, 1,000,000 loops each) a better way would be to do that using contexts e.g. In [8]: with cirq.with_debug(False):
...: %timeit cirq.I(q)
...:
630 ns ± 4.57 ns per loop (mean ± std. dev. of 7 runs, 1,000,000 loops each) |
Thanks for the extra context @NoureldinYosri @shef4 Thanks! I'm not sure yet about the scope of this issue.. will LYK after investigation if I need extra hands! Thanks! |
@zchen088 Constructing pauli's operations is slower because the After some investigation, it looks like the relative imports within the Test Codeq = cirq.q(0)
xhalf = cirq.X**0.5
with cirq.with_debug(False):
%timeit cirq.I(q)
%timeit cirq.X(q)
%timeit xhalf(q) Before my PR / on master
As you can see, the single qubit pauli operation here is ~4x slower than the other two. After my PR
In this case, the single qubit pauli operation now is only ~2x slower. This is as fast as it gets with the current type hierarchy. If this is still a bottleneck, maybe you can share your exact workflow and we can try to look for potential optimizations without making any major changes to the Cirq's type hierarchy, which would be a pretty big backwards incompatible change. xref #6097 |
Description of the issue
Pauli gate initialization is somewhat slower than other gates
How to reproduce the issue
Here's what I get on my machine:
Cirq version
1.3.0.dev20230802160330
The text was updated successfully, but these errors were encountered: