-
Notifications
You must be signed in to change notification settings - Fork 0
Plan wrapper functions to allow for easier cleanup of DAE setup changes #267
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
Open
danielmaclaren
wants to merge
25
commits into
main
Choose a base branch
from
ticket164wrapper
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
25 commits
Select commit
Hold shift + click to select a range
496a22e
temp storing changes to work on another ticket
danielmaclaren 81fdf27
Merge remote-tracking branch 'origin/main' into ticket164wrapper
danielmaclaren 1d2636e
three wrappers, tests and documentation
danielmaclaren f10dedb
fixed incorrect path within dae_table test
danielmaclaren 27aff24
Merge branch 'main' into ticket164wrapper
danielmaclaren ffd43aa
ruff checks
danielmaclaren 1228094
Merge branch 'ticket164wrapper' of https://github.com/IsisComputingGr…
danielmaclaren 67b5670
deleted files
danielmaclaren 3ff0cf6
ruff format changes
danielmaclaren 42a49cd
updated dae parameters in wrapper
danielmaclaren d8dabb3
ruff check and format
danielmaclaren fd772c1
ruff --fix
danielmaclaren 36805b1
removed if statement
danielmaclaren 9151497
updates that aren't working
danielmaclaren 7e03513
fix num_periods test
rerpha 0865761
updated tests for wrappers
danielmaclaren dba1ce2
updated wrapper tests
danielmaclaren 23affff
refactoring of tests
danielmaclaren 4432835
ruff checks
danielmaclaren 161818e
ruff checks
danielmaclaren c31c388
exposed wrapper files to __all__
danielmaclaren d8fb08b
ruff fixes
danielmaclaren b028f81
Merge remote-tracking branch 'origin/ticket164wrapper' into ticket164…
danielmaclaren be7125d
ruff fixes (plan stubs)
danielmaclaren 04cb045
corrected the rest of the comments
danielmaclaren File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,79 @@ | ||
| # Plan Wrappers | ||
|
|
||
| Plan wrappers that temporarily modify [DAE (Data Acquisition Electronics)](https://isiscomputinggroup.github.io/ibex_bluesky_core/devices/dae.html#dae-data-acquisition-electronics) settings during a plan, automatically restoring the original values afterwards. This ensures that your experiments don't permanently change instrument configuration. | ||
|
|
||
| ## Available Wrappers | ||
|
|
||
| ### DAE Table | ||
|
|
||
| :py:obj:`dae_table_wrapper <ibex_bluesky_core.plan_stubs.dae_table_wrapper>` | ||
|
|
||
| ```python | ||
| RE( | ||
| _with_dae_tables( | ||
| bps.null(), | ||
| dae=dae, | ||
| new_settings=modified_settings | ||
| ) | ||
| ) | ||
| ``` | ||
|
|
||
| Where `modified_settings` is a dataset in the form :py:obj:`DaeSettingsData < ibex_bluesky_core.devices.dae.DaeSettingsData>` | ||
|
|
||
| A function that wraps a plan to temporarily modify the DAE table. | ||
|
|
||
| ### Num Periods | ||
| :py:obj:`num_periods_wrapper <ibex_bluesky_core.plan_stubs.num_periods_wrapper>` | ||
|
|
||
| ```python | ||
| RE( | ||
| _with_num_periods( | ||
| bps.null(), | ||
| dae=dae, | ||
| number_of_periods=1000 | ||
| ) | ||
| ) | ||
| ``` | ||
| A function that wraps a plan to temporarily modify the number of periods. | ||
|
|
||
| ### Time Channels | ||
| :py:obj:`time_channels_wrapper <ibex_bluesky_core.plan_stubs.time_channels_wrapper>`: | ||
|
|
||
| ```python | ||
| RE( | ||
| _with_time_channels( | ||
| bps.null(), | ||
| dae=dae, | ||
| new_settings=modified_settings | ||
| ) | ||
| ) | ||
| ``` | ||
| Where `modified_settings` is a dataset in the form :py:obj:`DaeTCBSettingsData < ibex_bluesky_core.devices.dae.DaeTCBSettingsData>` | ||
|
|
||
| A function that wraps a plan to temporarily modify the time channels boundaries. | ||
|
|
||
| ## Usage | ||
|
|
||
| To use these wrappers, the plan written by the user must be wrapped by the function within the RunEngine: | ||
|
|
||
| ``` python | ||
|
|
||
| from bluesky import RunEngine | ||
| from ibex_bluesky_core.plan_stubs import _with_num_periods | ||
| from ibex_bluesky_core.devices.simpledae import SimpleDae | ||
|
|
||
| dae = SimpleDae() # Give your DAE options here | ||
| RE = RunEngine() | ||
|
|
||
| RE( | ||
| _with_num_periods( | ||
| bps.null(), # Default plan to run | ||
| dae=dae, | ||
| number_of_periods=1000 # Temporary number of periods to run | ||
| ) | ||
| ) | ||
|
|
||
| ``` | ||
|
|
||
| the plan with the modified DAE settings, restoring the original settings afterwards. | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| """Wrap a plan with temporary modification to DAE Settings.""" | ||
|
|
||
| from collections.abc import Generator | ||
|
|
||
| import bluesky.plan_stubs as bps | ||
| import bluesky.preprocessors as bpp | ||
| from bluesky.utils import Msg | ||
| from ophyd_async.plan_stubs import ensure_connected | ||
|
|
||
| from ibex_bluesky_core.devices.dae import Dae, DaeSettingsData | ||
|
|
||
|
|
||
| def _with_dae_tables( | ||
| plan: Generator[Msg, None, None], dae: Dae, new_settings: DaeSettingsData | ||
| ) -> Generator[Msg, None, None]: | ||
| """Wrap a plan with temporary modification to DAE Settings. | ||
|
|
||
| Args: | ||
| plan: The plan to wrap. | ||
| dae: The Dae instance. | ||
| new_settings: The new DAE Settings to apply temporarily. | ||
|
|
||
| Returns: | ||
| A generator which runs the plan with the modified DAE settings, restoring the original | ||
| settings afterwards. | ||
|
|
||
| """ | ||
| yield from ensure_connected(dae) | ||
|
|
||
| original_dae_setting = None | ||
|
|
||
| def _inner() -> Generator[Msg, None, None]: | ||
| nonlocal original_dae_setting | ||
| original_dae_setting = yield from bps.rd(dae.dae_settings) | ||
|
|
||
| yield from bps.mv(dae.dae_settings, new_settings) | ||
|
|
||
| yield from plan | ||
|
|
||
| def _cleanup() -> Generator[Msg, None, None]: | ||
| yield from bps.mv(dae.dae_settings, original_dae_setting) | ||
|
|
||
| return (yield from bpp.finalize_wrapper(_inner(), _cleanup())) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| """Wrap a plan with temporary modification to Periods Settings.""" | ||
|
|
||
| from collections.abc import Generator | ||
|
|
||
| import bluesky.plan_stubs as bps | ||
| import bluesky.preprocessors as bpp | ||
| from bluesky.utils import Msg | ||
| from ophyd_async.plan_stubs import ensure_connected | ||
|
|
||
| from ibex_bluesky_core.devices.dae import Dae | ||
|
|
||
|
|
||
| def _with_num_periods( | ||
| plan: Generator[Msg, None, None], dae: Dae, number_of_periods: int | ||
| ) -> Generator[Msg, None, None]: | ||
| """Wrap a plan with temporary modification to Periods Settings. | ||
|
|
||
| Args: | ||
| plan: The plan to wrap. | ||
| dae: The Dae instance. | ||
| number_of_periods: The number of periods to set to temporarily. | ||
|
|
||
| Returns: | ||
| A generator which runs the plan with the modified number of periods, restoring the original | ||
| number of periods afterwards. | ||
|
|
||
| """ | ||
| original_num_periods = None | ||
|
|
||
| def _inner() -> Generator[Msg, None, None]: | ||
| yield from ensure_connected(dae) | ||
| nonlocal original_num_periods | ||
| original_num_periods = yield from bps.rd(dae.number_of_periods) | ||
|
|
||
| yield from bps.mv(dae.number_of_periods, number_of_periods) | ||
|
|
||
| yield from plan | ||
|
|
||
| def _cleanup() -> Generator[Msg, None, None]: | ||
| yield from bps.mv(dae.number_of_periods, original_num_periods) | ||
|
|
||
| return (yield from bpp.finalize_wrapper(_inner(), _cleanup())) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| """Wrap a plan with temporary modification to Time Channel Settings.""" | ||
|
|
||
| from collections.abc import Generator | ||
|
|
||
| import bluesky.plan_stubs as bps | ||
| import bluesky.preprocessors as bpp | ||
| from bluesky.utils import Msg | ||
| from ophyd_async.plan_stubs import ensure_connected | ||
|
|
||
| from ibex_bluesky_core.devices.dae import Dae, DaeTCBSettingsData | ||
|
|
||
|
|
||
| def _with_time_channels( | ||
| plan: Generator[Msg, None, None], dae: Dae, new_tcb_settings: DaeTCBSettingsData | ||
| ) -> Generator[Msg, None, None]: | ||
| """Wrap a plan with temporary modification to Time Channel Settings. | ||
|
|
||
| Args: | ||
| plan: The plan to wrap. | ||
| dae: The Dae instance. | ||
| new_tcb_settings: The time channel settings to apply temporarily. | ||
|
|
||
| Returns: | ||
| A generator which runs the plan with the modified TCB settings, restoring the original | ||
| settings afterwards. | ||
|
|
||
| """ | ||
| yield from ensure_connected(dae) | ||
|
|
||
| original_time_channels = None | ||
|
|
||
| def _inner() -> Generator[Msg, None, None]: | ||
| nonlocal original_time_channels | ||
| original_time_channels = yield from bps.rd(dae.tcb_settings) | ||
|
|
||
| yield from bps.mv(dae.tcb_settings, new_tcb_settings) | ||
|
|
||
| yield from plan | ||
|
|
||
| def _cleanup() -> Generator[Msg, None, None]: | ||
| yield from bps.mv(dae.tcb_settings, original_time_channels) | ||
|
|
||
| return (yield from bpp.finalize_wrapper(_inner(), _cleanup())) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.