2

I have a python file, containing a pre-trained model. How can I execute this file from inside ns-3 code? The python file will start execution when enough amount of data is gerenerated by the ns-3, which will be given to the pre-trained model. Later, the model predicts one value and it is used in ns-3 during simulation.

I tried Calling Python script from C++ and using its output. It is not helpful in my case. I am expecting to execute only python file from ns-3.

gupta
  • 37
  • 6
  • You don't ever run Python files, it's always that you run a Python interpreter (in-process or as standalone executable) and that is used to run the Python file. Can you please elaborate what parts of the solutions you found where not usable in your scenario? – Ulrich Eckhardt Nov 26 '22 at 13:54

1 Answers1

1

In my case, I have tried the following piece of code in a function where I was required to execute the external python file from ns-3. This specific example is for the Ubuntu environment.

system("/[path_to_your_python]/anaconda3/bin/python /[path_to_your_inference_file]/inference.py");

Note: The inference.py file will be executed whenever the C++ function is called, making the simulation too time-consuming compared to normal circumstances.

Suggestion: I would suggest using ONNX.

a4arshad
  • 606
  • 1
  • 7
  • 18