NSLS-II-PDF / mmm-experiments

Python package for running multimodal madness experiments with BMM
BSD 3-Clause "New" or "Revised" License
1 stars 1 forks source link

Add the Scientific Value Agent #10

Closed matthewcarbone closed 1 year ago

matthewcarbone commented 2 years ago

@maffettone this still needs some work but here's the first draft!

This agent tries to gain a dynamic understanding of now "new" some observations are relative to those previously observed, and can be used with e.g. Expected Improvement to sample regions where high changes in some observed quantity are observed.

maffettone commented 1 year ago

One note from our chat is to make sure that the SVA can take an arbitratry callable to compute distance between two spectra. This will allow us to on the fly implement new functions like [the spectral distance used here (https://pubs.rsc.org/en/content/articlehtml/2022/dd/d2dd00025c), or use a latent distance from a VAE.

matthewcarbone commented 1 year ago

Ok I will:

matthewcarbone commented 1 year ago

@maffettone updated!

maffettone commented 1 year ago

This is looking sharp. My suggestion is instead of making the Agent a child class of agents.base.Agent, make it a mixin class. This way it can be mix and matched with beamline specific needs, and abused without rewriting things.

A simple example here is the SequentialAgentMixin, https://github.com/NSLS-II-PDF/mmm-experiments/blob/428814ae2efadfa8aa94d994b01660b0c93c470c/mmm_experiments/agents/base.py#L352-L376

and how that get's dropped into a PDF specific sequential agent in agents.pdf.SequentialAgent https://github.com/NSLS-II-PDF/mmm-experiments/blob/428814ae2efadfa8aa94d994b01660b0c93c470c/mmm_experiments/agents/pdf.py#L98-L110

matthewcarbone commented 1 year ago

@maffettone ok so if I understand correctly you're saying basically don't inherit the Agent class and instead write something like akin to SequentialAgentMixin? That way we can just inherit the ValueAgentMixin class and deploy the methods on various beamlines. Am I following?

maffettone commented 1 year ago

Bingo! Sorry if I pointed you in the wrong direction at the start. But this will let us make a BMMValueAgent and PDFValueAgent in 2 lines each. And should leave room to get jazzy with the MonarchSubject stuff.

matthewcarbone commented 1 year ago

@maffettone I attempted to implement the changes as requested. I basically cleaned up the init and made use of the attributes that I'm assuming will be defined (see the doc string). Let me know what you think!

matthewcarbone commented 1 year ago

This is all looking great! I outlined a couple changes that will probably raise bugs. Without diving too deep into the rest, I think it's ready for a class in agents.pdf. Make sure to rebase off main first.

Will do!

Poke around and test with that for comfort. You'll probably immediately hit kafka errors, because the offline stuff isn't merged in. So when you're ready, I'm ready, and we can find some of the bugs on the day off.

Sure I can try. I haven't really attempted to do anything with this "online" so to speak. Do you have a good resource/tutorial where I can play around in a sandbox-like environment?

maffettone commented 1 year ago

Unfortunately not. For the element of time, I'm going to start pushing on this and adding an offline mode asap.

matthewcarbone commented 1 year ago

@maffettone understood- next time. You're running on Thursday, right? I'm available all day over Teams/phone if you need anything on my end.

maffettone commented 1 year ago

Kicking off tomorrow through Thursday

matthewcarbone commented 1 year ago

Ok got it. Well in any case I'm available should you need anything 👍