boulder.sim2stone_trace#
Trace-based fallback for Func1 patterns that cannot be AST-matched.
When sim2stone_ast cannot identify the exact parametric form of a signal
(e.g. a complex lambda, external table, or multi-step expression), this module
wraps the script execution to record (t, value) series and compress them
to a PiecewiseLinear block with an adaptive tolerance.
Usage is intentionally optional: import failures (numpy not present) are silently handled and the caller falls back to an empty signal list.
Functions#
|
Reduce |
|
Sample a callable |
|
Sample a |
Module Contents#
- boulder.sim2stone_trace.compress_to_piecewise_linear(times, values, rtol=0.001, max_points=200)#
Reduce
(t, v)pairs to a compact piecewise-linear table.Uses Douglas–Peucker-style adaptive reduction: keep a point only if it deviates by more than
rtol * max(|values|)from the linear interpolant between its neighbours.Returns a list of
[t, v]pairs.
- boulder.sim2stone_trace.sample_callable(fn, t_start=0.0, t_end=1.0, n_points=500)#
Sample a callable
fn(t)uniformly over[t_start, t_end].Returns
(times, values). Silently skips points where the callable raises.
- boulder.sim2stone_trace.trace_func1_to_signal(func1_obj, signal_id, t_start=0.0, t_end=None, n_points=500, rtol=0.001)#
Sample a
ct.Func1or callable and emit aPiecewiseLinearsignal.- Parameters:
func1_obj – Any callable that accepts a float
tand returns a float.signal_id – STONE id to assign to the emitted signal block.
t_start – Time range to sample. If
t_endisNone, defaults to 1e-7 for objects withGaussianin their type, else 1.0.t_end – Time range to sample. If
t_endisNone, defaults to 1e-7 for objects withGaussianin their type, else 1.0.n_points – Number of sample points before compression.
rtol – Relative tolerance for Douglas–Peucker compression.
- Return type:
DetectedSignalorNone