OxIonics / ionics_fits

Small python fitting library with an emphasis on Atomic Molecular and Optical Physics
Apache License 2.0
0 stars 0 forks source link

Move calculation of segment durations in Molmer-Sorensen model #109

Closed AUTProgram closed 9 months ago

AUTProgram commented 9 months ago

This PR changes when the segment durations for Walsh-modulated Molmer-Sorensen model are calculated. So far, walsh_idx was used inside __init__ to calculate segment durations immediately when model is instantiated. Conceptually, there shouldn't be a problem with that since walsh_idx is not a ModelParameter and thus doesn't change during fitting. However, this behaviour causes problems when the model is used for analyses in AnalysisExpFragments because the Walsh index may be selected by the user in the dashboard. Since analyses are set as attributes in build_fragment() and ndscan parameter values are not yet available inside that method (stores have not been created yet, so xxx.get() throws exception), the walsh_idx of the model needs to be changed later. However, since segments durations are only calculated in __init__, even adding a walsh_idx attribute and changing it later won't do the trick. Instead, this PR moves the calculation of segment durations into the _func method of the model since by the time that method is called, the desired walsh_idx will always have been set. I'm not 100% happy with this approach since calculating the durations on each call to _func is wasteful because the durations aren't free parameters, so could have been pre-computed. However, if we want attributes to be freely modifiable by the user, then there aren't that many options.

But I assume that the extra operations required to calculate segment durations are not actually limiting the speed of fitting anyway, so probably not worth optimising further at this point.