Skip to content

Commit

Permalink
Add cnot test with earlier measure
Browse files Browse the repository at this point in the history
  • Loading branch information
daniel-mills-cqc committed May 2, 2024
1 parent 1bcadb3 commit d20da00
Showing 1 changed file with 66 additions and 0 deletions.
66 changes: 66 additions & 0 deletions pytket-mbqc-py/tests/test_graph_circuit.py
Original file line number Diff line number Diff line change
Expand Up @@ -248,3 +248,69 @@ def test_3_q_ghz():
n_shots = 100
result = backend.run_circuit(circuit=compiled_graph_circuit, n_shots=n_shots)
assert result.get_counts(cbits=output_c_reg)[(0, 0, 0)] == n_shots


@pytest.mark.parametrize(
"input_state, output_state",
[((0, 0), (0, 0)), ((0, 1), (0, 1)), ((1, 0), (1, 1)), ((1, 1), (1, 0))],
)
def test_cnot_early_measure(input_state, output_state):
circuit = GraphCircuit(n_physical_qubits=3)

target_qubit, vertex_one = circuit.add_input_vertex()
if input_state[1]:
circuit.X(target_qubit)

vertex_two = circuit.add_graph_vertex()
circuit.add_edge(vertex_one=vertex_one, vertex_two=vertex_two)

circuit.corrected_measure(vertex=vertex_one, t_multiple=0)

control_qubit, vertex_three = circuit.add_input_vertex()
if input_state[0]:
circuit.X(control_qubit)

vertex_four = circuit.add_graph_vertex()
circuit.add_edge(vertex_one=vertex_two, vertex_two=vertex_four)

circuit.corrected_measure(vertex=vertex_two, t_multiple=0)

vertex_five = circuit.add_graph_vertex()
circuit.add_edge(vertex_one=vertex_three, vertex_two=vertex_five)

circuit.corrected_measure(vertex=vertex_three, t_multiple=0)

vertex_six = circuit.add_graph_vertex()
circuit.add_edge(vertex_one=vertex_four, vertex_two=vertex_six)

circuit.corrected_measure(vertex=vertex_four, t_multiple=0)

vertex_seven = circuit.add_graph_vertex()
circuit.add_edge(vertex_one=vertex_five, vertex_two=vertex_seven)

circuit.corrected_measure(vertex=vertex_five, t_multiple=0)

vertex_eight = circuit.add_graph_vertex()
circuit.add_edge(vertex_one=vertex_six, vertex_two=vertex_eight)

circuit.add_edge(vertex_one=vertex_six, vertex_two=vertex_seven)

circuit.corrected_measure(vertex=vertex_six, t_multiple=0)

output_qubits = circuit.get_outputs()
output_reg = BitRegister(name="output", size=2)
circuit.add_c_register(register=output_reg)
circuit.Measure(qubit=output_qubits[vertex_seven], bit=output_reg[0])
circuit.Measure(qubit=output_qubits[vertex_eight], bit=output_reg[1])

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 d20da00

Please sign in to comment.