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.11,<3.14 (cocotb 2.0.1 supports up to 3.13)
  • 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]
sources = ["hdl/foo.sv", "../hdl/foo.sv", "hdl/*.vhdl", "**/*.vhdl"] # specify sources relative to cocotb.toml

# Optional: Defines to set for building
[build.defines]

# Optional: 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.

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-2.0.1.tar.gz (13.7 kB view details)

Uploaded Source

Built Distribution

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

cocotb_kernel-2.0.1-py3-none-any.whl (6.2 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for cocotb_kernel-2.0.1.tar.gz
Algorithm Hash digest
SHA256 a90fd24209412bbce53ffe2cda713952a709c5a8e19795df530c1849563bd88f
MD5 c47ca81732bf162661317c9cd2e49d3a
BLAKE2b-256 1309569e397fdc28a55bbf761d93859aceaa4ad1fc4bfdbfa7c730823c435b7b

See more details on using hashes here.

File details

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

File metadata

  • Download URL: cocotb_kernel-2.0.1-py3-none-any.whl
  • Upload date:
  • Size: 6.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: python-requests/2.32.5

File hashes

Hashes for cocotb_kernel-2.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 f11bbc9863aebf8b234774c9f9ab27af8cb4d02d8d7f485de59111ed9570bf6c
MD5 67639dc1b8ba8592ab6f577e4d30de33
BLAKE2b-256 1bb563d804b122ee37231b0359b5353ace0e0b841efa79b3938b4957e8411ab2

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