qat.opt.QUBO
- class qat.opt.QUBO(Q, offset_q=0, **kwargs)
Class representing Quadratic Unconstrained Binary Optimization (QUBO) problems.
The class allows for the representation of a problem as QUBO - by providing with a symmetric \(Q\) matrix and a QUBO offset energy \(E_Q\), both of which coming from the respective Hamiltonian encoding,
\[H = - x^T Q x - E_Q\]where \(x\) is the vector of binary values \(\{0,1\}\) we look for, such that \(H\) is minimum.
The class can also translate from a QUBO problem to an Ising problem via
to_ising()
by returning an Ising object.QUBO problems can be translated to a
CombinatorialProblem
object viato_combinatorial_problem()
.This class also inherits from the
CircuitGenerator
class which allows to construct QAOA-Ansätze.- Parameters
Q (2D numpy array) – a symmetric array representing the \(Q\) matrix from the Hamiltonian of the problem
offset_q (optional, double) – the value of the QUBO offset energy in the Hamiltonian of the problem
- get_best_parameters()
This method returns a dictionary with the best found parameters (after benchmarking) for simulated quantum annealing (SQA) of the respective QUBO problem. SQA is available in QLM, but the temperature parameters temp_max and temp_min could also be used for simulated annealing (SA), available in myQLM.
The method should be called from one of the child problem classes (e.g. GraphColouring, VertexCover, etc.) and not directly from the parent QUBO class as this will raise an exception.
- get_observable()
Returns an Observable for the problem containing an Ising tuple.
- Returns
an Ising Observable representing the problem
- Return type
- get_q_and_offset()
This method returns the \(Q\) matrix and QUBO energy offset, which define the QUBO object.
- Returns
2-element tuple containing
Q (2D numpy array) - a symmetric array representing the \(Q\) matrix from the Hamiltonian of the problem
offset_q (double) - the value of the QUBO offset energy in the Hamiltonian of the problem
- property q_matrix
The Q-matrix of the QUBO Hamiltonian as a symmetric numpy 2D array
- to_bqm()
Transforms a QUBO problem to DWave’s Binary Quadratic Model from the library
dimod
.- Returns
a BinaryQuadraticModel object
- Return type
BinaryQuadraticModel
- to_combinatorial_problem()
Translates the QUBO problem into a combinatorial problem.
- Returns
a combinatorial problem instance
- Return type
- to_ising()
Translates the QUBO problem into an Ising problem over spins.
- Returns
an Ising instance
- Return type
- to_job(gamma_t=None, tmax=1.0, **kwargs)
Returns a Job for the problem - ready to run on a QPU for simulated annealing (SA) or simulated quantum anealing (SQA). The second one comes in the QLM.
- Parameters:
tmax (float, optional) - time duration of the annealing. Default is 1.
gamma_t (
ArithExpression
, SQA only) - a function specifying the time dependence of Gamma. It should be produced using the variable ‘t’ created by the classVariable
.
- Returns
a ready to run Job for the problem
- Return type
Note
For the supported NP problems, some well performing max and min Gamma for a linearly decreasing gamma_t have been found and could be accessed via the method
get_best_parameters
of the respective problem class.