D-Wave Quantum Annealing Interface for JuMP
julia> import Pkg
julia> Pkg.add("DWave")DWaveNeal.jl only covered the simulated annealing wrapper that now lives at
DWave.Neal.Optimizer inside DWave.jl. The rest of DWave.jl provides
additional samplers and is not part of the old DWaveNeal.jl API surface.
For code that used DWaveNeal.Optimizer, install DWave.jl and switch to
DWave.Neal.Optimizer:
julia> import Pkg
julia> Pkg.add("DWave")
julia> using DWaveIf you still have an environment that depends on DWaveNeal, Pkg.add("DWaveNeal")
continues to work, but DWaveNeal.Optimizer now aliases
DWave.Neal.Optimizer and emits a deprecation warning on load.
using JuMP
using QUBO
using DWave
model = Model(DWave.Neal.Optimizer)
h = [-1, -1, -1]
J = [0 2 2; 0 0 2; 0 0 0]
@variable(model, s[1:3], Spin)
@objective(model, Min, h's + s'J * s)
optimize!(model)
for i = 1:result_count(model)
si = value.(s; result=i)
yi = objective_value(model; result=i)
println("H($si) = $yi")
endDWave.jl provides two families of optimizers:
DWave.Optimizerconnects to D-Wave cloud samplers and requires access to a Leap account.DWave.Neal.Optimizer,DWave.Greedy.Optimizer,DWave.Random.Optimizer, andDWave.Tabu.Optimizerwrap the classical samplers shipped indwave-samplersand run locally through the PythonCall/CondaPkg environment managed by the package.
Switching between them only requires changing the optimizer passed to
Model(...).
The classical samplers expose the same QUBO/Ising modeling interface as the QPU
wrapper, but they do not require DWAVE_API_TOKEN.
DWave.Neal.OptimizerDWave.Greedy.OptimizerDWave.Random.OptimizerDWave.Tabu.Optimizer
Example:
using JuMP
using QUBO
using DWave
model = Model(DWave.Tabu.Optimizer)
set_attribute(model, "num_reads", 32)
set_attribute(model, "timeout", 100)
set_attribute(model, "initial_states", [
1 1 -1 -1
-1 -1 1 1
])
h = [-1, -1, 0, 0]
J = [0 0 1 0; 0 0 0 1; 0 0 0 0; 0 0 0 0]
@variable(model, s[1:4], Spin)
@objective(model, Min, h' * s + s' * J * s)
optimize!(model)Sampler-specific options are forwarded as raw optimizer attributes via
set_attribute(model, name, value). For initial_states, the Greedy and Tabu
wrappers accept either a single Julia vector or a matrix whose rows are initial
states.
| Optimizer | Description | Raw optimizer attributes |
|---|---|---|
DWave.Neal.Optimizer |
Simulated annealing baseline. | num_reads, num_sweeps, num_sweeps_per_beta, beta_range, beta_schedule, beta_schedule_type, seed, initial_states_generator, interrupt_function |
DWave.Greedy.Optimizer |
Steepest-descent local search. | num_reads, initial_states, initial_states_generator, seed, large_sparse_opt |
DWave.Random.Optimizer |
Random-state sampling. | num_reads, time_limit, max_num_samples, seed |
DWave.Tabu.Optimizer |
Tabu-search local search. | initial_states, initial_states_generator, num_reads, seed, tenure, timeout, num_restarts, energy_threshold, coefficient_z_first, coefficient_z_restart, lower_bound_z |
The upstream planar and tree samplers are not wrapped yet. PlanarGraphSolver
only applies to planar Ising models without linear biases, and the tree
decomposition samplers expose exact-solver and marginal APIs that do not fit the
current QUBODrivers interface cleanly.
To use D-Wave's QPU it is necessary to obtain an API Token from Leap.
DWave.draw_topology and DWave.draw_embedding wrap D-Wave NetworkX's
Pegasus and Zephyr plotting helpers and return a Matplotlib figure by default.
Both helpers accept DWave.WorkingGraph values built from sampler metadata, so
plots use the full calibrated working graph rather than only the embedded
qubits.
using DWave
using QUBOTools
metadata = QUBOTools.metadata(sampleset)
DWave.draw_topology(DWave.WorkingGraph(metadata))
DWave.draw_embedding(metadata)Pass ax = existing_axis to draw into an existing Matplotlib axis; all other
keyword arguments are forwarded to the corresponding D-Wave NetworkX draw
function.
To verify that DWave can share a CondaPkg environment with the other Python-backed JuliaQUBO benchmark drivers, run:
julia --startup-file=no test/shared_condapkg_resolve.jlDisclaimer: The D-Wave wrapper for Julia is not officially supported by D-Wave Systems. If you are a commercial customer interested in official support for Julia from D-Wave, let them know!
Note: If you are using DWave.jl in your project, we recommend you to include the .CondaPkg entry in your .gitignore file. The PythonCall module will place a lot of files in this folder when building its Python environment.