geope.utils¤
geope.utils.trace_dot_jit(x, y)
¤
Compute the trace of the matrix product \(\mathrm{Tr}(xy)\).
JIT-compiled for use inside scan loops.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
Array
|
First matrix |
required |
y
|
Array
|
Second matrix |
required |
Returns:
| Type | Description |
|---|---|
Array
|
A scalar trace |
geope.utils.check_xy_comb(comb)
¤
Check whether a Pauli index combination is valid for XY-type interactions.
Allows single-body terms and two-body terms with identical non-identity Pauli indices (XX, YY), but not ZZ or mixed two-body terms.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
comb
|
tuple[int, ...]
|
Tuple of integers (0=I, 1=X, 2=Y, 3=Z). |
required |
Returns:
| Type | Description |
|---|---|
bool
|
|
geope.utils.check_Heisenberg_comb(comb)
¤
Check whether a Pauli index combination is valid for Heisenberg interactions.
Allows single-body terms and two-body terms with identical non-identity Pauli indices (XX, YY, ZZ).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
comb
|
tuple[int, ...]
|
Tuple of integers (0=I, 1=X, 2=Y, 3=Z). |
required |
Returns:
| Type | Description |
|---|---|
bool
|
|
geope.utils.restriction_function(restriction)
¤
Create a filter function from a list of allowed interaction strings.
Each string in restriction encodes an allowed Pauli combination
using characters 'x', 'y', 'z'.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
restriction
|
list[str]
|
List of strings, e.g. |
required |
Returns:
| Type | Description |
|---|---|
Callable[[tuple[int, ...]], bool]
|
A |
Callable[[tuple[int, ...]], bool]
|
index tuple and returns |
geope.utils.restriction_order_function(n, restriction)
¤
Create an ordered restriction filter from a dictionary.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
n
|
int
|
Number of qubits. |
required |
restriction
|
dict[int | tuple[int, ...], list[str]]
|
Dictionary mapping qubit indices (or tuples) to lists of interaction label strings. |
required |
Returns:
| Type | Description |
|---|---|
Callable[[tuple[int, ...]], bool]
|
A |
Callable[[tuple[int, ...]], bool]
|
index tuple and returns |
geope.utils.construct_restricted_pauli_basis(n, restriction)
¤
Construct a Pauli basis restricted by allowed interactions.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
n
|
int
|
Number of qubits. |
required |
restriction
|
list[str] | dict[int | tuple[int, ...], list[str]]
|
Either a list of allowed interaction strings or a dictionary mapping qubit indices to interaction labels. |
required |
Returns:
| Type | Description |
|---|---|
Basis
|
A |
geope.utils.construct_Heisenberg_pauli_basis(n)
¤
Construct the Pauli basis for a Heisenberg-type Hamiltonian.
Includes all single-body Pauli terms and two-body terms of the form XX, YY, ZZ on any pair of qubits.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
n
|
int
|
Number of qubits. |
required |
Returns:
| Type | Description |
|---|---|
Basis
|
A |
geope.utils.construct_two_body_pauli_basis(n)
¤
Construct the full two-body Pauli basis.
Includes all Pauli strings acting on at most two qubits.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
n
|
int
|
Number of qubits. |
required |
Returns:
| Type | Description |
|---|---|
Basis
|
A |
geope.utils.construct_full_pauli_basis(n)
¤
Construct the full \(n\)-qubit Pauli basis (excluding identity).
Contains all \(4^n - 1\) non-identity Pauli strings.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
n
|
int
|
Number of qubits. |
required |
Returns:
| Type | Description |
|---|---|
Basis
|
A |
geope.utils.creation_annihilation_operators(boson_truncation)
¤
Build truncated bosonic creation and annihilation operators.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
boson_truncation
|
int
|
Maximum occupation number. |
required |
Returns:
| Type | Description |
|---|---|
ndarray
|
A tuple |
ndarray
|
|
ndarray
|
raising operator, each of dimension |
geope.utils.construct_full_spin_boson_basis(n_spins, n_bosons, boson_truncation=3)
¤
Construct the full spin-boson Pauli-like basis.
Combines all \(n\)-qubit Pauli strings with bosonic position (\(q\)) and momentum (\(p\)) operators on each bosonic mode.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
n_spins
|
int
|
Number of spin (qubit) degrees of freedom. |
required |
n_bosons
|
int
|
Number of bosonic modes. |
required |
boson_truncation
|
int
|
Fock-space truncation level. Defaults to 3. |
3
|
Returns:
| Type | Description |
|---|---|
Basis
|
A |
geope.utils.construct_restricted_spin_boson_basis(n_spins, n_bosons, restriction, boson_truncation=3)
¤
Construct a restricted spin-boson basis.
Like construct_full_spin_boson_basis but only includes Pauli
strings matching the given restriction.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
n_spins
|
int
|
Number of spin (qubit) degrees of freedom. |
required |
n_bosons
|
int
|
Number of bosonic modes. |
required |
restriction
|
list[str] | dict[int | tuple[int, ...], list[str]]
|
Either a list of allowed interaction strings or a dictionary mapping qubit indices to interaction labels. |
required |
boson_truncation
|
int
|
Fock-space truncation level. Defaults to 3. |
3
|
Returns:
| Type | Description |
|---|---|
Basis
|
A |
geope.utils.prepare_random_parameters(proj_indices, expander=None, spread=1.0, key=None)
¤
Generate a random parameter vector for the projected subspace.
Samples uniform random values in \([- ext{spread}, ext{spread}]\) and optionally expands them through a constraint matrix.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
proj_indices
|
ndarray
|
Boolean |
required |
expander
|
ndarray | None
|
Optional constraint expansion |
None
|
spread
|
float
|
Half-width of the uniform sampling range. Defaults to 1.0. |
1.0
|
key
|
Array | None
|
JAX random key. Defaults to |
None
|
Returns:
| Type | Description |
|---|---|
ndarray
|
A parameter |
ndarray
|
with random values at projected positions and zeros elsewhere. |
geope.utils.multicontrol_unitary(local_unitary, num_controls)
¤
Embed a single-qubit unitary as a multi-controlled gate.
Places local_unitary in the bottom-right \(2 \times 2\) block
of a \(2^{n+1} \times 2^{n+1}\) identity matrix, where \(n\) is
num_controls.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
local_unitary
|
ndarray
|
A \(2 \times 2\) unitary matrix. |
required |
num_controls
|
int
|
Number of control qubits. |
required |
Returns:
| Type | Description |
|---|---|
ndarray
|
The full multi-controlled unitary matrix. |
geope.utils.qft_unitary(num_qubits)
¤
Construct the Quantum Fourier Transform unitary.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
num_qubits
|
int
|
Number of qubits. |
required |
Returns:
| Type | Description |
|---|---|
ndarray
|
A \(2^n \times 2^n\) QFT unitary matrix. |
geope.utils.merge_constraints(constraints, rtol=1e-09, atol=1e-12)
¤
Merge overlapping linear equality constraints.
Iteratively merges rows of the constraint matrix that share non-zero entries, verifying consistency of the overlap.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
constraints
|
list[ndarray]
|
List of 1-D arrays (all same length) representing linear constraints. |
required |
rtol
|
float
|
Relative tolerance for consistency check. Defaults to 1e-9. |
1e-09
|
atol
|
float
|
Absolute tolerance for consistency check. Defaults to 1e-12. |
1e-12
|
Returns:
| Type | Description |
|---|---|
list[list[float]]
|
A list of merged constraint vectors with no overlapping |
list[list[float]]
|
non-zero entries. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If overlapping constraints are inconsistent. |