From bab2648cef6a01968bdd58b624db963860edb6b5 Mon Sep 17 00:00:00 2001 From: Sanson Jones <72441937+donsano33@users.noreply.github.com> Date: Tue, 12 Dec 2023 10:08:17 +0100 Subject: [PATCH] Remove ability to input signals in DynamicsBackend.solve --- qiskit_dynamics/backend/dynamics_backend.py | 23 +++++-------------- .../dynamics/backend/test_dynamics_backend.py | 13 ++++------- 2 files changed, 10 insertions(+), 26 deletions(-) diff --git a/qiskit_dynamics/backend/dynamics_backend.py b/qiskit_dynamics/backend/dynamics_backend.py index 78771c942..f42ecad27 100644 --- a/qiskit_dynamics/backend/dynamics_backend.py +++ b/qiskit_dynamics/backend/dynamics_backend.py @@ -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, @@ -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. @@ -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, ) diff --git a/test/dynamics/backend/test_dynamics_backend.py b/test/dynamics/backend/test_dynamics_backend.py index 66961c799..3eab39338 100644 --- a/test/dynamics/backend/test_dynamics_backend.py +++ b/test/dynamics/backend/test_dynamics_backend.py @@ -37,7 +37,6 @@ _get_acquire_instruction_timings, _get_backend_channel_freqs, ) -from qiskit_dynamics.pulse import InstructionToSignals from ..common import QiskitDynamicsTestCase @@ -304,17 +303,13 @@ 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]])), @@ -322,10 +317,10 @@ def test_solve(self): 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)