Skip to content

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

Merged
mpharrigan merged 13 commits intoquantumlib:mainfrom
anurudhp:2024-04-remove-custom-pow
May 6, 2024
Merged

Remove attribute power and default to Power/GateWithRegisters.__pow__#903
mpharrigan merged 13 commits intoquantumlib:mainfrom
anurudhp:2024-04-remove-custom-pow

Conversation

@anurudhp
Copy link
Copy Markdown
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
Copy Markdown
Contributor Author

@tanujkhattar PTAL

Copy link
Copy Markdown
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

Comment thread qualtran/bloqs/mean_estimation/mean_estimation_operator_test.py Outdated
Comment thread qualtran/_infra/controlled.py Outdated
@anurudhp anurudhp force-pushed the 2024-04-remove-custom-pow branch from bfb4d47 to 22f3674 Compare April 29, 2024 23:22
Comment thread qualtran/bloqs/util_bloqs.py
@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
Copy Markdown
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
Copy Markdown
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
@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