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

Remove attribute power and default to Power/GateWithRegisters.__pow__ #903

Merged
merged 13 commits into from
May 6, 2024

Conversation

anurudhp
Copy link
Contributor

@anurudhp anurudhp commented Apr 28, 2024

  • Add _circuit_diagram_info_ for Controlled and Power to generate the same custom diagrams as before

@anurudhp
Copy link
Contributor Author

@tanujkhattar PTAL

Copy link
Collaborator

@tanujkhattar tanujkhattar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM % comments

qualtran/_infra/controlled.py Outdated Show resolved Hide resolved
@anurudhp anurudhp force-pushed the 2024-04-remove-custom-pow branch from bfb4d47 to 22f3674 Compare April 29, 2024 23:22
@anurudhp anurudhp force-pushed the 2024-04-remove-custom-pow branch from d6f8154 to 99482c4 Compare May 2, 2024 15:26
Comment on lines +466 to +479
def _circuit_diagram_info_(self, args: cirq.CircuitDiagramInfoArgs) -> cirq.CircuitDiagramInfo:
from qualtran.cirq_interop._bloq_to_cirq import _wire_symbol_to_cirq_diagram_info

if isinstance(self.subbloq, cirq.Gate):
sub_info = cirq.circuit_diagram_info(self.subbloq, args, None)
if sub_info is not None:
cv_info = cirq.circuit_diagram_info(self.ctrl_spec.to_cirq_cv())

return cirq.CircuitDiagramInfo(
wire_symbols=(*cv_info.wire_symbols, *sub_info.wire_symbols),
exponent=sub_info.exponent,
)

return _wire_symbol_to_cirq_diagram_info(self, args)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One change after the approval: I had to add a special case here because _wire_symbol_to_cirq_diagram_info doesn't recurse into the subgate. eg. XPowGate(0.25).controlled() was rendering X instead of X^0.25.

I added tests now to check that this works correctly

@anurudhp
Copy link
Contributor Author

anurudhp commented May 2, 2024

@tanujkhattar @mpharrigan PTAL

@anurudhp anurudhp requested a review from tanujkhattar May 6, 2024 15:30
@mpharrigan mpharrigan enabled auto-merge (squash) May 6, 2024 17:21
@mpharrigan mpharrigan merged commit 0262880 into quantumlib:main May 6, 2024
6 checks passed
@anurudhp anurudhp deleted the 2024-04-remove-custom-pow branch May 6, 2024 17:46
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.

3 participants