Skip to content

Commit

Permalink
Solve.unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
GuillermoAbadLopez committed Oct 31, 2024
1 parent 34e2f0e commit b1cb987
Showing 1 changed file with 4 additions and 8 deletions.
12 changes: 4 additions & 8 deletions tests/digital/test_circuit_optimizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,27 +71,23 @@ def test_run_gate_cancellations(self, mock_cancelation):
assert [type(gate).__name__ for gate in optimized_gates] == ["CZ", "Drag"]


@patch("qililab.digital.circuit_optimizer.CircuitOptimizer._create_circuit", return_value=[gates.CZ(0, 1), Drag(0, theta=np.pi, phase=np.pi / 2)])
@patch("qililab.digital.circuit_optimizer.CircuitOptimizer._sweep_circuit_cancelling_pairs_of_hermitian_gates", return_value=[gates.CZ(0, 1), Drag(0, theta=np.pi, phase=np.pi / 2)])
@patch("qililab.digital.circuit_optimizer.CircuitOptimizer._create_circuit", return_value=Circuit(5))
@patch("qililab.digital.circuit_optimizer.CircuitOptimizer._sweep_circuit_cancelling_pairs_of_hermitian_gates", return_value=[("CZ", [0, 1], {}), ("Drag", [0], {"theta": np.pi, "phase": np.pi / 2})])
@patch("qililab.digital.circuit_optimizer.CircuitOptimizer._get_circuit_gates", return_value=[("CZ", [0, 1], {}), ("Drag", [0], {"theta": np.pi, "phase": np.pi / 2})])
def test_run_gate_cancellations_with_mocks(self, mock_get_circuit_gates, mock_sweep_circuit, mock_create_circuit):
def test_cancel_pairs_of_hermitian_gates(self, mock_get_circuit_gates, mock_sweep_circuit, mock_create_circuit):
"""Test run gate cancellations with mocks."""
circuit = Circuit(2)
circuit.add(gates.RZ(0, theta=np.pi / 2))
circuit.add(gates.CZ(0, 1))
circuit.add(Drag(0, theta=np.pi, phase=np.pi / 2))

optimizer = CircuitOptimizer(None)
optimized_circuit = optimizer.cancel_pairs_of_hermitian_gates(circuit)
_ = optimizer.cancel_pairs_of_hermitian_gates(circuit)

mock_get_circuit_gates.assert_called_once_with(circuit)
mock_sweep_circuit.assert_called_once_with([("CZ", [0, 1], {}), ("Drag", [0], {"theta": np.pi, "phase": np.pi / 2})])
mock_create_circuit.assert_called_once_with([("CZ", [0, 1], {}), ("Drag", [0], {"theta": np.pi, "phase": np.pi / 2})], circuit.nqubits)

assert len(optimized_circuit) == 2
assert [gate.name for gate in optimized_circuit] == ["cz", "drag"]
assert [type(gate).__name__ for gate in optimized_circuit] == ["CZ", "Drag"]


def test_get_circuit_gates(self):
"""Test get circuit gates."""
Expand Down

0 comments on commit b1cb987

Please sign in to comment.