From 265a433cb62248c017795a45a3630634270ffffe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Guillermo=20Abad=20L=C3=B3pez?= <109400222+GuillermoAbadLopez@users.noreply.github.com> Date: Tue, 29 Oct 2024 12:48:02 +0100 Subject: [PATCH] Addint `transpile_circuits` test --- tests/digital/test_circuit_transpiler.py | 55 +++++++++++++++--------- 1 file changed, 35 insertions(+), 20 deletions(-) diff --git a/tests/digital/test_circuit_transpiler.py b/tests/digital/test_circuit_transpiler.py index 2244e4274..1da7e853e 100644 --- a/tests/digital/test_circuit_transpiler.py +++ b/tests/digital/test_circuit_transpiler.py @@ -634,23 +634,38 @@ def test_drag_schedule_error(self, digital_settings): with pytest.raises(ValueError, match=error_string): transpiler.circuit_to_pulses(circuits=[circuit]) - # @patch("qililab.digital.circuit_transpiler.CircuitTranspiler.route_circuit") - # @patch("qililab.digital.circuit_transpiler.CircuitTranspiler.circuit_to_native") - # @patch("qililab.digital.circuit_transpiler.CircuitTranspiler.circuit_to_pulses") - # def test_transpile_circuits(self, mock_to_pulses, mock_to_native, mock_route, digital_settings): - # """Test transpile_circuits method""" - # transpiler = CircuitTranspiler(digital_compilation_settings=digital_settings) - # placer = MagicMock() - # router = MagicMock() - # routing_iterations = 7 - - # # Mock the return values - # mock_route.return_value = [Circuit(5)]*2, {"q0": 0, "q1": 2, "q2": 1, "q3": 3, "q4": 4} - # mock_to_native.return_value = Circuit(5) - # mock_to_pulses.return_value = [PulseSchedule()] - - # circuit = random_circuit(5, 10, np.random.default_rng()) - - # transpiler.transpile_circuits([circuit]*2) - - # mock_to_pulses.assert_called_once_with(list(), list()) + @patch("qililab.digital.circuit_transpiler.CircuitTranspiler.route_circuit") + @patch("qililab.digital.circuit_transpiler.CircuitTranspiler.circuit_to_native") + @patch("qililab.digital.circuit_transpiler.CircuitTranspiler.circuit_to_pulses") + def test_transpile_circuits(self, mock_to_pulses, mock_to_native, mock_route, digital_settings): + """Test transpile_circuits method""" + transpiler = CircuitTranspiler(digital_compilation_settings=digital_settings) + placer = MagicMock() + router = MagicMock() + routing_iterations = 7 + list_size = 2 + + # Mock circuit for return values + mock_circuit = Circuit(5) + mock_circuit.add(X(0)) + + # Mock layout for return values + mock_layout = {"q0": 0, "q1": 2, "q2": 1, "q3": 3, "q4": 4} + + # Mock schedule for return values + mock_schedule = PulseSchedule() + + # Mock the return values + mock_route.return_value = mock_circuit, mock_layout + mock_to_native.return_value = mock_circuit + mock_to_pulses.return_value = [mock_schedule] + + circuit = random_circuit(5, 10, np.random.default_rng()) + + list_schedules, list_layouts = transpiler.transpile_circuits([circuit]*list_size, placer, router, routing_iterations) + + # Asserts: + mock_route.assert_called_with(circuit, placer, router, iterations=routing_iterations) + mock_to_native.assert_called_with(mock_circuit) + mock_to_pulses.assert_called_once_with([mock_circuit]*list_size) + assert list_schedules, list_layouts == ([mock_schedule]*list_size, [mock_layout]*list_size)