Skip to main content

D-Wave

D-Wave's quantum annealing hardware relies on metal loops of niobium that have tiny electrical currents running through them.

Solvers

We offer both D-Wave QPU Samplers and access to D-Wave Leap Hybrid.

ModelBackends (see catalog for complete list)
BinaryQuadraticModeldwave.Advantage_system6.4, dwave.Advantage2_prototype2.3, dwave.hybrid_binary_quadratic_model_version2p
ConstrainedQuadraticModeldwave.hybrid_constrained_quadratic_model_version1p
DiscreteQuadraticModeldwave.hybrid_discrete_quadratic_model_version1p

DwaveSamplerParameterModel

Parameters: Solver Parameter options accepted by D-Wave.

D-Wave Advantage

Binary Quadratic Model

import strangeworks as sw
from strangeworks_optimization import StrangeworksOptimizer
from strangeworks_optimization_models.parameter_models import DwaveSamplerParameterModel
from dimod import BinaryQuadraticModel

sw.authenticate('your-api-key')

linear = {1: -2, 2: -2, 3: -3, 4: -3, 5: -2}
quadratic = {(1, 2): 2, (1, 3): 2, (2, 4): 2, (3, 4): 2, (3, 5): 2, (4, 5): 2}
model = BinaryQuadraticModel(linear, quadratic, "BINARY")


solver = "dwave.Advantage_system6.4"
options = DwaveSamplerParameterModel(num_reads=100, chain_strength=50)

optimizer = StrangeworksOptimizer(model=model, solver=solver, options=options)
sw_job = optimizer.run()

print(f"Job slug: {sw_job.slug}")
print(f"Job status: {optimizer.status(sw_job.slug)}")

results = optimizer.results(sw_job.slug)

print(f"Best solution:\n{results.solution.first}")

D-Wave Leap Hybrid

Binary Quadratic Model

import strangeworks as sw
from strangeworks_optimization import StrangeworksOptimizer
from strangeworks_optimization_models.parameter_models import DwaveSamplerParameterModel
from dimod import BinaryQuadraticModel

sw.authenticate('your-api-key')

linear = {1: -2, 2: -2, 3: -3, 4: -3, 5: -2}
quadratic = {(1, 2): 2, (1, 3): 2, (2, 4): 2, (3, 4): 2, (3, 5): 2, (4, 5): 2}
model = BinaryQuadraticModel(linear, quadratic, "BINARY")

solver = "dwave.hybrid_binary_quadratic_model_version2p"

optimizer = StrangeworksOptimizer(model=model, solver=solver)
sw_job = optimizer.run()

Constrained Quadratic Model

import strangeworks as sw
from strangeworks_optimization import StrangeworksOptimizer
from strangeworks_optimization_models.parameter_models import DwaveSamplerParameterModel
from dimod import Binary, ConstrainedQuadraticModel

sw.authenticate('your-api-key')

weights = [0.9, 0.7, 0.2, 0.1]
capacity = 1
y = [Binary(f"y_{j}") for j in range(len(weights))]
x = [[Binary(f"x_{i}_{j}") for j in range(len(weights))] for i in range(len(weights))]
model = ConstrainedQuadraticModel()
model.set_objective(sum(y))

for i in range(len(weights)):
model.add_constraint(sum(x[i]) == 1, label=f"item_placing_{i}")

for j in range(len(weights)):
model.add_constraint(
sum(weights[i] * x[i][j] for i in range(len(weights))) - y[j] * capacity <= 0,
label=f"capacity_bin_{j}",
)

solver = "dwave.hybrid_constrained_quadratic_model_version1p"

optimizer = StrangeworksOptimizer(model=model, solver=solver)
sw_job = optimizer.run()

Discrete Quadratic Model

import strangeworks as sw
from strangeworks_optimization import StrangeworksOptimizer
from strangeworks_optimization_models.parameter_models import DwaveSamplerParameterModel
from dimod import DiscreteQuadraticModel
import random

sw.authenticate('your-api-key')

model = DiscreteQuadraticModel()
for i in range(10):
model.add_variable(4)
for i in range(9):
for j in range(i + 1, 10):
model.set_quadratic_case(i, random.randrange(0, 4), j, random.randrange(0, 4), random.random())

solver = "dwave.hybrid_discrete_quadratic_model_version1p"

optimizer = StrangeworksOptimizer(model=model, solver=solver)
sw_job = optimizer.run()