Coder Social home page Coder Social logo

met4fof / agentmet4fof Goto Github PK

View Code? Open in Web Editor NEW
22.0 5.0 8.0 10.12 MB

Metrological Agent-based system (MET4FOF project)

License: Other

Python 48.53% CSS 0.03% Jupyter Notebook 51.17% JavaScript 0.28%
abm agent-based-modeling agent-based-simulation mas python hacktoberfest measurement-uncertainties metrology multi-agent-system simulation

agentmet4fof's People

Contributors

anupam-prasad avatar bangxiangyong avatar bjoernludwigptb avatar gertjan123 avatar harislulic avatar mgrub avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

agentmet4fof's Issues

Check if we really need matplotlib==3.1.0

We should check if by now we could drop the constraint on matplotlib==3.1.0 not to loose compatibility with newer Python versions.

@bangxiangyong could you provide a test, which checks for the reason of the constraint so we can test if an upgrade would harm the agents?

running keras model in agent shows error

class Trainer(AgentMET4FOF):

    def init_parameters(self):
        r = random.randrange(10, 20)
        a = {'x': [1, 2, 3], 'y': r}

        # print(a['x'])
        a = pd.DataFrame(a['x'])
        #print(a.shape)
        a = np.array(a)
        #print(a.shape)
        X_train = a.reshape(a.shape[0], 1, a.shape[1])
        print(np.shape(X_train))

        inputs = Input(shape=(X_train.shape[1], X_train.shape[2]))
        L1 = LSTM(16, activation='relu', return_sequences=True,
                  kernel_regularizer=regularizers.l2(0.00))(inputs)
        output = TimeDistributed(Dense(X_train.shape[2]))(L1)

        model = Model(inputs=inputs, outputs=output)
        model.compile(optimizer='adam', loss='mse')
        model.fit(X_train, X_train, epochs=5, batch_size=32)

        model.predict(X_train)
#56 AttributeError: '_thread._local' object has no attribute 'value'

Incorporate the D-SI format

We might implement a class for or at least deeply integrate the D-SI into the message passing of the agents. This should be considered closely related to #19 .

Further materials about D-SI will be added here shortly.

Extract all examples/use cases into seperate repositories and clean up clutter

We tried that in #50 and found it very promising. The next extractions might be:

  • ml_uncertainty
  • demo
  • ML
  • ML_EXPERIMENTS
  • SENSORS
  • ZEMA_EMC
  • ... whatever could be moved from develop.

After that we can clean up the docs and requirements.txt and win

  • significantly increased overview
  • probably higher coverage
  • a much clearer structure
  • more presentable, accessible results, possibly with own DOIs and future citations.

Modularised plotting

Considerations:

  1. Zooming/Panning/etc. on an interactive
  2. A clear/standardised architecture
  3. Types of plots
  4. Supporting the web visualisation

Integration with OPC-UA

Will need to investigate whether which option is better and feasible:

  1. Replacing underlying communication of Pyro4 with OPC-UA
  2. Providing an external interface to OPC-UA

Executing run_dashboard.py brings up error

When I execute pythonrun_dashboard.py in the console I get the following output periodically:

Unable to connect to existing NameServer...
 * Serving Flask app "dashboard.Dashboard" (lazy loading)
 * Environment: production
   WARNING: Do not use the development server in a production environment.
   Use a production WSGI server instead.
 * Debug mode: off
 * Running on http://127.0.0.1:8050/ (Press CTRL+C to quit)
127.0.0.1 - - [30/Jul/2019 17:24:32] "GET /_favicon.ico HTTP/1.1" 200 -
127.0.0.1 - - [30/Jul/2019 17:24:33] "GET /_dash-layout HTTP/1.1" 200 -
127.0.0.1 - - [30/Jul/2019 17:24:33] "GET /_dash-dependencies HTTP/1.1" 200 -
127.0.0.1 - - [30/Jul/2019 17:24:33] "POST /_dash-update-component HTTP/1.1" 200 -
127.0.0.1 - - [30/Jul/2019 17:24:33] "POST /_dash-update-component HTTP/1.1" 204 -
127.0.0.1 - - [30/Jul/2019 17:24:33] "POST /_dash-update-component HTTP/1.1" 204 -
127.0.0.1 - - [30/Jul/2019 17:24:33] "POST /_dash-update-component HTTP/1.1" 204 -
[2019-07-30 17:24:33,106] ERROR in app: Exception on /_dash-update-component [POST]
Traceback (most recent call last):
  File "PATH\TO\MY\ENV\lib\site-packages\flask\app.py", line 2292, in wsgi_app
    response = self.full_dispatch_request()
  File "PATH\TO\MY\ENV\lib\site-packages\flask\app.py", line 1815, in full_dispatch_request
    rv = self.handle_user_exception(e)
  File "PATH\TO\MY\ENV\lib\site-packages\flask\app.py", line 1718, in handle_user_exception
    reraise(exc_type, exc_value, tb)
  File "PATH\TO\MY\ENV\lib\site-packages\flask\_compat.py", line 35, in reraise
    raise value
  File "PATH\TO\MY\ENV\lib\site-packages\flask\app.py", line 1813, in full_dispatch_request
    rv = self.dispatch_request()
  File "PATH\TO\MY\ENV\lib\site-packages\flask\app.py", line 1799, in dispatch_request
    return self.view_functions[rule.endpoint](**req.view_args)
  File "PATH\TO\MY\ENV\lib\site-packages\dash\dash.py", line 1147, in dispatch
    response.set_data(self.callback_map[output]['callback'](*args))
  File "PATH\TO\MY\ENV\lib\site-packages\dash\dash.py", line 1033, in add_context
    output_value = func(*args, **kwargs)
  File "PATH\TO\MY\REPOS\Met4FoF_Code\agentMet4FoF\dashboard\Dashboard.py", line 423, in plot_monitor_graphs
    if agentNetwork._get_mode() != "Running" and n_interval > 0:
  File "PATH\TO\MY\REPOS\Met4FoF_Code\agentMet4FoF\agents\AgentMET4FOF.py", line 653, in _get_mode
    return self._get_controller().get_attr('current_state')
  File "PATH\TO\MY\REPOS\Met4FoF_Code\agentMet4FoF\agents\AgentMET4FOF.py", line 789, in _get_controller
    self._controller = self.ns.proxy('AgentController')
AttributeError: 'int' object has no attribute 'proxy'
127.0.0.1 - - [30/Jul/2019 17:24:33] "POST /_dash-update-component HTTP/1.1" 500 -

Do we still need this script? If so we should update it.

Implement "Experiments"

This could be incorporating MLFlow, where the pipelines (#17) and parameters can be easily varied to compare their performances and logged systematically.

Implement a similar interface to sklearn's make_pipeline

Been having this in mind of viewing data analytics/ML as a workflow (which current implementation for ZEMA EMC with Haris Lulic is kind-of adopting already), that is a sequence of functions applied one after the other.

sklearn reference

Example:
group_of_agents = make_pipeline(FFT(), PCA(pca_parameters), LDA(lda_parameters))

  • The arguments are any number of objects which implements the function fit and transform similar to how sklearn structures its classes
  • The line above should instantiate 3 agents connected from left to right (FFT -> PCA -> LDA)
  • Further, for this to work, a generic ML agent class which accepts these data analytics methods should be developed

The advantage with the agent network architecture:

  1. Pipelines which use similar components/agents will only need to process once if the agent connections are made dynamic. The code below should create 4 agents (FFT -> PCA -> LDA & ANN) instead of 6 agents (sum of number of agents in both pipelines)
    Example:
group_of_agents_1 = make_pipeline(FFT(), PCA(pca_parameters), LDA()) 
group_of_agents_2 = make_pipeline(FFT(), PCA(pca_parameters), ANN()) 
  1. Entire data processing pipelines can be visualized via dashboard immediately
  2. Compatible immediately with sklearn and more fluid integration with data science
  3. Promotes incremental development for mathematical components. Such as when investigating the effect of added noise/bias, we can have two pipelines to be compared:
group_of_agents_1 = make_pipeline(AddNoise(), FFT(), LDA()) 
group_of_agents_2 = make_pipeline(FFT(),  LDA()) 

Enhance plotting possibilities of MonitorAgents

It would be nice, if the function create_monitor_data (used here and defined here) can be extended to allow for user-provided x values.

This would help with plotting infinite streams of time-series.

The new function could look something like this: (old behaviour is obtainable by explicitly setting xname or yname to None)

def create_monitor_data(data, xname="time", yname="data", label="Monitor Data"):
    if xname and yname:
        x = data[xname]
        y = data[yname]
    else:
        x = np.arange(len(data))
        y = data

    trace = go.Scatter(x=x, y=y,mode="lines", name=label)
    return trace

Unable to send pytorch model from one agent to another agent

from agentMET4FOF.agents import AgentMET4FOF, AgentNetwork, MonitorAgent
from agentMET4FOF.streams import SineGenerator

import torch.nn as nn
import torch.nn.functional as F


class Net(nn.Module):
    def __init__(self):
        super(Net, self).__init__()
        self.conv1 = nn.Conv2d(3, 6, 5)
        self.pool = nn.MaxPool2d(2, 2)
        self.conv2 = nn.Conv2d(6, 16, 5)
        self.fc1 = nn.Linear(16 * 5 * 5, 120)
        self.fc2 = nn.Linear(120, 84)
        self.fc3 = nn.Linear(84, 10)

    def forward(self, x):
        x = self.pool(F.relu(self.conv1(x)))
        x = self.pool(F.relu(self.conv2(x)))
        x = x.view(-1, 16 * 5 * 5)
        x = F.relu(self.fc1(x))
        x = F.relu(self.fc2(x))
        x = self.fc3(x)
        return x


class TrainerAgent(AgentMET4FOF):
    def init_parameters(self,minus_param=0.5,plus_param=0.5):
        self.net = Net()
        self.first_time = True

    def on_received_message(self, message):
        if self.first_time:
            self.send_output(self.net)
            self.first_time = False

class SineGeneratorAgent(AgentMET4FOF):
    def init_parameters(self):
        self.stream = SineGenerator()

    def agent_loop(self):
        if self.current_state == "Running":
            sine_data = self.stream.next_sample() #dictionary
            self.send_output(sine_data['x'])

def main():
    # start agent network server
    agentNetwork = AgentNetwork()
    # init agents
    gen_agent = agentNetwork.add_agent(agentType=SineGeneratorAgent)
    train_agent = agentNetwork.add_agent(agentType=TrainerAgent)
    predict_agent = agentNetwork.add_agent(agentType=TrainerAgent)
    monitor_agent = agentNetwork.add_agent(agentType=MonitorAgent)
    # connect agents : We can connect multiple agents to any particular agent
    agentNetwork.bind_agents(gen_agent, train_agent)
    agentNetwork.bind_agents(gen_agent, predict_agent)
    # connect
    agentNetwork.bind_agents(gen_agent, monitor_agent)
    agentNetwork.bind_agents(train_agent, predict_agent)
    agentNetwork.bind_agents(predict_agent, monitor_agent)
    # set all agents states to "Running"
    agentNetwork.set_running_state()

    # allow for shutting down the network after execution
    return agentNetwork


if __name__ == '__main__':
    main()

Error message as below:

Exception in thread oneway-call:
Traceback (most recent call last):
File "/usr/lib/python3.7/threading.py", line 917, in _bootstrap_inner
self.run()
File "/home/bangxiang93/PycharmProjects/agentMET4FOF_fresh_test/venv/lib/python3.7/site-packages/Pyro4/core.py", line 1891, in run
super(_OnewayCallThread, self).run()
File "/usr/lib/python3.7/threading.py", line 865, in run
self._target(*self._args, **self._kwargs)
File "/home/bangxiang93/PycharmProjects/agentMET4FOF_fresh_test/venv/lib/python3.7/site-packages/osbrain/agent.py", line 1680, in run
self._loop()
File "/home/bangxiang93/PycharmProjects/agentMET4FOF_fresh_test/venv/lib/python3.7/site-packages/osbrain/agent.py", line 1208, in _loop
if self._iterate():
File "/home/bangxiang93/PycharmProjects/agentMET4FOF_fresh_test/venv/lib/python3.7/site-packages/osbrain/agent.py", line 1245, in _iterate
self._process_events(events)
File "/home/bangxiang93/PycharmProjects/agentMET4FOF_fresh_test/venv/lib/python3.7/site-packages/osbrain/agent.py", line 1282, in _process_events
self._process_single_event(socket)
File "/home/bangxiang93/PycharmProjects/agentMET4FOF_fresh_test/venv/lib/python3.7/site-packages/osbrain/agent.py", line 1296, in _process_single_event
self._process_sub_event(socket, address, data)
File "/home/bangxiang93/PycharmProjects/agentMET4FOF_fresh_test/venv/lib/python3.7/site-packages/osbrain/agent.py", line 1452, in _process_sub_event
handler(self, message)
File "/home/bangxiang93/PycharmProjects/agentMET4FOF_fresh_test/agentMET4FOF-develop/agentMET4FOF/agents.py", line 334, in handle_process_data
proc_msg = self.on_received_message(message)
File "/home/bangxiang93/PycharmProjects/agentMET4FOF_fresh_test/agentMET4FOF-develop/agentMET4FOF_tutorials/tutorial_pytorch.py", line 35, in on_received_message
self.send_output(self.net)
File "/home/bangxiang93/PycharmProjects/agentMET4FOF_fresh_test/agentMET4FOF-develop/agentMET4FOF/agents.py", line 263, in send_output
self.send(self.PubAddr, packed_data, topic='data')
File "/home/bangxiang93/PycharmProjects/agentMET4FOF_fresh_test/venv/lib/python3.7/site-packages/osbrain/agent.py", line 1493, in send
topic=topic)
File "/home/bangxiang93/PycharmProjects/agentMET4FOF_fresh_test/venv/lib/python3.7/site-packages/osbrain/agent.py", line 1501, in _send_address
serializer=address.serializer)
File "/home/bangxiang93/PycharmProjects/agentMET4FOF_fresh_test/venv/lib/python3.7/site-packages/osbrain/agent.py", line 85, in serialize_message
return _serialize_callsserializer
File "/home/bangxiang93/PycharmProjects/agentMET4FOF_fresh_test/venv/lib/python3.7/site-packages/osbrain/agent.py", line 50, in
'pickle': lambda message: pickle.dumps(message, -1),
_pickle.PicklingError: Can't pickle <class 'main.Net'>: it's not the same object as main.Net

We should think about a way how to make debugging possible

Because of the subprocesses we are spawning, in general debugging does not work as usual. We should think about, if it is possible to make that available. It would strip a lot of print statements from the codes we are seeing being written using the agents and make debugging a lot easier.

Documentation of ML Experiments

The documentation of components for ML experiments is not complete, and the structure is quite scattered (agents.py , develop.* , etc).

The clarity can be improved by having more explanations and should probably be self-contained as a separate component?

Update .gitignore

There is some stuff missing and some things we don't need anymore.

remove previous buffer data

i have buffered data and send to agent, but i want to after each new sending, perevious data romves , i mean remove last buffer and replace with new data.

ModuleNotFoundError when using agentMET4FOF from PyPi

After setting up a clean python-venv and then pip install agentMET4FOF, execution of import agentMET4FOF.agents yields:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "%userprofile%\python_venv\agentmet4fof\lib\site-packages\agentMET4FOF\agents.py", line 24, in <module>
    from agentMET4FOF.dashboard.Dashboard import AgentDashboard as AgentDashboard        
  File "%userprofile%\python_venv\agentmet4fof\lib\site-packages\agentMET4FOF\dashboard\Dashboard.py", line 6, in <module>
    from agentMET4FOF.dashboard.Dashboard_ml_exp import get_ml_exp_layout, prepare_ml_exp_callbacks, get_experiments_list
  File "%userprofile%\python_venv\agentmet4fof\lib\site-packages\agentMET4FOF\dashboard\Dashboard_ml_exp.py", line 15, in <module>
    from agentMET4FOF.develop.ML_Experiment import load_experiment
ModuleNotFoundError: No module named 'agentMET4FOF.develop'

Details about the system:
OS: Windows 10 Pro 64bit
Python: 3.7.7 and 3.8.1
agentMET4FOF: 0.1.4

Current Workaround:
Use agentMET4FOF from a clone of the github-repo:

  • clone the repo to <directory_of_your_choice>
  • set up a python-venv with all requirements for agentMET4FOF
  • add <directory_of_your_choice> to the PYTHONPATH (either by setting a system variable or by using import sys;sys.path.append("<directory_of_your_choice>")

Struggle to run dashboard on Windows machine

There seems to be a problem with running the agents on Windows with Python 3.8.1 and multiprocess==0.70.9. A colleague gets the following error on execution of tutorial 1:

Starting NameServer...
Broadcast server running on 0.0.0.0:9091
NS running on 127.0.0.1:3333 (127.0.0.1) 
URI = PYRO:[email protected]:3333
INFO [2020-04-15 10:11:08.404372] (AgentController): INITIALIZED
Traceback (most recent call last):
  File "<string>", line 1, in <module>
ModuleNotFoundError: No module named 'multiprocess'
INFO [2020-04-15 10:11:30.828139] (SineGeneratorAgent_1): INITIALIZED
INFO [2020-04-15 10:11:39.270462] (MonitorAgent_1): INITIALIZED
[2020-04-15 10:11:39.358227] (SineGeneratorAgent_1): Connected output module: MonitorAgent_1
SET STATE:   Running
[2020-04-15 10:11:39.868856] (SineGeneratorAgent_1): Pack time: 0.0
[2020-04-15 10:11:39.869853] (SineGeneratorAgent_1): Sending: [0.]
[2020-04-15 10:11:39.869853] (MonitorAgent_1): Received: {'from': 'SineGeneratorAgent_1', 'data': array([0.]), 'senderType': 'SineGeneratorAgent', 'channel': 'default'}
[2020-04-15 10:11:39.869853] (MonitorAgent_1): Tproc: 0.0

On the same machine it is working with Python 3.7.7 and multiprocess==0.70.7. We haven't checked the multiprocess issues yet and he will continue with the working 3.7.7 configuration, so for now there is no further investigation.

Design a data class as an interface for streaming as well as static (, historical) datasets

To make working with the agents easier, we should be able to clarify on how input data should be structured to best fit the agents design.

Regarding streaming data, we should as well keep in mind to adapt the generators of PyDynamic to this design and view this as very closely connected.

That instantly leads to an extended development of the signals themselves probably, which benefits PyDynamic as well, maybe in extending the previously started class Signal. Maybe we can even base the development on that class.

Originally posted by @BjoernLudwigPTB in #18 (comment)

Handling plotly figure in send_plot

The send_plot funciton converts matplotlib figures into plotly or image base64 string, there is an option to directly send plotly figures as well, but we should test and implement it further.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.