py-aiger


Namepy-aiger JSON
Version 6.2.3 PyPI version JSON
download
home_pagehttps://github.com/mvcisback/py-aiger
SummaryA python library for manipulating sequential and-inverter gates.
upload_time2024-03-16 19:45:39
maintainer
docs_urlNone
authorMarcell Vazquez-Chanlatte
requires_python>=3.7,<4.0
licenseMIT
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            <figure>
  <img src="assets/logo_text.svg" alt="py-aiger logo" width=300px>
  <figcaption>
      pyAiger: A python library for manipulating sequential and
      combinatorial circuits.
  </figcaption>

</figure>


[![Build Status](https://cloud.drone.io/api/badges/mvcisback/py-aiger/status.svg)](https://cloud.drone.io/mvcisback/py-aiger)
[![codecov](https://codecov.io/gh/mvcisback/py-aiger/branch/master/graph/badge.svg)](https://codecov.io/gh/mvcisback/py-aiger)
[![PyPI version](https://badge.fury.io/py/py-aiger.svg)](https://badge.fury.io/py/py-aiger)
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
[![DOI](https://zenodo.org/badge/DOI/10.5281/zenodo.1405781.svg)](https://doi.org/10.5281/zenodo.1405781)

<!-- markdown-toc start - Don't edit this section. Run M-x markdown-toc-generate-toc again -->
**Table of Contents**

- [About PyAiger](#about-pyaiger)
- [Installation](#installation)
- [Boolean Expression DSL](#boolean-expression-dsl)
- [Sequential Circuit DSL](#sequential-circuit-dsl)
    - [Sequential composition](#sequential-composition)
    - [Parallel composition](#parallel-composition)
    - [Circuits with Latches/Feedback/Delay](#circuits-with-latchesfeedbackdelay)
    - [Relabeling](#relabeling)
    - [Evaluation](#evaluation)
    - [Useful circuits](#useful-circuits)
- [Extra](#extra)
- [Ecosystem](#ecosystem)
- [Related Projects](#related-projects)
- [Citing](#citing)

<!-- markdown-toc end -->


# About PyAiger

1. Q: How is Py-Aiger pronounced? A: Like "pie" + "grrr".
2. Q: Why python? Aren't you worried about performance?! A: No. The goals of this library are ease of use and hackability. 
3. Q: No, I'm really concerned about performance! A: This library is not suited to implement logic solvers. For everything else, such as the creation and manipulation of circuits with many thousands of gates in between solver calls, the library is really fast enough.
4. Q: Where does the name come from? A: <a href="http://fmv.jku.at/aiger/">Aiger</a> is a popular circuit format. The format is used in <a href="http://fmv.jku.at/hwmcc17/">hardware model checking</a>, <a href="http://www.syntcomp.org/">synthesis</a>, and is supported by <a href="https://github.com/berkeley-abc/abc">ABC</a>. The name is a combination of AIG (standing for <a href="https://en.wikipedia.org/wiki/And-inverter_graph">And-Inverter-Graph</a>) and the mountain <a href="https://en.wikipedia.org/wiki/Eiger">Eiger</a>.

# Installation

If you just need to use `aiger`, you can just run:

`$ pip install py-aiger`

For developers, note that this project uses the
[poetry](https://poetry.eustace.io/) python package/dependency
management tool. Please familarize yourself with it and then
run:

`$ poetry install`

# Usage

```
import aiger

x, y, z, w = aiger.atoms('x', 'y', 'z', 'w')

expr1 = z.implies(x & y)
expr2 = z & w

circ1 = expr1.with_output('z') \      # Get AIG for expr1 with output 'z'.
             .aig
circ2 = circ1 >> circ2                # Feed outputs of circ1 into circ2.
```

# Boolean Expression DSL
While powerful, when writing combinatorial circuits, the Sequential
Circuit DSL can be somewhat clumsy. For this common usecase, we have
developed the Boolean Expression DSL. All circuits generated this way
have a single output.

```python
import aiger
x, y, z = aiger.atoms('x', 'y', 'z')
expr1 = x & y  # circuit with inputs 'x', 'y' and 1 output computing x AND y.
expr2 = x | y  # logical or.
expr3 = x ^ y  # logical xor.
expr4 = x == y  # logical ==, xnor.
expr5 = x.implies(y)
expr6 = ~x  # logical negation.
expr7 = aiger.ite(x, y, z)  # if x then y else z.

# Atoms can be constants.
expr8 = x & True  # Equivalent to just x.
expr9 = x & False # Equivalent to const False.

# Specifying output name of boolean expression.
# - Output is a long uuid otherwise.
expr10 = expr5.with_output('x_implies_y')
assert expr10.output == 'x_implies_y'

# And you can inspect the AIG if needed.
circ = x.aig

# And of course, you can get a BoolExpr from a single output aig.
expr10 = aiger.BoolExpr(circ)
```


# Sequential Circuit DSL

```python
import aiger
from aiger import utils

# Parser for ascii AIGER format.
aig1 = aiger.load(path_to_aig1_file.aag)
aig2 = aiger.load(path_to_aig2_file.aag)
```

## Sequential composition
```python
aig3 = aig1 >> aig2
```

## Parallel composition
```python
aig4 = aig1 | aig2
```

## Circuits with Latches and Delayed Feedback
Sometimes one requires some outputs to be feed back into the circuits
as time delayed inputs. This can be accomplished using the `loopback`
method. This method takes in a variable number of dictionaries
encoding how to wire an input to an output. The wiring dictionaries
with the following keys and default values:

| Key         | Default | Meaning                          |
| ----------- | ------- | -------------------------------- |
| input       |         | Input port                       |
| output      |         | Output port                      |
| latch       | input   | Latch name                       |
| init        | True    | Initial latch value              |
| keep_output | True    | Keep loopbacked output as output |


```python
# Connect output y to input x with delay, initialized to True.
# (Default initialization is False.)
aig5 = aig1.loopback({
  "input": "x", "output": "y",
})

aig6 = aig1.loopback({
  "input": "x", "output": "y",
}, {
  "input": "z", "output": "z", "latch": "z_latch",
  "init": False, "keep_outputs": False
})

```

## Relabeling

There are two syntaxes for relabeling. The first uses indexing
syntax in a nod to [notation often used variable substition in math](https://mathoverflow.net/questions/243084/history-of-the-notation-for-substitution).

The syntax is the relabel method, which is preferable when one wants
to be explicit, even for those not familar with `py-aiger`.

```python
# Relabel input 'x' to 'z'.
aig1['i', {'x': 'z'}]
aig1.relabel('input', {'x': 'z'})

# Relabel output 'y' to 'w'.
aig1['o', {'y': 'w'}]
aig1.relabel('output', {'y': 'w'})

# Relabel latches 'l1' to 'l2'.
aig1['l', {'l1': 'l2'}]
aig1.relabel('latch', {'l1': 'l2'})
```

## Evaluation
```python
# Combinatoric evaluation.
aig3(inputs={'x':True, 'y':False})

# Sequential evaluation.
sim = aig3.simulate([{'x': 0, 'y': 0}, 
                    {'x': 1, 'y': 2},
                    {'x': 3, 'y': 4}])

# Simulation Coroutine
sim = aig3.simulator()  # Coroutine
next(sim)  # Initialize
print(sim.send({'x': 0, 'y': 0}))
print(sim.send({'x': 1, 'y': 2}))
print(sim.send({'x': 3, 'y': 4}))


# Unroll
aig4 = aig3.unroll(steps=10, init=True)
```

## Useful circuits
```python
# Fix input x to be False.
aig4 = aiger.source({'x': False}) >> aig3

# Remove output y. 
aig4 = aig3 >> aiger.sink(['y'])

# Create duplicate w of output y.
aig4 = aig3 >> aiger.tee({'y': ['y', 'w']})
```

# Extra
```python
aiger.common.eval_order(aig1)  # Returns topological ordering of circuit gates.

# Convert object into an AIG from multiple formats including BoolExpr, AIG, str, and filepaths.
aiger.to_aig(aig1)
```

# Ecosystem

### Stable
- [py-aiger-bv](https://github.com/mvcisback/py-aiger-bv): Extension of pyAiger for manipulating sequential bitvector circuits.
- [py-aiger-cnf](https://github.com/mvcisback/py-aiger-cnf): BoolExpr to Object representing CNF. Mostly used for interfacing with py-aiger-sat.
- [py-aiger-past-ltl](https://github.com/mvcisback/py-aiger-past-ltl): Converts Past Linear Temporal Logic to aiger circuits.
- [py-aiger-coins](https://github.com/mvcisback/py-aiger-coins): Library for creating circuits that encode discrete distributions.
- [py-aiger-sat](https://github.com/mvcisback/py-aiger-sat): Bridge between py-aiger and py-sat.
- [py-aiger-bdd](https://github.com/mvcisback/py-aiger-bdd): Aiger <-> BDD bridge.
- [py-aiger-gridworld](https://github.com/mvcisback/py-aiger-gridworld): Create aiger circuits representing gridworlds.
- [py-aiger-dfa](https://pypi.org/project/py-aiger-dfa/): Convert between finite automata and sequential circuits.


### Underdevelopment


- [py-aiger-spectral](https://github.com/mvcisback/py-aiger-spectral): A tool for performing (Fourier) Analysis of Boolean Functions.
- [py-aiger-abc](https://pypi.org/project/py-aiger-abc/): Aiger and abc bridge.

# Related Projects
- [pyAig](https://github.com/sterin/pyaig): Another python library
  for working with AIGER circuits.

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/mvcisback/py-aiger",
    "name": "py-aiger",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.7,<4.0",
    "maintainer_email": "",
    "keywords": "",
    "author": "Marcell Vazquez-Chanlatte",
    "author_email": "marcell.vc@eecs.berkeley.edu",
    "download_url": "https://files.pythonhosted.org/packages/19/d2/3c8ab1d4e9d1aef91a17a3ec10c2849f51e03184f5d08fca5db97fcca0b5/py_aiger-6.2.3.tar.gz",
    "platform": null,
    "description": "<figure>\n  <img src=\"assets/logo_text.svg\" alt=\"py-aiger logo\" width=300px>\n  <figcaption>\n      pyAiger: A python library for manipulating sequential and\n      combinatorial circuits.\n  </figcaption>\n\n</figure>\n\n\n[![Build Status](https://cloud.drone.io/api/badges/mvcisback/py-aiger/status.svg)](https://cloud.drone.io/mvcisback/py-aiger)\n[![codecov](https://codecov.io/gh/mvcisback/py-aiger/branch/master/graph/badge.svg)](https://codecov.io/gh/mvcisback/py-aiger)\n[![PyPI version](https://badge.fury.io/py/py-aiger.svg)](https://badge.fury.io/py/py-aiger)\n[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)\n[![DOI](https://zenodo.org/badge/DOI/10.5281/zenodo.1405781.svg)](https://doi.org/10.5281/zenodo.1405781)\n\n<!-- markdown-toc start - Don't edit this section. Run M-x markdown-toc-generate-toc again -->\n**Table of Contents**\n\n- [About PyAiger](#about-pyaiger)\n- [Installation](#installation)\n- [Boolean Expression DSL](#boolean-expression-dsl)\n- [Sequential Circuit DSL](#sequential-circuit-dsl)\n    - [Sequential composition](#sequential-composition)\n    - [Parallel composition](#parallel-composition)\n    - [Circuits with Latches/Feedback/Delay](#circuits-with-latchesfeedbackdelay)\n    - [Relabeling](#relabeling)\n    - [Evaluation](#evaluation)\n    - [Useful circuits](#useful-circuits)\n- [Extra](#extra)\n- [Ecosystem](#ecosystem)\n- [Related Projects](#related-projects)\n- [Citing](#citing)\n\n<!-- markdown-toc end -->\n\n\n# About PyAiger\n\n1. Q: How is Py-Aiger pronounced? A: Like \"pie\" + \"grrr\".\n2. Q: Why python? Aren't you worried about performance?! A: No. The goals of this library are ease of use and hackability. \n3. Q: No, I'm really concerned about performance! A: This library is not suited to implement logic solvers. For everything else, such as the creation and manipulation of circuits with many thousands of gates in between solver calls, the library is really fast enough.\n4. Q: Where does the name come from? A: <a href=\"http://fmv.jku.at/aiger/\">Aiger</a> is a popular circuit format. The format is used in <a href=\"http://fmv.jku.at/hwmcc17/\">hardware model checking</a>, <a href=\"http://www.syntcomp.org/\">synthesis</a>, and is supported by <a href=\"https://github.com/berkeley-abc/abc\">ABC</a>. The name is a combination of AIG (standing for <a href=\"https://en.wikipedia.org/wiki/And-inverter_graph\">And-Inverter-Graph</a>) and the mountain <a href=\"https://en.wikipedia.org/wiki/Eiger\">Eiger</a>.\n\n# Installation\n\nIf you just need to use `aiger`, you can just run:\n\n`$ pip install py-aiger`\n\nFor developers, note that this project uses the\n[poetry](https://poetry.eustace.io/) python package/dependency\nmanagement tool. Please familarize yourself with it and then\nrun:\n\n`$ poetry install`\n\n# Usage\n\n```\nimport aiger\n\nx, y, z, w = aiger.atoms('x', 'y', 'z', 'w')\n\nexpr1 = z.implies(x & y)\nexpr2 = z & w\n\ncirc1 = expr1.with_output('z') \\      # Get AIG for expr1 with output 'z'.\n             .aig\ncirc2 = circ1 >> circ2                # Feed outputs of circ1 into circ2.\n```\n\n# Boolean Expression DSL\nWhile powerful, when writing combinatorial circuits, the Sequential\nCircuit DSL can be somewhat clumsy. For this common usecase, we have\ndeveloped the Boolean Expression DSL. All circuits generated this way\nhave a single output.\n\n```python\nimport aiger\nx, y, z = aiger.atoms('x', 'y', 'z')\nexpr1 = x & y  # circuit with inputs 'x', 'y' and 1 output computing x AND y.\nexpr2 = x | y  # logical or.\nexpr3 = x ^ y  # logical xor.\nexpr4 = x == y  # logical ==, xnor.\nexpr5 = x.implies(y)\nexpr6 = ~x  # logical negation.\nexpr7 = aiger.ite(x, y, z)  # if x then y else z.\n\n# Atoms can be constants.\nexpr8 = x & True  # Equivalent to just x.\nexpr9 = x & False # Equivalent to const False.\n\n# Specifying output name of boolean expression.\n# - Output is a long uuid otherwise.\nexpr10 = expr5.with_output('x_implies_y')\nassert expr10.output == 'x_implies_y'\n\n# And you can inspect the AIG if needed.\ncirc = x.aig\n\n# And of course, you can get a BoolExpr from a single output aig.\nexpr10 = aiger.BoolExpr(circ)\n```\n\n\n# Sequential Circuit DSL\n\n```python\nimport aiger\nfrom aiger import utils\n\n# Parser for ascii AIGER format.\naig1 = aiger.load(path_to_aig1_file.aag)\naig2 = aiger.load(path_to_aig2_file.aag)\n```\n\n## Sequential composition\n```python\naig3 = aig1 >> aig2\n```\n\n## Parallel composition\n```python\naig4 = aig1 | aig2\n```\n\n## Circuits with Latches and Delayed Feedback\nSometimes one requires some outputs to be feed back into the circuits\nas time delayed inputs. This can be accomplished using the `loopback`\nmethod. This method takes in a variable number of dictionaries\nencoding how to wire an input to an output. The wiring dictionaries\nwith the following keys and default values:\n\n| Key         | Default | Meaning                          |\n| ----------- | ------- | -------------------------------- |\n| input       |         | Input port                       |\n| output      |         | Output port                      |\n| latch       | input   | Latch name                       |\n| init        | True    | Initial latch value              |\n| keep_output | True    | Keep loopbacked output as output |\n\n\n```python\n# Connect output y to input x with delay, initialized to True.\n# (Default initialization is False.)\naig5 = aig1.loopback({\n  \"input\": \"x\", \"output\": \"y\",\n})\n\naig6 = aig1.loopback({\n  \"input\": \"x\", \"output\": \"y\",\n}, {\n  \"input\": \"z\", \"output\": \"z\", \"latch\": \"z_latch\",\n  \"init\": False, \"keep_outputs\": False\n})\n\n```\n\n## Relabeling\n\nThere are two syntaxes for relabeling. The first uses indexing\nsyntax in a nod to [notation often used variable substition in math](https://mathoverflow.net/questions/243084/history-of-the-notation-for-substitution).\n\nThe syntax is the relabel method, which is preferable when one wants\nto be explicit, even for those not familar with `py-aiger`.\n\n```python\n# Relabel input 'x' to 'z'.\naig1['i', {'x': 'z'}]\naig1.relabel('input', {'x': 'z'})\n\n# Relabel output 'y' to 'w'.\naig1['o', {'y': 'w'}]\naig1.relabel('output', {'y': 'w'})\n\n# Relabel latches 'l1' to 'l2'.\naig1['l', {'l1': 'l2'}]\naig1.relabel('latch', {'l1': 'l2'})\n```\n\n## Evaluation\n```python\n# Combinatoric evaluation.\naig3(inputs={'x':True, 'y':False})\n\n# Sequential evaluation.\nsim = aig3.simulate([{'x': 0, 'y': 0}, \n                    {'x': 1, 'y': 2},\n                    {'x': 3, 'y': 4}])\n\n# Simulation Coroutine\nsim = aig3.simulator()  # Coroutine\nnext(sim)  # Initialize\nprint(sim.send({'x': 0, 'y': 0}))\nprint(sim.send({'x': 1, 'y': 2}))\nprint(sim.send({'x': 3, 'y': 4}))\n\n\n# Unroll\naig4 = aig3.unroll(steps=10, init=True)\n```\n\n## Useful circuits\n```python\n# Fix input x to be False.\naig4 = aiger.source({'x': False}) >> aig3\n\n# Remove output y. \naig4 = aig3 >> aiger.sink(['y'])\n\n# Create duplicate w of output y.\naig4 = aig3 >> aiger.tee({'y': ['y', 'w']})\n```\n\n# Extra\n```python\naiger.common.eval_order(aig1)  # Returns topological ordering of circuit gates.\n\n# Convert object into an AIG from multiple formats including BoolExpr, AIG, str, and filepaths.\naiger.to_aig(aig1)\n```\n\n# Ecosystem\n\n### Stable\n- [py-aiger-bv](https://github.com/mvcisback/py-aiger-bv): Extension of pyAiger for manipulating sequential bitvector circuits.\n- [py-aiger-cnf](https://github.com/mvcisback/py-aiger-cnf): BoolExpr to Object representing CNF. Mostly used for interfacing with py-aiger-sat.\n- [py-aiger-past-ltl](https://github.com/mvcisback/py-aiger-past-ltl): Converts Past Linear Temporal Logic to aiger circuits.\n- [py-aiger-coins](https://github.com/mvcisback/py-aiger-coins): Library for creating circuits that encode discrete distributions.\n- [py-aiger-sat](https://github.com/mvcisback/py-aiger-sat): Bridge between py-aiger and py-sat.\n- [py-aiger-bdd](https://github.com/mvcisback/py-aiger-bdd): Aiger <-> BDD bridge.\n- [py-aiger-gridworld](https://github.com/mvcisback/py-aiger-gridworld): Create aiger circuits representing gridworlds.\n- [py-aiger-dfa](https://pypi.org/project/py-aiger-dfa/): Convert between finite automata and sequential circuits.\n\n\n### Underdevelopment\n\n\n- [py-aiger-spectral](https://github.com/mvcisback/py-aiger-spectral): A tool for performing (Fourier) Analysis of Boolean Functions.\n- [py-aiger-abc](https://pypi.org/project/py-aiger-abc/): Aiger and abc bridge.\n\n# Related Projects\n- [pyAig](https://github.com/sterin/pyaig): Another python library\n  for working with AIGER circuits.\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "A python library for manipulating sequential and-inverter gates.",
    "version": "6.2.3",
    "project_urls": {
        "Homepage": "https://github.com/mvcisback/py-aiger",
        "Repository": "https://github.com/mvcisback/py-aiger"
    },
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "6f65c1c79bee5e59335b827ba353834429613b5342027e438264c7d69e940e0d",
                "md5": "6d46b6f30b1e54e054fc87aa557cca54",
                "sha256": "837bcd9f49b5a945e5877126f3238e08731d32d545fab05b2146c776dca9c45c"
            },
            "downloads": -1,
            "filename": "py_aiger-6.2.3-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "6d46b6f30b1e54e054fc87aa557cca54",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.7,<4.0",
            "size": 19152,
            "upload_time": "2024-03-16T19:45:37",
            "upload_time_iso_8601": "2024-03-16T19:45:37.089319Z",
            "url": "https://files.pythonhosted.org/packages/6f/65/c1c79bee5e59335b827ba353834429613b5342027e438264c7d69e940e0d/py_aiger-6.2.3-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "19d23c8ab1d4e9d1aef91a17a3ec10c2849f51e03184f5d08fca5db97fcca0b5",
                "md5": "59eea13f116c2ed7b1b79b33842bfce3",
                "sha256": "9d3c599bfa043047f465804137047f227a77ec8850b26e4a2c3a00107b1c8902"
            },
            "downloads": -1,
            "filename": "py_aiger-6.2.3.tar.gz",
            "has_sig": false,
            "md5_digest": "59eea13f116c2ed7b1b79b33842bfce3",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.7,<4.0",
            "size": 19597,
            "upload_time": "2024-03-16T19:45:39",
            "upload_time_iso_8601": "2024-03-16T19:45:39.374656Z",
            "url": "https://files.pythonhosted.org/packages/19/d2/3c8ab1d4e9d1aef91a17a3ec10c2849f51e03184f5d08fca5db97fcca0b5/py_aiger-6.2.3.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-03-16 19:45:39",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "mvcisback",
    "github_project": "py-aiger",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "lcname": "py-aiger"
}
        
Elapsed time: 0.21119s