APS-USAXS / usaxs-bluesky-ended-2023

Bluesky instrument for USAXS
0 stars 0 forks source link

RE.abort() needs to remove suspenders #570

Closed jilavsky closed 2 years ago

jilavsky commented 2 years ago

RE.abort() does not seem to remove suspenders and operations which do not require beam are still impossible after RE.abort() without beam. RE.abort() should remove the suspenders.

jilavsky commented 2 years ago

Need to add RE.clear_suspenders() into RE.abort() somehow.

prjemian commented 2 years ago

https://github.com/APS-USAXS/usaxs-bluesky/blob/a803031b8c806c74949ff53fab1ef4cc3cb2f678/instrument/devices/suspenders.py#L68-L74

https://github.com/APS-USAXS/usaxs-bluesky/blob/a803031b8c806c74949ff53fab1ef4cc3cb2f678/instrument/plans/scans.py#L141

and others

https://github.com/APS-USAXS/usaxs-bluesky/search?q=install_suspender

prjemian commented 2 years ago

Some suspenders are installed from routine scanning plans. But there is one that is only installed during initialization. Restore it with:

from instrument.framework.initialization import suspender_white_beam_ready
RE.install_suspender(suspender_white_beam_ready)
prjemian commented 2 years ago

This issue exists, mostly, because we have added suspenders to a plan and then aborted that plan without the suspenders being removed. Instead of calling https://github.com/APS-USAXS/usaxs-bluesky/blob/a803031b8c806c74949ff53fab1ef4cc3cb2f678/instrument/plans/scans.py#L141

could we use a suspender decorator that will catch abort and remove the suspender(s) automagically?

prjemian commented 2 years ago

In bluesky.preprocessors (a.k.a. bpp), there is:

def suspend_wrapper(plan, suspenders):
    """
    Install suspenders to the RunEngine, and remove them at the end.

    Parameters
    ----------
    plan : iterable or iterator
        a generator, list, or similar containing `Msg` objects
    suspenders : suspender or list of suspenders
        Suspenders to use for the duration of the wrapper

    Yields
    ------
    msg : Msg
        messages from plan, with 'install_suspender' and 'remove_suspender'
        messages inserted and appended
    """
prjemian commented 2 years ago

prototype code within a plan:

from bluesky import preprocessors as bpp

# ...

    @bpp.suspend_wrapper(suspend_BeamInHutch)
    def steps_that_might_be_suspended():
        yield from this()
        yield from that()

    result = yield from steps_that_might_be_suspended()
    # TODO: might need to return that `result`
prjemian commented 2 years ago

For example, we could decorate the SAXS, WAXS, and other plans with @bpp.suspend_wrapper(suspend_BeamInHutch)

@bpp.suspend_wrapper(suspend_BeamInHutch)
def SAXS ...
prjemian commented 2 years ago

What to do about https://github.com/APS-USAXS/usaxs-bluesky/blob/a803031b8c806c74949ff53fab1ef4cc3cb2f678/instrument/devices/suspenders.py#L74

I think you still want this at the global level? The only time you would want to remove it is like now, during a shut-down day.

jilavsky commented 2 years ago

I think the white beam ready suspender should be removed. It was there for historical reasons when we had routine searching for feedback after beam dump. That needed to know the white beam is ready even when it had no I000 value. Our current suspend_BeamInHutch already looks at front end shutter, so it is triggered by FES closing. I suggest removing this altogether and let's see, if we ever need it again. Let's simplify.