core.higher_ising_model#

Classes#

HigherIsingModel

A model for accepting HUBO problems.

Module Contents#

class HigherIsingModel#

A model for accepting HUBO problems.

This model has two index types, original indices and zero-origin indices. The original indices are the indices used in the given coefficients. The zero-origin indices are re-indexed indices starting from 0 and continuous. The coefficients are re-indexed to use zero-origin indices in the post-initialisation process. Thus, the coefficients attribute uses zero-origin indices. Furthermore, this model has three mappings; index_map, original_to_zero_origin_map and zero_origin_to_original_map because this model re-indexes the given coefficients to zero-origin indices in the post-initialisation process.

index_map is a mapping from the original indices to the original indices specified by users or identity. Let’s say the given coefficients are {(2, 3): 1.0, (3,): -1.0} and the index_map is {2: 5, 3:7}, and then the original indices are 2 and 3, and those mapped indices are 5 and 7. This mapping is used in ising2original_index method and QuantumConverter class to label qubits. ising2original_index method is also used in QuantumConverter class to decode the sampled bits into classical solutions. Which means this mapping is used only in quantum algorithms. If user did not have any specific mapping in mind, the identity mapping, in this example case {2: 2, 3: 3}, is used by default.

original_to_zero_origin_map is a mapping from the original indices to zero-origin indices. In this case, the original_to_zero_origin_map is {2:0, 3:1}. This mapping is used internally in this class to manage the coefficients with zero-origin indices and helps to easily manage quantum optimisation algorithms such as QAOA.

zero_origin_to_original_map is the inverse mapping of original_to_zero_origin_map. In this case, the zero_origin_to_original_map is {0:2, 1:3}. This mapping is used in ising2original_index method to convert the zero-origin index to the original index. And, again, this mapping is used only in quantum algorithms to decode the sampled bits into classical solutions.

coefficients: dict[tuple[int, Ellipsis], float]#
constant: float#
index_map: dict[int, int]#
property zero_origin_to_original_map: dict[int, int]#

A mapping from rebuilt indices (zero-origin) to the original indices.

Returns:

a mapping from rebuilt indices to original indices.

Return type:

dict[int, int]

property num_bits: int#

Returns the number of variables in the model, which is the number of bits since those variables are supposedly binary.

Returns:

Number of variables in the model.

Return type:

int

ising2original_index(ising_index: int) int#

Convert the rebuilt index (zero-origin) to the original index through the index_map.

Parameters:

ising_index (int) – a rebuilt index (zero-origin) for a virtual qubit

Returns:

the original index.

Return type:

int

calc_energy(state: list[int]) float#

Calculate the energy of the state.

Parameters:

state (list[int]) – A list of spin values (+1 or -1) representing the state of each variable.

Raises:

ValueError – If any element in state is not close to +1 or -1.

Returns:

The calculated energy of the given state.

Return type:

float

Examples

>>> higher_ising = HigherIsingModel({(0, 1): 2.0, (0,): 4.0, (1,): 5.0}, 6.0)
>>> higher_ising.calc_energy([1, -1])
3.0
normalize_by_abs_max() None#

Normalize coefficients by the absolute maximum value.

The coefficients for normalized is defined as:

\[W = \max(|w_{i_0, \dots, i_k}|)\]

where w are coefficients and their subscriptions imply a term to be applied. We normalize the Ising Hamiltonian as

\[\tilde{H} = \frac{1}{W} \left( C + \sum_i w_i Z_i + \cdots + \sum_{i_0, \dots, i_k} w_{i_0, \dots, i_k} Z_{i_0}\dots Z_{i_k} \right)\]
normalize_by_rms()#

Normalize coefficients by the root mean square.

The coefficients for normalized is defined as:

\[W = \sqrt{\frac{1}{\lvert E_k \rvert} \sum_{\{u_1, \dots, u_k\}} (w_{u_1,...,u_k}^{(k)})^2 + \cdots + \frac{1}{\lvert E_1 \rvert} \sum_u (w_u^{(1)})^2}\]

where w are coefficients and their subscriptions imply a term to be applied. E_i are the number of i-th order terms. We normalize the Ising Hamiltonian as

\[\tilde{H} = \frac{1}{W} \left( C + \sum_i w_i Z_i + \cdots + \sum_{i_0, \dots, i_k} w_{i_0, \dots, i_k} Z_{i_0}\dots Z_{i_k} \right)\]

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.

normalize_by_factor(factor: float) None#

Normalize coefficients by a given factor.

We normalize the Ising Hamiltonian as

\[\tilde{H} = \frac{1}{W} \left( C + \sum_i w_i Z_i + \cdots + \sum_{i_0, \dots, i_k} w_{i_0, \dots, i_k} Z_{i_0}\dots Z_{i_k} \right)\]

where W is the given normalization factor.

Parameters:

factor (float) – the normalization factor

classmethod from_hubo(hubo: dict[tuple[int, Ellipsis], float], constant: float = 0.0, simplify=False) HigherIsingModel#

Converts a Higher order Unconstrained Binary Optimisation (HUBO) problem to an equivalent Ising model.

HUBO:
\[\sum_{i} H_i x_i + \sum_{i, j} H_{i, j} x_i x_j + \sum_{i, j, k} H_{i, j, k} x_i x_j x_k,~\text{s.t.}~x_i \in \{0, 1\}\]
Higher Ising model:
\[\sum_{i} J_i z_i + \sum_{i, j} J_{i, j} z_i z_j + \sum_{i, j, k} J_{i, j, k} z_i z_j z_k, ~\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 HUBO to the spin variables (z_i) in the Ising model.

Parameters:
  • hubo (dict[tuple[int, ...], float]) – HUBO coefficients

  • constant (float) – Constant term in the HUBO

  • simplify (bool) – If True, remove coefficients close to zero (not yet implemented)

Returns:

The equivalent Ising model

Return type:

HigherIsingModel