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
2 changes: 1 addition & 1 deletion .copier-answers.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Changes here will be overwritten by Copier
_commit: 5ff720b
_commit: '4372075'
_src_path: https://github.com/python-project-templates/base.git
add_docs: true
add_extension: python
Expand Down
12 changes: 6 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,16 @@ lint-py: ## lint python with ruff
python -m ruff format --check dau_sim

lint-docs: ## lint docs with mdformat and codespell
python -m mdformat --check README.md docs/src
python -m codespell_lib README.md docs/src
python -m mdformat --check README.md $(wildcard docs/src)
python -m codespell_lib README.md $(wildcard docs/src)

fix-py: ## autoformat python code with ruff
python -m ruff check --fix dau_sim
python -m ruff format dau_sim

fix-docs: ## autoformat docs with mdformat and codespell
python -m mdformat README.md docs/src
python -m codespell_lib --write README.md docs/src
python -m mdformat README.md $(wildcard docs/src)
python -m codespell_lib --write README.md $(wildcard docs/src)

lint: lint-py lint-docs ## run all linters
lints: lint
Expand All @@ -50,9 +50,9 @@ check-dist: ## check python sdist and wheel with check-dist
check-dist -v

check-types: ## check python types with ty
ty check --python $$(which python)
python -m ty check

checks: check-dist
checks: check-dist check-types

# Alias
check: checks
Expand Down
6 changes: 3 additions & 3 deletions dau_sim/api.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from datetime import timedelta
from datetime import datetime, timedelta

from ccflow import BaseModel
from pydantic import ConfigDict
Expand All @@ -14,7 +14,7 @@ class SimulationResult(BaseModel):
model_config = ConfigDict(frozen=True)

module_name: str
traces: tuple[tuple[str, tuple[tuple[object, int], ...]], ...]
traces: tuple[tuple[str, tuple[tuple[datetime, int], ...]], ...]

def latest(self, signal: str) -> int | None:
"""Return the most recent value for a signal, if available."""
Expand Down Expand Up @@ -94,4 +94,4 @@ def write_vcd(
signals: list[str] | None = None,
exclude: list[str] | None = None,
) -> None:
self._compiled.write_vcd(path, dict(result.traces), timescale=timescale, signals=signals, exclude=exclude)
self._compiled.write_vcd(path, {name: list(values) for name, values in result.traces}, timescale=timescale, signals=signals, exclude=exclude)
14 changes: 8 additions & 6 deletions dau_sim/backends/cocotb_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
import time
import types
from collections.abc import Callable
from typing import Any
from typing import Any, cast

from dau_sim.compiler.compile import (
_build_domain_info,
Expand Down Expand Up @@ -700,9 +700,9 @@ def stop(self) -> None:
# Simulator module — drop-in replacement for cocotb.simulator


def _create_simulator_module(engine: SimulationEngine) -> types.ModuleType:
def _create_simulator_module(engine: SimulationEngine) -> Any:
"""Create a module object that mimics ``cocotb.simulator``."""
mod = types.ModuleType("cocotb.simulator")
mod: Any = types.ModuleType("cocotb.simulator")
mod.__package__ = "cocotb"

# Constants
Expand Down Expand Up @@ -752,7 +752,7 @@ def register_nextstep_callback(func: Callable, *args: Any) -> DauSimCallback:
def register_value_change_callback(signal: DauSimHandle, func: Callable, edge: int, *args: Any) -> DauSimCallback:
return engine.register_value_change_callback(signal, func, edge, *args)

def get_root_handle(name: str | None = None) -> DauSimHandle: # noqa: ARG001 (cocotb simulator API)
def get_root_handle(name: str | None = None) -> DauSimHandle | None: # noqa: ARG001 (cocotb simulator API)
return engine._root_handle

def get_sim_time() -> tuple[int, int]:
Expand Down Expand Up @@ -837,9 +837,9 @@ def run_cocotb(
else:
# Try Amaranth
try:
from dau_sim.frontends.amaranth_frontend import lower_amaranth_design
from dau_sim.frontends.amaranth_frontend import from_amaranth

ir_module = lower_amaranth_design(design)
ir_module = from_amaranth(design)
except (ImportError, TypeError):
raise TypeError(f"Cannot lower design of type {type(design).__name__}. Pass an Amaranth Elaboratable or a dau-sim IR Module.")

Expand All @@ -866,6 +866,8 @@ def _run_with_patched_simulator(
import cocotb._event_loop
import cocotb._gpi_triggers
import cocotb.simtime

cocotb = cast(Any, cocotb)
# isort: on

# Save originals
Expand Down
Loading