dq.sesolve
sesolve(
H: QArrayLike | TimeQArray,
psi0: QArrayLike,
tsave: ArrayLike,
*,
exp_ops: list[QArrayLike] | None = None,
method: Method = Tsit5(),
gradient: Gradient | None = None,
options: Options = Options()
) -> SESolveResult
Solve the Schrödinger equation.
This function computes the evolution of the state vector \(\ket{\psi(t)}\) at time \(t\), starting from an initial state \(\ket{\psi_0}\), according to the Schrödinger equation (with \(\hbar=1\) and where time is implicit(1)) $$ \frac{\dd\ket{\psi}}{\dt} = -i H \ket{\psi}, $$ where \(H\) is the system's Hamiltonian.
- With explicit time dependence:
- \(\ket\psi\to\ket{\psi(t)}\)
- \(H\to H(t)\)
Parameters:
-
H(qarray-like or timeqarray of shape (...H, n, n)) –Hamiltonian.
-
psi0(qarray-like of shape (...psi0, n, 1)) –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 fromt0totsave[-1]ift0is specified inoptions. -
exp_ops(list of qarray-like, each of shape (n, n)) –List of operators for which the expectation value is computed.
-
method– -
gradient–Algorithm used to compute the gradient. The default is method-dependent, refer to the documentation of the chosen method 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 | bool | None = None, t0: ScalarLike | None = None, save_extra: callable[[Array], PyTree] | None = None, )Parameters:
save_states- IfTrue, the state is saved at every time intsave, otherwise only the final state is returned.cartesian_batching- IfTrue, 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 toNonewhich uses the global default progress meter (seedq.set_progress_meter()). Set toTruefor a tqdm progress meter, andFalsefor 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. IfNone, defaults to the first time intsave.save_extra(function, optional) - A function with signaturef(QArray) -> PyTreethat takes a state as input and returns a PyTree. This can be used to save additional arbitrary data during the integration, accessible inresult.extra.
Returns:
-
dq.SESolveResultobject holding the result of the Schrödinger equation integration. Useresult.statesto access the saved states andresult.expectsto access the saved expectation values.Detailed result API
dq.SESolveResultAttributes:
states(qarray of shape (..., nsave, n, 1)) - Saved states withnsave = ntsave, ornsave = 1ifoptions.save_states=False.final_state(qarray of shape (..., n, 1)) - Saved final state.expects(array of shape (..., len(exp_ops), ntsave) or None) - Saved expectation values, if specified byexp_ops.extra(PyTree or None) - Extra data saved withsave_extra()if specified inoptions.infos(PyTree or None) - Method-dependent information on the resolution.tsave(array of shape (ntsave,)) - Times for which results were saved.method(Method) - Method used.gradient(Gradient) - Gradient used.options(Options) - Options used.
Examples:
import dynamiqs as dq
import jax.numpy as jnp
n = 16
a = dq.destroy(n)
H = a.dag() @ a
psi0 = dq.coherent(n, 1.0)
tsave = jnp.linspace(0, 1.0, 11)
result = dq.sesolve(H, psi0, tsave)
print(result)
|██████████| 100.0% ◆ elapsed 1.50ms ◆ remaining 0.00ms
==== SESolveResult ====
Method : Tsit5
Infos : 11 steps (11 accepted, 0 rejected)
States : QArray complex64 (11, 16, 1) | 1.4 Kb
Advanced use-cases
Defining a time-dependent Hamiltonian
If the Hamiltonian depends on time, it can be converted to a timeqarray using
dq.pwc(), dq.modulated(), or
dq.timecallable(). See the
Time-dependent operators
tutorial for more details.
Running multiple simulations concurrently
Both the Hamiltonian H and the initial state psi0 can be batched to
solve multiple Schrödinger 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 and psi0. The behaviour depends on the
value of the cartesian_batching option.
The results leading dimensions are
... = ...H, ...psi0
Hhas shape (2, 3, n, n),psi0has shape (4, n, 1),
then result.states has shape (2, 3, 4, ntsave, n, 1).
The results leading dimensions are
... = ...H = ...psi0 # (once broadcasted)
Hhas shape (2, 3, n, n),psi0has shape (3, n, 1),
then result.states has shape (2, 3, ntsave, n, 1).
See the Batching simulations tutorial for more details.