Skip to content

Commit 60b1fb9

Browse files
committed
Merge remote-tracking branch 'origin/main' into polref
2 parents 0dc33cc + c1bfb2c commit 60b1fb9

File tree

15 files changed

+182
-49
lines changed

15 files changed

+182
-49
lines changed

.github/workflows/Lint-and-test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ jobs:
66
strategy:
77
matrix:
88
os: [ "ubuntu-latest", "windows-latest" ]
9-
version: ['3.10', '3.11', '3.12']
9+
version: ['3.11', '3.12', '3.13']
1010
fail-fast: false
1111
steps:
1212
- uses: actions/checkout@v5

.github/workflows/release.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ jobs:
2626
- name: Build a binary wheel and a source tarball
2727
run: python3 -m build
2828
- name: Store the distribution packages
29-
uses: actions/upload-artifact@v4
29+
uses: actions/upload-artifact@v5
3030
with:
3131
name: python-package-distributions
3232
path: dist/
@@ -43,7 +43,7 @@ jobs:
4343
id-token: write # IMPORTANT: mandatory for trusted publishing
4444
steps:
4545
- name: Download all the dists
46-
uses: actions/download-artifact@v5
46+
uses: actions/download-artifact@v6
4747
with:
4848
name: python-package-distributions
4949
path: dist/
@@ -60,12 +60,12 @@ jobs:
6060
id-token: write # IMPORTANT: mandatory for sigstore
6161
steps:
6262
- name: Download all the dists
63-
uses: actions/download-artifact@v5
63+
uses: actions/download-artifact@v6
6464
with:
6565
name: python-package-distributions
6666
path: dist/
6767
- name: Sign the dists with Sigstore
68-
uses: sigstore/gh-action-sigstore-python@v3.0.1
68+
uses: sigstore/gh-action-sigstore-python@v3.1.0
6969
with:
7070
inputs: >-
7171
./dist/*.tar.gz

doc/_static/css/custom.css

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
a:hover {
2+
color: #ff8c00;
3+
}
4+
5+
.wy-menu-vertical p.caption {
6+
color: #ff5800;
7+
}
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
# 9. Kafka streaming
2+
3+
## Status
4+
5+
Current
6+
7+
## Context
8+
9+
Many facilities stream bluesky documents to an event-bus for consumption by out-of-process listeners.
10+
Event buses used for this purpose at other facilities include ZeroMQ, RabbitMQ, Kafka, Redis, NATS, and
11+
others.
12+
13+
The capability this provides is that callbacks can be run in different processes or on other computers,
14+
without holding up or interfering with the local `RunEngine`. Other groups at ISIS have expressed some
15+
interest in being able to subscribe to bluesky documents.
16+
17+
## Decision
18+
19+
- We will stream our messages to Kafka, as opposed to some other message bus. This is because we already
20+
have Kafka infrastructure available for other purposes (e.g. event data & sample-environment data).
21+
- At the time of writing, we will not **depend** on Kafka for anything critical. This is because the
22+
central Kafka instance is not currently considered "reliable" in an experiment controls context. However,
23+
streaming the documents will allow testing to be done. Kafka will eventually be deployed in a "reliable"
24+
way accessible to each instrument.
25+
- We will encode messages from bluesky using `msgpack` (with the `msgpack-numpy` extension), because:
26+
- It is the default encoder used by the upstream `bluesky-kafka` integration
27+
- It is a schema-less encoder, meaning we do not have to write/maintain fixed schemas for all the
28+
documents allowed by `event-model`
29+
- It has reasonable performance in terms of encoding speed and message size
30+
- `msgpack` is very widely supported in a range of programming languages
31+
- Kafka brokers will be configurable via an environment variable, `IBEX_BLUESKY_CORE_KAFKA_BROKER`
32+
33+
```{note}
34+
Wherever Kafka is mentioned above, the actual implementation may be a Kafka-like (e.g. RedPanda).
35+
```
36+
37+
### Alternatives considered
38+
39+
Encoding bluesky documents into JSON and then wrapping them in the
40+
[`json_json.fbs` flatbuffers schema](https://github.com/ess-dmsc/streaming-data-types/blob/58793c3dfa060f60b4a933bc085f831744e43f17/schemas/json_json.fbs)
41+
was considered.
42+
43+
We chose `msgpack` instead of json strings + flatbuffers because:
44+
- It is more standard in the bluesky community (e.g. it is the default used in `bluesky-kafka`)
45+
- Bluesky events will be streamed to a dedicated topic, which is unlikely to be confused with data
46+
using any other schema.
47+
48+
Performance/storage impacts are unlikely to be noticeable for bluesky documents, but nonetheless:
49+
- `msgpack`-encoded documents are 30-40% smaller than `json` + flatbuffers
50+
for a typical bluesky document
51+
- `msgpack`-encoding messages is ~5x faster than `json` + flatbuffers encoding
52+
for a typical bluesky document.
53+
54+
## Justification & Consequences
55+
56+
We will stream bluesky documents to Kafka, encoded using `msgpack-numpy`.
57+
58+
At the time of writing this is purely to enable testing, and will not be used for "production" workflows.

doc/callbacks/fitting/fitting.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
Similar to [`LivePlot`](/callbacks/plotting.md), [`ibex_bluesky_core`](ibex_bluesky_core) provides a thin wrapper around Bluesky's [`LiveFit`](ibex_bluesky_core.callbacks.LiveFit) class, enhancing it with additional functionality to better support real-time data fitting. This wrapper not only offers a wide selection of models to fit your data on, but also introduces guess generation for fit parameters. As new data points are acquired, the wrapper refines these guesses dynamically, improving the accuracy of the fit with each additional piece of data, allowing for more efficient and adaptive real-time fitting workflows.
44

5-
In order to use the wrapper, import[`LiveFit`](ibex_bluesky_core.callbacks.LiveFit from [`ibex_bluesky_core`](ibex_bluesky_core) rather than
5+
In order to use the wrapper, import [`LiveFit`](ibex_bluesky_core.callbacks.LiveFit) from [`ibex_bluesky_core`](ibex_bluesky_core) rather than
66
`bluesky` directly:
77
```py
88
from ibex_bluesky_core.callbacks.fitting import LiveFit

doc/conf.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,10 @@
7171
"style_nav_header_background": "#343131",
7272
}
7373
html_favicon = "favicon.svg"
74+
html_static_path = ["_static"]
75+
html_css_files = [
76+
"css/custom.css",
77+
]
7478

7579
autoclass_content = "both"
7680
myst_heading_anchors = 7
@@ -79,7 +83,7 @@
7983
intersphinx_mapping = {
8084
"python": ("https://docs.python.org/3", None),
8185
"bluesky": ("https://blueskyproject.io/bluesky/main/", None),
82-
"ophyd_async": ("https://blueskyproject.io/ophyd-async/main/", None),
86+
"ophyd_async": ("https://blueskyproject.io/ophyd-async/v0.13.4/", None),
8387
"event_model": ("https://blueskyproject.io/event-model/main/", None),
8488
"scipp": ("https://scipp.github.io/", None),
8589
"scippneutron": ("https://scipp.github.io/scippneutron/", None),

doc/dev/kafka.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# Kafka
2+
3+
`ibex_bluesky_core` uses [the `bluesky-kafka` library](https://github.com/bluesky/bluesky-kafka) to send documents
4+
emitted by the `RunEngine` to kafka. The kafka callback is automatically added by
5+
{py:obj}`ibex_bluesky_core.run_engine.get_run_engine`, and so no user configuration is required - the callback is always
6+
enabled.
7+
8+
Documents are encoded using [the `msgpack` format](https://msgpack.org/index.html) - using the `msgpack-numpy` library
9+
to also handle numpy arrays transparently.
10+
11+
The kafka broker to send to can be controlled using the `IBEX_BLUESKY_CORE_KAFKA_BROKER` environment variable, if
12+
an instrument needs to override the default. The kafka topic will be `<INSTRUMENT>_bluesky`, where `INSTRUMENT` is the
13+
instrument name with any NDX or NDH prefix stripped.
14+
15+
The message key will always be `doc` for bluesky documents; specifying a non-null key enforces message ordering.

0 commit comments

Comments
 (0)