qat.opt.NumberPartitioning

class qat.opt.NumberPartitioning(array_of_numbers, **kwargs)

Specialization of the Ising class for Number Partitioning.

Reference

“Ising formulations of many NP problems”, A. Lucas, 2014 - Section 2.1.

import numpy as np
from qat.opt import NumberPartitioning

array_of_numbers_size = np.random.randint(low=1, high=10000, size=1)[0]
array_of_numbers = np.random.randint(low=1, high=10000, size=array_of_numbers_size)

number_partitioning_problem = NumberPartitioning(array_of_numbers)

print("To anneal the problem, the solver would need "
      + str(array_of_numbers_size) + " spins.")
To anneal the problem, the solver would need 8954 spins.
Parameters

numbers_array (1D numpy array) – an array with all the numbers we want to partition

get_best_parameters()
Returns

6-key dictionary containing

  • n_monte_carlo_updates (int) - the number of Monte Carlo updates

  • n_trotters (int) - the number of “classical replicas” or “Trotter replicas”

  • gamma_max (double) - the starting magnetic field

  • gamma_min (double) - the final magnetic field

  • temp_max (double) - the starting temperature

  • temp_min (double) - the final temperature

qat.opt.number_partitioning.produce_j_h_and_offset(array_of_numbers)

Returns the \(J\) coupling matrix of the problem, along with the magnetic field \(h\) and the Ising energy offset.

Parameters

numbers_array (1D numpy array) – an array with all the numbers we want to partition