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

Implement generic MultiControlledBloq using single-controlled subbloq + And ladder. #1155

Merged
merged 14 commits into from
Jul 24, 2024

Conversation

anurudhp
Copy link
Contributor

@anurudhp anurudhp commented Jul 18, 2024

#1131

  • Add ControlledViaAnd that computes a single qubit control using CtrlSpecAnd, and uses a single-controlled subbloq.
  • Refactor MultiControlPauli to delegate to this. For the moment I did not remove it fully as it breaks too many things that switch between cirq-style and qualtran-style defs. This should be cleaned up in a follow-up PR.



@frozen
class MultiControlledBloq(Bloq):
Copy link
Collaborator

Choose a reason for hiding this comment

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

I see @mpharrigan's point that having both Controlled(sub_bloq, ctrl_spec) and MultiControlledBloq(sub_bloq, ctrl_spec) can be confusing and the implementation of both would actually be identical.

Regarding interface vs implementation, it may make things cleaner if we rename MultiControlledBloq to be more descriptive of the implementation, like ControlledViaAndLadder() and explain that the implementation performs CtrlSpecAnd -> Bloq.controlled() -> CtrlSpecAnd.adjoint() to decompose a bloq controlled by arbitrary CtrlSpec to a singly controlled Bloq via an And / And^{dagger} ladder and uses $num_controls$ ancilla qubits.

Then, this specific implementation can be used by users who want to depend upon this behavior instead of the behavior getting potentially updated if we decide to update the decomposition of Controlled Bloq later.

MultiControlledPauli can get removed and we will simply update the call sites to use ControlledViaAndLadder(ctrl_spec, XGate())

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I like the bloq name ControlledViaAndLadder, will use that

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.

Looking good. Left a final round of comments

target = soqs.pop('target')
(target_reg_name,) = [reg.name for reg in self.target_bloq.signature]
if self.n_ctrls == 0:
# TODO discuss if we should remove support for this case.
Copy link
Collaborator

Choose a reason for hiding this comment

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

This was specifically added after #677

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

@tanujkhattar tanujkhattar merged commit b550212 into quantumlib:main Jul 24, 2024
8 checks passed
@anurudhp anurudhp deleted the 2024/07/17-multi-control-U branch July 24, 2024 00:21
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