Simulation
The simulation module contains the functions used by the simulation backend to construct the transverse Ising Hamiltonian \(H\) and compute the Gibbs state density matrix \(\rho = e^{-\beta H} / \mathcal{Z}\) exactly over the full \(2^{n_{\text{qubits}}}\)-dimensional Hilbert space. Note that the matrices scale exponentially in the number of qubits, so this backend is only feasible for small models. The Hamiltonian formulation is explained in more detail on the Theory page.
compute_H(h, J, A, B, n_qubits, pauli_kron)
Computes the Hamiltonian of the annealer at relative time s.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
h
|
ndarray
|
Linear Ising terms. |
required |
J
|
ndarray
|
Quadratic Ising terms. |
required |
A
|
float
|
Coefficient of the off-diagonal terms, e.g. A(s). |
required |
B
|
float
|
Coefficient of the diagonal terms, e.g. B(s). |
required |
n_qubits
|
int
|
Number of qubits. |
required |
pauli_kron
|
PauliKron
|
Kronecker product Pauli matrices dict. |
required |
Returns:
| Type | Description |
|---|---|
ndarray
|
Hamiltonian matrix H. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the length of h or the shape of J does not match n_qubits. |
Source code in src/qbm/simulation/simulation.py
compute_rho(H, beta, diagonal=False)
Computes the trace normalized density matrix rho.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
H
|
ndarray
|
Hamiltonian matrix. |
required |
beta
|
float
|
Inverse temperature beta = 1 / (k_B * T). |
required |
diagonal
|
bool
|
Flag to indicate whether H is a diagonal matrix or not. |
False
|
Returns:
| Type | Description |
|---|---|
ndarray
|
Density matrix rho. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If H is not a square matrix or if beta is not positive. |
Source code in src/qbm/simulation/simulation.py
get_pauli_kron(n_visible, n_hidden)
Computes the necessary Pauli Kronecker product (sparse) matrices for a n_visible + n_hidden qubit problem. Used as an argument to compute_H, e.g. one would instantiate pauli_kron as pauli_kron = get_pauli_kron(n_visible, n_hidden), then pass to compute_H when computing the Hamiltonian.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
n_visible
|
int
|
Number of visible units. |
required |
n_hidden
|
int
|
Number of hidden units. |
required |
Returns:
| Type | Description |
|---|---|
PauliKron
|
Dictionary of Kronecker product Pauli terms, with keys ("x", i) mapping to |
PauliKron
|
sparse matrices I ⊗ σ_x^(i) ⊗ I, and keys ("z_diag", i) and ("zz_diag", i, j) |
PauliKron
|
mapping to the diagonals of I ⊗ σ_z^(i) ⊗ I and their pairwise products. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If n_visible or n_hidden is not positive. |
Source code in src/qbm/simulation/simulation.py
sparse_kron(i, n_qubits, A)
Compute I_{2^i} ⊗ A ⊗ I_{2^(n_qubits-i-1)}.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
i
|
int
|
Index of the "A" matrix. |
required |
n_qubits
|
int
|
Total number of qubits. |
required |
A
|
spmatrix
|
Matrix to tensor with identities. |
required |
Returns:
| Type | Description |
|---|---|
Any
|
I_{2^i} ⊗ A ⊗ I_{2^(n_qubits-i-1)}. |