core.ising_qubo#
Classes#
Functions#
|
Calculates the energy of the state. |
|
Converts a Quadratic Unconstrained Binary Optimization (QUBO) problem to an equivalent 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#
- num_bits() int #
- calc_energy(state: list[int]) float #
Calculates the energy of the state.
Examples
>>> ising = IsingModel({(0, 1): 2.0}, {0: 4.0, 1: 5.0}, 6.0) >>> ising.calc_energy([1, -1]) 3.0
- ising2qubo_index(index: int) int #
- normalize_by_abs_max()#
Normalize coefficients by the absolute maximum value.
The coefficients for normalized is defined as:
\[W = \max(|J_{ij}|, |h_i|)\]We normalize the Ising Hamiltonian as
\[\tilde{H} = \frac{1}{W}\sum_{ij}J_{ij}Z_iZ_j + \frac{1}{W}\sum_ih_iZ_i + \frac{1}{W}C\]
- normalize_by_rms()#
Normalize coefficients by the root mean square.
The coefficients for normalized is defined as:
\[W = \sqrt{ \frac{1}{E_2}\sum(w_ij^2) + \frac{1}{E_1}\sum(w_i^2) }\]where w_ij are quadratic coefficients and w_i are linear coefficients. E_2 and E_1 are the number of quadratic and linear terms respectively. We normalize the Ising Hamiltonian as
\[\tilde{H} = \frac{1}{W}\sum_{ij}J_{ij}Z_iZ_j + \frac{1}{W}\sum_ih_iZ_i + \frac{1}{W}C\]This method is proposed in [Sureshbabu et al., 2024]
[SHS+24]Shree Hari Sureshbabu, Dylan Herman, Ruslan Shaydulin, Joao Basso, Shouvanik Chakrabarti, Yue Sun, and Marco Pistoia. Parameter Setting in Quantum Approximate Optimization of Weighted Problems. Quantum, 8:1231, January 2024. URL: https://doi.org/10.22331/q-2024-01-18-1231, doi:10.22331/q-2024-01-18-1231.
- calc_qubo_energy(qubo: dict[tuple[int, int], float], state: list[int]) float #
Calculates the energy of the state.
Examples
>>> calc_qubo_energy({(0, 0): 1.0, (0, 1): 2.0, (1, 1): 3.0}, [1, 1]) 6.0
- qubo_to_ising(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 = qubo_to_ising(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 = qubo_to_ising(qubo) >>> assert ising.constant == -0.5 >>> assert ising.linear == {} >>> assert ising.quad == {(0, 1): 0.5}