This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
chipflow-lib is a Python library for working with the ChipFlow platform, enabling users to build ASIC (Application Specific Integrated Circuit) designs using the Amaranth HDL framework. The library provides a CLI tool (chipflow) that handles design elaboration, simulation, and submission to the ChipFlow cloud builder.
- Install dependencies:
pdm install - Python 3.11+ required
- Uses PDM for dependency management
- Run all tests:
pdm test - Run with coverage:
pdm test-cov - Run with HTML coverage report:
pdm test-cov-html - Run single test:
pdm run pytest tests/test_file.py::test_function_name - Run test for specific module with coverage:
pdm run python -m pytest --cov=chipflow_lib.MODULE tests/test_file.py -v
- Run all linting checks:
pdm lint- Includes: license header check, ruff linting, and pyright type checking
- Run ruff only:
pdm run ruff check - Run pyright only:
pdm run pyright chipflow_lib
- Build docs:
pdm docs - Test documentation:
pdm test-docs
- Run chipflow CLI:
pdm chipflow <command>
-
CLI System (
cli.py):- Entry point for the
chipflowcommand - Dynamically loads "steps" (silicon, sim, software) from configuration
- Steps can be extended via
chipflow.toml[chipflow.steps]section - Parses
chipflow.tomlconfiguration using Pydantic models
- Entry point for the
-
Configuration System:
chipflow.toml: User project configuration file (must exist inCHIPFLOW_ROOT)config_models.py: Pydantic models defining configuration schemaconfig.py: Configuration file parsing logic- Key configuration sections:
[chipflow],[chipflow.silicon],[chipflow.simulation],[chipflow.software],[chipflow.test]
-
Platform Abstraction (
platforms/):SiliconPlatform: Targets ASIC fabrication (supports SKY130, GF180, GF130BCD, IHP_SG13G2, HELVELLYN2)SimPlatform: Targets simulation (builds C++ CXXRTL simulator)SoftwarePlatform: RISC-V software build support- Each platform has process-specific port types (e.g.,
Sky130Portwith drive mode configuration)
-
Steps System (
steps/):- Extensible command architecture
silicon.py: Handles ASIC preparation and cloud submissionprepare: Elaborates Amaranth design to RTLILsubmit: Submits design to ChipFlow cloud builder (requiresCHIPFLOW_API_KEY)
sim.py: Simulation workflowbuild: Builds CXXRTL simulatorrun: Runs simulation with softwarecheck: Validates simulation against reference events
software.py: RISC-V software compilation
-
Pin Locking System (
_pin_lock.py):chipflow pin lock: Allocates physical pins for design components- Generates
pins.lockfile with persistent pin assignments - Attempts to reuse previous allocations when possible
- Package definitions in
_packages.pydefine available pins per package
-
IO Annotations (
platforms/_utils.py,platforms/_signatures.py):- IO signatures define standard interfaces (JTAG, SPI, I2C, UART, GPIO, QSPI)
IOModelconfigures electrical characteristics (drive mode, trip point, inversion)- Annotations attach metadata to Amaranth components for automatic pin allocation
-
Component Discovery via Configuration:
- User defines top-level components in
[chipflow.top]section asname = "module:ClassName" _get_cls_by_reference()dynamically imports and instantiates classestop_components()returns dict of instantiated components
- User defines top-level components in
-
Port Wiring:
_wire_up_ports()insteps/__init__.pyautomatically connects platform ports to component interfaces- Uses pin lock data to map logical interface names to physical ports
- Handles signal inversion, direction, and enable signals
-
Build Process:
- Amaranth elaboration → RTLIL format → Yosys integration → Platform-specific output
- For silicon: RTLIL sent to cloud builder with pin configuration
- For simulation: RTLIL → CXXRTL C++ → compiled simulator executable
-
Error Handling:
- Custom
ChipFlowErrorexception for user-facing errors - Causes are preserved and printed with
traceback.print_exception(e.__cause__) - CLI wraps unexpected exceptions in
UnexpectedErrorwith debug context
- Custom
- Follow PEP-8 style
- Use
snake_casefor Python - Type hints required (checked by pyright in standard mode)
- Ruff linting enforces: E4, E7, E9, F, W291, W293 (ignores F403, F405 for wildcard imports)
- All files must have SPDX license header:
# SPDX-License-Identifier: BSD-2-Clause - No trailing whitespace
- No whitespace on blank lines
- Tests located in
tests/directory - Fixtures in
tests/fixtures/ - Use public APIs when testing unless specifically instructed otherwise
- CLI commands count as public API
- Test coverage enforced via pytest-cov
- Create
chipflow.tomlwith[chipflow.silicon]section defining process and package - Run
chipflow pin lockto allocate pins - Run
chipflow silicon prepareto elaborate design - Set
CHIPFLOW_API_KEYenvironment variable - Run
chipflow silicon submit --waitto submit and monitor build
- Run
chipflow sim buildto build simulator - Run
chipflow sim runto run simulation (builds software automatically) - Run
chipflow sim checkto validate against reference events (requires[chipflow.test]configuration)
CHIPFLOW_ROOT: Project root directory (auto-detected if not set)CHIPFLOW_API_KEY: API key for cloud builder authenticationCHIPFLOW_API_KEY_SECRET: Deprecated, useCHIPFLOW_API_KEYinsteadCHIPFLOW_API_ORIGIN: Cloud builder URL (default: https://build.chipflow.com)CHIPFLOW_BACKEND_VERSION: Developer override for backend versionCHIPFLOW_SUBMISSION_NAME: Override submission name (default: git commit hash)