-
Notifications
You must be signed in to change notification settings - Fork 25
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ENH: add helpers to manage "batches" of runs #151
base: master
Are you sure you want to change the base?
Conversation
This is the result of a day of discussion on NSLS-II slack.
from bluesky import RunEngine
from bluesky.callbacks.core import LiveTable
from bluesky.plan_stubs import open_run, close_run, null
from event_model import RunRouter
from nslsii.batches import setup_batch
def inner_plan(M):
for j in range(M):
yield from open_run()
yield from close_run()
def batch(batch_md, *, N=5, M=1, comment_function=None):
add_to_batch, close_batch = yield from setup_batch(
batch_md, comment_function=comment_function
)
for j in range(N):
yield from add_to_batch(inner_plan(M=M))
yield from close_batch()
RE = RunEngine()
def only_outer(name, doc):
if doc.get("purpose") == "batch header":
return [
LiveTable(["step_uid", "step_comment", "step_index"], default_prec=25)
], []
return [], []
rr = RunRouter([only_outer])
RE(batch({"bob": "ardvark"}, N=5, M=2), rr) gives
|
Running with a supplemental data preprocessor (just motors in baseline) gives the following error KeyError Traceback (most recent call last)
File ~/miniconda3/envs/2022-2.3-py39-tiled/lib/python3.9/site-packages/bluesky/run_engine.py:1807, in RunEngine._create(self=<bluesky.run_engine.RunEngine object>, msg=Msg('create', obj=None, args=(), kwargs={'name': 'baseline'}, run=None))
1806 try:
-> 1807 current_run = self._run_bundlers[run_key]
run_key = None
self._run_bundlers = {}
self = <bluesky.run_engine.RunEngine object at 0x7f9c5363fe50>
1808 except KeyError as ke:
KeyError: None Which is, I assume, because the run key needs to be passed to baseline. Not sure how to do this. |
This is really a problem with set_run_key_wrapper itself, which I have created an issue for bluesky/bluesky#1529 |
Actually, there will be a problem with Monitors and Flyers as well, which are going to be kicked off twice when you nest runs like this. For this batch scheme to work, I think the easiest thing to do would be to somehow suppress the Baseline/Monitor/Flyer preprocessors, if that is possible. |
The logic to turn things off like that is hard to get right. If you are going down this route I would remove the pre-processor on the RE and directly decorate / wrap your inner plans. |
The pre-processors only get to see a stream of
The baseline wrapper does not know (naively) what This would fix baseline, but would still leave you with the double monitor_during / fly_during issue. |
I'm not actually using any monitors or flyers, so if the wrappers could be updated to propagate the run-key, that would be a work-able solution for me. I opened an issue on the Bluesky github, so anyone is welcome to fix it. Maybe I'll do it and submit a PR. It should be fixed regardless of the Batch stuff. For the double monitor/fly issue, this would mean foregoing the SupplementalData preprocessor altogether, and directly wrapping all plans in monitor/fly. This is probably not too much of an issue for me, but might be confusing. I think the only way to do it more cleanly is to find some way for the preprocessors to ignore the batch open_run/close_run. I thought of two ways.
This second way is something I could actually test relatively rapidly. To first order, I could just register an |
Yes, however if you are going down the route of these batches things are already pretty custom. You can still close over the SD object in your plans, you just can not hang it off of the RE.
Baking things into the contents of the message to opt-opt of an optional pre-processor is a code-smell. That said, a local thing you could try is to wrap the SD run-router in another layer that does the filtering. It is a bit ugly, but could work, and it being in application code rather than the library code makes it seem a bit better.
You really want another generation of documents in the event model ;) I do not like this option, but it will work and is consistent with the rest of the system.
Yes, but you would need to do both open and close I think or the wrappers might become unhappy about seeing a close with no open. |
This is the result of a day if discussion on NSLS-II slack.