Skip to content

dwavesystems/dwave-optimization

Repository files navigation

https://img.shields.io/pypi/v/dwave-optimization.svg?style=svg https://img.shields.io/pypi/pyversions/dwave-optimization.svg?style=svg https://circleci.com/gh/dwavesystems/dwave-optimization.svg?style=svg

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.

Example Usage

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

Installation from PyPI:

pip install dwave-optimization

During 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"

Testing

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 unittest

To 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=enabled

You can then run the tests using meson's test framework.

meson test -Cbuild

To run the doctests, install the docs requirements:

pip install --group docs

You can then run them using the docs/Makefile.

make -C docs doctest

About

Enables the formulation of nonlinear models for industrial optimization problems.

Resources

License

Contributing

Stars

Watchers

Forks

Packages

 
 
 

Contributors