wavepacket.testing
Utility classes and functions for writing Wavepacket tests.
Classes
Empty DOF without transformations. |
|
Empty operator that throws when it is applied. |
Functions
|
Assertion helper: Verify that two states are on the same grid and similar to each other. |
|
Creates a random wave function. |
Package Contents
- wavepacket.testing.assert_close(actual: wavepacket.grid.State, expected: wavepacket.grid.State, diff: float = 0) None
Assertion helper: Verify that two states are on the same grid and similar to each other.
- Parameters:
- actualwp.grid.State
The expected state
- expectedwp.grid.State
The state to be tested.
- difffloat
The maximum absolute difference between any coefficients of the two states.
- class wavepacket.testing.DummyDof(dvr_array: wavepacket.typing.RealData, fbr_array: wavepacket.typing.RealData)
Bases:
wavepacket.grid.DofBaseEmpty DOF without transformations.
- from_fbr(data: wavepacket.typing.ComplexData, index: int, is_ket: bool = True) wavepacket.typing.ComplexData
Translates a dimension of the input coefficients from the FBR into the Wavepacket-default “weighted DVR”
This function is not meant for public use. It does not handle errors explicitly, and is just awkward to use; you need to reach through the state abstraction and transform each index correctly.
- Parameters:
- datawp.typing.ComplexData
The input coefficients of the state to transform.
- indexint
The index of the coefficient array that should be transformed.
- is_ketbool, default=True
If the index is the coefficient for a ket state (True) or a bra state.
- Returns:
- wpt.ComplexData
The appropriately transformed coefficients. You generally need to wrap the result in a
wavepacket.grid.Statebefore further use.
- to_dvr(data: wavepacket.typing.ComplexData, index: int) wavepacket.typing.ComplexData
Translates a dimension of the input coefficients from the Wavepacket-default “weighted DVR” into the DVR.
This function is not meant for public use. It does not handle errors explicitly, and is just awkward to use; you need to reach through the state abstraction and transform each index correctly.
- Parameters:
- datawp.typing.ComplexData
The input coefficients of the state to transform.
- indexint
The index of the coefficient array that should be transformed.
- Returns:
- wpt.ComplexData
The appropriately transformed coefficients. You will generally not wrap the results into a
wavepacket.grid.State, because that class implicitly assumes a weighted DVR transformation.
- from_dvr(data: wavepacket.typing.ComplexData, index: int) wavepacket.typing.ComplexData
Translates a dimension of the input coefficients from the DVR into the Wavepacket-default “weighted DVR”.
This function is not meant for public use. It does not handle errors explicitly, and is just awkward to use; you need to reach through the state abstraction and transform each index correctly.
- Parameters:
- datawp.typing.ComplexData
The input coefficients of the state to transform.
- indexint
The index of the coefficient array that should be transformed.
- Returns:
- wpt.ComplexData
The appropriately transformed coefficients. They need to be wrapped in a
wavepacket.grid.Statebefore further use.
- to_fbr(data: wavepacket.typing.ComplexData, index: int, is_ket: bool = True) wavepacket.typing.ComplexData
Translates a dimension of the input coefficients from the Wavepacket-default “weighted DVR” into the FBR.
This function is not meant for public use. It does not handle errors explicitly, and is just awkward to use; you need to reach through the state abstraction and transform each index correctly.
- Parameters:
- datawp.typing.ComplexData
The input coefficients of the state to transform.
- indexint
The index of the coefficient array that should be transformed.
- is_ketbool, default=True
If the index is the coefficient for a ket state (True) or a bra state.
- Returns:
- wpt.ComplexData
The appropriately transformed coefficients. You will generally not wrap the results into a
wavepacket.grid.State, because that class implicitly assumes a weighted DVR transformation.
- class wavepacket.testing.DummyOperator(grid: wavepacket.grid.Grid)
Bases:
wavepacket.operator.OperatorBaseEmpty operator that throws when it is applied.
Used for testing where we need an operator, but do not get as far as actually doing something.
- apply_to_wave_function(psi: wavepacket.typing.ComplexData, t: float) wavepacket.typing.ComplexData
Applies the operator on a wave function.
This function is mainly for Wavepacket-internal use. It ignores most error handling (usually done by the wrapping
wavepacket.expression.ExpressionBase), and operates directly on coefficients to avoid the creation of temporary states.- Parameters:
- psiwpt.ComplexData
The coefficients describing the wave function on which the operator acts.
- tfloat
The time at which the operator should be evaluated. Only really needed for time-dependent operators, but to keep the interface uniform, this parameter is required.
- Returns:
- wpt.ComplexData
The coefficients of the resulting wave function.
- apply_from_left(rho: wavepacket.typing.ComplexData, t: float) wavepacket.typing.ComplexData
Applies the operator on a density operator from the left.
This function is mainly for Wavepacket-internal use. It ignores most error handling (usually done by the wrapping
wavepacket.expression.ExpressionBase), and operates directly on coefficients to avoid the creation of temporary states.- Parameters:
- rhowpt.ComplexData
The coefficients describing the density operator on which the operator acts.
- tfloat
The time at which the operator should be evaluated. Only really needed for time-dependent operators, but to keep the interface uniform, this parameter is required.
- Returns:
- wpt.ComplexData
The coefficients of the resulting density operator.
- apply_from_right(rho: wavepacket.typing.ComplexData, t: float) wavepacket.typing.ComplexData
Applies the operator on a density operator from the right.
This function is mainly for Wavepacket-internal use. It ignores most error handling (usually done by the wrapping
wavepacket.expression.ExpressionBase), and operates directly on coefficients to avoid the creation of temporary states.- Parameters:
- rhowpt.ComplexData
The coefficients describing the density operator on which the operator acts.
- tfloat
The time at which the operator should be evaluated. Only really needed for time-dependent operators, but to keep the interface uniform, this parameter is required.
- Returns:
- wpt.ComplexData
The coefficients of the resulting density operator.
- wavepacket.testing.random_state(grid: wavepacket.grid.Grid, seed: int) wavepacket.grid.State
Creates a random wave function.
Note that this function does not employ high-quality randomization, it is only meant to create states without accidental symmetries or lots of code.