-
Notifications
You must be signed in to change notification settings - Fork 48
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
Performance improvements in cirq interop #1054
base: main
Are you sure you want to change the base?
Performance improvements in cirq interop #1054
Conversation
@@ -99,6 +100,10 @@ def total_bits(self) -> int: | |||
|
|||
This is the product of bitsize and each of the dimensions in `shape`. | |||
""" | |||
return self._total_bits | |||
|
|||
@cached_property |
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.
just use cached method on the original method?
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.
functools
doesn't seem to have a cached_method
and I didn't want to add another dependency. using just cache
would require computing hash of the class itself which would again be slow.
@@ -157,7 +157,7 @@ def decompose_zero_selection( | |||
ctrl=ctrl, junk=junk, target=and_target | |||
) | |||
yield multi_controlled_and | |||
yield self._load_nth_data(zero_indx, lambda q: CNOT().on(and_target, q), **target_regs) | |||
yield self._load_nth_data(zero_indx, lambda q: cirq.CNOT(and_target, q), **target_regs) |
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.
use qualtran CNOT
so that it can immediately unwrap from CirqGateAsBloq without doing any logic?
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.
Using qualtran CNOT
is slower because CNOT
in Qualtran is not a GateWithRegisters
. So the cirq construction wraps it in a BloqAsCirqGate
; which ends up being slow. See the first profiling picture in my linked comment.
Low hanging fruits towards #1052. Achieves a ~15% improvement.
Before:
After: