pythonc++ns-3

Executing external python file from inside ns3


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.


Solution

  • 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.