Projectors#
- class Projectors(Plist, Pstruct, force_general=False)[source]#
Bases:
objectClass to handle sparse shared projectors.
- Parameters:
Plist (Sequence[ArrayLike]) – List of sparse projector matrices.
Pstruct (sp.csr_array) – Sparsity structure of the projectors.
force_general (bool, optional) – If true, treat all projectors as general sparse matrices even if diagonal.
Methods Summary
allP_at_v(v[, dagger])Compute all P_j @ v (or P_j^† @ v) and return an (n, k) matrix.
append(Pnew)Append a new projector.
Remove the first m projection matrices.
Extract all sparse P_j entries according to Pstruct.
Return True if all projectors are diagonal.
set_Pdata_column_stack(Pdata)Set projectors from column-stacked sparse entries.
Check if P is a valid projector (correct shape, subset of Pstruct).
weighted_sum_on_vector(v, weights[, dagger])Compute Σ_j weights[j] * P_j^(†) @ v efficiently without forming Σ_j P_j.
Methods Documentation
- allP_at_v(v, dagger=False)[source]#
Compute all P_j @ v (or P_j^† @ v) and return an (n, k) matrix.
Returns a matrix whose j-th column is P_j v (dagger=False) or P_j^† v (dagger=True). For diagonal projectors, dagger reduces to conjugation:
allP_at_v(v, dagger=True) == (Pdiags.conj().T * v).T (shape (n, k)).
- Parameters:
v (ndarray[tuple[int, ...], dtype[complexfloating]])
dagger (bool)
- Return type:
ndarray[tuple[int, …], dtype[complexfloating]]
- append(Pnew)[source]#
Append a new projector.
- Parameters:
Pnew (_Buffer | _SupportsArray[dtype[Any]] | _NestedSequence[_SupportsArray[dtype[Any]]] | bool | int | float | complex | str | bytes | _NestedSequence[bool | int | float | complex | str | bytes])
- Return type:
None
- erase_leading(m)[source]#
Remove the first m projection matrices.
- Parameters:
m (int)
- Return type:
None
- get_Pdata_column_stack()[source]#
Extract all sparse P_j entries according to Pstruct.
Orders as columns of a (nnz,k) matrix. Returns a matrix whose j-th column is P_j[Pstruct]
- Return type:
ndarray[tuple[int, …], dtype[complexfloating]]
- set_Pdata_column_stack(Pdata)[source]#
Set projectors from column-stacked sparse entries.
Use columns of Pdata as the sparse entries of each P_j with the current Pstruct.
- Parameters:
Pdata (ndarray[tuple[int, ...], dtype[complexfloating]] | sparray)
- Return type:
None
- validate_projector(P)[source]#
Check if P is a valid projector (correct shape, subset of Pstruct).
- Parameters:
P (csr_array)
- Return type:
bool
- weighted_sum_on_vector(v, weights, dagger=False)[source]#
Compute Σ_j weights[j] * P_j^(†) @ v efficiently without forming Σ_j P_j.
# Returns a vector of shape (n,).
- Parameters:
v (ndarray[tuple[int, ...], dtype[complexfloating]])
weights (ndarray[tuple[int, ...], dtype[float64]])
dagger (bool)
- Return type:
ndarray[tuple[int, …], dtype[complexfloating]]