qat.simulated_annealing: Simulated Annealing

myQLM is equipped with a simulated annealer (SA), which can solve combinatorial problems encoded in an Ising or Quadratic Unconstrained Binary Optimization (QUBO) formalism - see also an Introductory notebook.

Note

The full QLM appliance includes the even more powerful Simulated Quantum Annealing (SQA) solver which has been tested on a variety of benchmarks for the NP problems supported. The quality of the solutions is \(> 98 \%\) - see SQA benchmarking and performance for more details.

Below we present the class SimulatedAnnealing along with some helper functions. Albeit not quantum, the simulated annealing solver is wrapped with a Quantum Processing Unit (QPU) interface which is made to resemble the rest of the QPUs in the QLM. It therefore consists of an implementation of the submit_job() method, which receives a Job and returns a Result. The way a job is produced is by creating a schedule for the annealing - this is temperature and time steps during the simulation. The classes Ising and QUBO, along with classes for the supported NP problems in qat-opt have implemented the to_job() method, which makes this possible. Solving some of these NP problems has been shown in the example notebooks.

class qat.simulated_annealing.SimulatedAnnealing(temp_t, n_steps, seed=None)

A Simulated Annealing solver interfaced as a Quantum Processing Unit (QPU). which implements the submit_job() method of qat.core.qpu.QPUHandler

Parameters
  • temp_t (ArithExpression) – temperature-time dependence. It needs to be specified using a variable t instantiated with the class Variable.

  • n_steps (int) – number of annealing time steps in Temp(t) evolution.

  • seed (int, optional) – Randomness seed.

sa(J_coupling, h_mag, temp_list)

The algorithm implementing simulated annealing.

Parameters
  • J (2D numpy array) – an array with 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

  • temp_t (ArithExpression) – temperature-time dependence. It needs to be specified using a variable t instantiated with the class Variable.

Returns

an array representing the solution spin configuration after the simulated annealing

Return type

1D numpy array

submit_job(job)

Execute simulated annealing for a given job.

Parameters

job (Job) – the job to execute

Returns

a result with the solution spin configuration(s)

Return type

result (Result)

qat.simulated_annealing.service.extract_j_and_h_from_obs(obs)

A function to extract the \(J\) coupling matrix, magnetic field \(h\) and Ising energy offset \(E_I\) from the Hamiltonian of an Ising problem. The Hamiltonian should be of the form

\[H = - \sum_{ij} J_{ij} s_i s_j - \sum_i h_i s_i - E_I\]

with \(s_i, s_j \in \{-1,1\}\).

Parameters

obs (Observable) – an observable for an Ising problem

Returns

3-element tuple containing

  • J (2D numpy array) - an array with 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

qat.core.spins.integer_to_spins(integer, n_spins)

A function which translates an integer in decimal to its binary representation and then from the 0s and 1s in binary to a spin configuration with 1 and -1.

This function translates the integer value in the Result samples of the SimulatedAnnealing to a spin configuration with 1 and -1.

Parameters
  • integer (int) – a decimal integer number for the state

  • n_spins (int) – the number of spins in the problem

Returns

array of spins

Return type

1D numpy array

qat.core.spins.spins_to_integer(solution_configuration)

A function to translate from a spin configuration with 1 and -1 to a binary configuration with 0 and 1, to the corresponding decimal integer.

Parameters

spins_array (1D numpy array) – array of spins

Returns

the corresponding integer representing the state

Return type

int