Skip to content

Commit

Permalink
Added new test for Compute Uncompute (#108)
Browse files Browse the repository at this point in the history
  • Loading branch information
damiansteiger committed May 20, 2017
1 parent 12c0a5f commit ed62fd9
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
4 changes: 2 additions & 2 deletions projectq/meta/_compute.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ def run_uncompute(self):
for active_qubit in self.main_engine.active_qubits:
if active_qubit.id == qubit_id:
active_qubit.id = -1
del active_qubit
active_qubit.__del__()
qubit_found = True
break
if not qubit_found:
Expand Down Expand Up @@ -181,7 +181,7 @@ def add_uncompute(command, old_tags=deepcopy(cmd.tags)):
for active_qubit in self.main_engine.active_qubits:
if active_qubit.id == qubit_id:
active_qubit.id = -1
del active_qubit
active_qubit.__del__()
qubit_found = True
break
if not qubit_found:
Expand Down
4 changes: 3 additions & 1 deletion projectq/meta/_compute_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ def test_automatic_deallocation_of_qubit_in_uncompute():
ancilla = eng.allocate_qubit()
assert ancilla[0].id != -1
Rx(0.6) | ancilla
# Test that ancilla qubit has been register in MainEngine.active_qubits
# Test that ancilla qubit has been registered in MainEngine.active_qubits
assert ancilla[0] in eng.active_qubits
_compute.Uncompute(eng)
# Test that ancilla id has been set to -1
Expand All @@ -170,6 +170,8 @@ def test_automatic_deallocation_of_qubit_in_uncompute():
assert not ancilla[0] in eng.active_qubits
assert backend.received_commands[1].gate == Rx(0.6)
assert backend.received_commands[2].gate == Rx(-0.6)
# Test that there are no additional deallocate gates
assert len(backend.received_commands) == 4


def test_compute_uncompute_no_additional_qubits():
Expand Down

0 comments on commit ed62fd9

Please sign in to comment.