-
Notifications
You must be signed in to change notification settings - Fork 14
docs: restructure how-to and tutorial pages #1564
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
shree-iyengar-dls
wants to merge
32
commits into
main
Choose a base branch
from
1468_restructure_blueapi_docs
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.
+283
−154
Open
Changes from all commits
Commits
Show all changes
32 commits
Select commit
Hold shift + click to select a range
6c82b8c
docs: restructure how-to and tutorial pages
shree-iyengar-dls 7145c06
docs: change relative paths for cross-referencing
shree-iyengar-dls c598238
Merge branch 'main' into 1468_restructure_blueapi_docs
shree-iyengar-dls b7d552f
docs: addition to start rabbitmq section of run-bus.md
shree-iyengar-dls ddcb178
docs: add info on how to run a plan from docs page
shree-iyengar-dls 65ebde1
docs: add details on how to run a plan from the docs page
shree-iyengar-dls f2a670f
docs: finish off writing docs to run a plan through docs page
shree-iyengar-dls e7f9688
docs: fix reference in run-cli.md file
shree-iyengar-dls 417ed4a
chore: change image in docs from jpeg to png
shree-iyengar-dls 2e9099b
docs: update based on PR comments
shree-iyengar-dls 77a3ee1
style: reword Run Auth locally docs page
shree-iyengar-dls 4abb4d8
docs: add note about needing access to namespaces
shree-iyengar-dls 9f1ce6a
docs: add details to troubleshooting section
shree-iyengar-dls ad72bc7
Merge branch 'main' into 1468_restructure_blueapi_docs
shree-iyengar-dls 94c2586
change working in step 3 of run plan through docs page
shree-iyengar-dls 1d3ec09
style: fix typo in step 3 of run plan through docs page
shree-iyengar-dls 67ae317
docs: number and restructure tutorials section
shree-iyengar-dls 3f2dfec
docs: restructure how tos section
shree-iyengar-dls 8658cec
docs: move a couple of pages to how-to section
shree-iyengar-dls 4aeed5a
Update docs/how-to/local-auth.md
shree-iyengar-dls f99328a
docs: reorder files in tutorials folder
shree-iyengar-dls de79db7
docs: change file path in config docs page
shree-iyengar-dls 0ee422b
docs: rewrite tutorials section such that it walks through additions …
shree-iyengar-dls 7d6aa6a
chore: improve one of the error messages in def run_plan
shree-iyengar-dls d1bef1c
docs: add extra detail to top of Run a Plan from Docs page page
shree-iyengar-dls 8882fe2
docs: address comments for adding plns to init file
shree-iyengar-dls 6ca878a
style: fix typo
shree-iyengar-dls b3f08bc
docs: updates to tutorial pages after testing
shree-iyengar-dls 979405f
docs: update how-to pages
shree-iyengar-dls 1b3ffb0
chore: resolve issues due to CI failing
shree-iyengar-dls ccccaed
tests: fix test_run_plan_feedback unit test
shree-iyengar-dls 7d0a1df
docs: add detail on how to add extra config components and link to ho…
shree-iyengar-dls 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
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
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 was deleted.
Oops, something went wrong.
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
File renamed without changes.
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 @@ | ||
| [rabbitmq_stomp]. |
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,39 @@ | ||
| # 2. Quickstart guide | ||
|
|
||
| Blueapi acts as a worker that can run Bluesky plans against devices for a specific laboratory setup. It can control devices to collect data and export events to tell downstream services about the data it has collected. | ||
|
|
||
| You should be in the blueapi directory that you have cloned. From here, if you open VSCode, you will probably be prompted to 'Reopen in Container' which you can do and then run the following commands to start the worker. | ||
|
|
||
| If you not, you can still run the following from the venv created in page 1 but you may need to run the command below to have the dependencies required for this tutorial. | ||
|
|
||
| ``` | ||
| pip install .[demo] | ||
| ``` | ||
|
|
||
| ## Start Worker | ||
|
|
||
| To start the worker: | ||
| ``` | ||
| blueapi serve | ||
| ``` | ||
| This will use all the defaults in `src/blueapi/config.py` | ||
|
|
||
| ## Basic Introspection | ||
|
|
||
| Blueapi comes with a minimal CLI client for basic control/debugging. We can use this to see which plans and devices are available. In a new terminal window, run the following commands. | ||
|
|
||
| If working in a venv, you may need to reactivate it. To do this, assuming you are still in the blueapi repo in your terminal, use: | ||
| ``` | ||
| source .venv/bin/activate | ||
| ``` | ||
|
|
||
| Now, run the following to see what plans and devices are available: | ||
|
|
||
| ``` | ||
| blueapi controller plans | ||
| blueapi controller devices | ||
| ``` | ||
|
|
||
| We should now have an empty context. | ||
|
|
||
| See also [Full CLI reference](../reference/cli.md) | ||
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,28 @@ | ||
| # 3. Config add devices | ||
|
|
||
| Blueapi is highlighly configurable. The config details aspects that impact how Blueapi works and it is customisable. | ||
|
|
||
| As a first step, create a `config.yaml` file. This would be best placed in the `docs/resources` folder. | ||
|
|
||
| Intially, add devices using the following code: | ||
|
|
||
| ```yaml | ||
| env: | ||
| metadata: | ||
| instrument: demo | ||
| sources: | ||
| - kind: deviceManager | ||
| module: blueapi.tutorial.devices | ||
| ``` | ||
|
|
||
| The `env` section of the `config.yaml` file lets you create and set environment variables. The `demo` points to optional dependencies in the [pyproject.toml file](../../pyproject.toml). The module above points to the devices you will use for this tutorial which can be found [here](../../src/blueapi/tutorial/devices.py). | ||
|
|
||
| Save the file and restart the worker to use this new `config.yaml` file you have created. To do this, navigate back to the terminal window where the worker is running, CTRL+C to close it then run the following command: | ||
| ``` | ||
| blueapi --config docs/resources/config.yaml serve | ||
| ``` | ||
|
|
||
| The above command asuumes you created the `config.yaml` file in `docs/resources`. Else, replace `docs/resources/config.yaml` with whichever file path your `config.yaml` has. | ||
|
|
||
| Now run | ||
| ```blueapi controller devices``` in the same terminal window as you did when previously running this command and you should see `det` and `stage`. |
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,16 @@ | ||
| # 4. Config add plans | ||
|
|
||
| As well as adding devices to the `config.yaml`, you can add plans. Under the code you already have, add the following: | ||
|
|
||
| ``` yaml | ||
| - kind: planFunctions | ||
| module: dodal.plans | ||
| - kind: planFunctions | ||
| module: dodal.plan_stubs.wrapped | ||
| ``` | ||
| These plans that will be used in this tutorial can be found in the [dodal repository](https://github.com/DiamondLightSource/dodal/tree/b4b38f1e0cf480faeb29d67695440c45a148f169). Specifically, in `dodal/src/dodal/plans/wrapped.py` and `dodal/src/dodal/plan_stubs/wrapped.py`. | ||
|
|
||
| Save the changes you've made to the `config.yaml` file. Navigate back to the terminal where the blueapi worker is running. Restart the server to use this updated `config.yaml` file. | ||
|
|
||
| Now run | ||
| ```blueapi controller plans``` in the same terminal window used previously for this command and you should see a list of plans that can be run. For example, `count`, `list_grid_scan`, `num_scan` etc. |
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,92 @@ | ||
| # 5. Run a Plan | ||
|
|
||
| Now that we have a running worker and we have added plans and devices to the `config.yaml` file, we should be able to run a plan. | ||
|
|
||
| ## Example Plans | ||
| Run the following command in the terminal. (Same terminal where you ran `blueapi controller devices/plans`). | ||
|
|
||
| Run a Sleep plan | ||
| ``` | ||
| blueapi -c config.yaml controller run -i cm12345-1 sleep '{"time": 5}' | ||
| ``` | ||
| You may get this error in the terminal logs: | ||
| ``` | ||
| Error: Stomp configuration required to run plans is missing or disabled | ||
| ``` | ||
|
|
||
| We need to enable stomp in our `config.yaml` file. Add the following lines to your `config.yaml`. This should not be within the `env` section, but should rather be its own section. | ||
|
|
||
| ```yaml | ||
| stomp: | ||
| enabled: true | ||
| url: tcp://localhost:61613/ | ||
| ``` | ||
|
|
||
| Your overall config.yaml should now look like: | ||
|
|
||
| ```yaml | ||
| env: | ||
| metadata: | ||
| instrument: demo | ||
| sources: | ||
| - kind: deviceManager | ||
| module: blueapi.tutorial.devices | ||
| - kind: planFunctions | ||
| module: dodal.plans | ||
| - kind: planFunctions | ||
| module: dodal.plan_stubs.wrapped | ||
| stomp: | ||
| enabled: true | ||
| url: tcp://localhost:61613/ | ||
| ``` | ||
|
|
||
| If you had difficulties creating your `config.yaml` file, you can use the pre-made one in the `docs/resources` folder. | ||
|
|
||
| Try running the Sleep plan again. You may come across this error: | ||
|
|
||
| ``` | ||
| WARNING stomp.py could not connect to host localhost, port 61613: [Errno 111] Connection refused | ||
| ``` | ||
| To run a plan in blocking mode, we need the message bus to be started. Blueapi can publish updates to this message bus asynchronously and then the CLI can view these updates and display them to the user. Run the following command in a new terminal window and restart the blueapi server. | ||
|
|
||
| ```sh | ||
| echo "[rabbitmq_stomp].">enabled_plugins && podman run -it --rm --name rabbitmq-docs -v $(readlink -f enabled_plugins):/etc/rabbitmq/enabled_plugins:z -p 5672:5672 -p 61613:61613 rabbitmq:latest | ||
| ``` | ||
|
|
||
| Now, try running the Sleep plan. You should 'Plan succeeded' in the terminal logs of the terminal window where the blueapi server is running. | ||
|
|
||
| Below are some other plans you can try. In the terminal window where the Sleep plan was run, you should see | ||
| ``` | ||
| INFO root Stomp client subscribing to name='public.worker.event' | ||
| ``` | ||
|
|
||
| Press CTLR+C to disconnect the Stomp client then run a new plan. | ||
|
|
||
| Run a Scan | ||
| ``` | ||
| blueapi -c config.yaml controller run count '{"detectors": ["det"], "num":5}' -i cm1234-5 | ||
|
|
||
| ``` | ||
| Run a Step Scan | ||
| ``` | ||
| blueapi -c config.yaml controller run step_scan '{"detectors":["det"], "params":[["stage.x",[0,5,1]]]}' -i cm1234-5 | ||
| ``` | ||
|
|
||
| ## Adding extra components to the configuration | ||
|
|
||
| Having added the minimal configuration required to run a plan, we can add optional components. For example: | ||
|
|
||
| The CLI uses REST requests talk to the worker via a message broker on `tcp://localhost:61613`, | ||
| but you can customize this via the `config.yaml` file. | ||
|
|
||
| ```{literalinclude} ../../tests/unit_tests/valid_example_config/client.yaml | ||
| :language: yaml | ||
| ``` | ||
|
|
||
| Then run | ||
|
|
||
| ``` | ||
| blueapi -c custom-address.yaml controller plans | ||
| ``` | ||
|
|
||
| Other components that can be added to the config are detailed in the the [How-to-Guide section](../how-to/). |
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,75 @@ | ||
| # 6. Run a Plan from Docs page | ||
|
|
||
| As well as running plans through the CLI, it is possible to run plans using the docs page. This is an easy way to run one plan but if you need to run multiple plans, it may be easier to use the CLI. | ||
|
|
||
| In the terminal window where the worker is running, scroll to this line in the logs: | ||
|
|
||
| ``` | ||
| INFO uvicorn.error Uvicorn running on http://localhost:8000 (Press CTRL+C to quit) | ||
| ``` | ||
| Open the link (ctrl+click) and this should take you to the BlueAPI Control docs page. It should look like this: | ||
|
|
||
|
|
||
|  | ||
|
|
||
| Scrolling down will show you endpoints grouped. The different groups are described below. | ||
|
|
||
| ## Definitions: | ||
| - Plan: a set of instructions for one aspect of experiment orchestration. More details can be found [here](https://blueskyproject.io/bluesky/v1.13.1rc1/plans.html) | ||
| - Task: one individual instance of the plan being run. | ||
| - Device: hardware defined via ophyd protocols. For more information visit [dodal](https://github.com/DiamondLightSource/dodal) and its [Glossary page](https://diamondlightsource.github.io/dodal/main/reference/glossary.html). | ||
| - Environment - definition already provided under the endpoint. | ||
| - Meta - definition already provided under the endpoint. | ||
|
|
||
| ## Steps for running a plan | ||
| 1. Find available devices. | ||
|
|
||
| The first recommended step is to find out what devices are available on the instrument. Scroll down to the 'Get Devices' endpoint (/api/v1/devices) and press the downwards arrow which should expand it to show the 'Try it out' button. Click the 'Try it out' button to enable further interaction. | ||
|
|
||
|  | ||
|
|
||
| Next, press the 'Execute' button and scroll down to 'Responses' where you should see available devices (e.g. 'det' in the example below). Take note of the device name for later use. | ||
|
|
||
|  | ||
|
|
||
| 2. Create a task using one of the available devices. | ||
|
|
||
| Scroll back up to the 'Submit Task' endpoint (/api/v1/tasks). The default setting that should appear in the request body is the example of a 'count' task using detector 'x' and instrument session 'cm12345-1'. | ||
|
|
||
|  | ||
|
|
||
| Press the 'Try it out' button and replace the placeholder 'x' in the request body with the device you took note of in step 1 ('det' in this example). The instrument session can be left as 'cm12345-1' for the purposes of this tutorial. | ||
|
|
||
|  | ||
|
|
||
| Press 'Execute' and you should receive a '201' response that contains a 'task_id'. At the end of the response body box, press the clipboard symbol to copy this 'task_id'. | ||
|
|
||
|  | ||
|
|
||
| 3. Set created task in the previous step to be the active task | ||
|
|
||
| After creating a task in Step 2, it still needs to be set to be the active task. Scroll down to the 'Set Active Task' endpoint (/api/v1/worker/task). The default for 'task_id' should be 'string'. | ||
|
|
||
|  | ||
|
|
||
| Press 'Try it out' and paste the copied 'task_id' from earlier in the 'Request' body. | ||
|
|
||
|  | ||
|
|
||
| Press the 'Execute' button and scroll down to 'Responses' and check if you got a '200 Successful Response'. The BlueAPI docs page only provides feedback for submitting the task to be the active task. To check if the plan actually ran successfully, check the logs (e.g. through ArgoCD, see below). | ||
|
|
||
| 4. Check the logs in the terminal window where the blueapi server is running | ||
|
|
||
| To confirm if the plan ran successfully check the terminal logs. You should see something like: | ||
|
|
||
| ``` | ||
| INFO blueapi.worker.task_worker Task ran successfully - returned: None | ||
| ``` | ||
|
|
||
| ## Troubleshooting | ||
| - 401 Response/cannot Execute plan - reload whole BlueAPI docs web page and log-in again using Keycloak. | ||
| - 2XX Task was created but could not be run successfully, no response - check logs for correct instrument session, have motor limits been exceeded? | ||
| - New plan changes have been pushed to the repo but the plan isn't showing up | ||
| - May need to pull through PlanDev and reload the environment | ||
| - Make sure the blueapi pod is pointing to the correct commit in ArgoCD (check values.yaml file in pxx-depolyment repo which is accessed through [epics-containers] (https://github.com/epics-containers) ). | ||
| - Update values.yaml as needed, re-submit and re-create a task using BlueAPI and run again using same steps as above. |
2 changes: 1 addition & 1 deletion
2
docs/tutorials/scripting-plans.md → docs/tutorials/7. scripting-plans.md
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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Worker or server?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm is it better to say 'Blueapi contains a worker that can run ...' ?