Skip to content

v1.0.0-MATLABagent

Choose a tag to compare

@marcomelloni marcomelloni released this 10 Sep 11:41
· 1 commit to main since this release
c211204

MATLAB Agent v1.0.0

This release introduces significant updates to the MATLAB Agent, including the addition of a new interactive simulation mode, enhanced API functionality, improved documentation, and refactored code. These changes introduce the final simulation mode, increasing the agent's flexibility and usability, and making it easier to integrate real-time bidirectional data exchange (for both input and output) with MATLAB via TCP

MATLABagent v1.0.0

New Feature

Interactive Simulation Mode

The new interactive simulation mode allows for bidirectional data exchange between MATLAB and external systems in real-time. This mode is controlled via the newly introduced interactive.py controller, which manages TCP and RabbitMQ communication.

Key updates:

  • TCP and RabbitMQ support for real-time communication between MATLAB and external clients.
  • stream_source input is now a required parameter in the API payload to direct dynamic inputs to MATLAB.

Example API Payload (simulation.yaml):

simulation:
  request_id: abcdef12345
  # (RequestID) to identify each request.

  client_id: dt
  # Unique identifier of the sender of this simulation request

  simulator: matlab
  # Specifies the target system for the simulation.
  # Use 'matlab' to route the request to the MATLAB simulator.

  type: interactive
  # Specifies the simulation execution mode.
  # Options:
  #   - 'batch': runs the simulation in batch mode, where results are returned only after the entire computation is complete.
  #   - 'streaming': runs the simulation in streaming mode, providing real-time updates at each computation step.
  #   - 'interactive': same as 'streaming', where you need to provide a continuous stream of inputs and outputs.
  
  file: SimulationInteractive.m
  # The name of the MATLAB script or function file to execute for this simulation.

  inputs:
    # Input variables to be passed to the simulation.
    # If the simulation type is 'interactive', it is mandatory to specify 'stream_source' to indicate the source of the input stream.
    # stream_source: The source of the input stream, e.g., RabbitMQ, which streams real-time input data to the simulation.
    # This is required for interactive simulations.
    stream_source: # Source of the input stream, typically RabbitMQ for streaming mode.

    i1: ..
    i2: ..
    i3: ..

  outputs:
    # Expected output variables from the simulation.
    # Customize these keys based on what outputs your simulation provides.
    o1: ..
    o2: ..
    o3: ..
    o4: ..

Wrapper Structure Updates

To better support the new interactive simulation mode, the wrapper structure has been updated as follows:

  • Renamed: SimulationWrapper.m is now SimulationWrapperStreaming.m.
  • New Wrapper: A new wrapper, SimulationWrapperInteractive.m, has been introduced for managing real-time bidirectional communication with the Agent via TCP.

API Functions:

The new wrapper includes the following API, which can be imported and used within the interactive simulation:

  • get_initial_inputs():
    Retrieves the initial static parameters provided in the API payload during the handshake process. These inputs are parsed and stored upon the initial connection.
    initial_inputs = wrapper.get_initial_inputs();

  • get_input()
    Dynamically retrieves the latest input data frame. This function checks for new input data and updates the internal cache with the most recent data, retrying until a timeout occurs.
    latest_input = wrapper.get_input();

  • send_output()
    Sends an output frame to the Agent. The data is encoded as JSON and transmitted via TCP.

output_data = struct('key', 'value');
wrapper.send_output(output_data);
  • send_completed()

Sends a “simulation completed” packet to the Agent. This marks the end of the simulation and sends a timestamp with the status.
wrapper.send_completed();

Documentation and Resources Updates

The documentation has been updated to include a detailed description of the simulation modes: batch, streaming, and interactive.

  • New sections provide step-by-step guides on how to use the wrappers and Python clients (use_matlab_agent_batch.py, use_matlab_agent_streaming.py, use_matlab_agent_interactive.py).

  • A dedicated section for interactive simulation examples with MATLAB scripts (InteractiveSimulation.m, SimulationWrapperInteractive.m) and YAML payload conventions has been added.

  • Updated images, diagrams, and references now reflect the new wrapper structure and the interactive mode.

Removals and Reorganization

Obsolete Components Removed:

  • The old SimulationWrapper.m has been removed and replaced with more specialized wrappers for streaming and interactive modes.

  • The client use_matlab_agent.py has been replaced by three distinct clients (use_matlab_agent_batch.py, use_matlab_agent_streaming.py, use_matlab_agent_interactive.py).

Migration Guide

To migrate from v0.2.0-MATLABagent to v1.0.0-MATLABagent, follow the steps below:

  1. Update MATLAB Code
    Replace the Old Wrapper:
    For streaming simulations, replace SimulationWrapper.m with SimulationWrapperStreaming.m and use SimulationWrapperInteractive.m for interactive simulations

  2. Update Client Scripts
    Remove use_matlab_agent.py from your project and use New Python Clients:

  • For batch simulations: use_matlab_agent_batch.py
  • For streaming simulations: use_matlab_agent_streaming.py
  • For interactive simulations: use_matlab_agent_interactive.py
  1. Update Configuration Payloads
    The interactive simulation mode now requires the stream_source field, which specifies the source of the real-time input stream.

Contributors

Marco Melloni
Marco Melloni
Prasad Talasila
Prasad Talasila
Marco Picone
Marco Picone