qat.opt.Ising

class qat.opt.Ising(J, h, offset_i=0, **kwargs)

Class representing Ising problems.

The class allows for the representation of a problem in the Ising framework - by providing with a symmetric coupling matrix \(J\) with zero diagonal elements, magnetic field \(h\) and an Ising offset energy \(E_I\), all of which coming from the respective Hamiltonian encoding,

\[H = - s^T J s - h^T s - E_I\]

where \(s\) is the spin vector we look for with values \(\{-1,1\}\), such that \(H\) is minimum.

The class can also translate from an Ising problem to a QUBO problem through to_qubo() by returning a QUBO object.

Ising problems can be translated to a CombinatorialProblem object via to_combinatorial_problem().

Similarly to QUBO and CombinatorialProblem, this class inherits from the CircuitGenerator class, thus is able to generate QAOA-Ansätze.

Parameters
  • J (2D numpy array) – a symmetric array with zero diagonal elements for the coupling between each two spins - it represents the \(J\) matrix from the Hamiltonian of the problem

  • h (1D numpy array) – an array with the magnetic field acting on each of the spins, coming from the Hamiltonian of the problem

  • offset_i (optional, double) – the value of the Ising offset energy in the respective Hamiltonian

dump(fname)

Dumps the ising in a binary file (.circ)

Parameters

fname (str) – the file name

classmethod from_thrift(tobject)

Builds an Ising object out of a thrift Ising object. Does so in place.

get_best_parameters()

This method returns a dictionary with the best found parameters (after benchmarking) for simulated quantum annealing (SQA) of the respective Ising 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. MaxCut, NumberPartitioning, etc.) and not directly from the parent Ising class as this will raise an exception.

get_j_h_and_offset()

This method returns the \(J\) coupling matrix, the magnetic field \(h\) and Ising energy offset, which define the Ising object.

Returns

3-element tuple containing

  • J (2D numpy array) - a symmetric array with zero diagonal elements for the coupling between each two spins - it represents the \(J\) matrix from the Hamiltonian of the problem

  • h (1D numpy array) - an array with the magnetic field acting on each of the spins, coming from the Hamiltonian of the problem

  • offset_i (double) - the value of the Ising offset energy in the respective Hamiltonian

get_observable()

Returns an Observable for the problem containing an Ising tuple.

Returns

an Ising Observable representing the problem

Return type

Observable

property j_coupling_matrix

The J-coupling of the Ising Hamiltonian as a symmetric numpy 2D array with zero diagonal elements.

classmethod load(fname)

Loads an ising from a binary file.

Parameters

fname (str) – the file name

Returns

an ising object

Return type

Ising

property magnetic_field_h

The magnetic field h of the Ising Hamiltonian as a numpy 1D array

to_bqm()

Transforms an Ising problem to DWave’s Binary Quadratic Model from the library dimod.

Returns

a BinaryQuadraticModel object

Return type

BinaryQuadraticModel

to_combinatorial_problem()

Translates the Ising problem into a CombinatorialProblem.

Returns

a combinatorial problem instance

Return type

CombinatorialProblem

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 class Variable.

Returns

a ready to run Job for the problem

Return type

Job

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.

to_qubo()

Translates the Ising problem into a QUBO problem.

Returns

a QUBO object

Return type

QUBO