Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Kj/distributed #3

Open
wants to merge 23 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
50e07e1
Fix numpy version
dexter2206 Mar 28, 2023
637e0cd
Add printing ofr estimates for grid and block size
dexter2206 Mar 28, 2023
c07a459
Add draft of distributed runner
dexter2206 Mar 28, 2023
18abfe9
Add example script using distributed runner
dexter2206 Mar 28, 2023
b46d397
Implement measuring time + style fixes
dexter2206 Jul 20, 2023
f7dc742
Fix measuring time
dexter2206 Jul 20, 2023
f50d506
Add WIP implementation of ground-only sampler
dexter2206 Jul 27, 2023
39f8d5d
Reduce number of variables used in energy_diff
dexter2206 Sep 3, 2023
90c8777
Implement partial diff buffer optimization
dexter2206 Sep 3, 2023
0214346
Implement computing prefix part of energy diff on CPU
dexter2206 Sep 4, 2023
72c76a8
Fix _solve_subproblems signature
dexter2206 Sep 4, 2023
1da7b48
Make all iteration variables 64 bit
dexter2206 Sep 7, 2023
c7729c3
Fix typo in non-distributed sampler
dexter2206 Sep 8, 2023
14c9fd8
Update docs
dexter2206 Jan 14, 2024
026744f
Add Cython wrapper to .gitignore
dexter2206 Jan 14, 2024
a67a2df
Relax dependencies to make package installable on newer Python versions
dexter2206 Jan 14, 2024
c19467d
Use new Omnisolver plugin system
dexter2206 Jan 14, 2024
a00745c
Correctly restore variables labelling
dexter2206 Jan 14, 2024
fd9cf6f
Improve parameter naming
dexter2206 Jan 14, 2024
671b2e7
Format extension and improve style
dexter2206 Jan 14, 2024
6e7eb73
Add .clang-format file
dexter2206 Jan 14, 2024
d6c5754
Merge branch 'kj/distributed' of github.com:euro-hpc-pl/omnisolver-br…
dexter2206 Jan 14, 2024
e066068
Fix corner case when num_steps_per_kernel is larger than prefix size
dexter2206 May 26, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
BasedOnStyle: WebKit
AlignAfterOpenBracket: BlockIndent
ColumnLimit: 100
BinPackParameters: false
BinPackArguments: false
IncludeBlocks: Regroup
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -137,3 +137,5 @@ dmypy.json

# End of https://www.toptal.com/developers/gitignore/api/python
instances/

bruteforce_wrapper_gpu.cpp
20 changes: 0 additions & 20 deletions docs/Makefile

This file was deleted.

13 changes: 0 additions & 13 deletions docs/_templates/autoapi/index.rst

This file was deleted.

Binary file added docs/assets/logo-large.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/assets/logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
55 changes: 0 additions & 55 deletions docs/conf.py

This file was deleted.

110 changes: 76 additions & 34 deletions docs/index.md
Original file line number Diff line number Diff line change
@@ -1,49 +1,91 @@
# Welcome to omnisolver-pt documentation!
---
hide:
- navigation
---

The `omnisolver-bruteforce` is Omnisolver plugin implementing the bruteforce (a.k.a exhaustive
search) algorithm.
<p align="center">
<a href="https://github.com/euro-hpc-pl/omnisolver"><img src="assets/logo-large.png" alt="Omnisolver"></a>
</p>

## Installation
---

Currently, the `omnisolver-bruteforce` package requires working CUDA installation.
<h1></h1>

To install the plugin first set the `CUDAHOME` environmental library to your CUDA instalaltion location, e.g.:
<p align="center">
<a href="https://github.com/euro-hpc-pl/omnisolver/actions/workflows/quality_checks.yml">
<img src="https://github.com/euro-hpc-pl/omnisolver/actions/workflows/quality_checks.yml/badge.svg" alt="Tests"/>
</a>
<a href="https://euro-hpc-pl.github.io/omnisolver">
<img alt="Docs" src="https://img.shields.io/github/actions/workflow/status/euro-hpc-pl/omnisolver/quality_checks.yml?label=Docs">
</a>
</p>

```shell
# Rmember, your actual location may vary!
export CUDAHOME=/usr/local/cuda
```
**Documentation:** https://euro-hpc-pl.github.io/omnisolver

and then run:
**Source code:** https://github.com/euro-hpc-pl/omnisolver

```shell
pip install omnisolver-bruteforce
```
---

> **Warning**
> If you don't set the `CUDAHOME` directory, an attempt will be made to deduce it based on the location of your `nvcc` compiler.
> However, this process might not work in all the cases and should not be relied on.
Omnisolver is a collection of Binary Quadratic Model solvers and a framework for implementing them.

## Command line usage
```text
usage: omnisolver bruteforce-gpu [-h] [--output OUTPUT] [--vartype {SPIN,BINARY}] [--num_states NUM_STATES] [--suffix_size SUFFIX_SIZE] [--grid_size GRID_SIZE]
[--block_size BLOCK_SIZE] [--dtype {float,double}]
input

Bruteforce (a.k.a exhaustive search) sampler using CUA-enabled GPU

positional arguments:
input Path of the input BQM file in COO format. If not specified, stdin is used.
## Why Omnisolver?

### Benefits for the end-users

Omnisolver contains a selection of standard and more sophisticated algorithms for solving BQMs. All solvers are available through intuitive CLI or from Python scripts as dimod based Samplers.

### Benefits for solver creators

Omnisolver allows developer to focus on algorithms instead of common tasks like handling input/output or creating CLI.

## Quickstart

optional arguments:
-h, --help show this help message and exit
--output OUTPUT Path of the output file. If not specified, stdout is used.
--vartype {SPIN,BINARY}
Variable type
--num_states NUM_STATES
<!-- termynal -->

```
# Install base omnisolver package
$ pip install omnisolver
---> 100%
Successfuly installed omnisolver
# Install chosen plugins (e.g. parallel-tempering solver)
$ pip install omnisolver-pt
---> 100%
Successfuly installed omnisolver-pt
# Create an instance file in COOrdinate format
$ echo "0 1 1.0
> 1 2 1.0
> 2 0 1.0" > instance.txt
# Run solver
$ omnisolver pt --vartype SPIN instance.txt
0,1,2,energy,num_occurrences
1,-1,-1,-1.0,1
```

## Documentation
```{toctree}
:maxdepth: 1
## What's next?

Here are some resources to get you started:

- Start with user guide to learn about the installation methods and general usage patterns.
- Discover available solvers in our plugin list.
- If you are interested in developing your own solver, or are interested in in-depth details of how the Omnisolver
works, check our solver creator guide and reference manual.

## Citing

If you used Omnisolver in your research, consider citing it in your paper.
You can use the following BibTeX entry:

```text
@article{omnisolver2023,
title = {Omnisolver: An extensible interface to Ising spin–glass and QUBO solvers},
journal = {SoftwareX},
volume = {24},
pages = {101559},
year = {2023},
doi = {https://doi.org/10.1016/j.softx.2023.101559},
url = {https://www.softxjournal.com/article/S2352-7110(23)00255-8/},
author = {Konrad Jałowiecki and {\L}ukasz Pawela},
}
```
18 changes: 18 additions & 0 deletions docs/javascripts/mathjax.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
window.MathJax = {
tex: {
inlineMath: [["\\(", "\\)"]],
displayMath: [["\\[", "\\]"]],
processEscapes: true,
processEnvironments: true
},
options: {
ignoreHtmlClass: ".*|",
processHtmlClass: "arithmatex"
}
};

document$.subscribe(() => {


MathJax.typesetPromise()
})
35 changes: 0 additions & 35 deletions docs/make.bat

This file was deleted.

2 changes: 2 additions & 0 deletions docs/reference/omnisolver_bruteforce_distributed.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# ::: omnisolver.bruteforce.gpu.distributed
handler: python
2 changes: 2 additions & 0 deletions docs/reference/omnisolver_bruteforce_sampler.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# ::: omnisolver.bruteforce.gpu.sampler
handler: python
5 changes: 0 additions & 5 deletions docs/requirements.txt

This file was deleted.

55 changes: 55 additions & 0 deletions examples/distributed.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
from dimod import BQM
from numpy.random import default_rng

from omnisolver.bruteforce.gpu import BruteforceGPUSampler
from omnisolver.bruteforce.gpu.distributed import DistributedBruteforceGPUSampler


def random_bqm(num_variables, vartype, offset, rng):
linear = {
i: coef for i, coef in zip(range(num_variables), rng.uniform(-2, 2, size=num_variables))
}
quadratic = {
(i, j): coef
for (i, j), coef in zip(
[(i, j) for i in range(num_variables) for j in range(i + 1, num_variables)],
rng.uniform(-1, -1, size=(num_variables - 1) * num_variables // 2),
)
}
return BQM(linear, quadratic, offset, vartype=vartype)


NUM_VARIABLES = 40


def main():
sampler = DistributedBruteforceGPUSampler()
sampler2 = BruteforceGPUSampler()
rng = default_rng(1234)

bqm = random_bqm(NUM_VARIABLES, "BINARY", 0.0, rng)

import time

start = time.perf_counter()
result = sampler.sample(
bqm, num_states=100, num_fixed_vars=1, suffix_size=25, grid_size=1024, block_size=1024
)
duration = time.perf_counter() - start
distributed_en = [entry.energy for entry in result.data()]

print(f"Distributed finished in : {duration}s")

start = time.perf_counter()
result2 = sampler2.sample(
bqm, num_states=100, suffix_size=25, grid_size=2**12, block_size=512
)
duration = time.perf_counter() - start
single_en = [entry.energy for entry in result2.data()]
print(f"Single finished in: {duration}s")

print(max(abs(en1 - en2) for en1, en2 in zip(distributed_en, single_en)))


if __name__ == "__main__":
main()
Loading
Loading