Matrix exponentiation#

Matrix exponential computation.

class TensorFlowExpmBackend[source]#

Bases: ExpmBackend

Compute the matrix exponential using TensorFlow. Tends to be faster than scipy. Note that tensorflow is an optional dependency and thus needs to be installed separately.

Note

Recommended backend for fast and reliable matrix exponentiation.

compute(m: ndarray)[source]#

Compute the matrix exponential using TensorFlow.

Parameters:

m (ndarray) – Matrix.

Return type:

ndarray

Returns:

Matrix exponential

class SciPyExpmBackend(precision: ~typing.Literal['np.float32', 'np.float64'] = <class 'numpy.float64'>)[source]#

Bases: ExpmBackend

Compute the matrix exponential using SciPy.

Note

This is the default backend. Use TensorFlowExpmBackend if performance is an issue.

__init__(precision: ~typing.Literal['np.float32', 'np.float64'] = <class 'numpy.float64'>)[source]#

Initialize the backend.

Parameters:

precision (Literal['np.float32', 'np.float64']) – Precision of the matrix exponential, defaults to double precision. A lower precision is faster but much more prone to numerical issues, so please use with caution.

precision#

Precision of the matrix exponential

compute(m: ndarray)[source]#

Compute the matrix exponential using SciPy.

Parameters:

m (ndarray) – Matrix

Return type:

ndarray

Returns:

Matrix exponential

class JaxExpmBackend(max_squarings: int = 1024)[source]#

Bases: ExpmBackend

Compute the matrix exponential using Jax. This is faster than the other backends but tends to be less precise, so please use with caution. Note that jax is an optional dependency and thus needs to be installed separately.

__init__(max_squarings: int = 1024)[source]#

Initialize the backend.

Parameters:

max_squarings (int) – Maximum number of squarings (see jax.scipy.linalg.expm).

max_squarings#

Maximum number of squarings

compute(m: ndarray)[source]#

Compute the matrix exponential using Jax.

Parameters:

m (ndarray) – Matrix

Return type:

ndarray

Returns:

Matrix exponential

class Backend[source]#

Bases: ABC

Configure the backend for matrix exponentiation.

backend: ExpmBackend = <phasegen.expm.SciPyExpmBackend object>#

Backend for matrix exponentiation

abstract classmethod expm(m: ndarray)[source]#

Compute the matrix exponential.

Return type:

ndarray

classmethod register(backend: ExpmBackend)[source]#

Register a backend.