Stop space gouy phase model parameters being updated automatically
The way the unparser grabs the current values for component parameters (by default) is that it looks at a component's init signature, then looks for attributes with the same names as the parameters. If the current value for a parameter is different to the default value in the signature, it generates that parameter in KatScript.
This presents a problem for spaces, which define gouy_x
and gouy_y
init parameters to allow the user to explicitly set the gouy phases for a particular space, regardless of the beam tracing. The problem is that the gouy_x
and gouy_y
attributes of Space
are also set by the beam tracer itself when it traces. That means that gouy_x
and gouy_y
are not necessarily (actually almost never) their default signature values after tracing, so KatScript gets generated even though the user didn't specify them.
Here's an example of generated KatScript suffering from this problem:
# Originally parsed:
s s0 i1.p1 eom1.p1 L=1m
# Regenerated:
s s0 i1.p1 eom1.p1 L=1m gouy_x=9.860669607831348e-06 gouy_y=9.97834243410317e-06
One way to fix this is to define a custom dumper method for Space
which identifies this and handles it. We'd still need to figure out a way to know whether a gouy was set by the tracer versus the user. However, in the telecon discussion today (2021-07-01) @daniel-brown noted that this gouy overwriting behaviour is also annoying for another reason: because gouy phases are model parameters but can be set by the tracer, they are always considered to be "changing" by the simulation so always get recomputed every step of the model, which is slow. It seems the best way to fix this is therefore to store the "computed" gouy phases separately from the "user intended" gouy phases. There can be separate "user" gouy model parameters for when the user actually wants to set/sweep these.
The approach to fix this is therefore something like:
- Because gouy phases should be "unset" by default, change the
Space
init method to useNone
as default values forgouy_x
andgouy_y
instead of 0. If anything breaks, make sure the tracer assumes gouy phases that are set toNone
default to 0. - Create properties for
gouy_x
andgouy_y
inSpace
that first check if the user has explicitly set the gouy phase in the init method (e.g.if self._user_gouy_x is not None: ...
), and if so, return that value, otherwise return the one computed by the beam tracer. - Fix anything that breaks elsewhere
🙃
We might need to dig into @samuel.rowlinson's beam tracing code to change the gouy phase properties of the spaces that it sets when it performs a beam trace. We probably want to leave the gouy_x
and gouy_y
model parameters as the ones the user can set, but have the tracer store the "internal" ones as e.g. computed_gouy_x
and computed_gouy_y
.
This may or may not be complicated depending on what, if anything, breaks...