QUBO container#

The binary optimisation container used by trust-aware task allocation.

A Qubo is the problem \(\min_x\, x^T Q x + \text{offset}\) over \(x \in \{0, 1\}^n\). quantum_mind.applications.allocation.trust_aware_allocation() builds one from each person’s trust in the robot, and small instances are solved exactly with Qubo.brute_force(). General-purpose problem builders (max-cut, knapsack, portfolio) and solvers are left to dedicated optimisation libraries.

Classes

Qubo

Quadratic unconstrained binary optimisation problem.

class Qubo(Q, offset=0.0, labels=<factory>, name='QUBO')[source]#

Bases: object

Quadratic unconstrained binary optimisation problem.

Minimise \(x^T Q x + \text{offset}\) over \(x \in \{0, 1\}^n\).

Parameters:
  • Q (array_like) – (n, n) coefficient matrix (any square matrix; see normalised()).

  • offset (float, optional) – Constant energy offset.

  • labels (list of str, optional) – Variable names (default x0, x1, ...).

  • name (str, optional) – Problem name.

property n#

number of binary variables.

Type:

int

normalised()[source]#

Upper-triangular form with the same energies.

Returns:

Qubo

energy(x)[source]#

Energy of bit strings.

Parameters:

x (array_like) – One bit string (1-D) or one per row (2-D).

Returns:

float or numpy.ndarray

all_energies()[source]#

Energies of all \(2^n\) bit strings.

Index k holds the bits of k with \(x_0\) the least significant bit (Qiskit ordering).

Returns:

numpy.ndarray

Raises:

ValueError – If n > 22.

brute_force()[source]#

Exact minimum by enumeration (small n).

Returns:

to_ising()[source]#

Equivalent Ising model with spins \(s = 1 - 2x \in \{+1, -1\}\).

Returns:

  • h (numpy.ndarray) – Local fields.

  • J (numpy.ndarray) – Upper-triangular couplings.

  • c (float) – Constant, so that energy \(= h \cdot s + \sum_{i<j} J_{ij} s_i s_j + c\).