Skip to content

Commit

Permalink
Correct formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
daniel-mills-cqc committed Apr 5, 2024
1 parent 3eff2b3 commit dac312f
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 14 deletions.
22 changes: 11 additions & 11 deletions pytket-mbqc-py/pytket_mbqc_py/cnot_block.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,13 @@ class CNOTBlocksGraphCircuit(GraphCircuit):
the CNOT gates can be considered to be classical CNOT gates,
and the ideal outcome is deterministic.
"""

def __init__(
self,
n_physical_qubits: int,
input_state: Tuple[int],
n_layers: int,
) -> None:
self,
n_physical_qubits: int,
input_state: Tuple[int],
n_layers: int,
) -> None:
"""Initialisation method.
:param n_physical_qubits: The maximum number of physical qubits
Expand All @@ -35,6 +36,9 @@ def __init__(
:type n_layers: int
"""

self.input_state = input_state
self.n_layers = n_layers

# The number of rows of CNOT blocks
# note that this is one less than the number of entries in the
# input state as each CNOT has two inputs.
Expand All @@ -53,7 +57,6 @@ def __init__(
super().__init__(n_physical_qubits=n_physical_qubits)

for layer in range(n_layers):

# If this is the first layer then the control qubit of the first row needs
# to be initialised. If not then the control vertex is taken from
# the layer before.
Expand All @@ -65,7 +68,6 @@ def __init__(
control_vertex = cnot_block_vertex_list[layer - 1][0][4]

for row in range(n_rows):

# for each block the 0th qubit is the control.
cnot_block_vertex_list[layer][row].append(control_vertex)

Expand Down Expand Up @@ -122,13 +124,11 @@ def __init__(
# If this is not the 0th layer then the previous layer
# can be measured.
if layer > 0:

# If this is the 1th later then the inputs of the previous
# layer (the 0th layer) will not have been measured and should now be.
# Note that or other layers they will have been measured by this point
# as they are the 4th and 5th vertices of previous layers.
if layer == 1:

# If this is the 0th row then we need to measure the input
# control. It is not necessary in general as it would be the
# output target of previous blocks.
Expand Down Expand Up @@ -196,7 +196,7 @@ def __init__(
)

@property
def output_state(self) -> Tuple[int]:
def output_state(self) -> Tuple[int, ...]:
"""The ideal output bit string.
:return: The ideal output bit string.
Expand All @@ -205,5 +205,5 @@ def output_state(self) -> Tuple[int]:
output_state = list(self.input_state)
for _ in range(self.n_layers):
for i in range(len(self.input_state) - 1):
output_state[i+1] = output_state[i] ^ output_state[i+1]
output_state[i + 1] = output_state[i] ^ output_state[i + 1]
return tuple(output_state)
2 changes: 0 additions & 2 deletions pytket-mbqc-py/pytket_mbqc_py/graph_circuit.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,12 @@ def _add_vertex(self, qubit: Qubit) -> int:
return index

def add_input_vertex(self) -> Tuple[Qubit, int]:

qubit = super().get_qubit()
index = self._add_vertex(qubit=qubit)

return (qubit, index)

def add_graph_vertex(self) -> int:

qubit = self.get_qubit()
self.H(qubit)
index = self._add_vertex(qubit=qubit)
Expand Down
32 changes: 31 additions & 1 deletion pytket-mbqc-py/tests/test_graph_circuit.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,6 @@ def test_cnot(input_state, output_state):
((1, 1, 1), (1, 1, 1), 4),
((0, 0, 1), (0, 0, 1), 1),
((0, 1, 1), (0, 1, 0), 1),
((0, 1, 1, 0), (0, 1, 0, 1), 3),
],
)
def test_cnot_block(input_state, output_state, n_layers):
Expand Down Expand Up @@ -167,3 +166,34 @@ def test_cnot_block(input_state, output_state, n_layers):
n_shots=n_shots,
)
assert result.get_counts(output_reg)[output_state] == n_shots


@pytest.mark.high_compute
def test_large_cnot_block():
input_state = (0, 1, 1, 0)
output_state = (0, 1, 0, 1)
n_layers = 3
n_physical_qubits = 20

circuit = CNOTBlocksGraphCircuit(
n_physical_qubits=n_physical_qubits,
input_state=input_state,
n_layers=n_layers,
)

output_vertex_quibts = circuit.get_outputs()
output_reg = BitRegister(name="output", size=len(output_vertex_quibts))
circuit.add_c_register(register=output_reg)
for i, qubit in enumerate(output_vertex_quibts.values()):
circuit.Measure(qubit=qubit, bit=output_reg[i])

api_offline = QuantinuumAPIOffline()
backend = QuantinuumBackend(device_name="H1-1LE", api_handler=api_offline)
compiled_circuit = backend.get_compiled_circuit(circuit)

n_shots = 100
result = backend.run_circuit(
circuit=compiled_circuit,
n_shots=n_shots,
)
assert result.get_counts(output_reg)[output_state] == n_shots

0 comments on commit dac312f

Please sign in to comment.