Predicate DSL API Reference¶
predicate ¶
Predicate DSL — composable expressions for waveform queries.
This module provides a Python DSL for building signal predicates that are evaluated entirely in Rust. Expressions are pure data structures (an AST) — no waveform access happens in Python. The entire expression tree is handed to the Rust evaluator in a single PyO3 call.
Quick start¶
from tsunami.predicate import Signal, scope
# Direct signal references
clk = Signal("tb.dut.clk")
valid = Signal("tb.dut.tl_a_valid")
# Using a scope prefix
with scope("tb.dut") as s:
handshake = s.tl_a_valid & s.tl_a_ready
acquire = handshake & (s.tl_a_opcode == 4)
# Compose with operators
rising_valid = valid.rise()
sequence = acquire >> (s.tl_d_valid, 50_000) # with time window
violation = s.tl_d_valid.rise().preceded_by(acquire, within_ps=50_000).__invert__()
Supported operators¶
| Syntax | Meaning |
|---|---|
a & b |
Logical AND |
a \| b |
Logical OR |
~a |
Logical NOT |
a ^ b |
Logical XOR |
sig == val |
Signal equals constant |
sig > val / sig < val |
Unsigned comparison |
sig.rise() |
Rising edge (0 -> non-zero) |
sig.fall() |
Falling edge (non-zero -> 0) |
a >> b |
Sequence: a followed by b |
a >> (b, window_ps) |
Sequence with time window |
a.preceded_by(b, within_ps=N) |
b occurred before a within window |
sig[7:0] |
Bitfield extraction |
Expr
dataclass
¶
Base class for all predicate expression nodes.
All expression nodes carry a tag string that the Rust evaluator uses
to identify the node type via FromPyObject. You normally don't construct
Expr directly — use Signal and operators instead.
__xor__ ¶
Logical XOR: a ^ b is true when exactly one operand is non-zero.
__rshift__ ¶
Sequence operator.
a >> b— a followed by b (unbounded).a >> (b, window_ps)— a followed by b withinwindow_pspicoseconds.
Signal
dataclass
¶
Bases: Expr
Reference to a waveform signal by its full hierarchical path.
This is the primary leaf node in predicate expressions. The path must match a signal in the waveform file exactly (dot-separated hierarchy).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str
|
Full hierarchical path, e.g. |
required |
Example
__getitem__ ¶
Extract a bitfield: sig[7:0] for a range or sig[3] for a single bit.
PrecededBy
dataclass
¶
PrecededBy(tag: str = 'preceded_by', a: Expr = None, b: Expr = None, within_ps: Optional[int] = None)
Bases: Expr
scope ¶
Context manager that sets a hierarchy prefix for signal access.
Attribute access on the yielded proxy creates
Signal objects with the prefix prepended.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
prefix
|
str
|
Hierarchy prefix (e.g. |
required |
Example
signals ¶
Context manager for aliased signal bindings.
Maps short alias names to full signal paths. Useful when working with signals from a configuration dict.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
**kwargs
|
str
|
Mapping of alias name to full signal path. |
{}
|
ScopeProxy ¶
Provides attribute-based signal access with a hierarchy prefix.