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.
We could require the user to set self.segment_durations explicitly later on. But that's not really the user's job, the model should do that automatically based on the Walsh index. Therefore, self.walsh_idx should be the attribute that the user can change (which is what this PR does)
To avoid having to put the calculation of segment durations into _func, would need to ensure that whenever self.walsh_idx is changed, the segment durations are updated. One way of achieving this is to have an explicit set_walsh_idx() method that the user can call to override the walsh index if required. Another option is to make walsh_idx a property and define the setter such that whever walsh_idx is set, self.segment_durations are updated.
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.
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 sincewalsh_idx
is not aModelParameter
and thus doesn't change during fitting. However, this behaviour causes problems when the model is used for analyses inAnalysisExpFragments
because the Walsh index may be selected by the user in the dashboard. Since analyses are set as attributes inbuild_fragment()
and ndscan parameter values are not yet available inside that method (stores have not been created yet, soxxx.get()
throws exception), thewalsh_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 desiredwalsh_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.self.segment_durations
explicitly later on. But that's not really the user's job, the model should do that automatically based on the Walsh index. Therefore,self.walsh_idx
should be the attribute that the user can change (which is what this PR does)_func
, would need to ensure that wheneverself.walsh_idx
is changed, the segment durations are updated. One way of achieving this is to have an explicitset_walsh_idx()
method that the user can call to override the walsh index if required. Another option is to makewalsh_idx
a property and define the setter such that wheverwalsh_idx
is set,self.segment_durations
are updated.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.