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
evaluateaccepts a list of input values in input order.- The output is returned as a list of
0or1values. - Expressions cannot use custom variable names; they must use
I*input references and supported logic operators.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file circuit_static_description-0.1.0.tar.gz.
File metadata
- Download URL: circuit_static_description-0.1.0.tar.gz
- Upload date:
- Size: 4.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/2.4.1 CPython/3.11.15 Windows/10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
43ff7e68dbf07333245d87f39d5c0f81eef6459fd3c6e8ef1eb04f3364b71005
|
|
| MD5 |
ef9828c88e2f4a681beee293cfdac0cd
|
|
| BLAKE2b-256 |
8d5a3e658cf36ee191fd6c2e490929a05225d5e59f7899ec95047a4897e1628d
|
File details
Details for the file circuit_static_description-0.1.0-py3-none-any.whl.
File metadata
- Download URL: circuit_static_description-0.1.0-py3-none-any.whl
- Upload date:
- Size: 5.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/2.4.1 CPython/3.11.15 Windows/10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b41706f17d9cdc62b3f057216af7773b97229ec44fbf528c0e9b71093e644044
|
|
| MD5 |
c77c1f8a80b119438b70bee432ce646b
|
|
| BLAKE2b-256 |
8cc41aa3488440b62bfc430b54e8669b0171fffcf1c703ed09532668b728f4df
|