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
Make Cirq-FT registers multi-dimensional #6200
Make Cirq-FT registers multi-dimensional #6200
Conversation
Check out this pull request on See visual diffs & provide feedback on Jupyter Notebooks. Powered by ReviewNB |
|
cirq-ft/cirq_ft/algos/and_gate.py
Outdated
) -> cirq.OP_TREE: | ||
control, ancilla, target = quregs['control'], quregs['ancilla'], quregs['target'] | ||
if len(self.cv) == 2: | ||
yield self._decompose_single_and( | ||
self.cv[0], self.cv[1], control[0], control[1], *target | ||
) | ||
else: | ||
yield self._decompose_via_tree(control, self.cv, ancilla, *target) | ||
yield self._decompose_via_tree(control.tolist(), self.cv, ancilla.tolist(), *target) |
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.
why do we need tolist()
? Do we need to update the type signatures for _decompose_via_tree
if we're using list-specific things
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.
We need this mainly because Sequence[cirq.Qid]
is not compatible with NDArray[cirq.Qid]
.
I'll update the signature of _decompose_via_tree
to accept NDArray[cirq.Qid]
instead.
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.
that's kindof annoying
|
||
@classmethod | ||
def build(cls, **registers: int) -> 'Registers': | ||
return cls(Register(name=k, bitsize=v) for k, v in registers.items()) | ||
def build(cls, **registers: Union[int, Tuple[int, ...]]) -> 'Registers': |
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.
this is going to be really screwwy when combined with SelectionRegisters.build
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.
Hmm, I'll change SelectionRegisters.build
to follow the Register.build
interface and use 2 ** self.shape[0]
as the default iteration length. All call sites using non-default iteration length will be updated to use the full constructor
…i_dimensional_registers
…i_dimensional_registers
…i_dimensional_registers
@mpharrigan I've addressed all your comments and updated the PR. |
…i_dimensional_registers
This brings the Cirq-FT registers one step closer to Qualtran registers.
Some notable changes in this PR:
Register.bitsize
is nowRegister.shape
and a tuple instead of integertotal_bits
toRegister
class.Registers.bitsize
is nowRegisters.total_bits()
SelectionRegisters.build
interface is changed to matchRegisters.build
and all call sites are updated to use explicit constructor ifiteration_length
is non trivial (i.e. not2 ** self.shape[0]
)SwapWithZero
class where the target register is now 2D.cc @mpharrigan
Fixes #6053