Project-GrADyS / gradys-sim-nextgen

A distributed algorithm creation framework with a python-based simulator
https://project-gradys.github.io/gradys-sim-nextgen/
MIT License
3 stars 2 forks source link

Classes/functions not found #24

Open iiha7 opened 7 months ago

iiha7 commented 7 months ago

Hello, I am trying to run the "Simulating a data collection scenario" example. While copying the codes mentioned on the site and importing the libraries, I still see some classes/functions that are not found. I will attach 3 snippets, one for each file. How can I find these missing imports through the library? Because I searched throughout the repo and could not find it. Thanks a lot in advance.

SImpleGroundStationProtocol SImpleSensorProtocol SImpleUAVProtocol

iiha7 commented 7 months ago

Update: I only found the LoopMission class but not the rest :)

Thlamz commented 7 months ago

@iiha7 thank you for the report! I seem to have missed some needed classes in the doc page. I have updated it to show them and also included the full code at the start of the guide.

iiha7 commented 7 months ago

Thanks a lot for the response and update! I now get this Traceback error once I run the code

INFO [--------- Simulation started ---------] INFO server listening on 127.0.0.1:5678 Traceback (most recent call last): File "/home/hamza/GradysSImNextGen/UavScenario/execution.py", line 49, in main() File "/home/hamza/GradysSImNextGen/UavScenario/execution.py", line 45, in main simulation.start_simulation() File "/home/hamza/.local/lib/python3.8/site-packages/gradysim/simulator/simulation.py", line 221, in start_simulation is_running = self.step_simulation() File "/home/hamza/.local/lib/python3.8/site-packages/gradysim/simulator/simulation.py", line 175, in step_simulation self._initialize_simulation() File "/home/hamza/.local/lib/python3.8/site-packages/gradysim/simulator/simulation.py", line 149, in _initialize_simulation node.protocol_encapsulator.initialize() File "/home/hamza/.local/lib/python3.8/site-packages/gradysim/encapsulator/python.py", line 150, in initialize self.protocol.initialize() TypeError: initialize() missing 1 required positional argument: 'stage' INFO server closing INFO server closed Process Process-2: Traceback (most recent call last): File "/usr/lib/python3.8/multiprocessing/process.py", line 315, in _bootstrap self.run() File "/usr/lib/python3.8/multiprocessing/process.py", line 108, in run self._target(*self._args, **self._kwargs) File "/home/hamza/.local/lib/python3.8/site-packages/gradysim/simulator/handler/visualization.py", line 233, in _visualization_thread asyncio.run(main()) File "/usr/lib/python3.8/asyncio/runners.py", line 44, in run return loop.run_until_complete(main) File "/usr/lib/python3.8/asyncio/base_events.py", line 616, in run_until_complete return future.result() File "/home/hamza/.local/lib/python3.8/site-packages/gradysim/simulator/handler/visualization.py", line 231, in main await update_information() File "/home/hamza/.local/lib/python3.8/site-packages/gradysim/simulator/handler/visualization.py", line 223, in update_information websockets.broadcast(websocket_connections, json.dumps(information.copy())) File "", line 2, in copy File "/usr/lib/python3.8/multiprocessing/managers.py", line 834, in _callmethod conn.send((self._id, methodname, args, kwds)) File "/usr/lib/python3.8/multiprocessing/connection.py", line 206, in send self._send_bytes(_ForkingPickler.dumps(obj)) File "/usr/lib/python3.8/multiprocessing/connection.py", line 411, in _send_bytes self._send(header + buf) File "/usr/lib/python3.8/multiprocessing/connection.py", line 368, in _send n = write(self._handle, buf) BrokenPipeError: [Errno 32] Broken pipe

Could you please assist in it?

Thlamz commented 7 months ago

@iiha7 Those errors should have been caught by our unit tests, but the test that runs the code samples wasn't actually verifying if they ran without errors! Thanks for the report, fixed the code and the unit tests.

iiha7 commented 7 months ago

Thanks a lot everything is working perfectly! I was wondering what/how extra functionalities could be added to extract some additional network statistics such as rtt, total packet loss, throughput and any additional useful statistics ...? Also, could the framework be extended to define the network communication/protocol between the sensor/uav devices such as WIFI/Adhoc/ Zigbee... and so on

Thlamz commented 7 months ago

No problem!

About your questions, if the statistics you want to implement are based on information available to nodes in the simulation, you could implement them on the protocol itself, using the finalize() method to save the statistics to disk for further analysis. From your description, I gather that this is not the case and the information would not be available to the nodes.

In that case, you can implement your own CommunicationHandler (source code). This is the class that handles the delivery of messages in our simulator. The default implementation is very simple, only taking into consideration the distance between nodes and some configurable sources of failures. You are free to subclass it and implement a more complete handler, that includes adding statistics and defining the network communication protocols you want to implement.

If you are interested in a more complex simulator that already has some of those network protocols implemented, you can try https://github.com/Project-GrADyS/gradys-simulations (which is based on OMNeT++). You can even run your python protocols created with this library on it without any changes to the python code! Although be warned that it is harder to set up and use and has quite a learning curve.

Hope this answer helps you.

iiha7 commented 7 months ago

My initial goal was to run the OMNET++ framework initially, but I faced a couple of problems during setup. I was trying to make it work for a couple of days but I could not do it, I had a problem initially related to library files not recognizing python, and then later some problems related to gates not being recognized, so I decided to try the Python simulator to get something running :)

I will try to run the simulator again on OMNET++ and share the specific problems I face on that repo.