From b1cb987c9f5ae6aed120cebd4abbaf896ebd0e44 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Guillermo=20Abad=20L=C3=B3pez?= <109400222+GuillermoAbadLopez@users.noreply.github.com> Date: Thu, 31 Oct 2024 04:55:34 +0100 Subject: [PATCH] Solve.unit test --- tests/digital/test_circuit_optimizer.py | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/tests/digital/test_circuit_optimizer.py b/tests/digital/test_circuit_optimizer.py index 6e2ff6b66..c01c3a53a 100644 --- a/tests/digital/test_circuit_optimizer.py +++ b/tests/digital/test_circuit_optimizer.py @@ -71,10 +71,10 @@ 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)) @@ -82,16 +82,12 @@ def test_run_gate_cancellations_with_mocks(self, mock_get_circuit_gates, mock_sw 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."""