Skip to main content

PropagationSolver

PropagationSolver(
    system=None,
    t_min=0.0,
    t_max=1.0,
    t_steps=100,
    method='mesolve',
    opts=None,
    savefile=None,
    z_min=0.0,
    z_max=1.0,
    z_steps=10,
    z_steps_inner=2,
    num_density_z_func=None,
    num_density_z_args=None,
    interaction_strengths=None,
    velocity_classes=None,
    *,
    atom=None,
    real_drive=False,
)

Solver for the propagation of fields through a medium of systems.

Steps the fields through space with a finite-difference method, solving the Lindblad master equation for the :class:~clerq.system.System at each step (once per velocity class if the medium is Doppler broadened).

Parameters

Name Type Description Default
system dict | None Dict (or empty dict for defaults) describing the quantum system; passed to :class:~clerq.system.System. None
t_min float Start time of the simulation. 0.0
t_max float End time of the simulation. 1.0
t_steps int Number of time steps. 100
method str Solver method — 'mesolve' (Lindblad master equation) is the only supported value. 'mesolve'
opts dict | None Dict of QuTiP solver options. None
savefile str | None Path prefix for caching solved results ('.qu' extension appended automatically). Pass None to disable caching. None
z_min float The front of the medium. 0.0
z_max float The back of the medium. 1.0
z_steps int Number of space steps at which the solution is recorded. 10
z_steps_inner int | str Number of finite-difference steps made within each space step. Pass "auto" to start from 2 and let solve() raise it until the estimated step error is below step_error_warn (see :meth:solve). 2
num_density_z_func str | None Name of a function in clerq.t_funcs giving the number density profile over z. Square by default. None
num_density_z_args dict | None Dict of arguments for num_density_z_func. None
interaction_strengths list[float] | None Interaction strength of each field with the medium, one for each field. None
velocity_classes dict | None Dict defining the velocity classes for Doppler broadening, or None for no broadening. thermal_width and the thermal_delta_* values are cyclic frequencies, in the same units as decays rates and rabi_freq. Instead of thermal_delta_steps the classes can be given a maximum spacing thermal_delta_spacing (new in 0.15.0), or "auto" for the largest spacing whose spurious Doppler echoes fall outside the time window or are damped by the decay below thermal_delta_echo_tolerance (see thermal_delta_auto_spacing()). The density of the classes is Gaussian, exp(-(delta / thermal_width)**2) (thermal_weights); each class is weighted by this times the detuning interval it represents (thermal_widths). None
atom dict | None Deprecated name for system. None
real_drive bool Deprecated. Drive the Hamiltonian with Re(Omega) only, the behaviour before the complex-envelope drive. That is exact for resonant problems with real fields and a symmetric, equally weighted velocity-class grid, but wrong for a single detuned field (for example a two-level medium, optical depth 6, half-width detuning 2: transmission 1.1 instead of 0.30). The default drives the coupled pair with Omega and conj(Omega). False

Attributes

Name Description
rabi_freqs_zt The solved complex Rabi frequency of each field, as a cyclic frequency.
thermal_quadrature_weights Weight of each velocity class in the Doppler average.

Methods

Name Description
build_velocity_classes Build the velocity-class detuning grid and Boltzmann weights.
build_zlist Builds the space grid.
check Validates the PropagationSolver object.
coherences Gets the sum of coherences (off-diagonals) in a list of coupled
coherences_field Get the sum of coherences (off-diagonals) for the levels coupled by
fields_area Gets the integrated pulse area of each field.
get_json_dict Return the full problem definition as a JSON-serialisable dict.
init_Omegas_zt Inits the Rabi frequency array.
init_states_zt Inits the system density matrices.
load_results Loads the solution from a QuTiP pickle file.
mbsolve Deprecated name for :meth:PropagationSolver.solve.
mbsolve_ab Deprecated; use :meth:PropagationSolver.solve with step="ab".
mbsolve_euler Deprecated; use :meth:PropagationSolver.solve with step="euler".
populations Gets the sum of populations in a list of levels.
populations_field Gets the sum of populations for the upper (excited) level coupled by
save_results Saves the solution to a QuTiP pickle file.
solve Solves the propagation of the fields through the medium.
suggest_t_steps Estimate the t_steps needed to resolve the problem’s frequencies.
thermal_delta_auto_spacing Largest cyclic class spacing that is free of Doppler echoes and
to_autodiff Return a differentiable version of this problem.
z_step Returns the distance from one space point to the next.
z_step_inner Returns the distance from one inner space point to the next.

build_velocity_classes

PropagationSolver.build_velocity_classes(velocity_classes=None)

Build the velocity-class detuning grid and Boltzmann weights.

Parameters

Name Type Description Default
velocity_classes dict | None dict of velocity-class parameters, or None for the no-Doppler-broadening case (single detuning class at 0). None

Returns

Name Type Description
tuple[np.ndarray, np.ndarray] (thermal_delta_list, thermal_weights)

build_zlist

PropagationSolver.build_zlist(z_min, z_max, z_steps, z_steps_inner)

Builds the space grid.

Parameters

Name Type Description Default
z_min float The front of the medium, in your chosen length unit. required
z_max float The back of the medium. required
z_steps int The number of even-spaced steps on which to solve and record the solution. required
z_steps_inner int Between each z_step, make this many inner steps of the finite-difference solver (for numerical stability). required

Notes

  • If the problem requires a lot of space steps for stability, but you don’t need to record the solution at such a high-level of resolution, increase z_steps_inner.

check

PropagationSolver.check()

Validates the PropagationSolver object.

coherences

PropagationSolver.coherences(coupled_levels)

Gets the sum of coherences (off-diagonals) in a list of coupled level pairs.

Parameters

Name Type Description Default
coupled_levels list[list[int]] a list of pairs of level indexes required

Returns

Name Type Description
np.ndarray np.array, shape (z_steps+1, t_steps+1), dtype=complex

Note

Unlike System.get_fields_sum_coherence, which operates on a single-z time series with per-field weighting factors, this method sums over the full (z, t) array with unit weights.

coherences_field

PropagationSolver.coherences_field(field_idx)

Get the sum of coherences (off-diagonals) for the levels coupled by a field.

Parameters

Name Type Description Default
field_idx int index in the list of fields required

Returns: np.array, shape (z_steps+1, t_steps+1), dtype=complex

fields_area

PropagationSolver.fields_area()

Gets the integrated pulse area of each field.

Returns

Name Type Description
np.ndarray np.array [num_fields, num_z_steps]: Integrated area of each field
np.ndarray over time

get_json_dict

PropagationSolver.get_json_dict()

Return the full problem definition as a JSON-serialisable dict.

init_Omegas_zt

PropagationSolver.init_Omegas_zt()

Inits the Rabi frequency array.

_Omegas_zt is the internal angular-frequency field array; rabi_freqs_zt is its public cyclic view.

_Omegas_zt shape: (num_fields, z_steps+1, t_steps+1) — field-first. states_zt shape: (z_steps+1, t_steps+1, num_states, num_states) — z-first. These are inconsistent; correcting either is a breaking API change, deferred to a future major version.

init_states_zt

PropagationSolver.init_states_zt()

Inits the system density matrices.

load_results

PropagationSolver.load_results()

Loads the solution from a QuTiP pickle file.

Raises

Name Type Description
ValueError if the savefile was built from a different problem definition (hash mismatch), or was solved with the old factor**2 source-term weights and a field has factors other than 1, or was solved with velocity-class weights that ignored the class spacing on a non-uniform grid, or was solved with the other drive convention (savefiles without a drive marker used Re(Omega)) for a problem where the two differ (static detunings, level energies or an asymmetric class grid).

Notes

  • The path from which the results will be loaded is taken from self.savefile.
  • Old savefiles without metadata are loaded without integrity checking, with a warning, unless a field has factors other than 1 (see Raises).

mbsolve

PropagationSolver.mbsolve(*args, **kwargs)

Deprecated name for :meth:PropagationSolver.solve.

mbsolve_ab

PropagationSolver.mbsolve_ab(*args, **kwargs)

Deprecated; use :meth:PropagationSolver.solve with step="ab".

mbsolve_euler

PropagationSolver.mbsolve_euler(*args, **kwargs)

Deprecated; use :meth:PropagationSolver.solve with step="euler".

populations

PropagationSolver.populations(levels)

Gets the sum of populations in a list of levels.

Parameters

Name Type Description Default
levels list[int] a list of level indexes] required

Returns

Name Type Description
np.ndarray np.array, shape (z_steps+1, t_steps+1), dtype=np.real

populations_field

PropagationSolver.populations_field(field_idx, upper=True)

Gets the sum of populations for the upper (excited) level coupled by a field.

Parameters

Name Type Description Default
field_idx int index in the list of fields required

Returns

Name Type Description
np.ndarray np.array, shape (z_steps+1, t_steps+1), dtype=np.real

Note

  • Casting upper to int so upper is 1, lower is 0.

save_results

PropagationSolver.save_results()

Saves the solution to a QuTiP pickle file.

Notes

  • The path to which the results will be saved is taken from self.savefile.

solve

PropagationSolver.solve(
    step='ab',
    rho0=None,
    recalc=True,
    progress=True,
    progress_show_area=False,
    check_counter_prop_depletion=True,
    depletion_warn=0.01,
    depletion_error=0.1,
    check_stability=True,
    blowup_factor=1000.0,
    step_error_warn=0.1,
    max_z_steps_inner=512,
    t_step_error_warn=0.1,
    window_edge_warn=0.2,
    window_edge_frac=0.05,
)

Solves the propagation of the fields through the medium.

Parameters

Name Type Description Default
step str ‘euler (for Euler method) or ’ab’ (for Adams-Bashforth) 'ab'
rho0 Qobj the initial density matrix state None
recalc bool Recalculate the solution even if a savefile exists? True
progress bool Show a tqdm progress bar with elapsed time, ETA and current max field amplitude. True
progress_show_area bool Extend the progress bar with the pulse area ∫|Ω|dt for each field at the current z-step. Requires progress=True. False
check_counter_prop_depletion bool Run a post-solve depletion check on any counter-propagating fields. Set False to suppress. True
depletion_warn float Depletion fraction that triggers a UserWarning. 0.01
depletion_error float Depletion fraction that raises CounterPropagatingDepletionError. 0.1
check_stability bool Stop with :class:PropagationInstabilityError as soon as the solution blows up (non-finite field, field larger than blowup_factor times its initial peak, or a failed master-equation integration), and warn if the z-step looks too coarse. Set False to suppress. True
blowup_factor float Growth of the peak field, relative to its peak at z_min, treated as a blow-up. Raise it for media with genuine gain. 1000.0
step_error_warn float Estimated accumulated relative error (from the differences of dOmega/dz between z-steps, relative to the peak field) above which a UserWarning is issued suggesting a larger z_steps_inner. The largest value seen is kept in self.step_error_estimate. With z_steps_inner="auto" this is also the tolerance: the solve is repeated with more inner steps until the estimate is below it, or max_z_steps_inner is reached. 0.1
max_z_steps_inner int Upper limit for z_steps_inner="auto". 512
t_step_error_warn float With check_stability, warn if the time grid is too coarse to represent the fields and coherences: the relative error (to the peak) of interpolating them from every other time sample, self.t_step_error_estimate, exceeds this. The error of the full grid is smaller, by about a factor of 16 once the grid resolves the signal (a cubic spline), and by less on a coarser grid. 0.1
window_edge_warn float With check_stability, warn if a field is still changing near the edge of the time window (the first or last 5% of it) by more than this fraction of its peak, so that a pulse or its ringing is probably cut off. Kept in self.window_edge_estimate. 0.2
window_edge_frac float Fraction of the time window at each end that window_edge_warn looks at. Reduce it if the window deliberately starts or ends in the middle of a pulse. 0.05

Returns

Name Type Description
Omegas_zt np.ndarray The solved field complex Rabi frequency at each point in space z and time t, as an angular frequency (rabi_freqs_zt times 2 * pi).
np.ndarray self.states_zt: The solved density matrix at each point in space z and time t.

suggest_t_steps

PropagationSolver.suggest_t_steps(
    points_per_period=10.0,
    bandwidth_fraction=0.99,
)

Estimate the t_steps needed to resolve the problem’s frequencies.

Finds the largest frequency scale (cyclic, in the units of the problem) and returns enough steps over [t_min, t_max] for points_per_period samples per period of it. The scales are the bandwidth of the input fields (bandwidth_fraction of their power), their peak Rabi frequencies combined with the detunings and the Doppler width.

This is an estimate from the input fields: the medium can add structure (sidebands, ringing), so check the solved result too; solve() warns if the grid turns out to be too coarse.

Parameters

Name Type Description Default
points_per_period float Time samples per period of the fastest scale. 10.0
bandwidth_fraction float Fraction of an input field’s spectral power that its bandwidth must contain. Lower it for sharp-edged pulses, whose slowly decaying tails would otherwise dominate. 0.99

Returns

Name Type Description
int The suggested number of time steps; compare it with t_steps.

thermal_delta_auto_spacing

PropagationSolver.thermal_delta_auto_spacing(tolerance=None)

Largest cyclic class spacing that is free of Doppler echoes and resolves the thermal distribution.

Sampling the detuning at spacing h makes the summed response repeat at t = 1 / h. A coherence between levels i and j oscillates at b * Delta, where b is the difference of the two levels’ Doppler slopes (1 for a single co-propagating field; see System.level_doppler_slopes), so its echo is at t = 1 / (b h). Per pair of levels, the spacing is the larger of:

  • the one that puts the echo outside the time window: THERMAL_ECHO_MARGIN / (T * b), with T = t_max - t_min;
  • the one that damps the echo, at decay rate g of the coherence (System.level_decay_rates), below tolerance: g / (b * ln(1 / tolerance)).

The echo spacing is the smallest over all pairs of levels whose slopes differ; if none do, the window rule is used with b = 1. The result is also capped at pi * thermal_width / sqrt(ln(1 / tolerance)), below which the sum of the Gaussian weights is correct to tolerance. Without that cap a fast decay and a narrow thermal width would give a grid coarser than the distribution itself.

Parameters

Name Type Description Default
tolerance float | None largest echo amplitude allowed inside the window, as a fraction of the coherence. Default THERMAL_ECHO_TOLERANCE. None

Returns

Name Type Description
float The spacing, a cyclic frequency.

.. versionadded:: 0.15.0

to_autodiff

PropagationSolver.to_autodiff(**options)

Return a differentiable version of this problem.

.. versionadded:: 0.14.0

The result reproduces :meth:solve as a pure function of a parameter pytree (pulse parameters, interaction strengths, detunings, decay scale, or sampled input fields), so the propagated field and any loss of it can be differentiated exactly with JAX autodiff. Requires the jax extra (pip install 'clerq[jax]') and jax_enable_x64.

Parameters

Name Type Description Default
**options Any forwarded to :class:clerq.autodiff.AutodiffPropagation (step, strategy, rtol, atol, max_steps, …). {}

Returns

Name Type Description
Any The differentiable problem, an AutodiffPropagation.

Raises

Name Type Description
ImportError if the jax extra is not installed.
NotImplementedError for counter-propagating fields or pulse functions the autodiff backend does not support.

Examples

>>> ad = solver.to_autodiff()
>>> value, grads = ad.value_and_grad(loss)

z_step

PropagationSolver.z_step()

Returns the distance from one space point to the next.

z_step_inner

PropagationSolver.z_step_inner()

Returns the distance from one inner space point to the next.