Jupyter kernel for cocotb
Project description
cocotb Jupyter Kernel
This kernel adds support for using cocotb within Jupyter notebooks.
Why is a dedicated kernel needed?
cocotb works in conjunction with an HDL simulator. As such, attempting to import cocotb
within a notebook will not work because no simulator is attached. This kernel works by first building the HDL design and launching the simulator using cocotb's runners, then
having a cocotb test module launch ipykernel, which will connect to the notebook and execute code cells.
Installation
Prerequisites:
- Python 3.10+
- JupyterLab 4+ or Jupyter Notebook 6+
- An HDL simulator (such as Icarus Verilog, Verilator, or GHDL)
After installing the prerequisites, the kernel can be installed via pip.
pip install cocotb_kernel
To complete the installation of kernel, execute one of the following commands:
# Install to Jupyter's user directory, ~/.local/share/jupyter/kernel
python -m cocotb_kernel.install --user
# or, if using conda / venv
python -m cocotb_kernel.install --sys-prefix
# or, a custom prefix (Warning: kernel might not be detected by Jupyter)
python -m cocotb_kernel.install --prefix PREFIX
# or, install to Jupyter's base directory, /usr/local/share/jupyter (requires root)
sudo python -m cocotb_kernel.install
Usage
Before launching the kernel, create a TOML file named cocotb.toml
within the project's root directory (similar to cocotb's Makefile).
The TOML file follows the cocotb runner
build()
and test()
arguments, with a few exceptions, as shown:
# The simulator to build and simulate the HDL design
# https://docs.cocotb.org/en/stable/simulator_support.html
simulator = "icarus"
# The top level HDL module
hdl_toplevel = "foo"
# The language of the top level HDL module
hdl_toplevel_lang = "verilog"
# Optional: Verilog parameters or VHDL generics
[parameters]
# Build options
# https://docs.cocotb.org/en/stable/library_reference.html#cocotb.runner.Simulator.build
[build]
verilog_sources = ["hdl/foo.sv", "../hdl/foo.sv"] # specify sources relative to cocotb.toml
vhdl_sources = ["hdl/*.vhdl", "**/*.vhdl"] # wildcards are also supported
# Optional: Defines to set for building
[build.defines]
# Test options
# https://docs.cocotb.org/en/stable/library_reference.html#cocotb.runner.Simulator.test
[test]
# Optional: Extra environment variables to set for testing
[test.extra_env]
Once the TOML file is created, navigate to or launch JupyterLab within the project's root directory and create or open a notebook with the cocotb kernel.
Planned Features
- Move wavedrom support into kernel (cocotb v2.0 removes the wavedrom module)
- Ability to specify a custom TOML filename, from the default
cocotb.toml
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
File details
Details for the file cocotb_kernel-1.0.4.tar.gz
.
File metadata
- Download URL: cocotb_kernel-1.0.4.tar.gz
- Upload date:
- Size: 9.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: python-requests/2.32.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 61d53561cb5887e7369be412ceaeb95a77b06ecd189734d1339d053f4fde7523 |
|
MD5 | 47c74f17ece80145f9033c459ad7ce41 |
|
BLAKE2b-256 | 4b9f5b12456c946ba2d5f2b1cfa1db76ce630ce7456ae5e0c6d1ab62b66fe179 |
File details
Details for the file cocotb_kernel-1.0.4-py3-none-any.whl
.
File metadata
- Download URL: cocotb_kernel-1.0.4-py3-none-any.whl
- Upload date:
- Size: 6.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: python-requests/2.32.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | aa0b1bf165cc74dcfca00d81549819827dd3f8a6bac0236be5efb42dd59f7684 |
|
MD5 | 5b657af4d0d3170dd4d699a34974b7eb |
|
BLAKE2b-256 | 61793ae40003269673c6ba35dcd23419a9cea1a6a82a86521de8fdc400ce3f5d |