Skip to main content

Library for modeling functions over discrete sets using aiger circuits.

Project description

py-aiger-discrete

Library for modeling functions over discrete sets using aiger circuits.

Build Status docs badge codecov PyPI version License: MIT

Installation

If you just need to use py-aiger-discrete, you can just run:

$ pip install py-aiger-discrete

For developers, note that this project uses the poetry python package/dependency management tool. Please familarize yourself with it and then run:

$ poetry install

About

This library helps with modeling functions over finite sets using circuits.

f : A → B₁ × B₂ × … × Bₘ

where A ⊆ A₁ × A₂ × … × Aₙ.

This is done by providing:

  1. A encoder/decoder pair for each set to and from (unsigned) integers.
  2. A circuit that uses the bit-vector representation of these integers to compute f.
  3. A circuit that monitors if the input bit-vector sequence is valid, i.e., a member of A.

Functionally, the py-aiger-discrete library centers around the aiger_discrete.FiniteFunc class which has 4 attributes an aiger_bv.AIGBV object.

  1. A string valid_id indicating
  2. A circuit, circ, over named bit-vectors in the form of an aiger_bv.AIGBV object. One of the outputs must be named valid_id.
  3. A mapping from inputs to aiger_discrete.Encoding objects which encode/decode objects to integers. The standard bit-encoding of unsigned integers is feed into circ.
  4. A mapping from outputs to aiger_discrete.Encoding objects which encode/decode objects to integers. These encodings are used to decode the resulting bit-vectors of circ.

Usage

Below we provide a basic usage example. This example assumes basic knowledge of the py-aiger ecosystem and particularly py-aiger-bv.

import aiger_bv as BV

from aiger_discrete import Encoding, from_aigbv

# Will assume inputs are in 'A', 'B', 'C', 'D', or 'E'.
ascii_encoder = Encoding(
    decode=lambda x: chr(x + ord('A')),  # Make 'A' map to 0.
    encode=lambda x: ord(x) - ord('A'),
)

# Create function which maps: A -> B, B -> C, C -> D, D -> E.

x = BV.uatom(3, 'x')  # need 3 bits to capture 5 input types.
update_expr = (x + 1) & 0b111
circ = update_expr.with_output('y').aigbv

# Need to assert that the inputs are less than 4.
circ |= (x <= 4).with_output('##valid').aigbv

func = from_aigbv(
    circ,
    input_encodings={'x': ascii_encoder},
    output_encodings={'y': ascii_encoder},
    valid_id='##valid',
)

assert func('A') == 'B'
assert func('B') == 'C'
assert func('C') == 'D'
assert func('D') == 'E'
assert func('E') == 'A'

Note that py-aiger-discrete implements most of the circuit API as aiger_bv.AIGBV.

For example, sequential composition:

func12 = func1 >> func2

or parallel composition:

func12 = func1 | func2

or unrolling:

func_unrolled = func1.unroll(5)

or feedback:

func_cycle = func1.loopback({
    'input': 'x',
    'output': 'y',
    'keep_output': True,
    `input_encoder`: True,
    `init`: 'A',
})

Note that feedback now supports additional flag per wiring description called input_encoder which determines if the input or output encoding is used for initial latch value resp. The default is the input encoding.

or renaming:

func_renamed = func1['i', {'x': 'z'}]
assert func1.inputs == {'z'}

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

py-aiger-discrete-0.1.7.tar.gz (7.4 kB view details)

Uploaded Source

Built Distribution

py_aiger_discrete-0.1.7-py3-none-any.whl (7.5 kB view details)

Uploaded Python 3

File details

Details for the file py-aiger-discrete-0.1.7.tar.gz.

File metadata

  • Download URL: py-aiger-discrete-0.1.7.tar.gz
  • Upload date:
  • Size: 7.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.4 CPython/3.8.5 Linux/5.8.0-41-generic

File hashes

Hashes for py-aiger-discrete-0.1.7.tar.gz
Algorithm Hash digest
SHA256 6550f0bd6713fde49a40e5d05b884243a84357789e5ceacee60de110364c36bc
MD5 41b715bd7a9a7ac0dca48c6e573eb28b
BLAKE2b-256 a90509115f28afb7ad1deaf4f3d6b5a8ba08d3a09573d65f95169d337237e53e

See more details on using hashes here.

File details

Details for the file py_aiger_discrete-0.1.7-py3-none-any.whl.

File metadata

  • Download URL: py_aiger_discrete-0.1.7-py3-none-any.whl
  • Upload date:
  • Size: 7.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.4 CPython/3.8.5 Linux/5.8.0-41-generic

File hashes

Hashes for py_aiger_discrete-0.1.7-py3-none-any.whl
Algorithm Hash digest
SHA256 ef423b0278a3c9b8d072d5430249a0e7c8e96c0ed9f0ed8d334739a37ffe1b44
MD5 894844d7691476eaa57a8d84b432ac34
BLAKE2b-256 859531862fee6fc26bd460b67acf6b4d21673fb2d0d0de2eca365db18186c90d

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page