Skip to content

Commit

Permalink
preparing v0.1.3 (#169)
Browse files Browse the repository at this point in the history
  • Loading branch information
xtofalex authored Dec 12, 2024
1 parent 0296235 commit d0d8a57
Show file tree
Hide file tree
Showing 20 changed files with 913 additions and 188 deletions.
61 changes: 61 additions & 0 deletions najaeda_README/README
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
Naja EDA Python Package
=======================

Naja EDA is a Python package that provides data structures and APIs for developing post-synthesis Electronic Design Automation (EDA) algorithms.
It serves as the Python counterpart to the `Naja C++ project <https://github.com/najaeda/naja>`_.

Installation
------------

Install Naja EDA using pip:

.. code-block:: bash

pip install najaeda

Examples
--------

Load a design from a liberty file and a Verilog file
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Following snippet shows how to load primitive cells from a liberty file and
a netlist from a Verilog file.

.. code-block:: python

from os import path
from najaeda import netlist

benchmarks = path.join('..','benchmarks')
liberty_files = [
'NangateOpenCellLibrary_typical.lib',
'fakeram45_1024x32.lib',
'fakeram45_64x32.lib'
]
liberty_files = list(map(lambda p:path.join(benchmarks, 'liberty', p), liberty_files))

netlist.load_liberty(liberty_files)
top = netlist.load_verilog([path.join(benchmarks, 'verilog', 'tinyrocket.v')])

top.dump_verilog('tinyrocket_naja.v')

Print all the instances in the netlist
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Next example shows how to browse all the netlist and print all its content.

.. code-block:: python

def print_netlist(instance):
for child_instance in instance.get_child_instances():
print(f"{child_instance}:{child_instance.get_model_name()}")
print_netlist(child_instance)

Documentation
-------------

Comprehensive documentation is available on the `Naja GitHub repository <https://github.com/najaeda/naja>`_.

License
-------

This project is licensed under the Apache License 2.0. See the `LICENSE <https://github.com/najaeda/naja/blob/main/LICENSE>`_ file for details.
18 changes: 8 additions & 10 deletions najaeda_README/README.rst
Original file line number Diff line number Diff line change
@@ -1,15 +1,8 @@
Naja EDA Python Package
=======================

Naja EDA is a Python package that provides data structures and APIs for developing post-synthesis Electronic Design Automation (EDA) algorithms. It serves as the Python counterpart to the `Naja C++ project <https://github.com/najaeda/naja>`_.

Features
--------

- **Netlist Simplification**: Perform constant propagation and dead logic elimination.
- **Logic Replication**: Facilitate duplication of logic elements for optimization.
- **Netlist Partitioning**: Divide netlists into manageable sections.
- **Place and Route Support**: Assist in ASIC and FPGA design flows.
Naja EDA is a Python package that provides data structures and APIs for developing post-synthesis Electronic Design Automation (EDA) algorithms.
It serves as the Python counterpart to the `Naja C++ project <https://github.com/najaeda/naja>`_.

Installation
------------
Expand All @@ -22,17 +15,22 @@ Install Naja EDA using pip:
Examples
--------

Load a design from a liberty file and a Verilog file
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Following snippet shows how to load primitive cells from a liberty file and
a netlist from a Verilog file.
.. snippet:: load_design

Print all the instances in the netlist
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Next example shows how to browse all the netlist and print all its content.
.. snippet:: print_design

Documentation
-------------

Comprehensive documentation is available on the `Naja GitHub repository <https://github.com/najaeda/naja>`_.
Naja documentation is available on the `Naja GitHub repository <https://github.com/najaeda/naja>`_.

License
-------
Expand Down
2 changes: 1 addition & 1 deletion najaeda_README/preprocessor.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def replace_placeholders(self, snippets):
for match in self.placeholder_pattern.finditer(content):
snippet_name = match.group(1)
if snippet_name in snippets:
code_block = f".. code-block:: python\n\n {snippets[snippet_name].replace('\n', '\n ')}"
code_block = f"\n.. code-block:: python\n\n {snippets[snippet_name].replace('\n', '\n ')}"
content = content.replace(f".. snippet:: {snippet_name}", code_block)
else:
raise ValueError(f"Snippet {snippet_name} not found in source files. Available snippets: {snippets.keys()}")
Expand Down
11 changes: 7 additions & 4 deletions najaeda_examples/compute_stats/design_stats.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import logging
import os
import sys
from najaeda import netlist

class DesignsStats:
Expand Down Expand Up @@ -80,15 +81,15 @@ def compute_design_stats(design, designs_stats):

def compute_design_terms(design, design_stats):
for term in design.get_terms():
if term.get_direction() == netlist.Term.Input:
if term.get_direction() == netlist.Term.INPUT:
design_stats.terms["inputs"] = design_stats.terms.get("inputs", 0) + 1
bit_terms = sum(1 for _ in term.get_bits())
design_stats.bit_terms["inputs"] = design_stats.bit_terms.get("inputs", 0) + bit_terms
elif term.get_direction() == netlist.Term.Output:
elif term.get_direction() == netlist.Term.OUTPUT:
design_stats.terms["outputs"] = design_stats.terms.get("outputs", 0) + 1
bit_terms = sum(1 for _ in term.get_bits())
design_stats.bit_terms["outputs"] = design_stats.bit_terms.get("outputs", 0) + bit_terms
elif term.get_direction() == netlist.Term.InOut:
elif term.get_direction() == netlist.Term.INOUT:
design_stats.terms["inouts"] = design_stats.terms.get("inouts", 0) + 1
bit_terms = sum(1 for _ in term.get_bits())
design_stats.bit_terms["inouts"] = design_stats.bit_terms.get("inouts", 0) + bit_terms
Expand All @@ -99,7 +100,7 @@ def compute_design_terms(design, design_stats):

def compute_design_net_stats(design, design_stats):
for net in design.get_flat_nets():
if net.is_constant():
if net.is_const():
pass
nb_components = sum(1 for c in net.get_terms())
design_stats.net_stats[nb_components] = design_stats.net_stats.get(nb_components, 0) + 1
Expand Down Expand Up @@ -268,3 +269,5 @@ def dump_constants(design, analyzed_models):
for ins in design.getInstances():
model = ins.getModel()
dump_constants(model, analyzed_models)

sys.exit(0)
12 changes: 9 additions & 3 deletions najaeda_examples/load_design/najaeda_load_design.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,21 @@

# snippet-start: load_design
from os import path
import sys
from najaeda import netlist

benchmarks = path.join('..','benchmarks')
liberty_files = ['NangateOpenCellLibrary_typical.lib', 'fakeram45_1024x32.lib', 'fakeram45_64x32.lib']
liberty_files = [
'NangateOpenCellLibrary_typical.lib',
'fakeram45_1024x32.lib',
'fakeram45_64x32.lib'
]
liberty_files = list(map(lambda p:path.join(benchmarks, 'liberty', p), liberty_files))

netlist.load_liberty(liberty_files)
top = netlist.load_verilog([path.join(benchmarks, 'verilog', 'tinyrocket.v')])

#dump verilog
top.dump_verilog('tinyrocket_naja.v')
top.dump_verilog('.', 'tinyrocket_naja.v')
# snippet-end: load_design

sys.exit(0)
9 changes: 8 additions & 1 deletion najaeda_examples/print_design/najaeda_printdesign.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
# SPDX-License-Identifier: Apache-2.0

from os import path
import sys
from najaeda import netlist

# snippet-start: print_design
Expand All @@ -14,10 +15,16 @@ def print_netlist(instance):
# snippet-end: print_design

benchmarks = path.join('..','benchmarks')
liberty_files = ['NangateOpenCellLibrary_typical.lib', 'fakeram45_1024x32.lib', 'fakeram45_64x32.lib']
liberty_files = [
'NangateOpenCellLibrary_typical.lib',
'fakeram45_1024x32.lib',
'fakeram45_64x32.lib'
]
liberty_files = list(map(lambda p:path.join(benchmarks, 'liberty', p), liberty_files))

netlist.load_liberty(liberty_files)
top = netlist.load_verilog([path.join(benchmarks, 'verilog', 'tinyrocket.v')])

print_netlist(top)

sys.exit(0)
12 changes: 11 additions & 1 deletion najaeda_examples/run_regress.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
# SPDX-License-Identifier: Apache-2.0

import os
import sys
import subprocess

root_dir = os.getcwd()
Expand All @@ -12,11 +13,20 @@
for dir_name in next(os.walk(root_dir))[1]: # [1] gives the list of subdirectories
subdir_path = os.path.join(root_dir, dir_name)
print(f"Processing directory: {subdir_path}")

failure = False

# Iterate through the files in this subdirectory
for file in os.listdir(subdir_path):
if file.endswith(".py"):
test_path = os.path.join(subdir_path, file)
print(f"Running {test_path}...")
# Run the test using subprocess
subprocess.run(["python", test_path])
process_return = subprocess.run(["python3", file], cwd=subdir_path)
if process_return.returncode != 0:
print(f"Test {test_path} failed!")
failure = True
if failure:
sys.exit(1)

sys.exit(0)
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ build-backend = "scikit_build_core.build"

[project]
name = "najaeda"
version = "0.1.2"
version = "0.1.3"
description = "Naja EDA Python package"
authors = [{name = "Naja Authors", email = "[email protected]"}]
readme = "README.rst"
Expand Down
Loading

0 comments on commit d0d8a57

Please sign in to comment.