master-thesis/python/energy_flow_proper/hopsflow/util.py

34 lines
1.1 KiB
Python
Raw Normal View History

2021-11-04 15:33:08 +01:00
"""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