Compiled symbolic expressions
As mentioned in #107 and %Alpha 1 , symbolic expressions need to be compiled rather than using lambdas to evaluate these during simulation time. This MR contains an implementation of this, using the tinyexpr evaluation engine to compile and evaluate the expressions.
finesse.cyexpr
wraps the parts of tinexpr that we need, using a cy_expr
struct,
then this is used in ElementWorkspace
where an array of these structs is
created and initialised. Fast evaluation of symbolic parameters is then
performed using this array.
A working example is given in playground/symbolics/scan.py
.
This struct has also been used to overhaul how symbolic ABCD matrices get evaluated
during a simulation. Each relevant ConnectorWorkspace
now stores an array of pointers to cy_expr
containing the changing symbolic ABCD matrix elements (NULL
if not changing).
These are evaluated (with direct pointer access) during the update_parameter_values
routine of each of these workspaces.
Things to address now (before merging):
-
Fix seg fault that seems to be occurring when evaluating changing ABCD matrix elements in beam splitters -
Fix strange bug where te_compile
fails on a lens ABCD element expression, e.g:-1.0/itm_lens_f
; error in parsing seems to point to end of string for some reason.