https://github.com/spirali/haydi
Python framework for generating discrete structures
https://github.com/spirali/haydi
distributed enumeration generator isomorphism python
Last synced: about 1 year ago
JSON representation
Python framework for generating discrete structures
- Host: GitHub
- URL: https://github.com/spirali/haydi
- Owner: spirali
- License: mit
- Created: 2015-12-30T12:13:28.000Z (over 10 years ago)
- Default Branch: master
- Last Pushed: 2017-12-04T09:07:08.000Z (over 8 years ago)
- Last Synced: 2025-04-09T12:42:59.912Z (about 1 year ago)
- Topics: distributed, enumeration, generator, isomorphism, python
- Language: Python
- Homepage:
- Size: 651 KB
- Stars: 7
- Watchers: 4
- Forks: 4
- Open Issues: 7
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
[](https://travis-ci.org/spirali/haydi)
# Haystack Diver
Haydi (Haystack diver) is a **framework for generating discrete structures**. It
provides a way to define a structure from basic building blocks (e.g. Cartesian
product, mappings) and then enumerate all elements, all non-isomorphic elements,
or generate random elements.
* Pure Python implementation (Python 2.7+, PyPy supported)
* MIT license
* Sequential or distributed computation (via dask/distributed
(https://github.com/dask/distributed)
## Documentation
Full documentation is available at: https://haydi.readthedocs.io/en/latest/
## Example of usage
* Let us define **directed graphs on two vertices** (represented as a set of
edges):
```python
>>> import haydi as hd
>>> nodes = hd.USet(2, "n") # A two-element set with (unlabeled) elements {n0, n1}
>>> graphs = hd.Subsets(nodes * nodes) # Subsets of a cartesian product
```
* Now we can **iterate all elements**:
```python
>>> list(graphs.iterate())
[{}, {(n0, n0)}, {(n0, n0), (n0, n1)}, {(n0, n0), (n0, n1), (n1, n0)}, {(n0,
# ... 3 lines removed ...
n1)}, {(n1, n0)}, {(n1, n0), (n1, n1)}, {(n1, n1)}]
```
* or **iterate all non-isomorphic ones**:
```python
>>> list(graphs.cnfs()) # cnfs = canonical forms
[{}, {(n0, n0)}, {(n0, n0), (n1, n1)}, {(n0, n0), (n0, n1)}, {(n0, n0), (n0,
n1), (n1, n1)}, {(n0, n0), (n0, n1), (n1, n0)}, {(n0, n0), (n0, n1), (n1, n0),
(n1, n1)}, {(n0, n0), (n1, n0)}, {(n0, n1)}, {(n0, n1), (n1, n0)}]
```
* or **generate random instances**:
```python
>>> list(graphs.generate(3))
[{(n1, n0)}, {(n1, n1), (n0, n0)}, {(n0, n1), (n1, n0)}]
```
* Haydi supports standard operations like **map, filter and reduce**:
```python
>>> op = graphs.map(lambda g: len(g)).reduce(lambda x, y: x + y)
# Just a demonstration pipeline; nothing usefull
>>> op.run()
```
* We can run it transparently as a **distributed application**:
```python
>>> from haydi import DistributedContext
# We are now assuming that dask/distributed is running at hostname:1234
>>> context = DistributedContext("hostname", 1234)
>>> op.run(ctx=context)
```
## Authors
* Stanislav Böhm
* Jakub Beránek
* Martin Šurkovský