Skip to content

Commit dac312f

Browse files
Correct formatting
1 parent 3eff2b3 commit dac312f

File tree

3 files changed

+42
-14
lines changed

3 files changed

+42
-14
lines changed

pytket-mbqc-py/pytket_mbqc_py/cnot_block.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,13 @@ class CNOTBlocksGraphCircuit(GraphCircuit):
1515
the CNOT gates can be considered to be classical CNOT gates,
1616
and the ideal outcome is deterministic.
1717
"""
18+
1819
def __init__(
19-
self,
20-
n_physical_qubits: int,
21-
input_state: Tuple[int],
22-
n_layers: int,
23-
) -> None:
20+
self,
21+
n_physical_qubits: int,
22+
input_state: Tuple[int],
23+
n_layers: int,
24+
) -> None:
2425
"""Initialisation method.
2526
2627
:param n_physical_qubits: The maximum number of physical qubits
@@ -35,6 +36,9 @@ def __init__(
3536
:type n_layers: int
3637
"""
3738

39+
self.input_state = input_state
40+
self.n_layers = n_layers
41+
3842
# The number of rows of CNOT blocks
3943
# note that this is one less than the number of entries in the
4044
# input state as each CNOT has two inputs.
@@ -53,7 +57,6 @@ def __init__(
5357
super().__init__(n_physical_qubits=n_physical_qubits)
5458

5559
for layer in range(n_layers):
56-
5760
# If this is the first layer then the control qubit of the first row needs
5861
# to be initialised. If not then the control vertex is taken from
5962
# the layer before.
@@ -65,7 +68,6 @@ def __init__(
6568
control_vertex = cnot_block_vertex_list[layer - 1][0][4]
6669

6770
for row in range(n_rows):
68-
6971
# for each block the 0th qubit is the control.
7072
cnot_block_vertex_list[layer][row].append(control_vertex)
7173

@@ -122,13 +124,11 @@ def __init__(
122124
# If this is not the 0th layer then the previous layer
123125
# can be measured.
124126
if layer > 0:
125-
126127
# If this is the 1th later then the inputs of the previous
127128
# layer (the 0th layer) will not have been measured and should now be.
128129
# Note that or other layers they will have been measured by this point
129130
# as they are the 4th and 5th vertices of previous layers.
130131
if layer == 1:
131-
132132
# If this is the 0th row then we need to measure the input
133133
# control. It is not necessary in general as it would be the
134134
# output target of previous blocks.
@@ -196,7 +196,7 @@ def __init__(
196196
)
197197

198198
@property
199-
def output_state(self) -> Tuple[int]:
199+
def output_state(self) -> Tuple[int, ...]:
200200
"""The ideal output bit string.
201201
202202
:return: The ideal output bit string.
@@ -205,5 +205,5 @@ def output_state(self) -> Tuple[int]:
205205
output_state = list(self.input_state)
206206
for _ in range(self.n_layers):
207207
for i in range(len(self.input_state) - 1):
208-
output_state[i+1] = output_state[i] ^ output_state[i+1]
208+
output_state[i + 1] = output_state[i] ^ output_state[i + 1]
209209
return tuple(output_state)

pytket-mbqc-py/pytket_mbqc_py/graph_circuit.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,14 +51,12 @@ def _add_vertex(self, qubit: Qubit) -> int:
5151
return index
5252

5353
def add_input_vertex(self) -> Tuple[Qubit, int]:
54-
5554
qubit = super().get_qubit()
5655
index = self._add_vertex(qubit=qubit)
5756

5857
return (qubit, index)
5958

6059
def add_graph_vertex(self) -> int:
61-
6260
qubit = self.get_qubit()
6361
self.H(qubit)
6462
index = self._add_vertex(qubit=qubit)

pytket-mbqc-py/tests/test_graph_circuit.py

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,6 @@ def test_cnot(input_state, output_state):
139139
((1, 1, 1), (1, 1, 1), 4),
140140
((0, 0, 1), (0, 0, 1), 1),
141141
((0, 1, 1), (0, 1, 0), 1),
142-
((0, 1, 1, 0), (0, 1, 0, 1), 3),
143142
],
144143
)
145144
def test_cnot_block(input_state, output_state, n_layers):
@@ -167,3 +166,34 @@ def test_cnot_block(input_state, output_state, n_layers):
167166
n_shots=n_shots,
168167
)
169168
assert result.get_counts(output_reg)[output_state] == n_shots
169+
170+
171+
@pytest.mark.high_compute
172+
def test_large_cnot_block():
173+
input_state = (0, 1, 1, 0)
174+
output_state = (0, 1, 0, 1)
175+
n_layers = 3
176+
n_physical_qubits = 20
177+
178+
circuit = CNOTBlocksGraphCircuit(
179+
n_physical_qubits=n_physical_qubits,
180+
input_state=input_state,
181+
n_layers=n_layers,
182+
)
183+
184+
output_vertex_quibts = circuit.get_outputs()
185+
output_reg = BitRegister(name="output", size=len(output_vertex_quibts))
186+
circuit.add_c_register(register=output_reg)
187+
for i, qubit in enumerate(output_vertex_quibts.values()):
188+
circuit.Measure(qubit=qubit, bit=output_reg[i])
189+
190+
api_offline = QuantinuumAPIOffline()
191+
backend = QuantinuumBackend(device_name="H1-1LE", api_handler=api_offline)
192+
compiled_circuit = backend.get_compiled_circuit(circuit)
193+
194+
n_shots = 100
195+
result = backend.run_circuit(
196+
circuit=compiled_circuit,
197+
n_shots=n_shots,
198+
)
199+
assert result.get_counts(output_reg)[output_state] == n_shots

0 commit comments

Comments
 (0)