dq.mesolve
mesolve(
H: QArrayLike | TimeQArray,
jump_ops: list[QArrayLike | TimeQArray],
rho0: QArrayLike,
tsave: ArrayLike,
*,
exp_ops: list[QArrayLike] | None = None,
solver: Solver = Tsit5(),
gradient: Gradient | None = None,
options: Options = Options()
) -> MESolveResult
Solve the Lindblad master equation.
This function computes the evolution of the density matrix \(\rho(t)\) at time \(t\), starting from an initial state \(\rho_0\), according to the Lindblad master equation (with \(\hbar=1\) and where time is implicit(1)) $$ \frac{\dd\rho}{\dt} = -i[H, \rho] + \sum_{k=1}^N \left( L_k \rho L_k^\dag - \frac{1}{2} L_k^\dag L_k \rho - \frac{1}{2} \rho L_k^\dag L_k \right), $$ where \(H\) is the system's Hamiltonian and \(\{L_k\}\) is a collection of jump operators.
- With explicit time dependence:
- \(\rho\to\rho(t)\)
- \(H\to H(t)\)
- \(L_k\to L_k(t)\)
Parameters
-
H
(qarray-like or time-qarray of shape (...H, n, n))
–
Hamiltonian.
-
jump_ops
(list of qarray-like or time-qarray, each of shape (...Lk, n, n))
–
List of jump operators.
-
rho0
(qarray-like of shape (...rho0, n, 1) or (...rho0, n, n))
–
Initial state.
-
tsave
(array-like of shape (ntsave,))
–
Times at which the states and expectation values are saved. The equation is solved from
tsave[0]
totsave[-1]
, or fromt0
totsave[-1]
ift0
is specified inoptions
. -
exp_ops
(list of qarray-like, each of shape (n, n), optional)
–
List of operators for which the expectation value is computed.
-
solver
–
Solver for the integration. Defaults to
dq.solver.Tsit5
(supported:Tsit5
,Dopri5
,Dopri8
,Kvaerno3
,Kvaerno5
,Euler
,Rouchon1
,Rouchon2
,Expm
). -
gradient
–
Algorithm used to compute the gradient. The default is solver-dependent, refer to the documentation of the chosen solver for more details.
-
options
–
Generic options (supported:
save_states
,cartesian_batching
,progress_meter
,t0
,save_extra
).Detailed options API
dq.Options( save_states: bool = True, cartesian_batching: bool = True, progress_meter: AbstractProgressMeter | None = TqdmProgressMeter(), t0: ScalarLike | None = None, save_extra: callable[[Array], PyTree] | None = None, )
Parameters
- save_states - If
True
, the state is saved at every time intsave
, otherwise only the final state is returned. - cartesian_batching - If
True
, batched arguments are treated as separated batch dimensions, otherwise the batching is performed over a single shared batched dimension. - progress_meter - Progress meter indicating how far the solve has
progressed. Defaults to a tqdm
progress meter. Pass
None
for no output, see other options in dynamiqs/progress_meter.py. If gradients are computed, the progress meter only displays during the forward pass. - t0 - Initial time. If
None
, defaults to the first time intsave
. - save_extra (function, optional) - A function with signature
f(QArray) -> PyTree
that takes a state as input and returns a PyTree. This can be used to save additional arbitrary data during the integration, accessible inresult.extra
.
- save_states - If
Returns
dq.MESolveResult
object holding the result of the
Lindblad master equation integration. Use result.states
to access the
saved states and result.expects
to access the saved expectation values.
Detailed result API
dq.MESolveResult
Attributes
- states (qarray of shape (..., nsave, n, n)) - Saved states with
nsave = ntsave
, ornsave = 1
ifoptions.save_states=False
. - final_state (qarray of shape (..., n, n)) - Saved final state.
- expects (array of shape (..., len(exp_ops), ntsave) or None) - Saved
expectation values, if specified by
exp_ops
. - extra (PyTree or None) - Extra data saved with
save_extra()
if specified inoptions
. - infos (PyTree or None) - Solver-dependent information on the resolution.
- tsave (array of shape (ntsave,)) - Times for which results were saved.
- solver (Solver) - Solver used.
- gradient (Gradient) - Gradient used.
- options (Options) - Options used.
Advanced use-cases
Defining a time-dependent Hamiltonian or jump operator
If the Hamiltonian or the jump operators depend on time, they can be converted to
time-qarrays using dq.pwc()
,
dq.modulated()
, or
dq.timecallable()
. See the
Time-dependent operators
tutorial for more details.
Running multiple simulations concurrently
The Hamiltonian H
, the jump operators jump_ops
and the initial density matrix
rho0
can be batched to solve multiple master equations concurrently. All other
arguments are common to every batch. The resulting states and expectation values
are batched according to the leading dimensions of H
, jump_ops
and rho0
. The
behaviour depends on the value of the cartesian_batching
option.
The results leading dimensions are
... = ...H, ...L0, ...L1, (...), ...rho0
For example if:
H
has shape (2, 3, n, n),jump_ops = [L0, L1]
has shape [(4, 5, n, n), (6, n, n)],rho0
has shape (7, n, n),
then result.states
has shape (2, 3, 4, 5, 6, 7, ntsave, n, n).
The results leading dimensions are
... = ...H = ...L0 = ...L1 = (...) = ...rho0 # (once broadcasted)
For example if:
H
has shape (2, 3, n, n),jump_ops = [L0, L1]
has shape [(3, n, n), (2, 1, n, n)],rho0
has shape (3, n, n),
then result.states
has shape (2, 3, ntsave, n, n).
See the Batching simulations tutorial for more details.