-
Notifications
You must be signed in to change notification settings - Fork 53
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?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -145,7 +145,7 @@ def decompose_zero_selection( | |
if self.num_controls == 0: | ||
yield self._load_nth_data(zero_indx, cirq.X, **target_regs) | ||
elif self.num_controls == 1: | ||
yield self._load_nth_data(zero_indx, lambda q: CNOT().on(controls[0], q), **target_regs) | ||
yield self._load_nth_data(zero_indx, lambda q: cirq.CNOT(controls[0], q), **target_regs) | ||
else: | ||
ctrl = np.array(controls)[:, np.newaxis] | ||
junk = np.array(context.qubit_manager.qalloc(len(controls) - 2))[:, np.newaxis] | ||
|
@@ -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 commentThe reason will be displayed to describe this comment to others. Learn more. use qualtran There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Using qualtran |
||
yield cirq.inverse(multi_controlled_and) | ||
context.qubit_manager.qfree(list(junk.flatten()) + [and_target]) | ||
|
||
|
@@ -178,7 +178,7 @@ def nth_operation( | |
) -> Iterator[cirq.OP_TREE]: | ||
selection_idx = tuple(kwargs[reg.name] for reg in self.selection_registers) | ||
target_regs = {reg.name: kwargs[reg.name] for reg in self.target_registers} | ||
yield self._load_nth_data(selection_idx, lambda q: CNOT().on(control, q), **target_regs) | ||
yield self._load_nth_data(selection_idx, lambda q: cirq.CNOT(control, q), **target_regs) | ||
|
||
def _circuit_diagram_info_(self, args) -> cirq.CircuitDiagramInfo: | ||
from qualtran.cirq_interop._bloq_to_cirq import _wire_symbol_to_cirq_diagram_info | ||
|
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 acached_method
and I didn't want to add another dependency. using justcache
would require computing hash of the class itself which would again be slow.