ONNX Converter#
Export fitted Iguanas rule strings to a self-contained ONNX binary
classifier that can be served by any ONNX-compatible runtime
(e.g. onnxruntime, ONNX.js, Triton, Azure ML, etc.).
Functions#
rules_to_onnx#
- iguanas.onnx_converter.rules_to_onnx(rules: str | list[str], dtype: str = 'f32') onnx.onnx_ml_pb2.ModelProto[source]#
Convert Iguanas rule strings to an ONNX binary classifier.
- Parameters:
rules (str | list[str]) – One rule string or a list of rule strings. When a list is supplied, the rules are OR’d together — the model outputs 1 if any rule fires. Each rule must use the
X["col"] op valnotation produced by Iguanas, whereopis one of>=,>,<=,<,==,!=, and conditions may be combined with&/|.dtype (str, default
"f32") – Numeric dtype for the input tensor and thresholds."f32"→ float32,"f64"→ float64.
- Returns:
ONNX model with:
input
Xshape[N, num_features](dtype as requested)output
predictionshape[N](int64, values 0 or 1)
Feature names are stored in
metadata_propsas"feature_0","feature_1", … in first-appearance order.- Return type:
onnx.ModelProto
- Raises:
ValueError – If
rulesis empty,dtypeis not"f32"or"f64", or a rule string is syntactically invalid or uses unsupported node types.
Notes
Security. This conversion parses each rule with
astand emits a static ONNX graph; it never callseval(), and the resulting model executes no Python at scoring time. Only a whitelist of AST nodes (subscripted column access, numeric-literal comparisons, and&/|) is accepted — anything else raisesValueErrorrather than being executed. This makes ONNX export the recommended production deployment path, in contrast toapply_rules(), which compiles rule strings witheval()and therefore requires trusted rule sources.See also
- iguanas.rule_evaluation.apply_rules
In-process evaluation via
eval(); requires trusted rule strings.- iguanas.rule_evaluation.apply_rules_lazy
Lazy in-process evaluation, same
eval()caveat.