Skip to main content

Run gate-level HDL simulations from python.

Project description

CircuitSim

Python package Code style: black pre-commit

An interafce to perform simulations of gate-level HDL designs from python.

Installation

CircuitSim requires Python3.6 or greater The easiest way to install is via PyPi:

pip install circuitsim

Finally, to install in-place with the source, use:

cd <install location>
git clone https://github.com/circuitgraph/circuitsim.git
cd circuitsim
pip install -e .

In order to perform simulations, you must have at least one of the available simulators installed.

Using the simulator

Simulation can be performed using the CircuitSimulator class.

This allows the simulation to be compiled once and then quieried multiple times without having to recompile.

The CircuitSimulator accepts circuits in the form of circuitgraph Circuit objects.

Vectors are accepted and returned as dictionaries mapping input/output names to logical values (True or False).

Available simulators

Currently, iverilog, verilator, and VCS are supported. In order to use a given simulator, it must be in your PATH.

Usage Example

import random
import shutil

import circuitgraph as cg

from circuitsim import CircuitSimulator


def main():
    # Exercise 3 random inputs patterns 5 times.
    num_trials = 5
    num_vectors = 3
    c = cg.from_lib("c17")
    simulator = CircuitSimulator(c)
    for sim_num in range(num_trials):
        vectors = []
        for _ in range(num_vectors):
            vectors.append({i: random.choice([True, False])
                           for i in c.inputs()})
        sim_results = simulator.simulate(vectors)
        print(f"Simulation {sim_num}")
        print(f"inputs: {vectors}")
        print(f"outputs: {sim_results}")


if __name__ == "__main__":
    main()

Contributing

If you want to develop an improvement for this library, please consider the information below.

Tests are run using the builtin unittest framework. Some basic linting is performed using flake8.

pip instsall flake8
make test

Documentation is built using pdoc3.

pip install pdoc3
make doc

Code should be formatted using black. Pre-commit is used to automatically run black on commit.

pip install black pre-commit
pre-commit install

Pre-commit also runs a few other hooks, including a docstring formatter and linter. Docs follow the numpy documentation convention.

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

circuitsim-0.0.1.tar.gz (7.9 kB view details)

Uploaded Source

Built Distribution

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

circuitsim-0.0.1-py3-none-any.whl (8.9 kB view details)

Uploaded Python 3

File details

Details for the file circuitsim-0.0.1.tar.gz.

File metadata

  • Download URL: circuitsim-0.0.1.tar.gz
  • Upload date:
  • Size: 7.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.0 CPython/3.9.10

File hashes

Hashes for circuitsim-0.0.1.tar.gz
Algorithm Hash digest
SHA256 8875e64477dece633d3b51e6264b5c34cd60bef791f80c39666331c6a5fd4b76
MD5 7c19e6762bb59f66d6d43cb65f583826
BLAKE2b-256 ab331550ed7f525c992cc3ced4032248a43e718b0b57676a081c2efa2a675cc7

See more details on using hashes here.

File details

Details for the file circuitsim-0.0.1-py3-none-any.whl.

File metadata

  • Download URL: circuitsim-0.0.1-py3-none-any.whl
  • Upload date:
  • Size: 8.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.0 CPython/3.9.10

File hashes

Hashes for circuitsim-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 a49d0187a138bc017aff8a139ac677aee87602cd7bf03d49184a5125c36a92bc
MD5 2b014a2f2e002d6c3344f9e81b0ef45c
BLAKE2b-256 b96a4fe7c0ac37d39d4b35409dd76bdfbd17c80cdcbd7a7305332abdb5ff4419

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