Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
baf302b
Start event-driven example
toby-coleman Mar 16, 2025
b29dd82
None
toby-coleman Mar 16, 2025
bdd4675
WIP diagram for event-driven example
toby-coleman Mar 16, 2025
a03c94a
Prepare snippets on code
toby-coleman Mar 16, 2025
d5c218f
Fix typo in docstring
toby-coleman Mar 16, 2025
c43dba9
Writeup event-driven tutorial
toby-coleman Mar 21, 2025
be278a6
Fix broken links
toby-coleman Mar 21, 2025
a51f9a6
Update for implemented feature
toby-coleman Mar 21, 2025
c9a2036
Update links
toby-coleman Mar 21, 2025
258bd33
Add YAML version
toby-coleman Mar 21, 2025
cb19233
Add info on logging to tutorial
toby-coleman Mar 21, 2025
956148d
Add tags
toby-coleman Mar 21, 2025
6814620
Add tags
toby-coleman Mar 21, 2025
0928c57
Add tags to demos
toby-coleman Mar 21, 2025
34f9b04
Add tag index
toby-coleman Mar 21, 2025
57cb065
Add car wash demo
toby-coleman Mar 22, 2025
400a22a
Update with text descriptions
toby-coleman Mar 22, 2025
3942f86
README fixes
toby-coleman Mar 22, 2025
9244758
Minor updates
toby-coleman Mar 22, 2025
7fb6e23
Fix logger for types not supported by msgspec
toby-coleman Mar 22, 2025
78cac07
Remove logging conversions
toby-coleman Mar 22, 2025
f75bf3a
Install ipywidgets to remove warnings in notebooks
toby-coleman Mar 22, 2025
21059df
Merge remote-tracking branch 'origin/main' into docs/event-based-example
toby-coleman Apr 1, 2025
b7692b0
Update diagram
toby-coleman Apr 1, 2025
5df238f
Remove changes from #117
toby-coleman Apr 10, 2025
e5c562e
Remove from docs index
toby-coleman Apr 10, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ Some examples of what you can build with Plugboard include:
- A **command line interface** for executing models;
- Built to handle the **data intensive simulation** requirements of industrial process applications;
- Modern implementation with **Python 3.12 and above** based around **asyncio** with complete type annotation coverage;
- Built-in integrations for **loading/saving data** from cloud storage and SQL databases.
- Built-in integrations for **loading/saving data** from cloud storage and SQL databases;
- **Detailed logging** of component inputs, outputs and state for monitoring and process mining or surrogate modelling use-cases.

## 🔌 Installation

Expand All @@ -63,7 +64,7 @@ Support for parallelisation can be installed using `plugboard[ray]`.

## 🚀 Usage

Plugboard is built to help you with two things: defining process models, and executing those models. There are two main ways to interact with plugboard: via the Python API; or, via the CLI using model definitions saved in yaml or json format.
Plugboard is built to help you with two things: defining process models, and executing those models. There are two main ways to interact with plugboard: via the Python API; or, via the CLI using model definitions saved in yaml format.

### Building models with the Python API

Expand Down Expand Up @@ -134,7 +135,7 @@ flowchart LR

### Executing pre-defined models on the CLI

In many cases, we want to define components once, with suitable parameters, and then use them repeatedly in different simulations. Plugboard enables this workflow with model specification files in yaml or json format. Once the components have been defined, the simple model above can be represented with a yaml file like so.
In many cases, we want to define components once, with suitable parameters, and then use them repeatedly in different simulations. Plugboard enables this workflow with model specification files in yaml format. Once the components have been defined, the simple model above can be represented as follows.
```yaml
# my-model.yaml
plugboard:
Expand All @@ -161,21 +162,20 @@ plugboard process run my-model.yaml

## 📖 Documentation

For more information including a detailed API reference and step-by-step usage examples, refer to the [documentation site](https://docs.plugboard.dev). We recommend diving into the [tutorials](https://docs.plugboard.dev/examples/tutorials/hello-world/) for a step-by-step to getting started.
For more information including a detailed API reference and step-by-step usage examples, refer to the [documentation site](https://docs.plugboard.dev). We recommend diving into the [tutorials](https://docs.plugboard.dev/latest/examples/tutorials/hello-world/) for a step-by-step to getting started.

## 🐾 Roadmap

Plugboard is under active development, with new features in the works:

- Detailed logging of component inputs, outputs and state for monitoring and process mining or surrogate modelling use-cases.
- Support for strongly typed data messages and validation based on pydantic.
- Support for different parallelisation patterns such as: single-threaded with coroutines, single-host multi process, or distributed with Ray in Kubernetes.
- Data exchange between components with popular messaging technologies like RabbitMQ and Google Pub/Sub.
- Support for different message exchange patterns such as: one-to-one, one-to-many, many-to-one etc via a broker; or peer-to-peer with http requests.

## 👋 Contributions

Contributions are welcomed and warmly received! For bug fixes and smaller feature requests feel free to open an issue on this repo. For any larger changes please get in touch with us to discuss first. More information for developers can be found in [the contributing section](https://docs.plugboard.dev/contributing/) of the docs.
Contributions are welcomed and warmly received! For bug fixes and smaller feature requests feel free to open an issue on this repo. For any larger changes please get in touch with us to discuss first. More information for developers can be found in [the contributing section](https://docs.plugboard.dev/latest/contributing/) of the docs.

## ⚖️ Licence

Expand Down
2 changes: 2 additions & 0 deletions docs/examples/tutorials/.meta.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
tags:
- tutorial
9 changes: 9 additions & 0 deletions docs/examples/tutorials/more-components.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
---
tags:
- logging
- llm
- io
---
Plugboard's [`Component`][plugboard.component.Component] objects can run anything you can code in Python. This includes:

* Using your own or third-party Python packages;
Expand Down Expand Up @@ -54,6 +60,9 @@ We can now define a component to query a weather API and get temperature and win
--8<-- "examples/tutorials/003_more_components/hello_llm.py:weather"
```

!!! info
See how we used `self._logger` to record log messages. All Plugboard [`Component`][plugboard.component.Component] objects have a [structlog](https://www.structlog.org/) logger on the `_logger` attribute. See [configuration](../../../usage/configuration/) for more information on configuring the logging.

### Putting it all together

As usual, we can link all our components together in a [`LocalProcess`][plugboard.process.Process] and run them as follows:
Expand Down
4 changes: 4 additions & 0 deletions docs/examples/tutorials/running-in-parallel.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
---
tags:
- ray
---
Up until now we have running all our models in a single computational process. This is perfectly sufficient for simple models, or when your components can make use of [Python's asyncio](https://docs.python.org/3/library/asyncio.html) to avoid blocking.

As your models get larger and more computationally intensive you may benefit from running parts of the model in parallel. Plugboard integrates with the [Ray](https://docs.ray.io/) framework, allowing you to split your computation across multiple CPU cores, or even across nodes in a [Ray cluster](https://docs.ray.io/en/latest/cluster/getting-started.html).
Expand Down
4 changes: 2 additions & 2 deletions docs/usage/key-concepts.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ When implementing your own components, you will need to:
* Specify its inputs and ouputs using an [`IOController`][plugboard.component.IOController];
* Define a `step()` method the executes the main logic of your component for a single step; and
* Optionally define an `init()` method to do any required preparatory steps before the model in run.
* In the case of event based models, define custom `Event` subclasses and corresponding event handler methods decorated with `Event.handler`.
* In the case of event based models, define custom [`Event`][plugboard.events.Event] subclasses and corresponding event handler methods decorated with `Event.handler`.

### Connectors

Expand All @@ -42,7 +42,7 @@ graph LR;
A(Load data)-->D(Record output);
```

For models with explicitly declared input and output fields, connectors for each input-output pair must be defined explicitly using one of the `Connector` implementations. Connectors required for any events used in the model will be created for you automatically.
For models with explicitly declared input and output fields, connectors for each input-output pair must be defined explicitly using one of the [`Connector`][plugboard.connector.Connector] implementations. Connectors required for any events used in the model will be created for you automatically.

### Processes

Expand Down
5 changes: 5 additions & 0 deletions docs/usage/topics.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Topic index

To find information on a specific topic, you can look for pages under one of the tags below.

<!-- material/tags -->
2 changes: 2 additions & 0 deletions examples/demos/llm/.meta.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
tags:
- llm
3 changes: 3 additions & 0 deletions examples/demos/llm/002_bluesky_websocket/.meta.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
tags:
- io
- streaming
2 changes: 2 additions & 0 deletions examples/demos/physics-models/.meta.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
tags:
- physics-models
10 changes: 7 additions & 3 deletions examples/tutorials/003_more_components/hello_llm.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"""Simple hello world example."""
"""Simple LLM example."""

# fmt: off
import asyncio
Expand Down Expand Up @@ -36,8 +36,12 @@ async def step(self) -> None:
)
try:
response.raise_for_status()
except httpx.HTTPStatusError as e:
print(f"Error querying weather API: {e}")
except httpx.HTTPStatusError:
self._logger.error(
"Error querying weather API",
code=response.status_code,
message=response.text,
)
Comment thread
toby-coleman marked this conversation as resolved.
return
data = response.json()
self.temperature = data["current"]["temperature_2m"]
Expand Down
3 changes: 3 additions & 0 deletions mkdocs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ plugins:
- mike:
alias_type: symlink
canonical_version: latest
- meta
- tags

markdown_extensions:
- admonition
Expand Down Expand Up @@ -112,6 +114,7 @@ nav:
- Running in parallel: examples/tutorials/running-in-parallel.md
- Event-driven models: examples/tutorials/event-driven-models.md
- Configuration: usage/configuration.md
- Topics: usage/topics.md
- Demos:
- Fundamentals:
- Simple model: examples/demos/fundamentals/001_simple_model/simple-model.ipynb
Expand Down
2 changes: 1 addition & 1 deletion plugboard/utils/logging.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def _is_ipython() -> bool:


def _serialiser(obj: _t.Any, default: _t.Callable | None) -> bytes:
return json.encode(obj)
return json.encode(obj, enc_hook=default)


def configure_logging(settings: Settings) -> None:
Expand Down
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ websockets = ["websockets>=14.2"]
[dependency-groups]
dev = [
"ipython~=8.26",
"ipywidgets>=8.1.5",
"jupyterlab~=4.2",
"mypy~=1.11",
"nbstripout~=0.8",
Expand Down
46 changes: 41 additions & 5 deletions uv.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.