Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 6 additions & 15 deletions examples/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,27 +14,18 @@ or interactively with:
uv run python3 -i $SCRIPT_FILE
```

PyRTL has examples in two directories:
[`examples`](https://github.com/UCSBarchlab/PyRTL/tree/development/examples)
and
[`www/examples`](https://github.com/UCSBarchlab/PyRTL/tree/development/www/examples).

## Generating Jupyter Notebooks

Each example script is automatically converted to a Jupyter notebook in a
corresponding `ipynb-examples` directory,
Each example script is automatically converted to a Jupyter notebook in the
[`ipynb-examples`](https://github.com/UCSBarchlab/PyRTL/tree/development/ipynb-examples)
and
[`www/ipynb-examples`](https://github.com/UCSBarchlab/PyRTL/tree/development/www/ipynb-examples).
directory.
[`examples/tools/to_ipynb.py`](https://github.com/UCSBarchlab/PyRTL/blob/development/examples/tools/to_ipynb.py)
does these automatic conversions. Do not manually edit the generated Jupyter
performs these conversions. Do not manually edit the generated Jupyter
notebooks! Any manual changes will be lost the next time someone runs
`to_ipynb.py`.

If you update an example script, re-run `to_ipynb.py` to update its
corresponding Jupyter notebook. This process is automated with
[`examples/Makefile`](https://github.com/UCSBarchlab/PyRTL/blob/development/examples/Makefile)
and
[`www/examples/Makefile`](https://github.com/UCSBarchlab/PyRTL/blob/development/www/examples/Makefile).
Running `make` in these directories will re-generate Jupyter notebooks for any
modified examples in their `examples` directory.
[`examples/Makefile`](https://github.com/UCSBarchlab/PyRTL/blob/development/examples/Makefile).
Running `make` in the `examples` directory will re-generate Jupyter notebooks
for any modified examples.
File renamed without changes.
2 changes: 1 addition & 1 deletion www/examples/example-fir.py → examples/example-fir.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import pyrtl

# # Finite impulse filter example.
# # Finite impulse response filter example.


def fir(x: pyrtl.WireVector, bs: list[int]):
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
" # Finite impulse filter example.\n"
" # Finite impulse response filter example.\n"
]
},
{
Expand Down
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ Changelog = "https://github.com/UCSBarchlab/PyRTL/blob/development/CHANGELOG.md"
source = "vcs"

[tool.ruff]
exclude = ["ipynb-examples", "docs/_build", "www/_build", "www/ipynb-examples"]
exclude = ["ipynb-examples", "docs/_build", "www/_build"]

[tool.ruff.lint]
# See https://docs.astral.sh/ruff/rules/
Expand Down
10 changes: 3 additions & 7 deletions tests/test_examples.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,12 @@


def get_scripts(directory: str) -> list[Path]:
return list((Path(os.path.dirname(__file__)) / ".." / directory).glob("*.py"))
return list((Path(os.path.dirname(__file__)) / directory).glob("*.py"))


@pytest.mark.parametrize(
"file",
get_scripts("examples") + get_scripts("www/examples"),
ids=lambda path: path.name,
)
@pytest.mark.parametrize("file", get_scripts("../examples"), ids=lambda path: path.name)
def test_all_examples(file):
"""Test all Python scripts in ``examples/`` and ``www/examples``.
"""Test all Python scripts in ``examples/``.

This just checks that all Python scripts terminate with exit status 0.
"""
Expand Down
2 changes: 1 addition & 1 deletion www/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
# List of patterns, relative to source directory, that match files and
# directories to ignore when looking for source files.
# This pattern also affects html_static_path and html_extra_path.
exclude_patterns = ["examples", "ipynb-examples", "_build", "Thumbs.db", ".DS_Store"]
exclude_patterns = ["_build", "Thumbs.db", ".DS_Store"]

# Enable links to Python standard library classes (str, list, dict, etc).
intersphinx_mapping = {
Expand Down
10 changes: 0 additions & 10 deletions www/examples/Makefile

This file was deleted.

6 changes: 0 additions & 6 deletions www/examples/README.md

This file was deleted.

24 changes: 12 additions & 12 deletions www/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -115,11 +115,11 @@ differences between the approaches.
The code below provides everything needed to instantiate, simulate, and
visualize the resulting design.

.. jupyterlite:: ipynb-examples/example-gcd.ipynb
.. jupyterlite:: ../ipynb-examples/example-gcd.ipynb
:new_tab: True
:new_tab_button_text: Try this example in your browser

.. literalinclude:: examples/example-gcd.py
.. literalinclude:: ../examples/example-gcd.py

.. image:: ../docs/screenshots/gcd.png
:width: 16em
Expand All @@ -134,11 +134,11 @@ differences between the approaches.
an output ``y`` which is the resulting sum of products and is valid every
cycle (since the design is naturally fully pipelined).

.. jupyterlite:: ipynb-examples/example-fir.ipynb
.. jupyterlite:: ../ipynb-examples/example-fir.ipynb
:new_tab: True
:new_tab_button_text: Try this example in your browser

.. literalinclude:: examples/example-fir.py
.. literalinclude:: ../examples/example-fir.py

.. image:: ../docs/screenshots/fir.png
:width: 30em
Expand All @@ -154,11 +154,11 @@ differences between the approaches.
like :func:`~functools.reduce`, which is used to chain together multiple
``max_2`` elements into a bigger ``max_n``.

.. jupyterlite:: ipynb-examples/example-maxn.ipynb
.. jupyterlite:: ../ipynb-examples/example-maxn.ipynb
:new_tab: True
:new_tab_button_text: Try this example in your browser

.. literalinclude:: examples/example-maxn.py
.. literalinclude:: ../examples/example-maxn.py

.. image:: ../docs/screenshots/maxn.png
:width: 15em
Expand All @@ -176,11 +176,11 @@ differences between the approaches.
an 8-bit ROM address and returns the value stored in the ROM at that
address.

.. jupyterlite:: ipynb-examples/example-mul.ipynb
.. jupyterlite:: ../ipynb-examples/example-mul.ipynb
:new_tab: True
:new_tab_button_text: Try this example in your browser

.. literalinclude:: examples/example-mul.py
.. literalinclude:: ../examples/example-mul.py

.. image:: ../docs/screenshots/mul.png
:width: 15em
Expand All @@ -197,11 +197,11 @@ differences between the approaches.
final ``full_sum`` is produced by concatenating the wires in ``sum`` with
:func:`~pyrtl.concat_list`.

.. jupyterlite:: ipynb-examples/example-adder.ipynb
.. jupyterlite:: ../ipynb-examples/example-adder.ipynb
:new_tab: True
:new_tab_button_text: Try this example in your browser

.. literalinclude:: examples/example-adder.py
.. literalinclude:: ../examples/example-adder.py

.. image:: ../docs/screenshots/adder.png
:width: 15em
Expand Down Expand Up @@ -255,11 +255,11 @@ introduction to fixed 4-bit adders
<https://www.youtube.com/watch?v=bL3ihMA8_Gs>`_, let's go ahead and build an
`arbitrary` bitwidth adder.

.. jupyterlite:: ipynb-examples/example-ripple-carry.ipynb
.. jupyterlite:: ../ipynb-examples/example-ripple-carry.ipynb
:new_tab: True
:new_tab_button_text: Try this example in your browser

.. literalinclude:: examples/example-ripple-carry.py
.. literalinclude:: ../examples/example-ripple-carry.py

The code above includes ``ripple_add``, an adder generator with Python-style
slices on wires, ``counter``, an instance of :class:`~pyrtl.Register`, and all
Expand Down
Loading