HUBOInstance#

Module: iqm.applications.hubo

class iqm.applications.hubo.HUBOInstance(bp, vartype='BINARY')[source]#

Bases: ProblemInstance

A problem instance class for generic HUBO problems.

Internally, the HUBO instance is stored as a BinaryPolynomial object. This object stores the problem as a collection of terms and their coefficients. Each term is a frozenset of variables whose product makes up the term in the polynomial. For example, the polynomial:

\[1.3 x y - 3.7 x\]

is represented as:

{frozenset({'x', 'y'}): 1.3, frozenset({'x'}): -3.7}
Parameters:
  • bp (BinaryPolynomial | dict[tuple[Hashable, ...] | frozenset[Hashable], float]) –

    The input data for creating the instance. It can be one of the following:

    • A BinaryPolynomial object.

    • A dictionary mapping tuples/frozensets of variable names to coefficients. For the dictionary:

      • Keys must always be tuples or frozensets, even for single-variable terms. For example, ("var",): 0.5 represents a single-variable term, while "var": 0.5 would be incorrectly interpreted as a cubic term with variables "v", "a", "r".

      • Repeated variables in a tuple are treated based on vartype (consistent with the math: \(x^2 = x\) for \(x \in \{0, 1\}\) and \(x^2 = 1\) for \(x \in \{-1, 1\}\)).

      • Values are the coefficients of the corresponding terms.

  • vartype (Literal[Vartype.SPIN, 'SPIN', Vartype.BINARY, 'BINARY', Vartype.INTEGER, 'INTEGER', Vartype.REAL, 'REAL']) – Optional variable type for interpreting the dictionary input. Defaults to 'BINARY'.

Raises:
  • TypeError – If the variable labels of the input are not sortable (e.g., mixing integers and strings).

  • TypeError – If the input bp is a dictionary and the keys aren’t tuples or frozensets.

Attributes

average_quality

The average quality value over all possible bitstrings.

dim

The dimension of the problem, i.e., the number of variables in the polynomial.

Methods

quality

The 'quality' of the input bitstring.

property dim: int#

The dimension of the problem, i.e., the number of variables in the polynomial.

property average_quality: float#

The average quality value over all possible bitstrings.

For HUBO problems, this is equal to the constant term in the spin/Hamiltonian formulation of the cost function.

quality(bit_str)[source]#

The ‘quality’ of the input bitstring.

Calculates the value of the polynomial when the bit values from the bitstring are plugged in for the variables. The values in the bitstring correspond to the variables at their corresponding location in self.sorted_vars.

Parameters:

bit_str (str) – The bitstring representing the values to be plugged in for the variables.

Raises:

ValueError – If the length of the input bitstring does not match the number of variables of the problem.

Return type:

float

Inheritance

Inheritance diagram of iqm.applications.hubo.HUBOInstance