Realisation layer¶
realise ¶
Numerical realisation of symbolic models as dense complex128 operators in JAX.
The package provides operator construction, basis ordering, subspace and sector projectors,
exact diagonalisation and time evolution by eigendecomposition. It supports the numerical
validation of the static declarations made along a pipeline by a classical simulation of the
same model at small chain length. Importing the package enables the 64-bit mode of JAX via
qsimod.jax_setup.
hilbert ¶
Hilbert spaces, basis ordering and single-site operator matrices.
The following conventions are fixed in this module:
- Basis ordering. The local basis index is the occupation number on every algebra; a boson
with cutoff
n_maxhasn_max + 1levels. - Tensor-factor order. Register site 0 is the leftmost, most significant factor,
index = sum_j config[j] * prod_{k>j} dim[k]. - Pauli matrices.
Z = 2n - 1 = diag(-1, +1),X = [[0,1],[1,0]],Y = [[0,i],[-i,0]]; hencen = (Z+1)/2,sigma^+ = |1><0| = (X+iY)/2andXY = iZ.qsimod.pauliuses the same conventions. - Spin-1/2.
S^z = Z/2;S^+-coincide withsigma^+-. - Bosons. The occupation cutoff is set by a
RealisationRequest, with defaultn_max = 2.
Every operator is realised as a dense array.
RealisationRequest
dataclass
¶
The choices a numerical realisation requires in addition to the model.
Attributes:
| Name | Type | Description |
|---|---|---|
boson_cutoff |
int
|
the maximum occupation |
fermion_ordering |
tuple[str, ...] | None
|
the roles whose sites carry a Jordan-Wigner string, in the order in which the string runs. Defaults to every fermionic role, ascending by site. |
LocalSpace
dataclass
¶
The local Hilbert space of one register position.
Attributes:
| Name | Type | Description |
|---|---|---|
site |
int
|
the register index. |
algebra |
Algebra
|
the algebra of the site. |
dimension |
int
|
the number of levels kept. |
jordan_wigner_position |
int | None
|
for a fermionic site, its position in the Jordan-Wigner
ordering; |
HilbertSpace
dataclass
¶
A tensor product of local spaces, with an explicit basis ordering.
Attributes:
| Name | Type | Description |
|---|---|---|
spaces |
tuple[LocalSpace, ...]
|
the local spaces, ascending by register site. Site 0 is the leftmost tensor factor. |
request |
RealisationRequest
|
the realisation request from which the space was constructed, retained for reports. |
strides
property
¶
The mixed-radix stride of each tensor factor; site 0 is the most significant.
fermionic_sites
property
¶
The sites carrying a Jordan-Wigner position, in string order.
of
classmethod
¶
Construct the Hilbert space of a structural type.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
structure
|
StructureType
|
the structural type of the model. |
required |
request
|
RealisationRequest | None
|
the cutoffs and orderings; defaults are used if omitted. |
None
|
Returns:
| Type | Description |
|---|---|
HilbertSpace
|
The Hilbert space. |
Raises:
| Type | Description |
|---|---|
ValueError
|
if any degree of freedom has no finite-dimensional representation. |
space_at ¶
The local space at a register site.
Raises:
| Type | Description |
|---|---|
KeyError
|
if the site is not part of the space. |
configuration ¶
The occupation configuration of a basis index, in site order.
Raises:
| Type | Description |
|---|---|
IndexError
|
if the index is out of range. |
index_of ¶
The basis index of an occupation configuration given in site order.
Raises:
| Type | Description |
|---|---|
ValueError
|
if the configuration has the wrong length or an out-of-range occupation. |
basis_state ¶
The computational basis state of an occupation configuration.
configurations ¶
Every occupation configuration, in basis order; the whole basis is materialised.
embed ¶
Embed a local matrix at site into the full space as a tensor factor.
kron_of ¶
The tensor product with factors at the given sites and the identity elsewhere.
jordan_wigner_string ¶
The sites whose parity operator precedes a fermionic operator at site.
The result is empty for a non-fermionic site; otherwise it lists the fermionic sites with a strictly smaller Jordan-Wigner position.
local_matrix ¶
The matrix of one primitive operator on the local space of one site.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
symbol
|
OpSymbol
|
the primitive operator. |
required |
algebra
|
Algebra
|
the algebra of the site. |
required |
dimension
|
int
|
the local dimension of the site. |
required |
Returns:
| Type | Description |
|---|---|
Array
|
A |
Raises:
| Type | Description |
|---|---|
ValueError
|
if the operator is not defined on that algebra, or the algebra has no finite-dimensional representation. |
build ¶
Construction of dense JAX operators from symbolic models and Pauli sums.
Jordan-Wigner convention: a fermionic ladder operator at Jordan-Wigner position p is
realised as
psi_l = (-1)**p * (prod_{q < p} P_q) * sigma^-_l, P = diag(+1, -1) = 1 - 2n,
that is, the Jordan-Wigner transformation with alternating signs, under which
psi_l psi_{l+1} -> + sigma^-_{2l} sigma^-_{2l+2}. The parity string runs over the fermionic
sites with a strictly smaller Jordan-Wigner position. The anticommutation relations are carried
entirely by the explicit parity strings, and each term is assembled as a single tensor product.
build_operator ¶
build_operator(
hamiltonian: OperatorSum,
space: HilbertSpace,
environment: Mapping[str, float],
) -> Array
Realise a symbolic operator sum as a dense JAX array.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
hamiltonian
|
OperatorSum
|
the symbolic sum. |
required |
space
|
HilbertSpace
|
the Hilbert space in which the operator is constructed. |
required |
environment
|
Mapping[str, float]
|
values for every parameter occurring in the coefficients. |
required |
Returns:
| Type | Description |
|---|---|
Array
|
A |
Raises:
| Type | Description |
|---|---|
KeyError
|
if a coefficient refers to an unbound parameter. |
ValueError
|
if an operator is not defined on the algebra of its site. |
build_pauli_string ¶
Realise one Pauli string on a register of qubits qubits.
The tensor order is that of HilbertSpace; qubit 0
is the leftmost, most significant factor.
build_pauli_sum ¶
Realise a Pauli sum on a register of qubits qubits.
local_subspace_projector ¶
The projector onto a declared per-site occupation subspace, as a diagonal basis mask.
Raises:
| Type | Description |
|---|---|
ValueError
|
if the cutoff of the space cannot represent a listed occupation. |
sector_projector ¶
sector_projector(
constraints: Sequence[ConstraintOperator],
space: HilbertSpace,
environment: Mapping[str, float],
tolerance: float = 1e-10,
) -> Array
The projector onto a declared superselection sector.
A basis mask when every constraint operator is diagonal in the occupation basis, otherwise
the projector onto the kernel of sum_l (G_l - g_l)**2 from one eigh.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
constraints
|
Sequence[ConstraintOperator]
|
the declared constraint operators, with their target eigenvalues. |
required |
space
|
HilbertSpace
|
the Hilbert space. |
required |
environment
|
Mapping[str, float]
|
parameter values for the coefficients of the constraint operators. |
required |
tolerance
|
float
|
the largest admissible distance between an eigenvalue and its target. |
1e-10
|
Returns:
| Type | Description |
|---|---|
Array
|
The projector, as a dense array. |
sandwich ¶
The product P A P, the operator as it acts inside a declared subspace.
subspace_indices ¶
The basis indices retained by a diagonal projector, ascending.
restrict ¶
The block of operator on the basis states listed in indices.
sector ¶
Numerical realisation inside a declared sector, without constructing the full space.
SectorBasis enumerates the configurations admitted by a
LocalSubspace and a family of diagonal
ConstraintOperators by a pruned depth-first search, and
build_operator_in assembles P H P in that basis
by lookup. Terms that leave the sector are dropped. The realisation is therefore exact for a
model that is confined to the sector and lossy for a model whose leakage out of the sector is
the observable; the latter is realised densely. Fermionic degrees of freedom are rejected: a
Jordan-Wigner string is a property of the ordering and not a per-configuration amplitude.
SectorBasis
dataclass
¶
The configurations admitted by a declared subspace and a family of constraints.
Attributes:
| Name | Type | Description |
|---|---|---|
space |
HilbertSpace
|
the Hilbert space against which the configurations are indexed; it is never materialised as an array. |
configurations |
tuple[tuple[int, ...], ...]
|
the admitted configurations, in enumeration order. |
index |
Mapping[tuple[int, ...], int]
|
the position of each configuration in |
of
classmethod
¶
of(
structure: StructureType,
subspace: LocalSubspace | None = None,
constraints: Sequence[ConstraintOperator] = (),
request: RealisationRequest | None = None,
environment: Mapping[str, float] | None = None,
) -> SectorBasis
Enumerate the sector by depth-first search with pruning.
Sites are assigned in order, and each constraint is checked as soon as the last site of its support is assigned.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
structure
|
StructureType
|
the structural type of the model. |
required |
subspace
|
LocalSubspace | None
|
the declared per-site occupations; every occupation is admitted if omitted. |
None
|
constraints
|
Sequence[ConstraintOperator]
|
the declared constraint operators, with their target eigenvalues. |
()
|
request
|
RealisationRequest | None
|
the cutoffs and orderings; defaults are used if omitted. |
None
|
environment
|
Mapping[str, float] | None
|
values for the coefficients of the constraints. |
None
|
Returns:
| Type | Description |
|---|---|
SectorBasis
|
The basis. |
Raises:
| Type | Description |
|---|---|
ValueError
|
if any degree of freedom is fermionic. |
state ¶
The basis vector of one configuration, in the ordering of the sector.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
configuration
|
Sequence[int]
|
the occupations, in site order. |
required |
Returns:
| Type | Description |
|---|---|
Array
|
A unit vector of length |
Raises:
| Type | Description |
|---|---|
KeyError
|
if the configuration is not in the sector. |
build_operator_in ¶
build_operator_in(
hamiltonian: OperatorSum,
basis: SectorBasis,
environment: Mapping[str, float],
) -> Array
Realise a symbolic operator sum directly in the basis of a sector.
The result equals restrict(sandwich(build_operator(...), projector), indices) and is
constructed at the cost of the sector; terms that leave the sector are dropped.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
hamiltonian
|
OperatorSum
|
the symbolic sum. |
required |
basis
|
SectorBasis
|
the sector in which the operator is constructed. |
required |
environment
|
Mapping[str, float]
|
values for every parameter occurring in the coefficients. |
required |
Returns:
| Type | Description |
|---|---|
Array
|
A |
Raises:
| Type | Description |
|---|---|
KeyError
|
if a coefficient refers to an unbound parameter. |
evolve ¶
Exact diagonalisation, time evolution and error measures.
Time evolution is computed exactly: the propagator U(t) = V diag(exp(-i E t)) V^dagger is
obtained from one Hermitian eigendecomposition and carries no time-discretisation error. Two
error measures are provided: spectral_norm, the
operator 2-norm in which the Trotter error bounds are stated, and
max_abs_deviation, the largest absolute entry,
which is not a submultiplicative norm.
hermiticity_defect ¶
The defect max |H - H^dagger|, zero to machine precision for a Hermitian operator.
eigensystem ¶
The eigenvalues and eigenvectors of a Hermitian operator.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
operator
|
Array
|
a Hermitian array; |
required |
Returns:
| Type | Description |
|---|---|
Array
|
|
Array
|
the columns. |
low_lying_spectrum ¶
The count lowest eigenvalues of a Hermitian operator, ascending.
manifold_levels ¶
The levels continuing from a degenerate manifold, selected by overlap.
Each eigenvector is ranked by the weight it retains on the basis states of the manifold,
and the len(manifold) eigenvectors of largest weight are selected.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
operator
|
Array
|
the Hermitian operator to diagonalise. |
required |
manifold
|
Sequence[int]
|
the basis indices of the configurations of the manifold. |
required |
Returns:
| Type | Description |
|---|---|
Array
|
As many levels as the manifold has configurations, ascending, and the smallest weight |
float
|
that any selected eigenvector retains inside the manifold. |
spacing_deviation ¶
The largest level-by-level gap between two mean-centred spectra, in units of scale.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
left
|
ArrayLike
|
one spectrum, ascending. |
required |
right
|
ArrayLike
|
the other spectrum, of the same length. |
required |
scale
|
float
|
the energy unit in which the gap is reported. |
1.0
|
Returns:
| Type | Description |
|---|---|
float
|
The gap. |
propagator ¶
The propagator exp(-i H t) of a Hermitian H, from one eigendecomposition.
evolve_state ¶
Evolve state under a Hermitian H to each of times, from one eigendecomposition.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
operator
|
Array
|
the Hermitian generator. |
required |
state
|
Array
|
the initial state vector. |
required |
times
|
Sequence[float] | ArrayLike
|
the times at which the state is reported, as a sequence or a 1-d array. |
required |
Returns:
| Type | Description |
|---|---|
Array
|
An array of shape |
expectation ¶
The expectation value of operator in one state or a stack of states.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
operator
|
Array
|
a Hermitian observable. |
required |
states
|
Array
|
a state vector, or an array of shape |
required |
Returns:
| Type | Description |
|---|---|
Array
|
A scalar, or one real value per state. |
gauss_violation ¶
The gauge violation sum_l <G_l**2>, the diagnostic of gauge invariance.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
constraint_operators
|
Sequence[Array]
|
the realised constraint operators. |
required |
states
|
Array
|
a state vector, or a stack of states. |
required |
Returns:
| Type | Description |
|---|---|
Array
|
The summed expectation of the squares, per state. |
spectral_norm ¶
The operator 2-norm, the largest singular value.
The Trotter error bounds are stated in this norm.
max_abs_deviation ¶
The largest absolute entry of left - right.
This measure is not a submultiplicative norm and not the norm in which the Trotter bounds are stated.
commutator_spectral_norm ¶
The commutator norm ||[A, B]|| in the spectral norm, for Hermitian A and B.
i[A, B] is Hermitian, so its norm is its largest absolute eigenvalue.
jax_setup ¶
Process-global JAX configuration.
Importing this module enables the 64-bit mode of JAX. The setting is process-global and also
affects the JAX code of the importing program. Every operator is built in complex128; real
spectra, times and observables use float64.