Skip to content

torch_vn_algebra.hilbert_space

Source: torch_vn_algebra/hilbert_space.py. Signatures and docstrings as in the source.

HilbertSpace

class HilbertSpace(n: int, k: int, batch_size: int=1, n_channels: int=1, complex_valued: bool=True, device: Optional[torch.device]=None, precision: str='single')
Hilbert space H of dimension n with a distinguished k-dimensional subspace H0.

The space has a direct sum decomposition over n_channels factors (central decomposition
of the von Neumann algebra). Vectors have shape (batch, n_channels, n, 1).
Norm is defined as sqrt( sum_{c=1}^{n_channels} sum_{i=1}^{n} |ψ_{c,i}|^2 ).

Attributes:
    n: Ambient dimension (size of each factor space)
    k: Subspace dimension (support of the algebra, same for all channels)
    batch_size: Batch dimension
    n_channels: Number of factors in the direct sum
    complex_valued: bool
    device: torch.device
    dtype: torch.dtype

HilbertSpace.dim

@property
def dim(self) -> int

HilbertSpace.subspace_dim

@property
def subspace_dim(self) -> int

HilbertSpace.shape_ambient

@property
def shape_ambient(self) -> Tuple[int, int, int, int]

HilbertSpace.shape_ket

@property
def shape_ket(self) -> Tuple[int, int, int, int]

HilbertSpace.shape_bra

@property
def shape_bra(self) -> Tuple[int, int, int, int]

HilbertSpace.inner_product

def inner_product(self, bra: torch.Tensor, ket: torch.Tensor, bra_is_row: Optional[bool]=None) -> torch.Tensor
Global inner product <psi|phi>, summed over channels and components; returns (batch, 1, 1, 1).
`bra` is either a bra row (batch, C, 1, n), already conjugated (as returned by Basis.bra), or a
ket column (batch, C, n, 1) / flat vector (batch, C, n), which is conjugated here.
`ket` is a ket column (batch, C, n, 1) or a flat vector (batch, C, n).
For n = 1 a row and a column have the same shape (batch, C, 1, 1); in a complex space pass
bra_is_row=True (already conjugated) or False (conjugate it) to say which one is meant.

HilbertSpace.norm

def norm(self, ket: torch.Tensor) -> torch.Tensor
Global norm: sqrt( sum_c sum_i |ψ_{c,i}|^2 ).
Returns (batch, 1, 1, 1).

HilbertSpace.normalize

def normalize(self, ket: torch.Tensor, eps: float=1e-12) -> torch.Tensor
Normalize ket to unit global norm.

HilbertSpace.Basis

class Basis(parent: 'HilbertSpace', V: Optional[torch.Tensor]=None, initialization: str='random')
Orthonormal basis for the k-dimensional subspace H0.

The basis matrix V has shape (batch, n_channels, n, k). Each channel may have
its own orthonormal basis (columns orthonormal per channel).

HilbertSpace.Basis.projection

@property
def projection(self) -> torch.Tensor

HilbertSpace.Basis.restriction

@property
def restriction(self) -> torch.Tensor

HilbertSpace.Basis.embed_vector

def embed_vector(self, v_sub: torch.Tensor) -> torch.Tensor
Embed vector from subspace coordinates to ambient space.

HilbertSpace.Basis.restrict_vector

def restrict_vector(self, v_amb: torch.Tensor) -> torch.Tensor

HilbertSpace.Basis.embed_operator

def embed_operator(self, A_sub: torch.Tensor) -> torch.Tensor

HilbertSpace.Basis.restrict_operator

def restrict_operator(self, A_amb: torch.Tensor) -> torch.Tensor

HilbertSpace.Basis.ket

def ket(self, idx: int) -> torch.Tensor

HilbertSpace.Basis.bra

def bra(self, idx: int) -> torch.Tensor

HilbertSpace.Basis.outer_product

def outer_product(self, i: int, j: int) -> torch.Tensor

HilbertSpace.Basis.gram_matrix

def gram_matrix(self) -> torch.Tensor

HilbertSpace.Basis.is_orthonormal

def is_orthonormal(self, tol: float=1e-06) -> bool

HilbertSpace.Basis.orthonormalize

def orthonormalize(self)

HilbertSpace.Basis.random_subspace_vector

def random_subspace_vector(self, normalize: bool=True) -> torch.Tensor
Generate a random vector in the subspace (in ambient coordinates).
If normalize=True, the global norm (sum over channels) becomes 1.

HilbertSpace.standard_basis

def standard_basis(self) -> Basis

HilbertSpace.random_basis

def random_basis(self) -> Basis

HilbertSpace.haar_basis

def haar_basis(self) -> Basis

tensor_product_hilbert

def tensor_product_hilbert(spaces: List[HilbertSpace]) -> HilbertSpace

direct_sum_hilbert

def direct_sum_hilbert(spaces: List[HilbertSpace]) -> HilbertSpace