You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/source/events.md
+6-10Lines changed: 6 additions & 10 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,14 +1,10 @@
1
1
# Events and Subscriptions
2
2
3
-
!!! warning ":construction: Under Construction :construction:"
4
-
5
-
As of `12/15/2025`: These docs are a work in progress and may not be complete or fully accurate. Please check back later for updates.
6
-
7
3
Radiate provides an event system that allows you to monitor and react to the evolution process in real-time. This is great for:
8
4
9
5
- Tracking the progress of evolution
10
6
- Collecting metrics and statistics
11
-
- Implementing custom logging
7
+
- Implementing custom logging or logic based on the state of evolution
12
8
- Visualizing the evolution process
13
9
14
10
## Overview
@@ -19,7 +15,7 @@ The `GeneticEngine` trys it's best to off-load almost the entire compute workloa
19
15
20
16
!!! note "Threading Behavior"
21
17
22
-
Currently, the rust implementation is multi-threaded, meaning if you have multiple subscribers, there is no guarantee of the order in which they will be called. For python, regardless of if you are using a free-threaded interpreter (3.13t/3.14t, ect) or not, the events will be dispatched on a single thread in the order they were added.
18
+
Currently, the rust implementation is multi-threaded (if multi-threaded executors are used), meaning if you have multiple subscribers, there is no guarantee of the order in which they will be called. For python, regardless of if you are using a free-threaded interpreter (3.13t/3.14t, ect) or not, the events will be dispatched on a single thread in the order they were added.
23
19
24
20
---
25
21
## Event Types
@@ -66,7 +62,7 @@ Below there is a brief description of each event type with its representative da
66
62
{
67
63
'event_type': 'stop_event',
68
64
'index': 0, // Current generation number
69
-
// This will be a dictionary of metrics collected, see Engine's metrics docs for more info
65
+
// This will be a MetricSet (or dictionary in python) of metrics collected, see Engine's metrics docs for more info
70
66
'metrics': ...,
71
67
// This will be the decoded best individual found so far. So, if you are
72
68
// evolving a vector of FloatGenes, this will be a list of floats
@@ -164,7 +160,7 @@ The simplest way to subscribe to events is by providing a callback function:
164
160
use radiate::*;
165
161
166
162
let mut engine = GeneticEngine::builder()
167
-
.codec(your_codec)
163
+
.codec(FloatCodec::vector(6, -5.0..5.0))
168
164
.fitness_fn(your_fitness_fn)
169
165
.subscribe(|event: &EngineEvent<Vec<f32>>| {
170
166
if let EngineEvent::EpochComplete(index, best, metrics, score, objective) = event {
@@ -215,7 +211,7 @@ For more complex event handling, you can create a custom event handler class:
215
211
engine.run(rd.GenerationsLimit(100))
216
212
```
217
213
218
-
Its also completely possible to create more advanced forms of visualization or logging through this method. For example, below we will collect the score distrubution from each epoch using polars then plot it with matplotlib.
214
+
Its also completely possible to create more advanced forms of visualization or logging through this method. For example, below we will collect the scores from each epoch then use polars to create a DataFrame and finally plot it with matplotlib.
219
215
220
216
```python
221
217
class ScorePlotterHandler(rd.EventHandler):
@@ -278,7 +274,7 @@ For more complex event handling, you can create a custom event handler class:
For python, In come cases (primarily if you are decoding to a `np.array`) it is possible to compile your fitness function down to native C using [numba](https://numba.pydata.org).
30
+
For python, In some cases it is possible to compile your fitness function down to machine code using [numba](https://numba.pydata.org).
31
31
In most cases with this, this will result in your engine running as fast or almost as fast as rust. Check the examples page for an example using this method.
0 commit comments