wavepacket.solver

This module contains classes to solve the equations of motion set up by the classes in the wavepacket.expression module.

Classes

OdeSolver

A solver that uses scipy's ODE integrators as backend.

SolverBase

Abstract base class for all differential equation solvers.

Package Contents

class wavepacket.solver.OdeSolver(expr: wavepacket.expression.ExpressionBase, dt: float, **kwargs)

Bases: wavepacket.solver.solverbase.SolverBase

A solver that uses scipy’s ODE integrators as backend.

This solver merely wraps scipy.integrate.solve_ivp() in a Wavepacket solver. ODESolvers tend to be workhorses that can be applied to most systems without a second thought at the expense of performance. See [1] for more details on the convergence of solvers.

Parameters:
exprwp.expression.ExpressionBase

The right-hand side of the differential equation that encapsulates the quantum system.

dtfloat

The elementary time step for the time evolution.

**kwargs

Additional keyword parameters can be supplied that are directly forwarded to scipy. The most important parameters are “method” (defaults to “RK45”) and “rtol”, “atol” for the relative and absolute error tolerances (booth default to 1e-6).

References

step(state: wavepacket.grid.State, t: float) wavepacket.grid.State

Evolves the given state for one elementary time step.

Given a wave function or density operator at time t, this function should return the propagated wave function or density operator at the new time t+dt, where dt is the elementary time step.

Parameters:
statewp.grid.State

The state to be evolved in time

tfloat

The time at which the time evolution starts

Returns:
wp.grid.State

The state at the new time t+dt.

class wavepacket.solver.SolverBase(dt: float)

Bases: abc.ABC

Abstract base class for all differential equation solvers.

Each solver must take in the constructor the size of an elementary time step, and it must implement a method step() to evolve a state by one elementary time step forward in time.

Usually, a solver does not need to know what step it evolves or how a differential equation looks in detail. The form of the differential equation is encapsulated in a wavepacket.expression.ExpressionBase instance that is usually supplied to the specific implementations.

A solver may, however, implicitly assume properties of the differential equation. It may also take additional arguments, these details are documented in the specific implementations.

Parameters:
dtfloat

The size of an elementary time step.

Attributes:
dt
Raises:
wp.InvalidValueError

If the timestep is not positive.

property dt: float

Returns the size of the elementary time step.

abstractmethod step(state: wavepacket.grid.State, t: float) wavepacket.grid.State

Evolves the given state for one elementary time step.

Given a wave function or density operator at time t, this function should return the propagated wave function or density operator at the new time t+dt, where dt is the elementary time step.

Parameters:
statewp.grid.State

The state to be evolved in time

tfloat

The time at which the time evolution starts

Returns:
wp.grid.State

The state at the new time t+dt.

propagate(state0: wavepacket.grid.State, t0: float, num_steps: int, include_first: bool = True)

Generator function that yields the propagated wave function at multiple time steps.

This function allows you to propagate in one go with a for loop. It repeatedly calls step() and returns the wave function and current time.

Parameters:
state0wp.grid.State

The initial state to be propagated in time.

t0float

The initial time at which the state is given

num_stepsint

For how many elementary time steps the state should be propagated.

include_firstbool

If true, the function will start by yielding the initial state.

Yields:
float

The time at which the state is yielded. Starts optionally with t0 and progresses in units of dt.

wp.grid.State

The propagated state at the given time.

Raises:
wp.InvalidValueError

If num_steps is negative.