core.ising_qubo#
Classes#
Ising model as a special case of Higher Ising Model. |
Module Contents#
- class IsingModel(quad: dict[tuple[int, int], float], linear: dict[int, float], constant: float, index_map: dict[int, int] | None = None)#
Bases:
qamomile.core.higher_ising_model.HigherIsingModelIsing model as a special case of Higher Ising Model.
This class represents a quadratic Ising model, which is a special case of the Higher Ising Model where all terms are at most quadratic.
The model internally uses HigherIsingModel’s coefficients representation, but provides quad and linear properties for backward compatibility.
Initialize IsingModel.
- Parameters:
quad – Quadratic coefficients J_ij
linear – Linear coefficients h_i
constant – Constant term
index_map – Mapping from Ising indices to QUBO indices
- property quad: dict[tuple[int, int], float]#
Extract quadratic coefficients from parent’s coefficients.
- property linear: dict[int, float]#
Extract linear coefficients from parent’s coefficients.
- classmethod from_qubo(qubo: dict[tuple[int, int], float], constant: float = 0.0, simplify=False) IsingModel#
Converts a Quadratic Unconstrained Binary Optimization (QUBO) problem to an equivalent Ising model.
- QUBO:
- \[\sum_{ij} Q_{ij} x_i x_j,~\text{s.t.}~x_i \in \{0, 1\}\]
- Ising model:
- \[\sum_{ij} J_{ij} z_i z_j + \sum_i h_i z_i, ~\text{s.t.}~z_i \in \{-1, 1\}\]
- Correspondence:
- \[x_i = \frac{1 - z_i}{2}\]
where \((x_i \in \{0, 1\})\) and \((z_i \in \{-1, 1\})\).
This transformation is derived from the conventions used to describe the eigenstates and eigenvalues of the Pauli Z operator in quantum computing. Specifically, the eigenstates |0⟩ and |1⟩ of the Pauli Z operator correspond to the eigenvalues +1 and -1, respectively:
\[Z|0\rangle = |0\rangle, \quad Z|1\rangle = -|1\rangle\]This relationship is leveraged to map the binary variables (x_i) in QUBO to the spin variables (z_i) in the Ising model.
Examples
>>> qubo = {(0, 0): 1.0, (0, 1): 2.0, (1, 1): 3.0} >>> ising = IsingModel.from_qubo(qubo) >>> binary = [1, 0] >>> spin = [-1, 1] >>> qubo_energy = calc_qubo_energy(qubo, binary) >>> assert qubo_energy == ising.calc_energy(spin)
>>> qubo = {(0, 1): 2, (0, 0): -1, (1, 1): -1} >>> ising = IsingModel.from_qubo(qubo) >>> assert ising.constant == -0.5 >>> assert ising.linear == {} >>> assert ising.quad == {(0, 1): 0.5}