Direct conversion
There is a way to convert a QuadraticProgram(QP) from Qiskit into a BinaryQuadraticModel(BQM).
First the QP has to be created with Qiskit. It can have linear constraints, integer variables and binary variables. The objective can have linear and quadratic terms. Quadratic constraints and float variables are not supported in the following workflow. The qiskit-optimization package has a special converter named QuadraticProgramToQubo. This convenience converter wraps several conversions. By using the convert method one gets a QP back in QuadraticUnconstrainedBinaryOptimization (QUBO) problem form.
That is, constraints were transformed to be part of the objective function now. Integer variables are mapped to several binary variables.
Now, to transform this into Ocean framework, create a BQM instance with the objective function parts of the QUBO:
bqm_binary = dimod.as_bqm(qubo.objective.linear.to_array(), qubo.objective.quadratic.to_array(), dimod.BINARY)
This BQM can be submitted to a D-Wave QPU sampler, e.g. result = sampler.sample(bqm_binary, label="example_qp", num_reads=1024)
D-Wave Qiskit Plugin
By using the Plugin one can avoid the transformation and especially interpreting of results part.
The use is pretty straightforward. One should be aware, that the plugin was not updated to the new package structure in Qiskit (Aqua to optimization).
Imports:
from qiskit.optimization import QuadraticProgram
from qiskit.optimization.algorithms import MinimumEigenOptimizer
from dwave.plugins.qiskit import DWaveMinimumEigensolver
Model the QP in Qiskit.
model = QuadraticProgram("Binary Test")
Add variables, constraints and set objective function with linear and quadratic terms.
Use D-Wave QPU as a minimum eigen solver
dwave_solver = DWaveMinimumEigensolver()
optimizer = MinimumEigenOptimizer(dwave_solver)
result = optimizer.solve(model)
The result is in agreement with the original QP problem. To view the native QPU results use
result.min_eigen_solver_result.sampleset.to_pandas_dataframe()
For the parameter setting I have opened an issue on the plugins GitHub site, which has been solved: https://github.com/dwavesystems/dwave-qiskit-plugin/issues/1