DynamicsBackend#
- class DynamicsBackend(solver, target=None, **options)[source]#
Bases:
BackendV2
Pulse-level simulator backend.
This class provides a
BackendV2
interface wrapper around aSolver
instance setup to simulate pulse schedules. The backend can be configured to take advantage of standard transpilation infrastructure to describe pulse-level simulations in terms ofQuantumCircuit
s. Results are returned asResult
instances.A minimal
DynamicsBackend
requires specifying only aSolver
instance and a list of subsystem dimensions, indicating the subsystem decomposition of the model inSolver
. For example, the following code builds aDynamicsBackend
around aSolver
and indicates that the system specified by theSolver
decomposes as two3
dimensional subsystems.backend = DynamicsBackend( solver=solver, subsystem_dims=[3, 3] )
Without further configuration, the above
backend
can be used to simulate eitherSchedule
orScheduleBlock
instances.Pulse-level simulations defined in terms of
QuantumCircuit
instances can also be performed if each gate in the circuit has a corresponding pulse-level definition, either as an attached calibration, or as an instruction contained inbackend.target
.Additionally, a
DynamicsBackend
can be instantiated from an existing backend using theDynamicsBackend.from_backend()
method, utilizing the additionalsubsystem_list
argument to specify which qubits to include in the model:backend = DynamicsBackend.from_backend(backend, subsystem_list=[0, 1])
Supported options
The behaviour of the backend can be configured via the following options. These can either be passed as optional keyword arguments at construction, set with the
DynamicsBackend.set_options()
method after construction, or passed as runtime arguments toDynamicsBackend.run()
.shots
: Number of shots per experiment. Defaults to1024
.solver
: The Qiskit DynamicsSolver
instance used for simulation.solver_options
: Dictionary containing optional kwargs for passing toSolver.solve()
, indicating solver methods and options. Defaults to the empty dictionary{}
.subsystem_dims
: Dimensions of subsystems making up the system insolver
. Defaults to[solver.model.dim]
.meas_map
: Measurement map. Defaults to[[idx] for idx in range(len(subsystem_dims))]
.control_channel_map
: A dictionary mapping control channel labels to indices, to be used for control channel index lookup in theDynamicsBackend.control_channel()
method.initial_state
: Initial state for simulation, either the string"ground_state"
, indicating that the ground state for the system Hamiltonian should be used, or an arbitraryStatevector
orDensityMatrix
. Defaults to"ground_state"
.normalize_states
: Boolean indicating whether to normalize states before computing outcome probabilities, and normalize probablities before sampling. Defaults toTrue
. Setting toFalse
can result in errors if the solution tolerance results in probabilities with significant numerical deviation from a proper probability distribution.meas_level
: Form of measurement output. Supported values are1
and2
.1
returns IQ points and2
returns counts. Defaults tomeas_level == 2
.meas_return
: Level of measurement data to return. Formeas_level = 1
"single"
returns output from every shot."avg"
returns average over shots of measurement output. Defaults to"avg"
.iq_centers
: Centers for IQ distribution when usingmeas_level==1
results. Must have typeList[List[List[float, float]]]
formatted asiq_centers[subsystem][level] = [I, Q]
. IfNone
, theiq_centers
are dynamically generated to be equally spaced points on a unit circle with ground-state at(1, 0)
. The default isNone
.iq_width
: Standard deviation of IQ distribution around the centers formeas_level==1
. Must be a positive float. Defaults to0.2
.max_outcome_level
: Formeas_level == 2
, the maximum outcome for each subsystem. Values will be rounded down to be no larger thanmax_outcome_level
. Must be a positive integer orNone
. IfNone
, no rounding occurs. Defaults to1
.memory
: Boolean indicating whether to return a list of explicit measurement outcomes for every experimental shot. Defaults toTrue
.seed_simulator
: Seed to use in random sampling. Defaults toNone
.experiment_result_function
: Function for computing theExperimentResult
for each simulated experiment. This option defaults todefault_experiment_result_function()
, and any other function set to this option must have the same signature. Note that the default utilizes various other options that control results computation, and hence changing it will impact the meaning of other options.configuration
: APulseBackendConfiguration
instance orNone
. This option defaults toNone
, and is not required for the functioning of this class, but is provided for compatibility. A set configuration will be returned byDynamicsBackend.configuration()
.defaults
: APulseDefaults
instance orNone
. This option defaults toNone
, and is not required for the functioning of this class, but is provided for compatibility. A set defaults will be returned byDynamicsBackend.defaults()
.
Instantiate with a
Solver
instance and additional options.- Parameters:
- Raises:
QiskitError – If any instantiation arguments fail validation checks.
Methods
- control_channel(qubits)[source]#
Return the control channel with a given label specified by qubits.
This method requires the
control_channel_map
option is set, and otherwise will raise aNotImplementedError
.- Parameters:
qubits (
Union
[Tuple
[int
,int
],List
[Tuple
[int
,int
]]]) – The label for the control channel, or a list of labels.- Return type:
List
[ControlChannel
]- Returns:
A list containing the control channels specified by qubits.
- Raises:
NotImplementedError – If the control_channel_map option is not set for this backend.
QiskitError – If a requested channel is not in the control_channel_map.
- classmethod from_backend(backend, subsystem_list=None, rotating_frame='auto', array_library=None, vectorized=False, rwa_cutoff_freq=None, **options)[source]#
Construct a DynamicsBackend instance from an existing Backend instance.
Warning
Due to inevitable model inaccuracies, gates calibrated on a real backend will not have the same performance on the
DynamicsBackend
instance returned by this method. As such, gates and calibrations are not be copied into the constructedDynamicsBackend
.The
backend
must contain sufficient information in thetarget
,configuration
, and/ordefaults
attributes to be able to run simulations. The following table indicates which parameters are required, along with their primary and secondary sources:# Parameter
Primary source
Secondary source
hamiltonian
dictionary.configuration.hamiltonian
N/A
Control channel frequency specification.
configuration.u_channel_lo
N/A
Number of qubits in the backend model.
target.num_qubits
configuration.n_qubits
Pulse schedule sample size
dt
.target.dt
configuration.dt
Drive channel frequencies.
target.qubit_properties
defaults.qubit_freq_est
Measurement channel frequencies, if measurement channels explicitly appear in the model.
defaults.meas_freq_est
N/A
Note
The
target
,configuration
, anddefaults
attributes of the original backend are not copied into the constructedDynamicsBackend
instance, only the required data stored within these attributes will be extracted. If necessary, these attributes can be set and configured by the user.The optional argument
subsystem_list
specifies which subset of qubits to model in the constructedDynamicsBackend
. All other qubits are dropped from the model.Configuration of the underlying
Solver
is controlled via therotating_frame
,array_library
,vectorized
, andrwa_cutoff_freq
options. In contrast toSolver
initialization,rotating_frame
defaults to the string"auto"
, which allows this method to choose the rotating frame based onarray_library
:If a dense
array_library
is chosen, the rotating frame will be set to thestatic_hamiltonian
indicated by the Hamiltonian inbackend.configuration()
.If a sparse
array_library
is chosen, the rotating frame will be set to the diagonal ofstatic_hamiltonian
.
Otherwise the
rotating_frame
,array_library
,vectorized
, andrwa_cutoff_freq
are passed directly to theSolver
initialization.- Parameters:
backend (
BackendV1
) – TheBackend
instance to build theDynamicsBackend
from. Note that while the type hint indicates that backend should be aBackendV1
instance, this method also works forBackendV2
instances that have been set up with sufficiently populatedconfiguration
anddefaults
for backwards compatibility.subsystem_list (
Optional
[List
[int
]]) – The list of qubits in the backend to include in the model.rotating_frame (
Union
[ndarray
,number
,int
,float
,complex
,Tracer
,Array
,Array
,spmatrix
,BCOO
,list
,RotatingFrame
,str
,None
]) – Rotating frame argument for the internalSolver
. Defaults to"auto"
, allowing this method to pick a rotating frame.array_library (
Optional
[str
]) – Array library with which to store the operators in theSolver
. See the model evaluation section of the Models API documentation for a more detailed description of this argument.vectorized (
Optional
[bool
]) – If a Lindblad terms are present, whether or not to build theSolver
in a vectorized mode.rwa_cutoff_freq (
Optional
[float
]) – Rotating wave approximation argument for the internalSolver
.**options – Additional options to be applied in construction of the
DynamicsBackend
.
- Return type:
- Returns:
DynamicsBackend
- Raises:
QiskitError – If any required parameters are missing from the passed backend.
- qubit_properties(qubit)#
Return QubitProperties for a given qubit.
If there are no defined or the backend doesn’t support querying these details this method does not need to be implemented.
- Parameters:
qubit (
Union
[int
,List
[int
]]) – The qubit to get theQubitProperties
object for. This can be a single integer for 1 qubit or a list of qubits and a list ofQubitProperties
objects will be returned in the same order- Return type:
Union
[QubitProperties
,List
[QubitProperties
]]- Returns:
The
QubitProperties
object for the specified qubit. If a list of qubits is provided a list will be returned. If properties are missing for a qubit this can beNone
.- Raises:
NotImplementedError – if the backend doesn’t support querying the qubit properties
- run(run_input, validate=True, **options)[source]#
Run a list of simulations.
- Parameters:
run_input (
List
[Union
[QuantumCircuit
,Schedule
,ScheduleBlock
]]) – A list of simulations, specified byQuantumCircuit
,Schedule
, orScheduleBlock
instances.validate (
Optional
[bool
]) – Whether or not to run validation checks on the input.**options – Additional run options to temporarily override current backend options.
- Return type:
DynamicsJob
- Returns:
DynamicsJob object containing results and status.
- Raises:
QiskitError – If invalid options are set.
- solve(solve_input, t_span, y0=None, convert_results=True, validate=True)[source]#
Simulate a list of
QuantumCircuit
,Schedule
, orScheduleBlock
instances and return theOdeResult
.This method is analogous to
Solver.solve()
, however it additionally utilizes transpilation and the backend configuration to convertQuantumCircuit
instances into pulse-level schedules for simulation. The options for the solver will be drawn fromself.options.solver_options
, and ify0
is not specified, it will be set fromself.options.initial_state
.- Parameters:
t_span (
Union
[ndarray
,number
,int
,float
,complex
,Tracer
,Array
,Array
,spmatrix
,BCOO
,list
]) – Time interval to integrate over.y0 (
Union
[ndarray
,number
,int
,float
,complex
,Tracer
,Array
,Array
,spmatrix
,BCOO
,list
,QuantumState
,BaseOperator
,None
]) – Initial state.solve_input (
List
[Union
[QuantumCircuit
,Schedule
,ScheduleBlock
]]) – Time evolution of the system in terms of quantum circuits or qiskit pulse schedules.convert_results (
Optional
[bool
]) – IfTrue
, convert returned solver state results to the same class as y0. IfFalse
, states will be returned in the native array type used by the specified solver method.validate (
Optional
[bool
]) – Whether or not to run validation checks on the input.
- Returns:
object with formatted output types.
- Return type:
OdeResult
Attributes
- coupling_map#
Return the
CouplingMap
object
- dt#
Return the system time resolution of input signals
This is required to be implemented if the backend supports Pulse scheduling.
- Returns:
The input signal timestep in seconds. If the backend doesn’t define
dt
,None
will be returned.
- dtm#
Return the system time resolution of output signals
- Returns:
The output signal timestep in seconds.
- Raises:
NotImplementedError – if the backend doesn’t support querying the output signal timestep
- instruction_durations#
Return the
InstructionDurations
object.
- instruction_schedule_map#
Return the
InstructionScheduleMap
for the instructions defined in this backend’s target.
- instructions#
A list of Instruction tuples on the backend of the form
(instruction, (qubits)
- max_circuits#
- meas_map#
- num_qubits#
Return the number of qubits the backend has.
- operation_names#
A list of instruction names that the backend supports.
- operations#
A list of
Instruction
instances that the backend supports.
- options#
Return the options for the backend
The options of a backend are the dynamic parameters defining how the backend is used. These are used to control the
run()
method.
- provider#
Return the backend Provider.
- Returns:
the Provider responsible for the backend.
- Return type:
Provider
- target#
- version = 2#
- name#
Name of the backend.
- description#
Optional human-readable description.
- online_date#
Date that the backend came online.
- backend_version#
Version of the backend being provided. This is not the same as
BackendV2.version
, which is the version of theBackend
abstract interface.