mirror of
https://github.com/vale981/master-thesis
synced 2025-03-09 20:56:40 -04:00
34 lines
1.1 KiB
Python
34 lines
1.1 KiB
Python
|
"""Utilities for the energy flow calculation."""
|
||
|
import numpy as np
|
||
|
|
||
|
|
||
|
def apply_operator(ψ: np.ndarray, op: np.ndarray) -> np.ndarray:
|
||
|
"""
|
||
|
Applies the operator ``op`` to each element of the time series
|
||
|
ψ of the dimensions ``(*, dim)`` where ``dim`` is the hilbert
|
||
|
space dimension.
|
||
|
"""
|
||
|
|
||
|
return np.array((op @ ψ.T).T)
|
||
|
|
||
|
|
||
|
def mulitply_hierarchy(left: np.ndarray, right: np.ndarray) -> np.ndarray:
|
||
|
"""Multiply each hierarchy member with a member of ``left`` for each time step.
|
||
|
|
||
|
:param left: array of shape ``(hierarchy-width,)``
|
||
|
:param right: array of shape ``(time-steps, hierarchy-width, system-dimension)``
|
||
|
"""
|
||
|
|
||
|
return left[None, :, None] * right
|
||
|
|
||
|
|
||
|
def dot_with_hierarchy(left: np.ndarray, right: np.ndarray) -> np.ndarray:
|
||
|
r"""Calculates $\sum_k \langle\mathrm{left} | \right^{(e_k)}$ for
|
||
|
each time step.
|
||
|
|
||
|
:param left: array of shape ``(time-steps, system-dimension, hierarchy-width,)``
|
||
|
:param right: array of shape ``(time-steps, hierarchy-width, system-dimension)``
|
||
|
"""
|
||
|
|
||
|
return np.sum(left[:, None, :] * right, axis=(1, 2)).real
|