Tutorial 1 - A simple pipeline to plot a signal¶

First we define a simple pipeline of three agents. Two agents will generate a signal (in our case based on the SineGeneratorAgent), one of which is a default signal and one with customized parameters. The third one plots the signals on the dashboard, thus needs to be of type MonitorAgent or MetrologicalMonitorAgent. Besides, the outputs of the signal agents need to be bound to the MonitorAgent.

Each agent has an internal current_state which can be used as a switch to change the behaviour of the agent. The available states are listed here.

As soon as all agents are initialized and the connections are set up, the agent network is started by accordingly changing all agents’ state simultaneously.

[3]:
# %load tutorial_1_generator_agent.py
from time import sleep

import numpy as np

from agentMET4FOF.agents import AgentNetwork, MonitorAgent, SineGeneratorAgent


def demonstrate_generator_agent_use() -> AgentNetwork:
    # Start agent network server.
    agent_network = AgentNetwork()

    # Initialize agents by adding them to the agent network.
    default_sine_agent = agent_network.add_agent(
        name="Default Sine generator", agentType=SineGeneratorAgent
    )
    custom_sine_agent = agent_network.add_agent(
        name="Custom Sine generator", agentType=SineGeneratorAgent
    )
    custom_sine_agent.init_parameters(
        sfreq=50,
        sine_freq=np.pi,
        amplitude=0.75,
    )
    monitor_agent = agent_network.add_agent(
        name="Showcase a default and a customized sine signal", agentType=MonitorAgent
    )

    # Interconnect agents by either way:
    # 1) by agent network.bind_agents(source, target).
    agent_network.bind_agents(default_sine_agent, monitor_agent)

    # 2) by the agent.bind_output().
    custom_sine_agent.bind_output(monitor_agent)

    # Set all agents' states to "Running".
    agent_network.set_running_state()

    # Allow for shutting down the network after execution
    return agent_network


if __name__ == "__main__":
    signal_demo_network = demonstrate_generator_agent_use()
    sleep(60)
    signal_demo_network.shutdown()

Error on connecting to existing name server at http://0.0.0.0:3333: Could not locate the name server!
Starting NameServer...
Broadcast server running on 0.0.0.0:9091
NS running on 0.0.0.0:3333 (0.0.0.0)
URI = PYRO:Pyro.NameServer@0.0.0.0:3333
INFO [2021-07-30 09:59:43.033947] (Default_Sine_generator): INITIALIZED
INFO [2021-07-30 09:59:43.083714] (Custom_Sine_generator): INITIALIZED
INFO [2021-07-30 09:59:43.133350] (Showcase_a_default_and_a_customized_sine_signal): INITIALIZED
[2021-07-30 09:59:43.165943] (Default_Sine_generator): Connected output module: Showcase_a_default_and_a_customized_sine_signal
[2021-07-30 09:59:43.182657] (Custom_Sine_generator): Connected output module: Showcase_a_default_and_a_customized_sine_signal

|----------------------------------------------------------|
|                                                          |
| Your agent network is starting up. Open your browser and |
| visit the agentMET4FOF dashboard on http://0.0.0.0:8050/ |
|                                                          |
|----------------------------------------------------------|

SET STATE:   Running
127.0.0.1 - - [30/Jul/2021 11:59:43] "POST /_dash-update-component HTTP/1.1" 200 61
127.0.0.1 - - [30/Jul/2021 11:59:43] "POST /_dash-update-component HTTP/1.1" 200 61
127.0.0.1 - - [30/Jul/2021 11:59:43] "POST /_dash-update-component HTTP/1.1" 200 70
127.0.0.1 - - [30/Jul/2021 11:59:43] "POST /_dash-update-component HTTP/1.1" 204 0
/home/ludwig10/code/agentMET4FOF/agentMET4FOF/dashboard/Dashboard_agt_net.py:817: UserWarning:

The Dashboard shows a plot for monitor agent 'Showcase_a_default_and_a_customized_sine_signal' without any axes labels specified. The labels will be represented by generic place holders. Check out tutorial 4 to find out how to specify custom labels.

127.0.0.1 - - [30/Jul/2021 11:59:43] "POST /_dash-update-component HTTP/1.1" 200 312
127.0.0.1 - - [30/Jul/2021 11:59:43] "POST /_dash-update-component HTTP/1.1" 200 61
127.0.0.1 - - [30/Jul/2021 11:59:43] "POST /_dash-update-component HTTP/1.1" 200 70
127.0.0.1 - - [30/Jul/2021 11:59:43] "POST /_dash-update-component HTTP/1.1" 204 0
127.0.0.1 - - [30/Jul/2021 11:59:43] "POST /_dash-update-component HTTP/1.1" 200 312
127.0.0.1 - - [30/Jul/2021 11:59:43] "POST /_dash-update-component HTTP/1.1" 200 61
127.0.0.1 - - [30/Jul/2021 11:59:43] "POST /_dash-update-component HTTP/1.1" 200 61
[2021-07-30 09:59:44.043635] (Default_Sine_generator): Pack time: 0.000226
[2021-07-30 09:59:44.044166] (Default_Sine_generator): Sending: {'quantities': array([0.]), 'time': array([0.])}
[2021-07-30 09:59:44.045358] (Showcase_a_default_and_a_customized_sine_signal): Received: {'from': 'Default_Sine_generator', 'data': {'quantities': array([0.]), 'time': array([0.])}, 'senderType': 'SineGeneratorAgent', 'channel': 'default'}
[2021-07-30 09:59:44.045690] (Showcase_a_default_and_a_customized_sine_signal): Buffer: {'Default_Sine_generator': {'quantities': array([0.]), 'time': array([0.])}}
[2021-07-30 09:59:44.045760] (Showcase_a_default_and_a_customized_sine_signal): Tproc: 0.000295
[2021-07-30 09:59:44.095094] (Showcase_a_default_and_a_customized_sine_signal): Received: {'from': 'Custom_Sine_generator', 'data': {'quantities': array([0.]), 'time': array([0.])}, 'senderType': 'SineGeneratorAgent', 'channel': 'default'}
[2021-07-30 09:59:44.094609] (Custom_Sine_generator): Pack time: 0.000172
[2021-07-30 09:59:44.095426] (Showcase_a_default_and_a_customized_sine_signal): Buffer: {'Default_Sine_generator': {'quantities': array([0.]), 'time': array([0.])}, 'Custom_Sine_generator': {'quantities': array([0.]), 'time': array([0.])}}
[2021-07-30 09:59:44.095142] (Custom_Sine_generator): Sending: {'quantities': array([0.]), 'time': array([0.])}
[2021-07-30 09:59:44.095463] (Showcase_a_default_and_a_customized_sine_signal): Tproc: 0.000293
[2021-07-30 09:59:45.044626] (Default_Sine_generator): Pack time: 0.0008
[2021-07-30 09:59:45.045930] (Default_Sine_generator): Sending: {'quantities': array([0.06279052]), 'time': array([0.002])}
[2021-07-30 09:59:45.047612] (Showcase_a_default_and_a_customized_sine_signal): Received: {'from': 'Default_Sine_generator', 'data': {'quantities': array([0.06279052]), 'time': array([0.002])}, 'senderType': 'SineGeneratorAgent', 'channel': 'default'}
[2021-07-30 09:59:45.048850] (Showcase_a_default_and_a_customized_sine_signal): Buffer: {'Default_Sine_generator': {'quantities': array([0.        , 0.06279052]), 'time': array([0.   , 0.002])}, 'Custom_Sine_generator': {'quantities': array([0.]), 'time': array([0.])}}
[2021-07-30 09:59:45.048990] (Showcase_a_default_and_a_customized_sine_signal): Tproc: 0.001239
[2021-07-30 09:59:45.094519] (Custom_Sine_generator): Pack time: 0.00012
[2021-07-30 09:59:45.095080] (Custom_Sine_generator): Sending: {'quantities': array([0.28845673]), 'time': array([0.02])}
[2021-07-30 09:59:45.096230] (Showcase_a_default_and_a_customized_sine_signal): Received: {'from': 'Custom_Sine_generator', 'data': {'quantities': array([0.28845673]), 'time': array([0.02])}, 'senderType': 'SineGeneratorAgent', 'channel': 'default'}
[2021-07-30 09:59:45.097126] (Showcase_a_default_and_a_customized_sine_signal): Buffer: {'Default_Sine_generator': {'quantities': array([0.        , 0.06279052]), 'time': array([0.   , 0.002])}, 'Custom_Sine_generator': {'quantities': array([0.        , 0.28845673]), 'time': array([0.  , 0.02])}}
[2021-07-30 09:59:45.097229] (Showcase_a_default_and_a_customized_sine_signal): Tproc: 0.000899
127.0.0.1 - - [30/Jul/2021 11:59:45] "POST /_dash-update-component HTTP/1.1" 200 61
127.0.0.1 - - [30/Jul/2021 11:59:45] "POST /_dash-update-component HTTP/1.1" 200 61
127.0.0.1 - - [30/Jul/2021 11:59:45] "POST /_dash-update-component HTTP/1.1" 200 70
127.0.0.1 - - [30/Jul/2021 11:59:45] "POST /_dash-update-component HTTP/1.1" 200 61
127.0.0.1 - - [30/Jul/2021 11:59:45] "POST /_dash-update-component HTTP/1.1" 204 0
127.0.0.1 - - [30/Jul/2021 11:59:45] "POST /_dash-update-component HTTP/1.1" 200 410
127.0.0.1 - - [30/Jul/2021 11:59:45] "POST /_dash-update-component HTTP/1.1" 200 70
127.0.0.1 - - [30/Jul/2021 11:59:45] "POST /_dash-update-component HTTP/1.1" 204 0
[2021-07-30 09:59:46.043679] (Default_Sine_generator): Pack time: 0.000211
[2021-07-30 09:59:46.044379] (Default_Sine_generator): Sending: {'quantities': array([0.12533323]), 'time': array([0.004])}
[2021-07-30 09:59:46.046502] (Showcase_a_default_and_a_customized_sine_signal): Received: {'from': 'Default_Sine_generator', 'data': {'quantities': array([0.12533323]), 'time': array([0.004])}, 'senderType': 'SineGeneratorAgent', 'channel': 'default'}
[2021-07-30 09:59:46.047529] (Showcase_a_default_and_a_customized_sine_signal): Buffer: {'Default_Sine_generator': {'quantities': array([0.        , 0.06279052, 0.12533323]), 'time': array([0.   , 0.002, 0.004])}, 'Custom_Sine_generator': {'quantities': array([0.        , 0.28845673]), 'time': array([0.  , 0.02])}}
[2021-07-30 09:59:46.047635] (Showcase_a_default_and_a_customized_sine_signal): Tproc: 0.00102
[2021-07-30 09:59:46.094527] (Custom_Sine_generator): Pack time: 0.00016
[2021-07-30 09:59:46.095153] (Showcase_a_default_and_a_customized_sine_signal): Received: {'from': 'Custom_Sine_generator', 'data': {'quantities': array([0.53253704]), 'time': array([0.04])}, 'senderType': 'SineGeneratorAgent', 'channel': 'default'}
[2021-07-30 09:59:46.094884] (Custom_Sine_generator): Sending: {'quantities': array([0.53253704]), 'time': array([0.04])}
[2021-07-30 09:59:46.097297] (Showcase_a_default_and_a_customized_sine_signal): Buffer: {'Default_Sine_generator': {'quantities': array([0.        , 0.06279052, 0.12533323]), 'time': array([0.   , 0.002, 0.004])}, 'Custom_Sine_generator': {'quantities': array([0.        , 0.28845673, 0.53253704]), 'time': array([0.  , 0.02, 0.04])}}
[2021-07-30 09:59:46.097420] (Showcase_a_default_and_a_customized_sine_signal): Tproc: 0.002168
127.0.0.1 - - [30/Jul/2021 11:59:46] "POST /_dash-update-component HTTP/1.1" 200 410
127.0.0.1 - - [30/Jul/2021 11:59:46] "POST /_dash-update-component HTTP/1.1" 200 61
127.0.0.1 - - [30/Jul/2021 11:59:46] "POST /_dash-update-component HTTP/1.1" 204 0
[2021-07-30 09:59:47.045113] (Showcase_a_default_and_a_customized_sine_signal): Received: {'from': 'Default_Sine_generator', 'data': {'quantities': array([0.18738131]), 'time': array([0.006])}, 'senderType': 'SineGeneratorAgent', 'channel': 'default'}
[2021-07-30 09:59:47.046707] (Showcase_a_default_and_a_customized_sine_signal): Buffer: {'Default_Sine_generator': {'quantities': array([0.        , 0.06279052, 0.12533323, 0.18738131]), 'time': array([0.   , 0.002, 0.004, 0.006])}, 'Custom_Sine_generator': {'quantities': array([0.        , 0.28845673, 0.53253704]), 'time': array([0.  , 0.02, 0.04])}}
[2021-07-30 09:59:47.043935] (Default_Sine_generator): Pack time: 0.000295
[2021-07-30 09:59:47.046908] (Showcase_a_default_and_a_customized_sine_signal): Tproc: 0.001603
[2021-07-30 09:59:47.044920] (Default_Sine_generator): Sending: {'quantities': array([0.18738131]), 'time': array([0.006])}
[2021-07-30 09:59:47.094838] (Custom_Sine_generator): Pack time: 0.000245
[2021-07-30 09:59:47.095659] (Custom_Sine_generator): Sending: {'quantities': array([0.69469143]), 'time': array([0.06])}
[2021-07-30 09:59:47.097286] (Showcase_a_default_and_a_customized_sine_signal): Received: {'from': 'Custom_Sine_generator', 'data': {'quantities': array([0.69469143]), 'time': array([0.06])}, 'senderType': 'SineGeneratorAgent', 'channel': 'default'}
[2021-07-30 09:59:47.098943] (Showcase_a_default_and_a_customized_sine_signal): Buffer: {'Default_Sine_generator': {'quantities': array([0.        , 0.06279052, 0.12533323, 0.18738131]), 'time': array([0.   , 0.002, 0.004, 0.006])}, 'Custom_Sine_generator': {'quantities': array([0.        , 0.28845673, 0.53253704, 0.69469143]), 'time': array([0.  , 0.02, 0.04, 0.06])}}
[2021-07-30 09:59:47.099170] (Showcase_a_default_and_a_customized_sine_signal): Tproc: 0.001653
127.0.0.1 - - [30/Jul/2021 11:59:47] "POST /_dash-update-component HTTP/1.1" 200 61
127.0.0.1 - - [30/Jul/2021 11:59:47] "POST /_dash-update-component HTTP/1.1" 200 70
127.0.0.1 - - [30/Jul/2021 11:59:47] "POST /_dash-update-component HTTP/1.1" 204 0
127.0.0.1 - - [30/Jul/2021 11:59:47] "POST /_dash-update-component HTTP/1.1" 200 471
127.0.0.1 - - [30/Jul/2021 11:59:47] "POST /_dash-update-component HTTP/1.1" 200 61
127.0.0.1 - - [30/Jul/2021 11:59:47] "POST /_dash-update-component HTTP/1.1" 200 61
127.0.0.1 - - [30/Jul/2021 11:59:47] "POST /_dash-update-component HTTP/1.1" 200 61
[2021-07-30 09:59:48.046405] (Default_Sine_generator): Pack time: 0.000789
[2021-07-30 09:59:48.051703] (Default_Sine_generator): Sending: {'quantities': array([0.24868989]), 'time': array([0.008])}
[2021-07-30 09:59:48.061048] (Showcase_a_default_and_a_customized_sine_signal): Received: {'from': 'Default_Sine_generator', 'data': {'quantities': array([0.24868989]), 'time': array([0.008])}, 'senderType': 'SineGeneratorAgent', 'channel': 'default'}
[2021-07-30 09:59:48.066669] (Showcase_a_default_and_a_customized_sine_signal): Buffer: {'Default_Sine_generator': {'quantities': array([0.        , 0.06279052, 0.12533323, 0.18738131, 0.24868989]), 'time': array([0.   , 0.002, 0.004, 0.006, 0.008])}, 'Custom_Sine_generator': {'quantities': array([0.        , 0.28845673, 0.53253704, 0.69469143]), 'time': array([0.  , 0.02, 0.04, 0.06])}}
[2021-07-30 09:59:48.067071] (Showcase_a_default_and_a_customized_sine_signal): Tproc: 0.005775
[2021-07-30 09:59:48.094548] (Custom_Sine_generator): Pack time: 0.00015
[2021-07-30 09:59:48.095136] (Custom_Sine_generator): Sending: {'quantities': array([0.74997391]), 'time': array([0.08])}
[2021-07-30 09:59:48.096008] (Showcase_a_default_and_a_customized_sine_signal): Received: {'from': 'Custom_Sine_generator', 'data': {'quantities': array([0.74997391]), 'time': array([0.08])}, 'senderType': 'SineGeneratorAgent', 'channel': 'default'}
[2021-07-30 09:59:48.097694] (Showcase_a_default_and_a_customized_sine_signal): Buffer: {'Default_Sine_generator': {'quantities': array([0.        , 0.06279052, 0.12533323, 0.18738131, 0.24868989]), 'time': array([0.   , 0.002, 0.004, 0.006, 0.008])}, 'Custom_Sine_generator': {'quantities': array([0.        , 0.28845673, 0.53253704, 0.69469143, 0.74997391]), 'time': array([0.  , 0.02, 0.04, 0.06, 0.08])}}
[2021-07-30 09:59:48.097824] (Showcase_a_default_and_a_customized_sine_signal): Tproc: 0.001523
[2021-07-30 09:59:49.044435] (Default_Sine_generator): Pack time: 0.000309
[2021-07-30 09:59:49.046205] (Default_Sine_generator): Sending: {'quantities': array([0.30901699]), 'time': array([0.01])}
[2021-07-30 09:59:49.046610] (Showcase_a_default_and_a_customized_sine_signal): Received: {'from': 'Default_Sine_generator', 'data': {'quantities': array([0.30901699]), 'time': array([0.01])}, 'senderType': 'SineGeneratorAgent', 'channel': 'default'}
[2021-07-30 09:59:49.051126] (Showcase_a_default_and_a_customized_sine_signal): Buffer: {'Default_Sine_generator': {'quantities': array([0.        , 0.06279052, 0.12533323, 0.18738131, 0.24868989,
       0.30901699]), 'time': array([0.   , 0.002, 0.004, 0.006, 0.008, 0.01 ])}, 'Custom_Sine_generator': {'quantities': array([0.        , 0.28845673, 0.53253704, 0.69469143, 0.74997391]), 'time': array([0.  , 0.02, 0.04, 0.06, 0.08])}}
[2021-07-30 09:59:49.053322] (Showcase_a_default_and_a_customized_sine_signal): Tproc: 0.006407
[2021-07-30 09:59:49.095964] (Custom_Sine_generator): Pack time: 0.000746
[2021-07-30 09:59:49.097849] (Custom_Sine_generator): Sending: {'quantities': array([0.68987981]), 'time': array([0.1])}
[2021-07-30 09:59:49.098312] (Showcase_a_default_and_a_customized_sine_signal): Received: {'from': 'Custom_Sine_generator', 'data': {'quantities': array([0.68987981]), 'time': array([0.1])}, 'senderType': 'SineGeneratorAgent', 'channel': 'default'}
[2021-07-30 09:59:49.102829] (Showcase_a_default_and_a_customized_sine_signal): Buffer: {'Default_Sine_generator': {'quantities': array([0.        , 0.06279052, 0.12533323, 0.18738131, 0.24868989,
       0.30901699]), 'time': array([0.   , 0.002, 0.004, 0.006, 0.008, 0.01 ])}, 'Custom_Sine_generator': {'quantities': array([0.        , 0.28845673, 0.53253704, 0.69469143, 0.74997391,
       0.68987981]), 'time': array([0.  , 0.02, 0.04, 0.06, 0.08, 0.1 ])}}
[2021-07-30 09:59:49.103233] (Showcase_a_default_and_a_customized_sine_signal): Tproc: 0.004633
[2021-07-30 09:59:50.043612] (Default_Sine_generator): Pack time: 0.000273
[2021-07-30 09:59:50.044007] (Default_Sine_generator): Sending: {'quantities': array([0.36812455]), 'time': array([0.012])}
[2021-07-30 09:59:50.044267] (Showcase_a_default_and_a_customized_sine_signal): Received: {'from': 'Default_Sine_generator', 'data': {'quantities': array([0.36812455]), 'time': array([0.012])}, 'senderType': 'SineGeneratorAgent', 'channel': 'default'}
[2021-07-30 09:59:50.045715] (Showcase_a_default_and_a_customized_sine_signal): Buffer: {'Default_Sine_generator': {'quantities': array([0.        , 0.06279052, 0.12533323, 0.18738131, 0.24868989,
       0.30901699, 0.36812455]), 'time': array([0.   , 0.002, 0.004, 0.006, 0.008, 0.01 , 0.012])}, 'Custom_Sine_generator': {'quantities': array([0.        , 0.28845673, 0.53253704, 0.69469143, 0.74997391,
       0.68987981]), 'time': array([0.  , 0.02, 0.04, 0.06, 0.08, 0.1 ])}}
[2021-07-30 09:59:50.045804] (Showcase_a_default_and_a_customized_sine_signal): Tproc: 0.001438
[2021-07-30 09:59:50.094365] (Custom_Sine_generator): Pack time: 8.9e-05
[2021-07-30 09:59:50.094765] (Custom_Sine_generator): Sending: {'quantities': array([0.52365403]), 'time': array([0.12])}
[2021-07-30 09:59:50.094914] (Showcase_a_default_and_a_customized_sine_signal): Received: {'from': 'Custom_Sine_generator', 'data': {'quantities': array([0.52365403]), 'time': array([0.12])}, 'senderType': 'SineGeneratorAgent', 'channel': 'default'}
[2021-07-30 09:59:50.095690] (Showcase_a_default_and_a_customized_sine_signal): Buffer: {'Default_Sine_generator': {'quantities': array([0.        , 0.06279052, 0.12533323, 0.18738131, 0.24868989,
       0.30901699, 0.36812455]), 'time': array([0.   , 0.002, 0.004, 0.006, 0.008, 0.01 , 0.012])}, 'Custom_Sine_generator': {'quantities': array([0.        , 0.28845673, 0.53253704, 0.69469143, 0.74997391,
       0.68987981, 0.52365403]), 'time': array([0.  , 0.02, 0.04, 0.06, 0.08, 0.1 , 0.12])}}
[2021-07-30 09:59:50.095752] (Showcase_a_default_and_a_customized_sine_signal): Tproc: 0.000757
NS shut down.
[2021-07-30 09:59:51.045556] (Showcase_a_default_and_a_customized_sine_signal): Received: {'from': 'Default_Sine_generator', 'data': {'quantities': array([0.42577929]), 'time': array([0.014])}, 'senderType': 'SineGeneratorAgent', 'channel': 'default'}
[2021-07-30 09:59:51.052541] (Showcase_a_default_and_a_customized_sine_signal): Buffer: {'Default_Sine_generator': {'quantities': array([0.        , 0.06279052, 0.12533323, 0.18738131, 0.24868989,
       0.30901699, 0.36812455, 0.42577929]), 'time': array([0.   , 0.002, 0.004, 0.006, 0.008, 0.01 , 0.012, 0.014])}, 'Custom_Sine_generator': {'quantities': array([0.        , 0.28845673, 0.53253704, 0.69469143, 0.74997391,
       0.68987981, 0.52365403]), 'time': array([0.  , 0.02, 0.04, 0.06, 0.08, 0.1 , 0.12])}}