dwave-optimization is an open-source library for formulating nonlinear optimization models for use with D-Wave's Stride™ hybrid solver. Models are constructed symbolically using an array-based syntax inspired by NumPy.
The package includes:
- A class for nonlinear models used by the Stride quantum-classical hybrid nonlinear solver.
- Model generators for common optimization problems.
The quadratic assignment problem problem is a combinatorial
optimization problem.
There are n facilities and n potential locations, a flow between each pair
of facilities, and a distance between each pair of locations.
The problem is to assign each facility to a location in order to minimize the
sum of each distance multiplied by each matching flow.
This small example builds a quadratic assignment using dwave-optimization symbols. There is also a generator for this problem.
from dwave.optimization import Model
model = Model()
flows = model.constant([[0, 4, 2],
[3, 0, 7],
[1, 8, 0]])
distances = model.constant([[0, 1, 2],
[1, 0, 3],
[2, 3, 0]])
assignment = model.list(3)
model.minimize((flows * distances[assignment, :][:, assignment]).sum())For explanations of the terminology, see the Ocean glossary.
For a discussion about performance, see Performance Benchmarks.
Installation from PyPI:
pip install dwave-optimizationDuring package development, it is often convenient to use an editable install. See meson-python's editable installs for more details.
pip install --group dev --group blas
pip install --editable . \
--no-build-isolation \
--config-settings=editable-verbose=true \
--config-settings=setup-args="-Dblas=enabled"All code should be thoroughly tested and all pull requests should include tests.
To run the Python tests, first install the package using an editable install as described above. The tests can then be run with unittest.
python -m unittestTo run the C++ tests, first install the project dependencies, then setup a
meson build directory. You must configure the build as a debug build for
the tests to run.
pip install --group dev --group blas
meson setup build -Dbuildtype=debug -Dblas=enabledYou can then run the tests using meson's test framework.
meson test -CbuildTo run the doctests, install the docs requirements:
pip install --group docsYou can then run them using the docs/Makefile.
make -C docs doctest