boundlab.interp.Interpreter#

class boundlab.interp.Interpreter[source]#

Bases: Generic[E]

Methods

__init__

Initialize an interpreter with a dispatcher.

and_then

Return a new interpreter that applies another function to the output of this one.

items

product

Return a new interpreter that produces tuples of results from this and other interpreters.

register

Register a handler for an operator.

__init__(dispatcher)[source]#

Initialize an interpreter with a dispatcher.

The dispatcher maps ONNX operator names to handler functions.

Keys are the ONNX op_type strings (e.g. "Gemm", "Relu", "Reshape"). Custom-domain ops (e.g. "diff_pair" from the boundlab domain) are also keyed by bare op_type.

register(key, value)[source]#

Register a handler for an operator.

items()[source]#
product(*other)[source]#

Return a new interpreter that produces tuples of results from this and other interpreters.

and_then(other)[source]#

Return a new interpreter that applies another function to the output of this one.

__call__(model)[source]#

Build an expression-level interpreter for an ONNX model.

Parameters:

model (ir.Model | str | Path) –

An onnx_ir.Model or a str / pathlib.Path pointing to an .onnx file.

The ONNX graph is walked in topological order (ONNX guarantees this). For each node:

  • Initializer inputs are wrapped as Tensor and passed as positional arguments.

  • Optional/missing inputs (empty-string name) are passed as None.

  • Node attributes are converted to Python scalars / lists and passed as keyword arguments.

  • The dispatcher is keyed on the bare op_type (domain is ignored); e.g. a custom boundlab::diff_pair node is dispatched as "diff_pair".

Returns:

  • A callable interpret(*exprs) that maps input

  • Expr objects to output expression(s).

Return type:

Callable[…, E]

Examples

>>> import torch, tempfile, os
>>> from boundlab.interp import Interpreter, ONNX_BASE_INTERPRETER
>>> from boundlab.zono import interpret
>>> import boundlab.expr as expr