Skip to content

Commit 0968c53

Browse files
committed
Add custom copilto instructions for examples
1 parent 2ed4482 commit 0968c53

1 file changed

Lines changed: 96 additions & 0 deletions

File tree

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
---
2+
applyTo: "examples/**/*.py,examples/**/*.ipynb"
3+
---
4+
5+
# Project Overview
6+
7+
Plugboard is an event-driven modelling and orchestration framework in Python for simulating and driving complex processes with many interconnected stateful components.
8+
9+
## Planning a model
10+
11+
Help users to plan their models from a high-level overview to a detailed design. This should include:
12+
13+
* The inputs and outputs of the model;
14+
* The components that will be needed to implement each part of the model, and any inputs, outputs and parameters they will need;
15+
* The data flow between components.
16+
17+
For example, a model of a hot-water tank might have components for the water tank, the heater and the thermostat. Additional components might be needed to load data from a file or database, and similarly to save simulation results.
18+
19+
## Implementing components
20+
21+
Help users set up the components they need to implement their model. Custom components can be implemented by subclassing the [`Component`][plugboard.component.Component]. Common components for tasks like loading data can be imported from [`plugboard.library`][plugboard.library].
22+
23+
An empty component looks like this:
24+
25+
```python
26+
from plugboard.component import Component
27+
from plugboard.schemas import ComponentArgsDict
28+
29+
class Offset(Component):
30+
"""Implements `x = a + offset`."""
31+
io = IO(inputs=["a"], outputs=["x"])
32+
33+
def __init__(self, offset: float = 0, **kwargs: _t.Unpack[ComponentArgsDict]) -> None:
34+
super().__init__(**kwargs)
35+
self._offset = offset
36+
37+
async def step(self) -> None:
38+
# TODO: Implement business logic here
39+
# Example `self.x = self.a + self._offset`
40+
pass
41+
```
42+
43+
## Connecting components into a process
44+
45+
You can help users to connect their components together. For initial development and testing use a [LocalProcess][plugboard.process.LocalProcess] to run the model in a single process.
46+
47+
Example code to connect components together and create a process:
48+
49+
```python
50+
from plugboard.connector import AsyncioConnector
51+
from plugboard.process import LocalProcess
52+
from plugboard.schemas import ConnectorSpec
53+
54+
connect = lambda in_, out_: AsyncioConnector(
55+
spec=ConnectorSpec(source=in_, target=out_)
56+
)
57+
process = LocalProcess(
58+
components=[
59+
Random(name="random", iters=5, low=0, high=10),
60+
Offset(name="offset", offset=10),
61+
Scale(name="scale", scale=2),
62+
Sum(name="sum"),
63+
Save(name="save-input", path="input.txt"),
64+
Save(name="save-output", path="output.txt"),
65+
],
66+
connectors=[
67+
# Connect x output of the component named "random" to the value_to_save input of the component named "save-input", etc.
68+
connect("random.x", "save-input.value_to_save"),
69+
connect("random.x", "offset.a"),
70+
connect("random.x", "scale.a"),
71+
connect("offset.x", "sum.a"),
72+
connect("scale.x", "sum.b"),
73+
connect("sum.x", "save-output.value_to_save"),
74+
],
75+
)
76+
```
77+
78+
If you need a diagram of the process you can import `plugboard.diagram.markdown_diagram` and use it to create a markdown representation of the process:
79+
80+
```python
81+
from plugboard.diagram import markdown_diagram
82+
diagram = markdown_diagram(process)
83+
print(diagram)
84+
```
85+
86+
## Running the model
87+
88+
You can help users to run their model. For example, to run the model defined above:
89+
90+
```python
91+
92+
import asyncio
93+
94+
async with process:
95+
await process.run()
96+
```

0 commit comments

Comments
 (0)