HUBOInstance#
Module: iqm.applications.hubo
- class iqm.applications.hubo.HUBOInstance(bp, vartype='BINARY')[source]#
Bases:
ProblemInstanceA problem instance class for generic HUBO problems.
Internally, the HUBO instance is stored as a
BinaryPolynomialobject. This object stores the problem as a collection of terms and their coefficients. Each term is afrozensetof 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
BinaryPolynomialobject.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.5represents a single-variable term, while"var": 0.5would 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:
Attributes
The average quality value over all possible bitstrings.
The dimension of the problem, i.e., the number of variables in the polynomial.
Methods
The 'quality' of the input bitstring.
- 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:
Inheritance
