Package: circuitdb
Data set of optimal circuits for Boolean functions that have low arity.Installation and UsageThis library is available as apackage on PyPI:python -m pip install circuitdbThe library can be imported in the usual ways:import circuitdb
from circuitdb import circuitdbExamplesThis 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 thelogicalclass defined in thelogicallibrary. In the example below, a circuit is retrieved for the functionf(x,y,z) =xandyandzcorresponding to the truth table(0, 0, 0, 0, 0, 0, 0, 1). Retrieved circuits are represented as instances of thecircuitclass defined in thecircuitlibrary; in the example below, theto_legiblemethod 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 indices2and3in the overall list of gates. In accordance with the requirements of thecircuitclass, 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 gateslogical.everyis specified), a smallest circuit that can be built usinganycombination 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))DevelopmentAll installation and development dependencies are fully specified inpyproject.toml. Theproject.optional-dependenciesobject is used tospecify optional requirementsfor various development tasks. This makes it possible to specify additional options (such asdocs,lint, and so on) when performing installation usingpip:python -m pip install .[docs,lint]DocumentationThe documentation can be generated automatically from the source files usingSphinx:python -m pip install .[docs]
cd docs
sphinx-apidoc -f -E --templatedir=_templates -o _source .. && make htmlTesting and ConventionsAlldoctestunit tests are executed and their coverage is measured when usingpytest(see thepyproject.tomlfile for configuration details):python -m pip install .[test]
python -m pytestStyle conventions are enforced usingPylint:python -m pip install .[lint]
python -m pylint src/circuitdbContributionsIn order to contribute to the source code, open an issue or submit a pull request on theGitHub pagefor this library.VersioningThe version number format for this library and the changes to the library associated with version number increments conform withSemantic Versioning 2.0.0.PublishingThis library can be published as apackage on PyPIby a package maintainer. First, install the dependencies required for packaging and publishing:python -m pip install .[publish]Ensure that the correct version number appears inpyproject.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 anautomation rulethat 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 thewheelpackage:rm -rf build dist src/*.egg-info
python -m build --sdist --wheel .Finally, upload the package distribution archive toPyPIusing thetwinepackage:python -m twine upload dist/*