Skip to content

Commit c696323

Browse files
Rename cirq_ft.Registers to cirq_ft.Signature to match data types in Qualtran (#6300)
* Rename cirq_ft.Registers to cirq_ft.Signature to match data types in Qualtran * Fix coverage tests --------- Co-authored-by: Fionn Malone <[email protected]>
1 parent 61d9671 commit c696323

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+269
-227
lines changed

cirq-ft/cirq_ft/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747
GateWithRegisters,
4848
GreedyQubitManager,
4949
Register,
50-
Registers,
50+
Signature,
5151
SelectionRegister,
5252
TComplexity,
5353
map_clean_and_borrowable_qubits,

cirq-ft/cirq_ft/algos/and_gate.ipynb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@
6666
"from cirq_ft import And, infra\n",
6767
"\n",
6868
"gate = And()\n",
69-
"r = gate.registers\n",
69+
"r = gate.signature\n",
7070
"quregs = infra.get_named_qubits(r)\n",
7171
"operation = gate.on_registers(**quregs)\n",
7272
"circuit = cirq.Circuit(operation)\n",

cirq-ft/cirq_ft/algos/and_gate.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,8 @@ def _validate_cv(self, attribute, value):
6060
raise ValueError(f"And gate needs at-least 2 control values, supplied {value} instead.")
6161

6262
@cached_property
63-
def registers(self) -> infra.Registers:
64-
return infra.Registers.build(control=len(self.cv), ancilla=len(self.cv) - 2, target=1)
63+
def signature(self) -> infra.Signature:
64+
return infra.Signature.build(control=len(self.cv), ancilla=len(self.cv) - 2, target=1)
6565

6666
def __pow__(self, power: int) -> "And":
6767
if power == 1:

cirq-ft/cirq_ft/algos/and_gate_test.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,17 +45,17 @@ def random_cv(n: int) -> List[int]:
4545
@pytest.mark.parametrize("cv", [[1] * 3, random_cv(5), random_cv(6), random_cv(7)])
4646
def test_multi_controlled_and_gate(cv: List[int]):
4747
gate = cirq_ft.And(cv)
48-
r = gate.registers
49-
assert r['ancilla'].total_bits() == r['control'].total_bits() - 2
48+
r = gate.signature
49+
assert r.get_left('ancilla').total_bits() == r.get_left('control').total_bits() - 2
5050
quregs = infra.get_named_qubits(r)
5151
and_op = gate.on_registers(**quregs)
5252
circuit = cirq.Circuit(and_op)
5353

5454
input_controls = [cv] + [random_cv(len(cv)) for _ in range(10)]
55-
qubit_order = infra.merge_qubits(gate.registers, **quregs)
55+
qubit_order = infra.merge_qubits(gate.signature, **quregs)
5656

5757
for input_control in input_controls:
58-
initial_state = input_control + [0] * (r['ancilla'].total_bits() + 1)
58+
initial_state = input_control + [0] * (r.get_left('ancilla').total_bits() + 1)
5959
result = cirq.Simulator(dtype=np.complex128).simulate(
6060
circuit, initial_state=initial_state, qubit_order=qubit_order
6161
)
@@ -78,7 +78,7 @@ def test_multi_controlled_and_gate(cv: List[int]):
7878

7979
def test_and_gate_diagram():
8080
gate = cirq_ft.And((1, 0, 1, 0, 1, 0))
81-
qubit_regs = infra.get_named_qubits(gate.registers)
81+
qubit_regs = infra.get_named_qubits(gate.signature)
8282
op = gate.on_registers(**qubit_regs)
8383
# Qubit order should be alternating (control, ancilla) pairs.
8484
c_and_a = sum(zip(qubit_regs["control"][1:], qubit_regs["ancilla"]), ()) + (

cirq-ft/cirq_ft/algos/apply_gate_to_lth_target.ipynb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,9 +69,9 @@
6969
"`selection`-th qubit of `target` all controlled by the `control` register.\n",
7070
"\n",
7171
"#### Parameters\n",
72-
" - `selection_regs`: Indexing `select` registers of type Tuple[`SelectionRegister`, ...]. It also contains information about the iteration length of each selection register.\n",
72+
" - `selection_regs`: Indexing `select` signature of type Tuple[`SelectionRegister`, ...]. It also contains information about the iteration length of each selection register.\n",
7373
" - `nth_gate`: A function mapping the composite selection index to a single-qubit gate.\n",
74-
" - `control_regs`: Control registers for constructing a controlled version of the gate.\n"
74+
" - `control_regs`: Control signature for constructing a controlled version of the gate.\n"
7575
]
7676
},
7777
{
@@ -91,7 +91,7 @@
9191
"apply_z_to_odd = cirq_ft.ApplyGateToLthQubit(\n",
9292
" cirq_ft.SelectionRegister('selection', 3, 4),\n",
9393
" nth_gate=_z_to_odd,\n",
94-
" control_regs=cirq_ft.Registers.build(control=2),\n",
94+
" control_regs=cirq_ft.Signature.build(control=2),\n",
9595
")\n",
9696
"\n",
9797
"g = cq_testing.GateHelper(\n",

cirq-ft/cirq_ft/algos/apply_gate_to_lth_target.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,10 @@ class ApplyGateToLthQubit(unary_iteration_gate.UnaryIterationGate):
3737
`selection`-th qubit of `target` all controlled by the `control` register.
3838
3939
Args:
40-
selection_regs: Indexing `select` registers of type Tuple[`SelectionRegisters`, ...].
40+
selection_regs: Indexing `select` signature of type Tuple[`SelectionRegisters`, ...].
4141
It also contains information about the iteration length of each selection register.
4242
nth_gate: A function mapping the composite selection index to a single-qubit gate.
43-
control_regs: Control registers for constructing a controlled version of the gate.
43+
control_regs: Control signature for constructing a controlled version of the gate.
4444
4545
References:
4646
[Encoding Electronic Spectra in Quantum Circuits with Linear T Complexity]

cirq-ft/cirq_ft/algos/apply_gate_to_lth_target_test.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,10 @@ def test_apply_gate_to_lth_qubit_diagram():
5454
gate = cirq_ft.ApplyGateToLthQubit(
5555
cirq_ft.SelectionRegister('selection', 3, 5),
5656
lambda n: cirq.Z if n & 1 else cirq.I,
57-
control_regs=cirq_ft.Registers.build(control=2),
57+
control_regs=cirq_ft.Signature.build(control=2),
5858
)
59-
circuit = cirq.Circuit(gate.on_registers(**infra.get_named_qubits(gate.registers)))
60-
qubits = list(q for v in infra.get_named_qubits(gate.registers).values() for q in v)
59+
circuit = cirq.Circuit(gate.on_registers(**infra.get_named_qubits(gate.signature)))
60+
qubits = list(q for v in infra.get_named_qubits(gate.signature).values() for q in v)
6161
cirq.testing.assert_has_diagram(
6262
circuit,
6363
"""
@@ -89,11 +89,11 @@ def test_apply_gate_to_lth_qubit_make_on():
8989
gate = cirq_ft.ApplyGateToLthQubit(
9090
cirq_ft.SelectionRegister('selection', 3, 5),
9191
lambda n: cirq.Z if n & 1 else cirq.I,
92-
control_regs=cirq_ft.Registers.build(control=2),
92+
control_regs=cirq_ft.Signature.build(control=2),
9393
)
94-
op = gate.on_registers(**infra.get_named_qubits(gate.registers))
94+
op = gate.on_registers(**infra.get_named_qubits(gate.signature))
9595
op2 = cirq_ft.ApplyGateToLthQubit.make_on(
96-
nth_gate=lambda n: cirq.Z if n & 1 else cirq.I, **infra.get_named_qubits(gate.registers)
96+
nth_gate=lambda n: cirq.Z if n & 1 else cirq.I, **infra.get_named_qubits(gate.signature)
9797
)
9898
# Note: ApplyGateToLthQubit doesn't support value equality.
9999
assert op.qubits == op2.qubits

cirq-ft/cirq_ft/algos/arithmetic_gates.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ class BiQubitsMixer(infra.GateWithRegisters):
137137
"""Implements the COMPARE2 (Fig. 1) https://static-content.springer.com/esm/art%3A10.1038%2Fs41534-018-0071-5/MediaObjects/41534_2018_71_MOESM1_ESM.pdf
138138
139139
This gates mixes the values in a way that preserves the result of comparison.
140-
The registers being compared are 2-qubit registers where
140+
The signature being compared are 2-qubit signature where
141141
x = 2*x_msb + x_lsb
142142
y = 2*y_msb + y_lsb
143143
The Gate mixes the 4 qubits so that sign(x - y) = sign(x_lsb' - y_lsb') where x_lsb' and y_lsb'
@@ -147,8 +147,8 @@ class BiQubitsMixer(infra.GateWithRegisters):
147147
adjoint: bool = False
148148

149149
@cached_property
150-
def registers(self) -> infra.Registers:
151-
return infra.Registers.build(x=2, y=2, ancilla=3)
150+
def signature(self) -> infra.Signature:
151+
return infra.Signature.build(x=2, y=2, ancilla=3)
152152

153153
def __repr__(self) -> str:
154154
return f'cirq_ft.algos.BiQubitsMixer({self.adjoint})'
@@ -221,8 +221,8 @@ class SingleQubitCompare(infra.GateWithRegisters):
221221
adjoint: bool = False
222222

223223
@cached_property
224-
def registers(self) -> infra.Registers:
225-
return infra.Registers.build(a=1, b=1, less_than=1, greater_than=1)
224+
def signature(self) -> infra.Signature:
225+
return infra.Signature.build(a=1, b=1, less_than=1, greater_than=1)
226226

227227
def __repr__(self) -> str:
228228
return f'cirq_ft.algos.SingleQubitCompare({self.adjoint})'
@@ -437,7 +437,7 @@ def _has_unitary_(self):
437437
class ContiguousRegisterGate(cirq.ArithmeticGate):
438438
"""Applies U|x>|y>|0> -> |x>|y>|x(x-1)/2 + y>
439439
440-
This is useful in the case when $|x>$ and $|y>$ represent two selection registers such that
440+
This is useful in the case when $|x>$ and $|y>$ represent two selection signature such that
441441
$y < x$. For example, imagine a classical for-loop over two variables $x$ and $y$:
442442
443443
>>> N = 10
@@ -460,8 +460,8 @@ class ContiguousRegisterGate(cirq.ArithmeticGate):
460460
Note that both the for-loops iterate over the same ranges and in the same order. The only
461461
difference is that the second loop is a "flattened" version of the first one.
462462
463-
Such a flattening of selection registers is useful when we want to load multi dimensional
464-
data to a target register which is indexed on selection registers $x$ and $y$ such that
463+
Such a flattening of selection signature is useful when we want to load multi dimensional
464+
data to a target register which is indexed on selection signature $x$ and $y$ such that
465465
$0<= y <= x < N$ and we want to use a `SelectSwapQROM` to laod this data; which gives a
466466
sqrt-speedup over a traditional QROM at the cost of using more memory and loading chunks
467467
of size `sqrt(N)` in a single iteration. See the reference for more details.

cirq-ft/cirq_ft/algos/generic_select_test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,7 @@ def test_generic_select_consistent_protocols_and_controlled():
256256

257257
# Build GenericSelect gate.
258258
gate = cirq_ft.GenericSelect(select_bitsize, num_sites, dps_hamiltonian)
259-
op = gate.on_registers(**infra.get_named_qubits(gate.registers))
259+
op = gate.on_registers(**infra.get_named_qubits(gate.signature))
260260
cirq.testing.assert_equivalent_repr(gate, setup_code='import cirq\nimport cirq_ft')
261261

262262
# Build controlled gate

cirq-ft/cirq_ft/algos/hubbard_model.ipynb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@
171171
" logN = (2 * (dim - 1).bit_length() + 1)\n",
172172
" # 2 * (4 * (N - 1)) : From 2 SelectMajoranaFermion gates.\n",
173173
" # 4 * (N/2) : From 1 mulit-controlled ApplyToLthQubit gate on N / 2 targets.\n",
174-
" # 2 * 7 * logN : From 2 CSWAPS on logN qubits corresponding to (p, q) select registers.\n",
174+
" # 2 * 7 * logN : From 2 CSWAPS on logN qubits corresponding to (p, q) select signature.\n",
175175
" assert cost.t == 10 * N + 14 * logN - 8\n",
176176
" assert cost.rotations == 0\n",
177177
" x.append(N)\n",

0 commit comments

Comments
 (0)