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
- Introduces interactive mode for bidirectional data exchange. The interactive mode
requires stream_source for sending inputs from client to the Matlab agent.
The API payloads and configuration gets updated.
- Updates the Matlab Wrapper codes for stream and interactive simulation modes.
- Adds new examples and expands documentation to describe all simulation modes.
Copy file name to clipboardExpand all lines: agents/matlab/README.md
+13-9Lines changed: 13 additions & 9 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -3,9 +3,10 @@
3
3
The MATLAB Agent is a Python-based connector designed to interface with MATLAB simulations through various methods. It provides the following functionalities:
4
4
5
5
-**Batch Simulation**: Executes predefined MATLAB routines with specified input parameters, collecting the final results upon completion.
6
-
-**Streaming Simulation (Agent-Based)**: Allows sending input once, with the output being received in real-time during the simulation.
6
+
-**Streaming Simulation**: Executes MATLAB simulations where input parameters are sent once at the beginning, and results are transmitted continuously in real-time as the simulation progresses.
7
+
-**Interactive Simulation**: Enables bidirectional communication with MATLAB during simulation execution, allowing continuous exchange of data, both input parameters and output results flow in real-time throughout the simulation process.
7
8
8
-
The MATLAB Agent is primarily built to integrate with the Simulation Bridge but can also be utilized by external systems via RabbitMQ exchange methods. Communication parameters and other settings must be defined in the YAML-based configuration file.
9
+
The MATLAB Agent is primarily built to integrate with the Simulation Bridge [_sim_bridge_](../../README.md)but can also be utilized by external systems via RabbitMQ exchange methods. Communication parameters and other settings must be defined in the YAML-based configuration file.
When you modify the code and want to release a new version, increment the version number in `pyproject.toml`:
316
319
317
320
```toml
318
-
version = "0.3.0"
321
+
version = "0.4.0"
319
322
```
320
323
321
324
Then rebuild the package:
@@ -349,6 +352,7 @@ Inside this folder, you'll find:
349
352
-`use.yaml` — Configuration file for the communication protocol (e.g., RabbitMQ settings)
350
353
-`simulation.yaml` — The simulation request payload that will be sent to the MATLAB Agent
351
354
-`use_matlab_agent.py` — Python script to send the request and receive the results
355
+
-`use_matlab_agent_interactive.py` — Python script to interact with the MATLAB Agent in real-time
352
356
353
357
For detailed instructions on how to configure and use the client, refer to the [Use Matlab Agent](./matlab_agent/resources/README.md) in the `agents/matlab/matlab_agent/resources/` folder.
Copy file name to clipboardExpand all lines: agents/matlab/matlab_agent/docs/README.md
+53-2Lines changed: 53 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -58,14 +58,14 @@ An Streaming simulation is designed to receive a predefined input configuration
58
58
59
59
### Streaming Requirements
60
60
61
-
For this type of simulation, you must use the `SimulationWrapper` class, which should be placed in the same folder as the `Simulation.m` file. The `SimulationWrapper.m` handles the TCP/IP connection and communication with the MATLAB agent script.
61
+
For this type of simulation, you must use the `SimulationWrapperStreaming` class, which should be placed in the same folder as the `SimulationStreaming.m` file. The `SimulationWrapperStreaming.m` handles the TCP/IP connection and communication with the MATLAB agent script.
62
62
63
63
The simulation logic must be entirely contained within the main function, defined at the top level as `Simulation()`. This function is responsible for managing both inputs and outputs in the following format:
64
64
65
65
```matlab
66
66
function Simulation()
67
67
% 🔌 Initialize the wrapper
68
-
wrapper = SimulationWrapper();
68
+
wrapper = SimulationWrapperStreaming();
69
69
70
70
% Receive input from the MATLAB agent (via JSON)
71
71
inputs = wrapper.get_inputs();
@@ -94,3 +94,54 @@ These files provide reference implementations to help you structure your simulat
94
94
#### Notes
95
95
96
96
No additional files are handled. All data is transmitted exclusively through the TCP socket.
97
+
98
+
---
99
+
100
+
## Interactive Simulation
101
+
102
+
An interactive simulation continuously exchanges data with the MATLAB Agent. The MATLAB code reacts to new input frames and can send updated outputs at any time during execution. Unlike batch or streaming modes, the simulation remains active while new frames arrive asynchronously.
103
+
104
+
Use the `SimulationWrapperInteractive` class located alongside your `InteractiveSimulation.m` file. This wrapper manages two TCP connections:
105
+
106
+
1.**Output stream** – sends simulation results to the MATLAB Agent.
107
+
2.**Input stream** – receives new frames coming from the message broker.
108
+
109
+
### Interactive Flow
110
+
111
+
1.**Instantiate the wrapper**
112
+
113
+
```matlab
114
+
wrapper = SimulationWrapperInteractive();
115
+
```
116
+
117
+
2.**Retrieve initial parameters**
118
+
Before entering the main loop the simulation can pull a first packet of inputs provided during the handshake.
119
+
120
+
```matlab
121
+
init_data = wrapper.get_initial_inputs();
122
+
% ... initialise simulation state using init_data ...
123
+
```
124
+
125
+
3.**Main loop**
126
+
Continuously poll for new frames, update the state and emit outputs.
127
+
128
+
```matlab
129
+
while true
130
+
data_in = wrapper.get_input();
131
+
if ~isempty(data_in)
132
+
% ... update simulation state ...
133
+
wrapper.send_output(struct('inputs', data_in));
134
+
end
135
+
pause(0.01); % small delay to avoid busy waiting
136
+
end
137
+
```
138
+
139
+
4.**Finalisation**
140
+
When the simulation ends, optionally call wrapper.send_completed() and clean up any resources.
141
+
```matlab
142
+
wrapper.send_completed();
143
+
```
144
+
145
+
The corresponding API payload must specify `inputs.stream_source` with a RabbitMQ URL pointing to the topic where input frames will be published.
146
+
147
+
Refer to `examples/interactive-simulation` for a full example.
0 commit comments