Skip to main content

A boolean gate circuit description package for saving, loading, and evaluating logic circuits.

Project description

circuit-static-description

A text-based boolean gate circuit description format that is easy to save and port.

Installation

Install from PyPI:

pip install circuit-static-description

Python package usage

This project provides a Python package named circuit_static_description. The package supports saving circuits, loading circuits, and evaluating outputs.

Importing

from circuit_static_description import Circuit

Circuit description format

A circuit description contains only the number of inputs, the number of outputs, and the expression for each output. There are no intermediate variable names.

  • Input references use I0, I1, I2, etc.
  • Output lines use fixed names OUT0, OUT1, etc.
  • Supported logic operators: AND, OR, NOT, XOR, NAND, NOR.

Example:

INPUTS 3
OUTPUTS 2
OUT0 = AND(I0, I1)
OUT1 = NOR(I2, XOR(I0, I1))

Saving a circuit

from circuit_static_description import Circuit

circuit = Circuit(
    input_count=3,
    output_count=2,
    outputs=[
        "AND(I0, I1)",
        "NOR(I2, XOR(I0, I1))",
    ],
)

circuit.save("example.circuit")

Loading a circuit

from circuit_static_description import Circuit

circuit = Circuit.load("example.circuit")

Evaluating a circuit

result = circuit.evaluate([1, 0, 1])
print(result)
# Example output: [0, 0]

Notes

  • evaluate accepts a list of input values in input order.
  • The output is returned as a list of 0 or 1 values.
  • Expressions cannot use custom variable names; they must use I* input references and supported logic operators.

Benchmarking sequential evaluation

The repository includes a local benchmark script in tests/benchmark.py for measuring sequential Circuit.evaluate(...) performance on random circuits.

The benchmark script uses tqdm to show progress while running evaluation loops.

Run the benchmark from the project root with the Poetry environment active:

python tests/benchmark.py

For a shorter run, use the quick mode:

python tests/benchmark.py --quick

This script is for local testing only and is not included in the published PyPI package.

Benchmark details

  • tests/benchmark.py generates a random circuit with input size, output size, and depth.
  • It performs a small calibration run first to choose a comfortable workload that should finish in under 5 minutes.
  • It reports the sequential evaluation time for the generated circuit.

Example output

Circuit benchmark
Input count: 16, output count: 128, depth: 6
Rounds: 200
Sequential time: 2.1234s

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

circuit_static_description-0.1.1.tar.gz (5.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

circuit_static_description-0.1.1-py3-none-any.whl (6.0 kB view details)

Uploaded Python 3

File details

Details for the file circuit_static_description-0.1.1.tar.gz.

File metadata

  • Download URL: circuit_static_description-0.1.1.tar.gz
  • Upload date:
  • Size: 5.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.4.1 CPython/3.11.15 Windows/10

File hashes

Hashes for circuit_static_description-0.1.1.tar.gz
Algorithm Hash digest
SHA256 d0034818a67b542bf1a7de4e8f141edcaea6bc33d07bfc955003fdea0da3ec54
MD5 0e6dea64b93b7d87eded858c2f8d7261
BLAKE2b-256 b40241d83c05f622b42288de16e4f1e73df8ba136218275b68b4bd2eb99a21f3

See more details on using hashes here.

File details

Details for the file circuit_static_description-0.1.1-py3-none-any.whl.

File metadata

File hashes

Hashes for circuit_static_description-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 00d86640e1a774520956ef21ebaecd91c2898d8a4b916361dadff6517295b108
MD5 325951e90f26d951b67826daaa4340b8
BLAKE2b-256 3f818d0305ffd4d63528e712690245f304a6489115e4a1eaed19e964e4df6f2a

See more details on using hashes here.

Supported by

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