Skip to content

Commit

Permalink
Addint transpile_circuits test
Browse files Browse the repository at this point in the history
  • Loading branch information
GuillermoAbadLopez committed Oct 29, 2024
1 parent 46ab052 commit 265a433
Showing 1 changed file with 35 additions and 20 deletions.
55 changes: 35 additions & 20 deletions tests/digital/test_circuit_transpiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

0 comments on commit 265a433

Please sign in to comment.