Skip to content

Commit

Permalink
Merge pull request #894 from qiboteam/fix_execute_circuits
Browse files Browse the repository at this point in the history
Rename initial_state in execute_circuits
  • Loading branch information
Edoardo-Pedicillo committed May 6, 2024
2 parents 483c5a5 + 0a5b88c commit 41fcafd
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
10 changes: 5 additions & 5 deletions src/qibolab/backends.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,27 +109,27 @@ def execute_circuit(self, circuit, initial_state=None, nshots=1000):
self.assign_measurements(measurement_map, readout)
return result

def execute_circuits(self, circuits, initial_state=None, nshots=1000):
def execute_circuits(self, circuits, initial_states=None, nshots=1000):
"""Executes multiple quantum circuits with a single communication with
the control electronics.
Circuits are unrolled to a single pulse sequence.
Args:
circuits (list): List of circuits to execute.
initial_state (:class:`qibo.models.circuit.Circuit`): Circuit to prepare the initial state.
initial_states (:class:`qibo.models.circuit.Circuit`): Circuit to prepare the initial state.
If ``None`` the default ``|00...0>`` state is used.
nshots (int): Number of shots to sample from the experiment.
Returns:
List of ``MeasurementOutcomes`` objects containing the results acquired from the execution of each circuit.
"""
if isinstance(initial_state, Circuit):
if isinstance(initial_states, Circuit):
return self.execute_circuits(
circuit=[initial_state + circuit for circuit in circuits],
circuits=[initial_states + circuit for circuit in circuits],
nshots=nshots,
)
if initial_state is not None:
if initial_states is not None:
raise_error(
ValueError,
"Hardware backend only supports circuits as initial states.",
Expand Down
6 changes: 5 additions & 1 deletion tests/test_backends.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,15 @@ def test_measurement_samples():

def test_execute_circuits():
backend = QibolabBackend("dummy")
initial_state_circuit = Circuit(3)
initial_state_circuit.add(gates.GPI(0, phi=np.pi / 2))
circuit = Circuit(3)
circuit.add(gates.GPI2(i, phi=np.pi / 2) for i in range(3))
circuit.add(gates.M(0, 1, 2))

results = backend.execute_circuits(5 * [circuit], nshots=100)
results = backend.execute_circuits(
5 * [circuit], initial_states=initial_state_circuit, nshots=100
)
assert len(results) == 5
for result in results:
assert result.samples().shape == (100, 3)
Expand Down

0 comments on commit 41fcafd

Please sign in to comment.