Skip to main content

Jupyter kernel for cocotb

Project description

cocotb Jupyter Kernel

Binder

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

cocotb_kernel-1.0.2.tar.gz (9.4 kB view details)

Uploaded Source

Built Distribution

cocotb_kernel-1.0.2-py3-none-any.whl (6.4 kB view details)

Uploaded Python 3

File details

Details for the file cocotb_kernel-1.0.2.tar.gz.

File metadata

  • Download URL: cocotb_kernel-1.0.2.tar.gz
  • Upload date:
  • Size: 9.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: python-requests/2.32.3

File hashes

Hashes for cocotb_kernel-1.0.2.tar.gz
Algorithm Hash digest
SHA256 afaa0455ee933c07425a6520d4fb782c9bd10da9b664495d98d90ad6027e0584
MD5 b5537fc6a23b2273dc07f1b8ec3b6e8b
BLAKE2b-256 33e44ac3873d0f0e1c4d7053a45068beba78ac8bd5678c4dbc3d110ced0394c1

See more details on using hashes here.

File details

Details for the file cocotb_kernel-1.0.2-py3-none-any.whl.

File metadata

File hashes

Hashes for cocotb_kernel-1.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 55cdc945b03e2dd4e6b55ca41d51986fc1ec5a150b8de8a653922c435a1cddfb
MD5 12dbc1eb3c42c457844e1e1453f7ffcf
BLAKE2b-256 58c15e775c2024fc94cfa33121058bdb35db2a83274b8256b84689ec22e8b0cd

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page