Skip to main content

circuitdb

Data set of optimal circuits for Boolean functions that have low arity.

PyPI version and link. Read the Docs documentation status. GitHub Actions status. Coveralls test coverage summary.

Installation and Usage

This library is available as a package on PyPI:

python -m pip install circuitdb

The library can be imported in the usual ways:

import circuitdb
from circuitdb import circuitdb

Examples

This library provides a database that contains an (arbitrary but fixed) example of the smallest possible logical circuit (in terms of the number of unary and/or binary gates) for each possible logical function (from a finite set of functions). This library represents logical functions using tuples, in accordance with the conventions of the logical class defined in the logical library. In the example below, a circuit is retrieved for the function f (x, y, z) = x and y and z corresponding to the truth table (0, 0, 0, 0, 0, 0, 0, 1). Retrieved circuits are represented as instances of the circuit class defined in the circuit library; in the example below, the to_legible method of the circuit’s gate list is used to retrieve a human-readable representation of the circuit:

>>> from circuitdb import circuitdb
>>> c = circuitdb((0, 0, 0, 0, 0, 0, 0, 1))
>>> c.gate.to_legible() # Use method belonging to circuit object's gate list to inspect the circuit.
(('id',), ('id',), ('id',), ('and', 0, 1), ('and', 2, 3), ('id', 4))

The human-readable representation of the circuit above consists of a list of unary and binary gates. Each gate is represented as a tuple. The first entry in each gate tuple is the name of the logical function corresponding to that gate. The remaining entries in the gate tuple are the indices of the input gates to that gate. For example, the entry ('and', 2, 3) represents a gate that is a conjunction of the gates that have indices 2 and 3 in the overall list of gates. In accordance with the requirements of the circuit class, the three inputs are represented using identity gates that have no input indices.

For any given logical function, it is possible to construct a corresponding circuit using a variety of gate sets. For each function, the database contains an example of a smallest circuit for each of a small collection of sets of unary and binary gates. In the remaining examples below, circuits for the function (0, 0, 1, 0, 0, 0, 0, 1) are retrieved. All gates in the circuit retrieved below can be found in the set {logical.id_, logical.not_, logical.and_, logical.or_}:

>>> from logical import logical
>>> c = circuitdb(
...     (0, 0, 1, 0, 0, 0, 0, 1),
...     frozenset([logical.id_, logical.not_, logical.and_, logical.or_])
... )
>>> c.gate.to_legible()
(('id',), ('id',), ('id',), ('and', 0, 2), ('or', 0, 2), ('not', 4), ('or', 3, 5), ('and', 1, 6), ('id', 7))

On the other hand, all gates in the circuit retrieved below can be found in the set {logical.id_, logical.not_, logical.and_, logical.xor_}:

>>> circuitdb(
...     (0, 0, 1, 0, 0, 0, 0, 1),
...     frozenset([logical.id_, logical.not_, logical.and_, logical.xor_])
... ).gate.to_legible()
(('id',), ('id',), ('id',), ('not', 0), ('xor', 2, 3), ('and', 1, 4), ('id', 5))

By default (or if the set of all gates logical.every is specified), a smallest circuit that can be built using any combination of unary or binary gates is returned:

>>> circuitdb((0, 0, 1, 0, 0, 0, 0, 1)).gate.to_legible()
(('id',), ('id',), ('id',), ('xor', 0, 2), ('nimp', 1, 3), ('id', 4))

Development

All installation and development dependencies are fully specified in pyproject.toml. The project.optional-dependencies object is used to specify optional requirements for various development tasks. This makes it possible to specify additional options (such as docs, lint, and so on) when performing installation using pip:

python -m pip install .[docs,lint]

Documentation

The documentation can be generated automatically from the source files using Sphinx:

python -m pip install .[docs]
cd docs
sphinx-apidoc -f -E --templatedir=_templates -o _source .. && make html

Testing and Conventions

All doctest unit tests are executed and their coverage is measured when using pytest (see the pyproject.toml file for configuration details):

python -m pip install .[test]
python -m pytest

Style conventions are enforced using Pylint:

python -m pip install .[lint]
python -m pylint src/circuitdb

Contributions

In order to contribute to the source code, open an issue or submit a pull request on the GitHub page for this library.

Versioning

The version number format for this library and the changes to the library associated with version number increments conform with Semantic Versioning 2.0.0.

Publishing

This library can be published as a package on PyPI by a package maintainer. First, install the dependencies required for packaging and publishing:

python -m pip install .[publish]

Ensure that the correct version number appears in pyproject.toml, and that any links in this README document to the Read the Docs documentation of this package (or its dependencies) have appropriate version numbers. Also ensure that the Read the Docs project for this library has an automation rule that activates and sets as the default all tagged versions. Create and push a tag for this version (replacing ?.?.? with the version number):

git tag ?.?.?
git push origin ?.?.?

Remove any old build/distribution files. Then, package the source into a distribution archive using the wheel package:

rm -rf build dist src/*.egg-info
python -m build --sdist --wheel .

Finally, upload the package distribution archive to PyPI using the twine package:

python -m twine upload dist/*

Metadata

Release files for circuitdb 2.0.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for circuitdb 2.0.0
File Size Uploaded Provenance Actions
circuitdb-2.0.0.tar.gz 20.0 kB Without provenance Details for circuitdb-2.0.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for circuitdb 2.0.0
File Interpreter ABI Platform Actions
circuitdb-2.0.0-py3-none-any.whl Python 3 none any Details for circuitdb-2.0.0-py3-none-any.whl

Total release size: 38.1 kB

Release files / circuitdb-2.0.0.tar.gz

Download URL circuitdb-2.0.0.tar.gz
Size 20.0 kB
Tags Source
SHA-256 checksum
How to use checksums
2ae163338d3d1702bc8e5f4437dde66753f3aab22ae48274d1632434cc65516e
BLAKE2b-256 checksum
How to use checksums
56f559c64dee420332fd37915cea6865b14ac85e86299c093b49b388d9fc165b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.10.2

Release files / circuitdb-2.0.0-py3-none-any.whl

Download URL circuitdb-2.0.0-py3-none-any.whl
Size 18.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
9a5526c6a41407ebccaebe2974a9102c9f835d41a318eb70ecd578614d7f4dfc
BLAKE2b-256 checksum
How to use checksums
53e9ac1ec04f156d3dc70b7c7427d10ceb7ea2cae71fb20859702c6ee48a7b97
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.10.2

Security for circuitdb 2.0.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page