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.

[2]:
# %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 parameters of the specified agentType can either be handed over as **kwargs
    # in the network instance's add_agent() method, or...
    custom_sine_agent = agent_network.add_agent(
        name="Custom Sine generator",
        agentType=SineGeneratorAgent,
        sfreq=75,
        sine_freq=np.pi,
    )
    # ... in a separate call of the agent instance's init_parameters() method.
    custom_sine_agent.init_parameters(
        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 [2022-02-03 21:05:44.331772] (Default_Sine_generator): INITIALIZED
INFO [2022-02-03 21:05:44.360827] (Custom_Sine_generator): INITIALIZED
INFO [2022-02-03 21:05:44.386817] (Showcase_a_default_and_a_customized_sine_signal): INITIALIZED
[2022-02-03 21:05:44.399664] (Default_Sine_generator): Connected output module: Showcase_a_default_and_a_customized_sine_signal
[2022-02-03 21:05:44.405280] (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://127.0.0.1:8050/ |
|                                                            |
|------------------------------------------------------------|

SET STATE:   Running
[2022-02-03 21:05:45.338354] (Default_Sine_generator): Pack time: 0.001391
[2022-02-03 21:05:45.343559] (Default_Sine_generator): Sending: {'quantities': array([0.]), 'time': array([0.])}
[2022-02-03 21:05:45.347733] (Showcase_a_default_and_a_customized_sine_signal): Received: {'from': 'Default_Sine_generator', 'data': {'quantities': array([0.]), 'time': array([0.])}, 'senderType': 'SineGeneratorAgent', 'channel': 'default'}
[2022-02-03 21:05:45.350192] (Showcase_a_default_and_a_customized_sine_signal): Buffer: {'Default_Sine_generator': {'quantities': array([0.]), 'time': array([0.])}}
[2022-02-03 21:05:45.351553] (Showcase_a_default_and_a_customized_sine_signal): Tproc: 0.002991
[2022-02-03 21:05:45.375015] (Custom_Sine_generator): Pack time: 0.00176
[2022-02-03 21:05:45.378430] (Showcase_a_default_and_a_customized_sine_signal): Received: {'from': 'Custom_Sine_generator', 'data': {'quantities': array([0.]), 'time': array([0.])}, 'senderType': 'SineGeneratorAgent', 'channel': 'default'}
[2022-02-03 21:05:45.379148] (Custom_Sine_generator): Sending: {'quantities': array([0.]), 'time': array([0.])}
[2022-02-03 21:05:45.385440] (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.])}}
[2022-02-03 21:05:45.386185] (Showcase_a_default_and_a_customized_sine_signal): Tproc: 0.007304
[2022-02-03 21:05:46.336481] (Default_Sine_generator): Pack time: 0.000488
[2022-02-03 21:05:46.340135] (Default_Sine_generator): Sending: {'quantities': array([0.38460898]), 'time': array([0.01])}
[2022-02-03 21:05:46.340536] (Showcase_a_default_and_a_customized_sine_signal): Received: {'from': 'Default_Sine_generator', 'data': {'quantities': array([0.38460898]), 'time': array([0.01])}, 'senderType': 'SineGeneratorAgent', 'channel': 'default'}
[2022-02-03 21:05:46.345115] (Showcase_a_default_and_a_customized_sine_signal): Buffer: {'Default_Sine_generator': {'quantities': array([0.        , 0.38460898]), 'time': array([0.  , 0.01])}, 'Custom_Sine_generator': {'quantities': array([0.]), 'time': array([0.])}}
[2022-02-03 21:05:46.345760] (Showcase_a_default_and_a_customized_sine_signal): Tproc: 0.004564
[2022-02-03 21:05:46.366489] (Custom_Sine_generator): Pack time: 0.000678
[2022-02-03 21:05:46.370212] (Custom_Sine_generator): Sending: {'quantities': array([0.28845673]), 'time': array([0.01])}
[2022-02-03 21:05:46.379294] (Showcase_a_default_and_a_customized_sine_signal): Received: {'from': 'Custom_Sine_generator', 'data': {'quantities': array([0.28845673]), 'time': array([0.01])}, 'senderType': 'SineGeneratorAgent', 'channel': 'default'}
[2022-02-03 21:05:46.403425] (Showcase_a_default_and_a_customized_sine_signal): Buffer: {'Default_Sine_generator': {'quantities': array([0.        , 0.38460898]), 'time': array([0.  , 0.01])}, 'Custom_Sine_generator': {'quantities': array([0.        , 0.28845673]), 'time': array([0.  , 0.01])}}
[2022-02-03 21:05:46.406775] (Showcase_a_default_and_a_customized_sine_signal): Tproc: 0.020121
[2022-02-03 21:05:47.336524] (Default_Sine_generator): Pack time: 0.000599
[2022-02-03 21:05:47.339019] (Default_Sine_generator): Sending: {'quantities': array([0.71004939]), 'time': array([0.02])}
[2022-02-03 21:05:47.339234] (Showcase_a_default_and_a_customized_sine_signal): Received: {'from': 'Default_Sine_generator', 'data': {'quantities': array([0.71004939]), 'time': array([0.02])}, 'senderType': 'SineGeneratorAgent', 'channel': 'default'}
[2022-02-03 21:05:47.344371] (Showcase_a_default_and_a_customized_sine_signal): Buffer: {'Default_Sine_generator': {'quantities': array([0.        , 0.38460898, 0.71004939]), 'time': array([0.  , 0.01, 0.02])}, 'Custom_Sine_generator': {'quantities': array([0.        , 0.28845673]), 'time': array([0.  , 0.01])}}
[2022-02-03 21:05:47.344878] (Showcase_a_default_and_a_customized_sine_signal): Tproc: 0.005222
[2022-02-03 21:05:47.365561] (Custom_Sine_generator): Pack time: 0.000555
[2022-02-03 21:05:47.368761] (Showcase_a_default_and_a_customized_sine_signal): Received: {'from': 'Custom_Sine_generator', 'data': {'quantities': array([0.53253704]), 'time': array([0.02])}, 'senderType': 'SineGeneratorAgent', 'channel': 'default'}
[2022-02-03 21:05:47.368108] (Custom_Sine_generator): Sending: {'quantities': array([0.53253704]), 'time': array([0.02])}
[2022-02-03 21:05:47.375238] (Showcase_a_default_and_a_customized_sine_signal): Buffer: {'Default_Sine_generator': {'quantities': array([0.        , 0.38460898, 0.71004939]), 'time': array([0.  , 0.01, 0.02])}, 'Custom_Sine_generator': {'quantities': array([0.        , 0.28845673, 0.53253704]), 'time': array([0.  , 0.01, 0.02])}}
[2022-02-03 21:05:47.375647] (Showcase_a_default_and_a_customized_sine_signal): Tproc: 0.005395
[2022-02-03 21:05:48.336290] (Default_Sine_generator): Pack time: 0.000678
[2022-02-03 21:05:48.339054] (Default_Sine_generator): Sending: {'quantities': array([0.92625524]), 'time': array([0.03])}
[2022-02-03 21:05:48.339381] (Showcase_a_default_and_a_customized_sine_signal): Received: {'from': 'Default_Sine_generator', 'data': {'quantities': array([0.92625524]), 'time': array([0.03])}, 'senderType': 'SineGeneratorAgent', 'channel': 'default'}
[2022-02-03 21:05:48.365860] (Custom_Sine_generator): Pack time: 0.000724
[2022-02-03 21:05:48.346087] (Showcase_a_default_and_a_customized_sine_signal): Buffer: {'Default_Sine_generator': {'quantities': array([0.        , 0.38460898, 0.71004939, 0.92625524]), 'time': array([0.  , 0.01, 0.02, 0.03])}, 'Custom_Sine_generator': {'quantities': array([0.        , 0.28845673, 0.53253704]), 'time': array([0.  , 0.01, 0.02])}}
[2022-02-03 21:05:48.369095] (Custom_Sine_generator): Sending: {'quantities': array([0.69469143]), 'time': array([0.03])}
[2022-02-03 21:05:48.346546] (Showcase_a_default_and_a_customized_sine_signal): Tproc: 0.006717
[2022-02-03 21:05:48.371092] (Showcase_a_default_and_a_customized_sine_signal): Received: {'from': 'Custom_Sine_generator', 'data': {'quantities': array([0.69469143]), 'time': array([0.03])}, 'senderType': 'SineGeneratorAgent', 'channel': 'default'}
[2022-02-03 21:05:48.388990] (Showcase_a_default_and_a_customized_sine_signal): Buffer: {'Default_Sine_generator': {'quantities': array([0.        , 0.38460898, 0.71004939, 0.92625524]), 'time': array([0.  , 0.01, 0.02, 0.03])}, 'Custom_Sine_generator': {'quantities': array([0.        , 0.28845673, 0.53253704, 0.69469143]), 'time': array([0.  , 0.01, 0.02, 0.03])}}
[2022-02-03 21:05:48.389764] (Showcase_a_default_and_a_customized_sine_signal): Tproc: 0.017948
[2022-02-03 21:05:49.334544] (Default_Sine_generator): Pack time: 0.000107
[2022-02-03 21:05:49.334972] (Default_Sine_generator): Sending: {'quantities': array([0.99996522]), 'time': array([0.04])}
[2022-02-03 21:05:49.335138] (Showcase_a_default_and_a_customized_sine_signal): Received: {'from': 'Default_Sine_generator', 'data': {'quantities': array([0.99996522]), 'time': array([0.04])}, 'senderType': 'SineGeneratorAgent', 'channel': 'default'}
[2022-02-03 21:05:49.335881] (Showcase_a_default_and_a_customized_sine_signal): Buffer: {'Default_Sine_generator': {'quantities': array([0.        , 0.38460898, 0.71004939, 0.92625524, 0.99996522]), 'time': array([0.  , 0.01, 0.02, 0.03, 0.04])}, 'Custom_Sine_generator': {'quantities': array([0.        , 0.28845673, 0.53253704, 0.69469143]), 'time': array([0.  , 0.01, 0.02, 0.03])}}
[2022-02-03 21:05:49.335959] (Showcase_a_default_and_a_customized_sine_signal): Tproc: 0.000742
[2022-02-03 21:05:49.363757] (Custom_Sine_generator): Pack time: 0.00011
[2022-02-03 21:05:49.364182] (Custom_Sine_generator): Sending: {'quantities': array([0.74997391]), 'time': array([0.04])}
[2022-02-03 21:05:49.364331] (Showcase_a_default_and_a_customized_sine_signal): Received: {'from': 'Custom_Sine_generator', 'data': {'quantities': array([0.74997391]), 'time': array([0.04])}, 'senderType': 'SineGeneratorAgent', 'channel': 'default'}
[2022-02-03 21:05:49.364982] (Showcase_a_default_and_a_customized_sine_signal): Buffer: {'Default_Sine_generator': {'quantities': array([0.        , 0.38460898, 0.71004939, 0.92625524, 0.99996522]), 'time': array([0.  , 0.01, 0.02, 0.03, 0.04])}, 'Custom_Sine_generator': {'quantities': array([0.        , 0.28845673, 0.53253704, 0.69469143, 0.74997391]), 'time': array([0.  , 0.01, 0.02, 0.03, 0.04])}}
[2022-02-03 21:05:49.365063] (Showcase_a_default_and_a_customized_sine_signal): Tproc: 0.000664
[2022-02-03 21:05:50.336098] (Default_Sine_generator): Pack time: 0.000511
[2022-02-03 21:05:50.338496] (Default_Sine_generator): Sending: {'quantities': array([0.91983974]), 'time': array([0.05])}
[2022-02-03 21:05:50.339476] (Showcase_a_default_and_a_customized_sine_signal): Received: {'from': 'Default_Sine_generator', 'data': {'quantities': array([0.91983974]), 'time': array([0.05])}, 'senderType': 'SineGeneratorAgent', 'channel': 'default'}
[2022-02-03 21:05:50.349178] (Showcase_a_default_and_a_customized_sine_signal): Buffer: {'Default_Sine_generator': {'quantities': array([0.        , 0.38460898, 0.71004939, 0.92625524, 0.99996522,
       0.91983974]), 'time': array([0.  , 0.01, 0.02, 0.03, 0.04, 0.05])}, 'Custom_Sine_generator': {'quantities': array([0.        , 0.28845673, 0.53253704, 0.69469143, 0.74997391]), 'time': array([0.  , 0.01, 0.02, 0.03, 0.04])}}
[2022-02-03 21:05:50.349932] (Showcase_a_default_and_a_customized_sine_signal): Tproc: 0.009823
[2022-02-03 21:05:50.365870] (Custom_Sine_generator): Pack time: 0.00076
[2022-02-03 21:05:50.379973] (Showcase_a_default_and_a_customized_sine_signal): Received: {'from': 'Custom_Sine_generator', 'data': {'quantities': array([0.68987981]), 'time': array([0.05])}, 'senderType': 'SineGeneratorAgent', 'channel': 'default'}
[2022-02-03 21:05:50.373635] (Custom_Sine_generator): Sending: {'quantities': array([0.68987981]), 'time': array([0.05])}
[2022-02-03 21:05:50.387528] (Showcase_a_default_and_a_customized_sine_signal): Buffer: {'Default_Sine_generator': {'quantities': array([0.        , 0.38460898, 0.71004939, 0.92625524, 0.99996522,
       0.91983974]), 'time': array([0.  , 0.01, 0.02, 0.03, 0.04, 0.05])}, 'Custom_Sine_generator': {'quantities': array([0.        , 0.28845673, 0.53253704, 0.69469143, 0.74997391,
       0.68987981]), 'time': array([0.  , 0.01, 0.02, 0.03, 0.04, 0.05])}}
[2022-02-03 21:05:50.388292] (Showcase_a_default_and_a_customized_sine_signal): Tproc: 0.007594
[2022-02-03 21:05:51.337162] (Default_Sine_generator): Pack time: 0.000738
[2022-02-03 21:05:51.342613] (Showcase_a_default_and_a_customized_sine_signal): Received: {'from': 'Default_Sine_generator', 'data': {'quantities': array([0.69820537]), 'time': array([0.06])}, 'senderType': 'SineGeneratorAgent', 'channel': 'default'}
[2022-02-03 21:05:51.342614] (Default_Sine_generator): Sending: {'quantities': array([0.69820537]), 'time': array([0.06])}
[2022-02-03 21:05:51.353736] (Showcase_a_default_and_a_customized_sine_signal): Buffer: {'Default_Sine_generator': {'quantities': array([0.        , 0.38460898, 0.71004939, 0.92625524, 0.99996522,
       0.91983974, 0.69820537]), 'time': array([0.  , 0.01, 0.02, 0.03, 0.04, 0.05, 0.06])}, 'Custom_Sine_generator': {'quantities': array([0.        , 0.28845673, 0.53253704, 0.69469143, 0.74997391,
       0.68987981]), 'time': array([0.  , 0.01, 0.02, 0.03, 0.04, 0.05])}}
[2022-02-03 21:05:51.365000] (Custom_Sine_generator): Pack time: 0.000373
[2022-02-03 21:05:51.366463] (Custom_Sine_generator): Sending: {'quantities': array([0.52365403]), 'time': array([0.06])}
[2022-02-03 21:05:51.354944] (Showcase_a_default_and_a_customized_sine_signal): Tproc: 0.007321
[2022-02-03 21:05:51.369610] (Showcase_a_default_and_a_customized_sine_signal): Received: {'from': 'Custom_Sine_generator', 'data': {'quantities': array([0.52365403]), 'time': array([0.06])}, 'senderType': 'SineGeneratorAgent', 'channel': 'default'}
[2022-02-03 21:05:51.374387] (Showcase_a_default_and_a_customized_sine_signal): Buffer: {'Default_Sine_generator': {'quantities': array([0.        , 0.38460898, 0.71004939, 0.92625524, 0.99996522,
       0.91983974, 0.69820537]), 'time': array([0.  , 0.01, 0.02, 0.03, 0.04, 0.05, 0.06])}, 'Custom_Sine_generator': {'quantities': array([0.        , 0.28845673, 0.53253704, 0.69469143, 0.74997391,
       0.68987981, 0.52365403]), 'time': array([0.  , 0.01, 0.02, 0.03, 0.04, 0.05, 0.06])}}
[2022-02-03 21:05:51.374676] (Showcase_a_default_and_a_customized_sine_signal): Tproc: 0.004771