Skip to content

Commit

Permalink
Remove ability to input signals in DynamicsBackend.solve
Browse files Browse the repository at this point in the history
  • Loading branch information
donsano33 committed Dec 12, 2023
1 parent 64fb51a commit bab2648
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 26 deletions.
23 changes: 6 additions & 17 deletions qiskit_dynamics/backend/dynamics_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -347,12 +347,10 @@ def solve(
self,
t_span: Array,
y0: Union[Array, QuantumState, BaseOperator],
signals: Optional[
solve_input: Optional[
Union[
List[QuantumCircuit],
List[Union[Schedule, ScheduleBlock]],
List[Signal],
Tuple[List[Signal], List[Signal]],
]
] = None,
convert_results: bool = True,
Expand All @@ -363,12 +361,8 @@ def solve(
Args:
t_span: Time interval to integrate over.
y0: Initial state.
signals: Specification of time-dependent coefficients to simulate, either in
Signal format or as Qiskit Pulse Pulse schedules.
If specifying in Signal format, if ``dissipator_operators is None``,
specify as a list of signals for the Hamiltonian component, otherwise
specify as a tuple of two lists, one for Hamiltonian components, and
one for the ``dissipator_operators`` coefficients.
solve_input: Time evolution of the system in terms of quantum circuits or qiskit
pulse schedules.
convert_results: If ``True``, convert returned solver state results to the same class
as y0. If ``False``, states will be returned in the native array type
used by the specified solver method.
Expand All @@ -379,18 +373,13 @@ def solve(
"""
if validate:
_validate_run_input(
signals, accepted_types=(QuantumCircuit, Schedule, ScheduleBlock, Signal)
solve_input, accepted_types=(QuantumCircuit, Schedule, ScheduleBlock)
)
signals = [
build_schedule(signal, self, dt=self.options.solver._dt)
if isinstance(signal, QuantumCircuit)
else signal
for signal in signals
]
schedules, _ = _to_schedule_list(solve_input, backend=self)
solver_results = self.options.solver.solve(
t_span=t_span,
y0=y0,
signals=signals,
signals=schedules,
convert_results=convert_results,
**self.options.solver_options,
)
Expand Down
13 changes: 4 additions & 9 deletions test/dynamics/backend/test_dynamics_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@
_get_acquire_instruction_timings,
_get_backend_channel_freqs,
)
from qiskit_dynamics.pulse import InstructionToSignals
from ..common import QiskitDynamicsTestCase


Expand Down Expand Up @@ -304,28 +303,24 @@ def test_pi_pulse(self):
self.assertDictEqual(counts, {"1": 1024})

def test_solve(self):
"""Test the ODE simulation with different signal and y0 types."""
"""Test the ODE simulation with different input and y0 types."""
n_samples = 100
with pulse.build() as x_sched0:
pulse.play(pulse.Waveform([1.0] * n_samples), pulse.DriveChannel(0))
x_circ0 = QuantumCircuit(1)
x_circ0.x(0)
x_circ0.add_calibration("x", [0], x_sched0)
x_signal0 = InstructionToSignals(
dt=self.simple_backend.dt,
carriers=self.simple_backend.options.solver._channel_carrier_freqs,
).get_signals(x_sched0)[0]

y0_variety = [
Statevector(np.array([[1.0], [0.0]])),
Operator(np.eye(2)),
DensityMatrix(QuantumCircuit(1)),
Choi(QuantumCircuit(1)),
]
signal_variety = [x_sched0, x_circ0, x_signal0]
for signal, y0 in product(signal_variety, y0_variety):
input_variety = [x_sched0, x_circ0]
for solve_input, y0 in product(input_variety, y0_variety):
solver_results = self.simple_backend.solve(
t_span=[0, n_samples * self.simple_backend.dt], y0=y0, signals=[signal]
t_span=[0, n_samples * self.simple_backend.dt], y0=y0, solve_input=[solve_input]
)
if isinstance(solver_results, list):
assert all(result.success for result in solver_results)
Expand Down

0 comments on commit bab2648

Please sign in to comment.