Python DSL for constructing QUBOs from mathematical expressions.
Switch branches/tags
Nothing to show
Clone or download



PyQUBO allows you to create QUBOs or Ising models from flexible mathematical expressions easily. Some of the features of PyQUBO are

  • Python-based.
  • QUBO generation (compile) is fast.
  • Automatic validation of constraints. (details)
  • Placeholder for parameter tuning. (details)

For more details, see PyQUBO Documentation.

Example Usage

This example constructs a simple expression and compile it to model. By calling model.to_qubo(), we get the resulting QUBO. (This example solves Number Partitioning Problem with a set S = {4, 2, 7, 1})

>>> from pyqubo import Spin
>>> s1, s2, s3, s4 = Spin("s1"), Spin("s2"), Spin("s3"), Spin("s4")
>>> H = (4*s1 + 2*s2 + 7*s3 + s4)**2
>>> model = H.compile()
>>> qubo, offset = model.to_qubo()
>>> pprint(qubo)
{('s1', 's1'): -160.0,
 ('s1', 's2'): 64.0,
 ('s1', 's3'): 224.0,
 ('s1', 's4'): 32.0,
 ('s2', 's2'): -96.0,
 ('s2', 's3'): 112.0,
 ('s2', 's4'): 16.0,
 ('s3', 's3'): -196.0,
 ('s3', 's4'): 56.0,
 ('s4', 's4'): -52.0}

For more examples, see example notebooks.


pip install pyqubo


python install

Supported Python Versions

Python 2.7, 3.4, 3.5, 3.6 and 3.7 are supported.


Run all tests.

python -m unittest discover test

Show coverage report.

coverage run -m unittest discover
coverage html

Run test with circleci CLI.

circleci build --job $JOBNAME

Run doctest.

make doctest


Recruit Communications Co., Ltd.


Released under the Apache License 2.0.


We welcome contributions to this project. See CONTRIBUTING.