DSL (Example Construction)¶
The spflow.dsl module provides a small, example-oriented expression layer for constructing
simple circuits with algebraic syntax. It is intended for documentation and showcase snippets;
production model construction is typically done directly via spflow.modules.
Construction-only DSL for building SPFlow circuits.
This module provides a small, non-invasive expression layer for writing examples with algebraic syntax while keeping the core spflow.modules API unchanged.
The DSL is intentionally minimal:
Products: term(A) * term(B)
Weighted sums (mixtures): 0.4 * term(A) + 0.6 * term(B)
To obtain an actual Module, call .build() on the resulting expression.
Notes
Weights must be provided for sums; term(A) + term(B) is intentionally disallowed.
Weighted sums are restricted to terms with out_shape.channels == 1 for simplicity.
For convenience in docs/examples, dsl() can temporarily enable operator overloads on spflow.modules.module.Module within a context manager, so that expressions like 0.4 * Normal(0) * Normal(1) + 0.6 * Normal(0) * Normal(1) work without wrapping leaves.
- class spflow.dsl.Buildable(*args, **kwargs)[source]¶
Bases:
ProtocolProtocol for objects that can build a Module.
- class spflow.dsl.ProductExpr(factors)[source]¶
Bases:
BuildableProduct of one or more sub-expressions.
- class spflow.dsl.SumExpr(terms)[source]¶
Bases:
BuildableA weighted mixture of expressions.
Terms are stored as (weight, expr) pairs and normalized on build.
- class spflow.dsl.Term(module)[source]¶
Bases:
BuildableLeaf expression node that wraps a concrete Module.
- module: Module¶
- class spflow.dsl.WeightedExpr(weight, expr)[source]¶
Bases:
objectA weighted expression term used as an input to mixtures.
- spflow.dsl.as_expr(value)[source]¶
Convert a Module or DSL expression to a DSL expression.
- Return type:
- spflow.dsl.build(value)[source]¶
Build a concrete Module from a DSL expression (or pass through Module).
- Return type:
Module
- spflow.dsl.dsl()[source]¶
Temporarily enable DSL operator overloads on Module.
This is intended for documentation/examples. It monkeypatches operator methods on spflow.modules.module.Module for the duration of the context manager and restores the original methods afterward.
Within the context: - Module * Module builds a ProductExpr - float * Module and Module * float create a WeightedExpr - WeightedExpr + WeightedExpr (+ …) creates a SumExpr - Module + Module remains disallowed (weights must be explicit)