simmynet is a package: simmynet/__init__.py re-exports the compiled core simmynet._core and the pure-Python wrapper simmynet.wrapper. Requires Python ≥ 3.9. sn.__version__ is "2.2.0".
$\mathrm{Step}(w \cdot \mathrm{vec}(W_{\text{compiled}}) + b)$ for a word. factors is $L$ row-major $k \times k$ matrices concatenated in word order (empty list = identity); weight has $k^2$ entries; k ∈ {2, 3, 4}, otherwise ValueError. Folds on every call.
CompiledWord
(k, factors)
object
A word folded once into a single $k \times k$ matrix.
Matrix2x2, Matrix3x3, Matrix4x4
classes
Fixed-size row-major double matrices.
gemm_count() / reset_gemm_count()
int / None
Matrix-multiplication passes executed so far (shared by every submodule).
dsl, finite_field, wrapper
submodules
Also importable as simmynet.dsl, simmynet.finite_field.
Matrix2x2 / Matrix3x3 / Matrix4x4 (replace $N$ by 2, 3 or 4)
Member
Kind
Description
Matrix()
constructor
Identity matrix.
identity(), zero()
static
Identity / all-zero matrix.
from_list(flat)
static
Build from $N^2$ row-major numbers; ValueError otherwise.
dim
class property
$N$ (read from the class, e.g. Matrix3x3.dim).
to_list()
method
Row-major list of $N^2$ floats.
m[i, j], m[i, j] = v
item access
Get/set; IndexError if out of range.
a * b, a @ b
operators
Matrix product (counts one pass).
apply(x)
method
Matrix-vector product with a length-$N$ list.
max_abs_diff(other)
method
$\max_{ij} \lvert a_{ij} - b_{ij} \rvert$.
a == b
operator
Exact element-wise equality.
Exceptions
Exception
Raised for
SimmyNetError
Base class of the four below.
LexError
Unexpected character in DSL source.
ParseError
Syntax error.
CompileError
Unknown names, dimension mismatches, no separating lift, …
SimmyNetRuntimeError
Run-time errors, e.g. Job.decide() on a job with no hyperplane.
ValueError, IndexError
Bad sizes / indices on matrix types and finite_field.Mat2; EllipticCurve.with_trace with a Hasse–Weil-violating trace; Legendre counting outside its domain.
OverflowError
A finite_field result that does not fit in int64.
RuntimeError
Editing or re-flushing a DSLGroup after a successful flush.
Wrapper layer (deferred execution)
simmynet.wrapper (re-exported from simmynet) records what you ask for and enters the C++ core only when a result is needed.
Pattern
What happens
C++ crossings
Graph builder
*, @, + on Generator / Word concatenate lazily (O(1) rope nodes, iterative flattening). No arithmetic.
0
JIT lowering + cache
Word.decide(weight, bias) flattens once, builds the C++ CompiledWord (one fold, $W_{\text{compiled}}$), caches it in the Word; later calls reuse it.
first call: compile + decide; afterwards: 1 per call, O(1) in the word length
DSL string builders
DSLGroup / DSLProgram assemble DSL text; the C++ interpreter is entered once by run() or compile().
1 per builder
Generator(name, matrix)
An immutable $k \times k$ generator ($k = 2, 3, 4$); matrix is nested rows or a flat list.
An immutable lazy product; the result of combining generators.
Member
Description
a * b, a @ b, a + b
Concatenation (the group operation; + is additive notation for it, not matrix addition). Mixing dimensions raises ValueError.
w ** n
Repetition by squaring over shared sub-words; n = 0 is the identity, negative n raises ValueError.
Word.identity(k)
The empty word.
len(w), w.dim, w.factors, iteration
Inspection (factors flattens iteratively and caches; no recursion limit).
w.decide(weight, bias=0.0)
Step(weight · vec(W_compiled) + bias); compiles and caches on first use; thread-safe (one compile even under races).
w.compile(), w.is_compiled
Explicit lowering to a CompiledWord; cache flag.
w.matrix
$W_{\text{compiled}}$, row-major (cached).
w.decide_once(weight, bias)
One-shot decision through eval_word_compiled; caches nothing (folds per call).
r=Generator.rotation("r",90)s=Generator("s",[[-1,0],[0,1]])w=r*s*r# lazy
w.decide([0,0,0,1],-0.5)# True: r*s*r == s; first call compiles once
DSLGroup(name)
Builds group name { ... }. Every method appends one statement and validates names and expressions (no braces, commas, comments or newlines can be smuggled into the text).
flush once → dsl.RunResult (cached; a second call returns the same object)
compile(sharpness=10.0)
flush once → dsl.Program; the caller owns it, the builder keeps no reference
A group flushes exactly once: after a successful flush, editing it or flushing it again raises RuntimeError. A failed flush (e.g. CompileError) holds no C++ resources and does not consume the builder. DSLProgram(*groups) flushes several groups together (run, compile, source) and freezes them. GenRef / DSLWord combine with *, @, +, ** n (a single generator may take negative n: g ** -1) and render as r * s^2 * R(pi/4).
g=DSLGroup("D4")rr=g.generator("r",rotation=90)ss=g.generator("s",matrix=[[-1,0],[0,1]])g.subgroup("D",[rr,ss]);g.subgroup("H",[ss])g.separate("InH",[0,0,0,1],-0.5)g.classify("InH",word=rr*ss*rr,expect=1)g.verify("InH","H","D")g.run().passed# ONE flush to the C++ interpreter
Helpers
Helper
Returns
Description
synthesize_space(points, name="Auto")
SynthesisResult
One flush; points = [((x, y), label), …]. Fields lifts (e.g. ['k1 = abs(x - y)']), weight, bias, log, n_points, separation. A plain Python object: the C++ Program is dropped before returning.
input_vector, final_vector, decision, score, soft_score (the last three are None for eval jobs), trace → list[(label, vector)]
The hierarchy is Program → Group → Task → Job. Job.evaluate() runs the constant-folded graph (one $k \times k$ pass); reference=True runs the unfolded Kronecker-expanded oracle, which yields the per-layer trace.
prog=dsl.Interpreter().compile(source)job=prog.groups[0].tasks[0].jobs[0]job.folded_factors,job.folded_matrix# constant folding, visible
job.evaluate(trace=True).decision# one k x k pass
simmynet.finite_field
Exact int64 arithmetic. A result that cannot be certified inside int64 is never wrapped: functions returning a matrix or scalar raise OverflowError; those returning an optional return None.
Elliptic curves and traces
Name
Signature
Returns
Description
EllipticCurve
(a, b, q)
object
$y^2 = x^3 + ax + b$ over $\mathbb{F}_q$ ($a$, $b$ reduced mod $q$); properties a, b, q, trace (None if unresolved).
EllipticCurve.valid
()
bool
$3 \lt q \le 2^{62}$, $q$ odd, $q \bmod 3 \ne 0$, and nonsingular mod $q$. Primality is not tested.
EllipticCurve.with_trace
(a_q)
EllipticCurve
Copy with a known trace attached. Raises ValueError if $a_q^2 \gt 4q$ (Hasse–Weil bound; no elliptic curve over $\mathbb{F}_q$ has such a trace). The bound is necessary, not sufficient: it does not prove $a_q$ is the trace of this curve. The original curve is left untouched.
EllipticCurve.resolve
(resolver)
EllipticCurve
Copy with the trace from resolver(curve) -> int \| None. None leaves the trace unresolved; a Hasse-violating value raises ValueError.
EllipticCurve.count_points
()
int
$\#E(\mathbb{F}_q)$ including the point at infinity, by exact $O(q)$ Legendre-symbol summation $1 + \sum_x (1 + \chi(x^3 + ax + b))$. Only for prime $q$ with $5 \le q \le 10^6$ (MAX_LEGENDRE_MODULUS); raises ValueError for composite or out-of-range $q$ or a singular curve. Not Schoof’s algorithm.
EllipticCurve.compute_trace
()
int
$a_q = q + 1 - \#E(\mathbb{F}_q)$; same domain and errors.
EllipticCurve.with_computed_trace
()
EllipticCurve
Copy with compute_trace() attached; same domain and errors.
legendre_trace_resolver
(curve)
int \| None
curve.resolve(legendre_trace_resolver); None outside the counter’s domain.
hasse_bound_holds
(t, q)
bool
Exact $t^2 \le 4q$ in 128-bit arithmetic; False for $q \le 0$.
MAX_LEGENDRE_MODULUS
int
1000000.
schoof_trace_stub
(curve)
None
Placeholder for a future Schoof/SEA resolver: alwaysNone. Schoof/SEA is not implemented.