Ocean-compatible collection of greedy/brute-force solvers/samplers
Project description
dwave-greedy
An implementation of a steepest descent solver for binary quadratic models.
Steepest descent is the discrete analogue of gradient descent, but the best move is computed using a local minimization rather rather than computing a gradient. At each step, we determine the dimension along which to descend based on the highest energy drop caused by a variable flip.
>>> import greedy
...
>>> solver = greedy.SteepestDescentSolver()
>>> sampleset = solver.sample_ising({0: 2, 1: 2}, {(0, 1): -1})
...
>>> print(sampleset)
0 1 energy num_oc.
0 -1 -1 -5.0 1
['SPIN', 1 rows, 1 samples, 2 variables]
Installation
Install from a package on PyPI:
pip install dwave-greedy
or install from source:
pip install git+https://github.com/dwavesystems/dwave-greedy.git#egg=dwave-greeedy
Note: installation from source involves a “cythonization” step. To install project requirements automatically, make sure to use a PEP-517 compliant pip, e.g. pip>=10.0.
To build from source:
pip install -r requirements.txt
python setup.py build_ext --inplace
python setup.py install
Examples
Simple frustrated Ising triangle:
import dimod
import greedy
# Construct a simple problem
bqm = dimod.BQM.from_qubo({'ab': 1, 'bc': 1, 'ca': 1})
# Instantiate the sampler
sampler = greedy.SteepestDescentSampler()
# Solve the problem
result = sampler.sample(bqm)
Large RAN1 sparse problem (requires NetworkX package):
import dimod
import greedy
import networkx
# Generate random Erdős-Rényi sparse graph with 10% density
graph = networkx.fast_gnp_random_graph(n=1000, p=0.1)
# Generate RAN1 problem on the sparse graph
bqm = dimod.generators.random.ran_r(r=1, graph=graph)
# Instantiate the sampler
sampler = greedy.SteepestDescentSampler()
# Run steepest descent for 100 times, each time from a random state
sampleset = sampler.sample(bqm, num_reads=100)
# Print the best energy
print(min(sampleset.record.energy))
License
Released under the Apache License 2.0. See LICENSE file.
Contributing
Ocean’s contributing guide has guidelines for contributing to Ocean packages.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distributions
Hashes for dwave_greedy-0.2.3-cp310-cp310-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0efa12174a7e8cd5f3f30a066f3f6a398643e94d5ee7886069c0922f5e6b3f02 |
|
MD5 | e2fa0fdca035a43aac862f9f85b3c774 |
|
BLAKE2b-256 | 97913ef2950fec17095ecba1be890920d2ea7201c08ffd83318cdb73e1d4ad70 |
Hashes for dwave_greedy-0.2.3-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e77a1cd69e4262a722b8e6ec52c4f5792dec11c8aaec2583985e1bb5c08fa60a |
|
MD5 | 6ee8c91e40a66e4108884c4900ecac24 |
|
BLAKE2b-256 | 12db91afb2d955f2858ab1d00e9279e3699fe158bab29ce5f0b74e6b19c2ffd2 |
Hashes for dwave_greedy-0.2.3-cp310-cp310-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d189c765b662b3ffda2512542d983bcdcb3408d9610441ff80ace816ca50ac84 |
|
MD5 | 23836607e3185064b9102d3243c1b493 |
|
BLAKE2b-256 | b5006aa9dfc715261511c7b071aa0128b9b1a28f1d6f0ffa6e6bae92572ed60a |
Hashes for dwave_greedy-0.2.3-cp39-cp39-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4bfec3ed3b926a406db53702f3bf312f727841a2195def0283b31f1d9b446896 |
|
MD5 | 63fae204650dac1d166e7f007249319e |
|
BLAKE2b-256 | 229c32a7b995138f3182dba57c38b7433fe2cb4a7d6e9ee4d99126620d9edb38 |
Hashes for dwave_greedy-0.2.3-cp39-cp39-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 664fe4517cda0871a78891eb21b4cce6e28976c0b23912718ec3b0513626e820 |
|
MD5 | 615a6f53385c058452008e25ce99ccb0 |
|
BLAKE2b-256 | 6c31bf098103fe92478d7c7ad19942f4f27a868c097c5d6c52a760323aaded88 |
Hashes for dwave_greedy-0.2.3-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 547264c452d3be219a034bfafa821924276ccd000e834d635f5df60cca7ffb2c |
|
MD5 | 25ab853557b530991ec29cd5033d30ee |
|
BLAKE2b-256 | bd844e01ba79db34a05765c6ba113e25eff3979c18fef4cc6383c1fee9515a4e |
Hashes for dwave_greedy-0.2.3-cp39-cp39-manylinux_2_5_x86_64.manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 895e4b4c116e550dbe71cad20a83793b4d50d11cc910f3f49b01329219f7ccd0 |
|
MD5 | 3eb002ec18e12e5cd62b395dbd250c0c |
|
BLAKE2b-256 | 45b81ee72b827a631c1ae3fb4fb9d2b0f46fe96e08c791c02c474bdf29f3dd7a |
Hashes for dwave_greedy-0.2.3-cp39-cp39-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3b4d0ab8557319ec13003479dd7a0d529e6ebc3777e0218c96c017265e7eb7c8 |
|
MD5 | ce4125b9ca8572ef0c016fef946d0190 |
|
BLAKE2b-256 | cb8066aed750e8df0310e183ec2b5bc46fd1b2e7df76cc3dac1b463c055671c4 |
Hashes for dwave_greedy-0.2.3-cp38-cp38-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f856efca1b41712460535eb8664efd4f2216e8f9452b96b654672d030a065ed3 |
|
MD5 | ccda1ff78cc59a7a33be1069e6fb7372 |
|
BLAKE2b-256 | 311eca2f7b4be552398d35e81bfccb2827f96b51ba3090efbd2eb9eb3765e567 |
Hashes for dwave_greedy-0.2.3-cp38-cp38-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 75dbb9ddac5216dd2a9f89a55729a8a55b13187fa1fd25add2b38e9d695f5d19 |
|
MD5 | 80bd13a113b8358c3dd944cad696154d |
|
BLAKE2b-256 | e80be6bb5b5f6c3f35981e118d52c07c1446729757dd23b59444132b9e38f840 |
Hashes for dwave_greedy-0.2.3-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | bcfc30f9e46cb060c23085ab02fc874d868a9c6328ef1f8aae77e1e96378f0ca |
|
MD5 | b3d06db26ea1aef531324bcef07002d1 |
|
BLAKE2b-256 | 190f34424af5f0e9f540f7dbdb4e9e9b2030658666a381a5453ea01852928100 |
Hashes for dwave_greedy-0.2.3-cp38-cp38-manylinux_2_5_x86_64.manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8a06860b0f66d207060e8fd229012f7aa71aa21bcc0019d04367d1b00bac29e8 |
|
MD5 | 0e1b137b0fe9934f58dbb4f14ef3e13e |
|
BLAKE2b-256 | 8092aeec071f93ad5fa4acc636330e4bf24059da06c42a372c342a464790f915 |
Hashes for dwave_greedy-0.2.3-cp38-cp38-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | bb7c3e91bd05fa8354891536448530f52b5ca22645abcb05754ce412b4f93bc3 |
|
MD5 | 55a35c68736e9593fe543b302f54a09d |
|
BLAKE2b-256 | 1b82361359215f39fadc3e9b91293d117dcef5960921d609a63626b75c27fb65 |
Hashes for dwave_greedy-0.2.3-cp37-cp37m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | de8686449b395e20342698dc4c64f4d25a07ef4398ceaeee16d638255c46b42a |
|
MD5 | e9027b42090fdd4e6e4677f8a20ef20e |
|
BLAKE2b-256 | 5807c04407601701a8ef817d77697843aef03c79fdae925165dc51e18b4c63ce |
Hashes for dwave_greedy-0.2.3-cp37-cp37m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3688926d86c5b2307ed97b633869475fc966ce80fe25d5d49d19e611e86652ab |
|
MD5 | cbcfbd9fd76a198cd251a1bae5c97c87 |
|
BLAKE2b-256 | 51b5aab7806e83aaab7363b4d21abaefe9a797eed7479b561fbe4929cb6883eb |
Hashes for dwave_greedy-0.2.3-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 97ca77ea92effb7124debe860ec7037ed4b0fface74e3dc8a002a1286b1768d8 |
|
MD5 | d88def4ff70d718102e9820fb02495b3 |
|
BLAKE2b-256 | 33723216b8f496bf40f35ada50da766a8d7198b62209ae901b5775ddf41a0d64 |
Hashes for dwave_greedy-0.2.3-cp37-cp37m-manylinux_2_5_x86_64.manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7f5c30fe2f0dfa8c4fc948a5e85cf617dc64ab11b0af017d38f6d26a6d09670c |
|
MD5 | 112b4d810c292fee94636d4bbb55c14a |
|
BLAKE2b-256 | b5543d8a5e97686db3bb11f76508c8eb376874b0fbcf62730352d5abb59adeb3 |
Hashes for dwave_greedy-0.2.3-cp37-cp37m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7e589d17d2bd52fb18c3cd311814cf3504c67cdf8c8a703dd970fed0acf30b6f |
|
MD5 | c2e8f7b537aadb5beb1c5e4e08fff611 |
|
BLAKE2b-256 | 36b06fdb6fd22d43983ebaf953cd38dd4e92d6e8bdd292c49c631897d1f3aa80 |
Hashes for dwave_greedy-0.2.3-cp36-cp36m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 45d93d6a42e6e30a8e805703eeef7ad3c47c0ac5f95cf20e57466d54374504e9 |
|
MD5 | 0e243732799db0671b607f1732061a90 |
|
BLAKE2b-256 | c8bd8b9ce95f5dc882016432bf159012b4d82fc71d7ad16871eb295fc46928a4 |
Hashes for dwave_greedy-0.2.3-cp36-cp36m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e7efd7825ee3868a106020263c9163bc44d46c2b8fd02e65bfc15df91e28aac4 |
|
MD5 | be905f4866d3ce1d96c4c2397e9399d8 |
|
BLAKE2b-256 | da18be1b9e7982a633a3919f7eaefde157ea41a2fd0d56b17b4f9ae7aae4b6ea |
Hashes for dwave_greedy-0.2.3-cp36-cp36m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3f010a7a618d46baf5ec3d316e3eeebfcf463ef8b37bd2f7a61123d6ee487374 |
|
MD5 | f818ac65e3304cd09be16616916b9d07 |
|
BLAKE2b-256 | 4faec6bbc3eec806b4a93c9a32cc053705adf49b5e7670b59b81eddffd11fe96 |
Hashes for dwave_greedy-0.2.3-cp36-cp36m-manylinux_2_5_x86_64.manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | caa9695c2a48e3d448c88d334d57e5069c8f17f5b2f294971a6690d531fd436b |
|
MD5 | ee1ca0462632706d6c15534a50c5086a |
|
BLAKE2b-256 | c9bc594613b9d14fe773d15eeffda5f003403355a9b735c2a2428d33f02fcdf6 |
Hashes for dwave_greedy-0.2.3-cp36-cp36m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4ce24ed37dfdfd214e9f98b422463d455874aa06f0ce163b20d7ee93563ad500 |
|
MD5 | 06b15093a36b28e88f11ca19f10bfe1c |
|
BLAKE2b-256 | 0f3b69d95bc16e933b6820d55ea6d5c76a4a15aecdcdb7cd17a6ace5ad4cfed5 |