|
| 1 | +--- |
| 2 | +related: |
| 3 | + - title: ScanArgument |
| 4 | + url: learn/scans/scanargument.md |
| 5 | + - title: GUI Config |
| 6 | + url: learn/scans/gui-config.md |
| 7 | + - title: Learn by Example |
| 8 | + url: learn/scans/learn-by-example.md |
| 9 | +--- |
| 10 | + |
| 11 | +# Argument Bundles |
| 12 | + |
| 13 | +This page explains how scans can describe repeated positional input bundles when a normal fixed |
| 14 | +Python signature is not enough. |
| 15 | + |
| 16 | +## The Scan Signature |
| 17 | + |
| 18 | +In the current scan implementation, a scan definition is described largely by its `__init__` |
| 19 | +signature plus a few class attributes. |
| 20 | + |
| 21 | +The scan server serializes that signature and publishes it to clients. The client then uses it to: |
| 22 | + |
| 23 | +- expose the scan under `scans.<name>` |
| 24 | +- attach a live Python signature in IPython |
| 25 | +- validate kwargs and bundled positional inputs |
| 26 | +- resolve device-name strings to device objects when the annotations require that |
| 27 | + |
| 28 | +This means the signature is no longer only local Python documentation. It is part of the runtime API |
| 29 | +contract between the scan server, the client, and GUIs. |
| 30 | + |
| 31 | +## `arg_input` and `arg_bundle_size` |
| 32 | + |
| 33 | +!!! tip |
| 34 | + `arg_input` and `arg_bundle_size` are special cases for scans with an undefined number of |
| 35 | + input arguments. Most scans developed in plugins do not need them. |
| 36 | + |
| 37 | +If the number of input arguments is not fixed, the usual Python-style fixed signature is not enough. |
| 38 | + |
| 39 | +For example, a line scan can work with any number of motors in parallel, so the scan cannot rely on |
| 40 | +one fixed positional argument layout in the way an ordinary Python function usually would. |
| 41 | + |
| 42 | +In those cases, scans with repeated positional bundles declare those bundles explicitly. |
| 43 | + |
| 44 | +For a line scan, that can look like this: |
| 45 | + |
| 46 | +```py |
| 47 | +arg_input = { |
| 48 | + "device": DeviceBase, |
| 49 | + "start": float, |
| 50 | + "stop": float, |
| 51 | +} |
| 52 | +arg_bundle_size = {"bundle": 3, "min": 1, "max": None} |
| 53 | +``` |
| 54 | + |
| 55 | +`arg_bundle_size` then tells BEC how many positional values belong to one bundle and how many |
| 56 | +bundles are allowed. |
| 57 | + |
| 58 | +This is what lets BEC validate a call such as: |
| 59 | + |
| 60 | +```py |
| 61 | +scans.line_scan(dev.samx, -1, 1, dev.samy, -2, 2, steps=5, relative=False) |
| 62 | +``` |
| 63 | + |
| 64 | +without treating those positional arguments as an unstructured `*args` blob. |
| 65 | + |
| 66 | +Rich input metadata for individual parameters is covered separately on |
| 67 | +[ScanArgument](scanargument.md). |
| 68 | + |
| 69 | +## Reloading The Scan Server |
| 70 | + |
| 71 | +If you add a new scan or change an existing scan class, the scan server must reload that Python code |
| 72 | +before the changes become available. |
| 73 | + |
| 74 | +In practice, that means you should restart or reload the scan server after editing scan |
| 75 | +implementations. Otherwise the running server will continue using the old version of the scan. |
| 76 | + |
| 77 | +## Next Step |
| 78 | + |
| 79 | +After argument bundles, continue with [GUI Config](gui-config.md) to see how scans group inputs for |
| 80 | +graphical clients. |
| 81 | + |
| 82 | +## What To Remember |
| 83 | + |
| 84 | +!!! info "What to remember" |
| 85 | + - The serialized scan signature is part of the runtime API between the scan server, clients, and GUIs. |
| 86 | + - `arg_input` and `arg_bundle_size` define repeated positional bundles such as move targets or line-scan ranges. |
| 87 | + - `ScanArgument` covers rich metadata for individual inputs, while argument bundles describe repeated positional structure. |
| 88 | + - After changing scan code, the scan server must be reloaded or restarted. |
0 commit comments