Python API

Hi all,

Following the instructions in the wiki, I was able to build Pulse with Python API support. I have my PYTHONPATH also updated appropriately. Looks like the pulse.cdm.bind module is missing? See below for the output from running a howto script. What have I misunderstood here? Any ideas.

TIA,
Satish

schimaku@eri:~/Development/Pulse/engine/src/python/pulse/howto$ python3 HowTo_AcuteStress.py
Traceback (most recent call last):
File “HowTo_AcuteStress.py”, line 7, in
from pulse.cpm.PulsePhysiologyEngine import PulsePhysiologyEngine
File “/home/schimaku/Development/Pulse/engine/src/python/pulse/cpm/PulsePhysiologyEngine.py”, line 9, in
from pulse.cdm.io.engine import serialize_actions_to_string,
File “/home/schimaku/Development/Pulse/engine/src/python/pulse/cdm/io/engine.py”, line 6, in
from pulse.cdm.bind.Engine_pb2 import AnyActionData,
ModuleNotFoundError: No module named ‘pulse.cdm.bind’

Hi epitomeri

You should have added 2 paths to your PYTHONPATH, the location of the python shared object, as well as the python folder as part of the pulse source code

Your path should look something like:

ENV PYTHONPATH /source/src/python:/pulse/bin

The error looks like you did not add the folder from the source code…

What is your python path?

Hi Aaron,

I believe that my PYTHONPATH is as expected. Please see below.

schimaku@eri:~$ echo $PYTHONPATH
/home/schimaku/Development/Pulse/engine/src/python:/home/schimaku/Development/Pulse/builds/install/bin

The /src/python folder contains the following:
CMakeLists.txt init.py pulse pybind setup.py venv

The ‘bin’ folder is the one that contains ‘PyPulse.cpython-38-x86_64-linux-gnu.so’.

What else could I be missing?

Thanks in advance,
Satish

Do you have any files in your

/home/schimaku/Development/Pulse/engine/src/python/pulse/cdm/bind/

aaron.bray@krs-812:~/Programming/pulse/engine/src/python/pulse/howto$ ls ~/Programming/pulse/engine/src/python/pulse/cdm/bind/ Actions_pb2.py Engine_pb2.py Inhaler_pb2.py Patient_pb2.py AnesthesiaMachineActions_pb2.py Enums_pb2.py __init__.py Physiology_pb2.py AnesthesiaMachine_pb2.py EnvironmentActions_pb2.py MechanicalVentilatorActions_pb2.py Properties_pb2.py BlackBox_pb2.py EnvironmentConditions_pb2.py MechanicalVentilator_pb2.py __pycache__ Circuit_pb2.py Environment_pb2.py PatientActions_pb2.py Scenario_pb2.py Compartment_pb2.py EquipmentActions_pb2.py PatientAssessments_pb2.py Substance_pb2.py Conditions_pb2.py Events_pb2.py PatientConditions_pb2.py SubstanceQuantity_pb2.py ElectroCardioGram_pb2.py InhalerActions_pb2.py PatientNutrition_pb2.py TestReport_pb2.py

No, as I mentioned in my original email, that module is missing somehow. There is no folder by name ‘bind’ under ‘cdm’. Have I not installed Pulse correctly? I did use the flag ‘-DPulse_PYTHON_API:BOOL=ON’ in my cmake command.

Hmm
Those should have been generated during the build
I am currently generating these files in the source directory, which is not great…

You can regenerate those missing files by running this script from your install/bin

aaron.bray@krs-812:~/Programming/builds/manual/pulse-engine/install/bin$ ./run.sh protoc

Hi epitomeri

I found a few issues I needed to correct to get python running.
I pushed them to the head of 3.x, should be a quick rebuild if you make install from the Innerbuild

You should be good to go!

Let me know if you are still having issues!

Thanks. In general, my Python build issues got resolved after I switched to 3.x branch from Master! The build is successful and the ‘bind’ folder is in place.

schimaku@eri:~/Development/Pulse-3.0/engine/src/python/pulse/howto$ python3 HowTo_AcuteStress.py
Unable to load initial state file

Could you tell me where to find the inputs necessary to run the scripts in the ‘howto’ folder? Running one of them threw an error as you can see above. Since I am a first time user, my goal is to go through some examples to understand what it is that Pulse can/cannot do. I figured that the scripts in the ‘howto’ folder are a good starting point unless you recommend otherwise.

Thanks in advance,
Satish

Hi Satish,

I accidentially responded to your question on the wrong forum thread

Moving the answer to this thread now

The HowTo files all load up a saved state that is found in your install/bin/states folder.
In the code, they are specified via a relative directory, so these how to files are expected to be run in the install/bin folder, like this:

aaron.bray@krs-812:~/Programming/builds/manual/pulse-engine/install/bin$ python3 ~/Programming/pulse/engine/src/python/pulse/howto/HowTo_AcuteStress.py

I also run via PyCharm and just change the working directory
Note, There is a pycharm project in the source/src/python folder you can point pycharm to

I will add this to the python wiki page

Thanks Aaron. It worked now!