wavepacket.expression

Classes that wrap operators into expressions for use in partial differential equations.

Classes

ExpressionBase

Base class for expressions.

ExpressionSum

Sum of multiple expressions.

CommutatorLiouvillian

Represents a commutator expression in a Liouville von-Neumann equation.

OneSidedLiouvillian

An expression that simply applies an operator from the left or right of a density operator.

SchroedingerEquation

Expression wrapper for a Schrödinger equation.

Package Contents

class wavepacket.expression.ExpressionBase(time_dependent: bool)

Bases: abc.ABC

Base class for expressions.

By deriving from this class and implementing the method ExpressionBase.apply(), you can add custom expressions.

Parameters:
time_dependent: bool

Sets whether the expression is time-dependent or not.

Attributes:
time_dependent: bool, readonly

If the expression is time-dependent or not.

Some functionality, for example special solvers, may require time-independent expressions. This property typically evaluates the time-dependence of the underlying operator(s).

Notes

All differential equations have the form \dot \rho = \mathcal{L}(\rho) (or equivalently \dot \psi = \hat H \psi), that is, the left-hand side is just the time derivative. This matches the common convention for the Liouville von-Neumann equation, but differs from the usual form of the Schrödinger equation, where the imaginary factor is on the left-hand side of the equation.

time_dependent: Final[bool]
abstractmethod apply(state: wavepacket.grid.State, t: float) wavepacket.grid.State

Applies the expression to the input state and returns the result.

Parameters:
statewp.grid.State

The state on which the expression is applied.

tfloat

The time at which the expression is evaluated. Only really needed for time-dependent expressions, but to keep the interface uniform, this parameter is required.

Raises:
wp.BadGridError

If the grids of the state and the wrapped operator do not match.

wp.BadStateError

If the state is invalid or has the wrong time. For example, a Schrödinger equation makes little sense for a density operator.

class wavepacket.expression.ExpressionSum(expressions: Iterable[ExpressionBase])

Bases: ExpressionBase

Sum of multiple expressions.

You should rarely construct this class directly. It is created implicitly if you sum two or more expressions. Note that it is perfectly possible to construct an invalid sum, for example, by adding a SchroedingerEquation to some Liouvillian; the result will not accept any state without exceptions.

Parameters:
expressionsIterable[wp.operator.ExpressionBase]

The expressions that should be summed up.

Raises:
wp.InvalidValueError

if the list of expressions is empty.

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

Applies the expression to the input state and returns the result.

Parameters:
statewp.grid.State

The state on which the expression is applied.

tfloat

The time at which the expression is evaluated. Only really needed for time-dependent expressions, but to keep the interface uniform, this parameter is required.

Raises:
wp.BadGridError

If the grids of the state and the wrapped operator do not match.

wp.BadStateError

If the state is invalid or has the wrong time. For example, a Schrödinger equation makes little sense for a density operator.

class wavepacket.expression.CommutatorLiouvillian(op: wavepacket.operator.OperatorBase)

Bases: wavepacket.expression.expressionbase.ExpressionBase

Represents a commutator expression in a Liouville von-Neumann equation.

Given an operator H, this commutator expression is given by \mathcal{L}(\hat \rho) = -\imath (\hat H \hat \rho - \hat \rho \hat H).

Parameters:
opwp.operator.OperatorBase

The operator to commute with the density operator.

Notes

The extra factor of -i is added to ensure that the commutator can be directly plugged into a Liouville von-Neumann equation. defined as \frac{\partial \hat \rho}{\partial t} = \mathcal{L}(\hat \rho). If you need the raw commutator, you have to multiply the result with the imaginary number.

apply(rho: wavepacket.grid.State, t: float) wavepacket.grid.State

Applies the expression to the input state and returns the result.

Parameters:
statewp.grid.State

The state on which the expression is applied.

tfloat

The time at which the expression is evaluated. Only really needed for time-dependent expressions, but to keep the interface uniform, this parameter is required.

Raises:
wp.BadGridError

If the grids of the state and the wrapped operator do not match.

wp.BadStateError

If the state is invalid or has the wrong time. For example, a Schrödinger equation makes little sense for a density operator.

class wavepacket.expression.OneSidedLiouvillian(op: wavepacket.operator.OperatorBase, side: Side = Side.LEFT)

Bases: wavepacket.expression.expressionbase.ExpressionBase

An expression that simply applies an operator from the left or right of a density operator.

This operator is basically the same as the wp.expression.SchroedingerEquation but applies the operator onto a density operator, and it lacks the factor of “-1j”.

This expression is found occasionally in the context of open quantum systems or when relaxing a density operator to a thermal state.

Parameters:
opwp.operator.OperatorBase

The operator to apply with the density operator.

side: wp.expression.OneSidedLiouvillian.Side

If the operator should be applied from the LEFT or RIGHT of the density operator.

class Side(*args, **kwds)

Bases: enum.Enum

Create a collection of name/value pairs.

Example enumeration:

>>> class Color(Enum):
...     RED = 1
...     BLUE = 2
...     GREEN = 3

Access them by:

  • attribute access:

    >>> Color.RED
    <Color.RED: 1>
    
  • value lookup:

    >>> Color(1)
    <Color.RED: 1>
    
  • name lookup:

    >>> Color['RED']
    <Color.RED: 1>
    

Enumerations can be iterated over, and know how many members they have:

>>> len(Color)
3
>>> list(Color)
[<Color.RED: 1>, <Color.BLUE: 2>, <Color.GREEN: 3>]

Methods can be added to enumerations, and members can have their own attributes – see the documentation for details.

LEFT = 0
RIGHT = 1
apply(rho: wavepacket.grid.State, t: float) wavepacket.grid.State

Applies the expression to the input state and returns the result.

Parameters:
statewp.grid.State

The state on which the expression is applied.

tfloat

The time at which the expression is evaluated. Only really needed for time-dependent expressions, but to keep the interface uniform, this parameter is required.

Raises:
wp.BadGridError

If the grids of the state and the wrapped operator do not match.

wp.BadStateError

If the state is invalid or has the wrong time. For example, a Schrödinger equation makes little sense for a density operator.

class wavepacket.expression.SchroedingerEquation(hamiltonian: wavepacket.operator.OperatorBase)

Bases: wavepacket.expression.expressionbase.ExpressionBase

Expression wrapper for a Schrödinger equation.

You should wrap a Hamiltonian in an object of this type so that the solvers can subsequently solve the resulting equation.

Parameters:
hamiltonianwp.operator.OperatorBase

The Hamiltonian that is wrapped by this class.

Notes

The Schrödinger equation is given by \dot \psi = -\imath \hat H \psi, so this class only multiplies the wave function with the negative imaginary number, and wraps the input Hamiltonian into an expression so that solvers can work with it.

apply(psi: wavepacket.grid.State, t: float) wavepacket.grid.State

Applies the expression to the input state and returns the result.

Parameters:
statewp.grid.State

The state on which the expression is applied.

tfloat

The time at which the expression is evaluated. Only really needed for time-dependent expressions, but to keep the interface uniform, this parameter is required.

Raises:
wp.BadGridError

If the grids of the state and the wrapped operator do not match.

wp.BadStateError

If the state is invalid or has the wrong time. For example, a Schrödinger equation makes little sense for a density operator.