# Python PatientPool HowTo Issue

**URL:** https://discourse.kitware.com/t/python-patientpool-howto-issue/1069
**Category:** Pulse Physiology Engine
**Created:** [July 21, 2023, 8:56pm UTC](https://discourse.kitware.com/t/python-patientpool-howto-issue/1069 "2023-07-21T20:56:42Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![robert.bixler](https://discourse.kitware.com/letter_avatar_proxy/v4/letter/r/51bf81/32.png) [@robert.bixler](https://discourse.kitware.com/u/robert.bixler)
#### Post date: [July 21, 2023, 8:56pm UTC](https://discourse.kitware.com/t/python-patientpool-howto-issue/1069/1 "2023-07-21T20:56:42Z")

</div>

I’m trying to set up a patient pool to evaluate how the system scales for multiple patients. When trying to run the “HowTo\_PatientPool.py” in the python howtos, I run into a couple of errors.

First, I get an import error for the hemorrhage action:

> Traceback (most recent call last):  
> File “~\pulse\engine\src\python\pulse\howto\HowTo\_PatientPool.py”, line 10, in   
> from pulse.cdm.patient\_actions import SEHemorrhage, eHemorrhageType,   
> ImportError: cannot import name ‘eHemorrhageType’ from ‘pulse.cdm.patient\_actions’ (~pulse\engine\src\python\pulse\cdm\patient\_actions.py)

That’s overall fine, I just removed the import and the application of a hemorrhage.

The next issue I run into is this:

> Traceback (most recent call last):  
> File “~\pulse\engine\src\python\pulse\howto\HowTo\_PatientPool.py”, line 114, in   
> HowTo\_PatientPool()  
> File “~\pulse\engine\src\python\pulse\howto\HowTo\_PatientPool.py”, line 59, in HowTo\_PatientPool  
> if not pool.initialize\_engines():  
> ^^^^^^^^^^^^^^^^^^^^^^^^^  
> File “~\pulse\engine\src\python\pulse\engine\PulseEnginePool.py”, line 64, in initialize\_engines  
> self.\_is\_active = self.\_\_pool.initialize\_engines(json, PyPulse.serialization\_format.json)  
> ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^  
> TypeError: initialize\_engines(): incompatible function arguments. The following argument types are supported:  
> 1. (self: PyPulse.EnginePool) → bool
> 
> Invoked with: \<PyPulse.EnginePool object at 0x0000026FD2A4C230\>, (long EngingeInitialization JSON follows…), \<serialization\_format.json: 0\>

I believe it is calling the function here:

[https://gitlab.kitware.com/physiology/engine/-/blob/stable/src/cpp/cdm/PhysiologyEnginePool.cpp#L83](https://gitlab.kitware.com/physiology/engine/-/blob/stable/src/cpp/cdm/PhysiologyEnginePool.cpp#L83)

It looks like this function does not take any arguments, and the howto code is sending a json.

If I just remove the arguments from the function call in the howto (line 64 in PulseEnginePool.py),

> self.\_is\_active = self.\_\_pool.initialize\_engines(json, PyPulse.serialization\_format.json)

changed to

> self.\_is\_active = self.\_\_pool.initialize\_engines()

the function at line 60 of HowTo\_PatientPool.py returns false, ending the script with the message:

> “Unable to load/stabilize any engine”

I’m fine continuing to try and get it to work. Any suggestions for a fix would be appreciated. I also wanted to make sure to bring it up in case a fix is needed for the howto for anyone to use the PatientPool example in the future.

---

<div class="post-metadata">

### Author: ![abray](https://discourse.kitware.com/user_avatar/discourse.kitware.com/abray/32/12_2.png) [@abray](https://discourse.kitware.com/u/abray)
#### Post date: [July 24, 2023, 1:32pm UTC](https://discourse.kitware.com/t/python-patientpool-howto-issue/1069/2 "2023-07-24T13:32:45Z")

</div>

Hey @robert.bixler

The engine pooling is still a work in progress.  
We are about to make a pretty big push on this, so I will let you know as features come online for this.

Currently the best way to run within python is serially, using python threads that call native C++ tends to upset the GIL.

---

<div class="post-metadata">

### Author: ![robert.bixler](https://discourse.kitware.com/letter_avatar_proxy/v4/letter/r/51bf81/32.png) [@robert.bixler](https://discourse.kitware.com/u/robert.bixler)
#### Post date: [July 28, 2023, 6:21am UTC](https://discourse.kitware.com/t/python-patientpool-howto-issue/1069/3 "2023-07-28T06:21:50Z")

</div>

Ok, thanks. I would be interested to hear about those features when they become available.

In the mean time I think I’ve rigged up a solution by initializing patients, serializing their states to a file, and using Python’s multiprocessing function to advance time. Each process serializes the state from a file and advances a given amount of time in parallel with the other processes, then serializes the state back to the file.
