pyqubo.readthedocs.io Open in urlscan Pro
2606:4700::6810:fd78  Public Scan

Submitted URL: http://pyqubo.readthedocs.io/
Effective URL: https://pyqubo.readthedocs.io/en/latest/
Submission: On November 15 via api from US — Scanned from DE

Form analysis 1 forms found in the DOM

GET search.html

<form id="rtd-search-form" class="wy-form" action="search.html" method="get">
  <input type="text" name="q" placeholder="Search docs">
  <input type="hidden" name="check_keywords" value="yes">
  <input type="hidden" name="area" value="default">
</form>

Text Content

pyqubo
latest


Manual:

 * Getting Started
 * Contribution

Class Reference:

 * Expression
 * Model
 * Array
 * Integer
 * Logical Constraint
 * Logical Gate
 * Utils

On-Demand H100 SXM GPUs for $3.49/hr/GPU with Lambda 640 GB of vRAM in one 8x
instance Launch now
Ad by EthicalAds   ·   ℹ️
pyqubo
 * Docs »
 * PyQUBO
 * Edit on GitHub

--------------------------------------------------------------------------------


PYQUBO¶

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

 * Python based (C++ backend).
 * Fully integrated with Ocean SDK. (details)
 * Automatic validation of constraints. (details)
 * Placeholder for parameter tuning. (details)

For more details, see PyQUBO Documentation.


EXAMPLE USAGE¶


CREATING QUBO¶

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,
('s2', 's2'): -96.0,
('s3', 's1'): 224.0,
('s3', 's2'): 112.0,
('s3', 's3'): -196.0,
('s4', 's1'): 32.0,
('s4', 's2'): 16.0,
('s4', 's3'): 56.0,
('s4', 's4'): -52.0}



INTEGRATION WITH D-WAVE OCEAN¶

PyQUBO can output the BinaryQuadraticModel(BQM) which is compatible with Sampler
class defined in D-Wave Ocean SDK. In the example below, we solve the problem
with SimulatedAnnealingSampler.

>>> import neal
>>> sampler = neal.SimulatedAnnealingSampler()
>>> bqm = model.to_bqm()
>>> sampleset = sampler.sample(bqm, num_reads=10)
>>> decoded_samples = model.decode_sampleset(sampleset)
>>> best_sample = min(decoded_samples, key=lambda x: x.energy)
>>> best_sample.sample # doctest: +SKIP
{'s1': 0, 's2': 0, 's3': 1, 's4': 0}


If you want to solve the problem by actual D-Wave machines, just replace the
sampler by a DWaveCliqueSampler instance, for example.

For more examples, see example notebooks.


BENCHMARKING¶

Since the core logic of the new PyQUBO (>=1.0.0) is written in C++ and the logic
itself is also optimized, the execution time to produce QUBO has become shorter.
We benchmarked the execution time to produce QUBOs of TSP with the new PyQUBO
(1.0.0) and the previous PyQUBO (0.4.0). The result shows the new PyQUBO runs
1000 times faster as the problem size increases.



Execution time includes building Hamiltonian, compilation, and producing QUBOs.
The code to produce the above result is found in here.


INSTALLATION¶

pip install pyqubo


or

python setup.py install



SUPPORTED PYTHON VERSIONS¶

Python 3.5, 3.6, 3.7, 3.8 and 3.9 are supported.


SUPPORTED OPERATING SYSTEMS¶

 * Linux (32/64bit)
 * OSX (64bit, >=10.9)
 * Win (64bit)

Manual:

 * Getting Started
 * Contribution

Class Reference:

 * Expression
 * Model
 * Array
 * Integer
 * Logical Constraint
 * Logical Gate
 * Utils


INDICES AND TABLES¶

 * Index
 * Module Index
 * Search Page

Next

--------------------------------------------------------------------------------

© Copyright Recruit Communications Co., Ltd Revision 721131fc.

Built with Sphinx using a theme provided by Read the Docs.