OxfordIonTrapGroup / ndscan

N-dimensional scans for ARTIQ
GNU Lesser General Public License v3.0
18 stars 15 forks source link

Master-side online analyses for scans #389

Open dnadlinger opened 5 months ago

dnadlinger commented 5 months ago

As it says in the title: It would be useful to be able to run online analyses (i.e. while the scan is running) also master-side with custom code rather than just the pre-defined fits in the applets.

This came out of a discussion on how to show randomised benchmarking (RBM) data as it comes in. ABaQuS (one of the Oxford experiments) currently have a local patch that (if I understand correctly) allows running an arbitrary callback after points have been completed, which they use to directly update some datasets to show a preliminary fit while the scan is still in progress. It would obviously be nicer to do this is in a way better integrated with the rest of ndscan. But of course, we already have the concept of online analysis execution in ndscan, so let's just extend this to be able to run with custom code master-side as well!

People (such as @hartytp) have been wanting custom online analyses for a while anyway. The OI implementation appears to allow the experiment to just specify a Python class to run on the client, with the actual implementation still being executed on the client. This works, but has the disadvantage of having to keep the code in sync. (They seem to be using this only to plug in the ionics_fits library, which is fairly static, presumably somewhat circumventing this issue.) just serialises the entire code and ships that to the applets. Our approach would be an alternative to that.

In summary:

At this point, we should be able to e.g. implement the Lorentzian online fit to a fluorescence scan as a custom online analysis rather than client side OnlineFit without much of a visible difference.


@JammyL This is part 2 of the RBM live analysis discussion we had on 2023-05-05 (part 1 being off-to-the-side previews for subscans).

hartytp commented 5 months ago

People (such as @hartytp) have been wanting custom online analyses for a while anyway. The OI implementation appears to allow the experiment to just specify a Python class to run on the client, with the actual implementation still being executed on the client. This works, but has the disadvantage of having to keep the code in sync. (They seem to be using this only to plug in the ionics_fits library, which is fairly static, presumably somewhat circumventing this issue.) Our approach would be an alternative to that.

Not quite. The implementation I went for base64-encodes a pickle of the analysis class and sends that to the client. This means, for example, that one can define an arbitrary analysis class in the experiment repo and have that work with the client.

dnadlinger commented 5 months ago

Ah, thanks for the correction – I wrote this almost a year ago, clearly I didn't check ionics-fits too carefully back then!

hartytp commented 5 months ago

Tangentially related: one thing that comes up from time to time is wanting to do a bit of simple post analysis on datasets and use that as a result channel. For example, say I want to calculate an nbar from a red and blue sideband height and then plot / fit that for a heating rate scan.

Right now that's a little cumbersome to implement (requires an rpc with a bit of self.channel.sink.get_last()). I wonder if there is a nice way of making this kind of thing easier.

dnadlinger commented 5 months ago

For that, I think the approach we discussed in https://github.com/OxfordIonTrapGroup/ndscan/issues/273#issuecomment-1254117582 is still the way to go.