Skip to content

Commit

Permalink
fix: deprecate initial_state
Browse files Browse the repository at this point in the history
  • Loading branch information
changsookim committed Nov 25, 2024
1 parent 49b6572 commit 4f6ac8e
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 20 deletions.
20 changes: 4 additions & 16 deletions src/qibolab/backends.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,22 +107,16 @@ def execute_circuit(self, circuit, initial_state=None, nshots=1000):
Args:
circuit (:class:`qibo.models.circuit.Circuit`): Circuit to execute.
initial_state (:class:`qibo.models.circuit.Circuit`): Circuit to prepare the initial state.
If ``None`` the default ``|00...0>`` state is used.
initial_state (None): Must be ``None`` as qibolab backend does not support initial state preparation.
nshots (int): Number of shots to sample from the experiment.
Returns:
``MeasurementOutcomes`` object containing the results acquired from the execution.
"""
if isinstance(initial_state, Circuit):
return self.execute_circuit(
circuit=initial_state + circuit,
nshots=nshots,
)
if initial_state is not None:
raise_error(
ValueError,
"Hardware backend only supports circuits as initial states.",
"Hardware backend does not support initial states.",
)

# This should be done in qibo side
Expand Down Expand Up @@ -154,22 +148,16 @@ def execute_circuits(self, circuits, initial_states=None, nshots=1000):
Args:
circuits (list): List of circuits to execute.
initial_states (:class:`qibo.models.circuit.Circuit`): Circuit to prepare the initial state.
If ``None`` the default ``|00...0>`` state is used.
initial_states (None): Must be ``None`` as qibolab backend does not support initial state preparation.
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_states, Circuit):
return self.execute_circuits(
circuits=[initial_states + circuit for circuit in circuits],
nshots=nshots,
)
if initial_states is not None:
raise_error(
ValueError,
"Hardware backend only supports circuits as initial states.",
"Hardware backend does not support initial states.",
)

# This should be done in qibo side
Expand Down
8 changes: 4 additions & 4 deletions tests/test_backends.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,8 @@ def test_execute_circuit_initial_state():

initial_circuit = Circuit(1)
circuit.add(gates.GPI2(0, phi=np.pi / 2))
backend.execute_circuit(circuit, initial_state=initial_circuit)
with pytest.raises(ValueError):
backend.execute_circuit(circuit, initial_state=initial_circuit)


@pytest.mark.parametrize(
Expand Down Expand Up @@ -140,10 +141,9 @@ def test_execute_circuits():
circuit.add(gates.GPI2(i, phi=np.pi / 2) for i in range(3))
circuit.add(gates.M(0, 1, 2))
circuit._wire_names = list(range(3))
circuit = initial_state_circuit + circuit

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

0 comments on commit 4f6ac8e

Please sign in to comment.