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

Performance improvements in cirq interop #1054

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

tanujkhattar
Copy link
Collaborator

@tanujkhattar tanujkhattar commented Jun 5, 2024

Low hanging fruits towards #1052. Achieves a ~15% improvement.

Before:

image

After:

image

@@ -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
Copy link
Collaborator

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?

Copy link
Collaborator Author

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)
Copy link
Collaborator

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?

Copy link
Collaborator Author

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.

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.

2 participants