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#

compress_to_piecewise_linear(times, values[, rtol, ...])

Reduce (t, v) pairs to a compact piecewise-linear table.

sample_callable(fn[, t_start, t_end, n_points])

Sample a callable fn(t) uniformly over [t_start, t_end].

trace_func1_to_signal(func1_obj, signal_id[, t_start, ...])

Sample a ct.Func1 or callable and emit a PiecewiseLinear signal.

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.Func1 or callable and emit a PiecewiseLinear signal.

Parameters:
  • func1_obj – Any callable that accepts a float t and returns a float.

  • signal_id – STONE id to assign to the emitted signal block.

  • t_start – Time range to sample. If t_end is None, defaults to 1e-7 for objects with Gaussian in their type, else 1.0.

  • t_end – Time range to sample. If t_end is None, defaults to 1e-7 for objects with Gaussian in their type, else 1.0.

  • n_points – Number of sample points before compression.

  • rtol – Relative tolerance for Douglas–Peucker compression.

Return type:

DetectedSignal or None