index.py
class Basis
Computational basis factory for qudits of local dimension
Calling Basis(d)(k_1,\n\dots,\n k_n) returns the tensor-product basis ket State.
| name | type | default |
|---|---|---|
| d | int | None |
| span | int | -1 |
init
No Definition provided
py
def __init__(self: Any, d: int) -> AnyImplementation
python
def __init__(self, d: int):
self.d = dclass State
Quantum state container backed by a NumPy array.
- Pure state: a 1D normalized vector
with . - Mixed state: a 2D density matrix
with .
Exposes basic operations (dagger, trace, tensor product, projectors).
isDensity
True iff this object is a density matrix
py
def isDensity(self: Any) -> boolImplementation
python
def isDensity(self) -> bool:
return self.ndim == 2isPure
For densities, checks
py
def isPure(self: Any) -> boolImplementation
python
def isPure(self) -> bool:
if not self.isDensity:
return True
tr = np.trace(self ** 2).real
return bool(np.isclose(tr, 1.0))d
Hilbert space dimension (vector length or matrix size).
py
def d(self: Any) -> intImplementation
python
def d(self) -> int:
return int(self.shape[0])norm
Return a re-normalized copy:
py
def norm(self: Any) -> 'State'Implementation
python
def norm(self) -> 'State':
if not self.isDensity:
return State(self / np.linalg.norm(self))
return State(self / self.tr().real)density
Return density operator.
Vector:
py
def density(self: Any) -> 'State'Implementation
python
def density(self) -> 'State':
if not self.isDensity:
return State(np.outer(self, self.conj()))
return selfH
No Definition provided
py
def H(self: Any) -> 'State'Implementation
python
def H(self) -> 'State':
return State(self.conj().T)kron
No Definition provided
py
def kron(self: Any, other: Any) -> 'State'Implementation
python
def kron(self, other: Any) -> 'State':
return State(np.kron(self, other))tr
Vector: returns
py
def tr(self: Any) -> complexImplementation
python
def tr(self) -> complex:
if not self.isDensity:
return complex(np.vdot(self, self))
return complex(np.trace(self))proj
Vector:
py
def proj(self: Any) -> 'State'Implementation
python
def proj(self) -> 'State':
if not self.isDensity:
return self.density()
evals, evecs = LA.eig(self)
matrix: np.ndarray = np.zeros_like(self, dtype=np.complex128)
for i in range(len(evals)):
if np.abs(evals[i]) > 1e-08:
matrix += np.outer(evecs[:, i], evecs[:, i].conj())
return State(matrix)oproj
Orthogonal complement projector:
py
def oproj(self: Any) -> 'State'Implementation
python
def oproj(self) -> 'State':
proj = self.proj()
perp = np.eye(proj.shape[0], dtype=np.complex128) - proj
return State(perp)