Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deprecate initial_state #1106

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading