Interoperability with annealing framework

One can translate from the presented problem formulations, namely Ising, QUBO and Combinatorial problem to a Binary Quadratic Model as specified by DWave’s library dimod. This is achived by simply calling the method to_bqm() of Ising (or the respective to_bqm() and to_bqm() for QUBO and CombinatorialProblem):

import numpy as np
from qat.opt import Ising

np.random.seed(316)

# Specify the Ising problem
problem_size = 5  # number of qubits
h_field = np.random.rand(problem_size)  # Magnetic field h

# J-coupling matrix
any_mat = np.random.rand(problem_size, problem_size)
j_mat = ((any_mat + np.transpose(any_mat)) / 2  # make it symmetric
         - np.diag(np.diag(any_mat)))  # make it with 0s as the diagonal elements

# Offset - can be 0
offset = 2.18

# Create an Ising problem
problem_Ising = Ising(J=j_mat, h=h_field, offset_i=offset)

# Translate to DWave's Binary Quadratic Model
bqm_problem = problem_Ising.to_bqm()

This method also works for the NP-Hard problems encoded on myQLM, for example:

# import required libraries
import numpy as np
import networkx as nx
from qat.opt import VertexCover

# Specify the problem
graph = nx.Graph()
graph.add_nodes_from(np.arange(6))
graph.add_edges_from([(0, 1), (0, 2), (0, 3), (0, 4), (0, 5), (1, 5)])

# Impose constraints for proper encoding
B = 1
A = B + 0.01

# Create problem
vertex_cover_problem = VertexCover(graph, A=A, B=B)

# Translate to DWave's Binary Quadratic Model
bqm_problem = vertex_cover_problem.to_bqm()