Skip to content

Comments

CSWAP and CMultiSWAP#176

Closed
ncrubin wants to merge 4 commits intoquantumlib:mainfrom
ncrubin:control_swap_registers
Closed

CSWAP and CMultiSWAP#176
ncrubin wants to merge 4 commits intoquantumlib:mainfrom
ncrubin:control_swap_registers

Conversation

@ncrubin
Copy link
Collaborator

@ncrubin ncrubin commented Apr 1, 2023

Controlled Swap between two registers of bit length of size one and controlled swap between two registers of bit lenght size n, n>1.

Controlled Swap between two registers of bit length of size
one and controlled swap between two registers of bit lenght
size n, n>1.
@ncrubin ncrubin requested a review from mpharrigan April 1, 2023 00:05
@tanujkhattar
Copy link
Collaborator

@ncrubin FYI, Multi Target CSWAP already exists as a cirq gate, but I understand if we want to have it as a bloq as well given the importance.

See https://github.com/quantumlib/cirq-qubitization/blob/main/cirq_qubitization/cirq_algos/swap_network.py

def pretty_name(self) -> str:
return "CSWAP"

def build_composite_bloq(
Copy link
Collaborator

Choose a reason for hiding this comment

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

have you tried actually decomposing the bloq? That's when it will check the code to see if it results in a well-formed composite bloq.

bloq = CMultiSWAP(...)
cbloq = bloq.decompose_bloq()

from cirq_qubitization.jupyter_tools import show_bloq
show_bloq(cbloq)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I haven't yet..but I will tomorrow!

return "CSWAP"

def build_composite_bloq(
self, bb: 'CompositeBloqBuilder', *, cntrl_and_targets: NDArray[Soquet]
Copy link
Collaborator

Choose a reason for hiding this comment

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

The arguments should match the registers, so you should have three arguments (following the bb and *) named ctrl, reg_x, and reg_y

Comment on lines +72 to +74
FancyRegister('ctrl', 1, wireshape=(1,)),
FancyRegister('reg_x', self.reg_length, wireshape=(1,)),
FancyRegister('reg_y', self.reg_length, wireshape=(1,)),
Copy link
Collaborator

Choose a reason for hiding this comment

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

wireshape=(1,) is equivalent to "list of length 1", which can have a use (usually when writing generic code that works for a list of any size) but is probably inappropriate here. wireshape=tuple() (which is the default argument, so you can just not put it) is analogous to "the item itself -- not in a list".

Comment on lines +95 to +96
returned_x.append(out_reg_x)
returned_y.append(out_reg_y)
Copy link
Collaborator

Choose a reason for hiding this comment

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

this style is good for making it clear that the output quantum variables are distinct from the input ones. You can be more concise by just overwriting the original array values

ctrl, reg_x[n_idx], reg_y[n_idx] = bb.add(...)

@ncrubin
Copy link
Collaborator Author

ncrubin commented Apr 4, 2023

@ncrubin FYI, Multi Target CSWAP already exists as a cirq gate, but I understand if we want to have it as a bloq as well given the importance.

See https://github.com/quantumlib/cirq-qubitization/blob/main/cirq_qubitization/cirq_algos/swap_network.py

yup just wanted a simple example to play around with making bloqs.

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