Multi-language (Julia + Python) coding : data transfer in a two-step simulation

Hi everyone,

I’m currently working on coupling two models for lung simulation: a first model coded in Python that calculates the evolution of pressure in the respiratory system using finite elements, and a second model coded in Julia that focuses more specifically on volumic transfers from alveoli to blood.

Thus, in my simulation, an increment proceeds as follows:

  • First, the first Python model calculates the pressures at the ends of the respiratory system.
  • Then, these pressures are read as initial conditions for the second Julia model, which calculates volumes at the alveoli.
  • Finally, the first model is updated with the Julia data, and the next increment can begin.

My problem is that during the same increment, I read a line from a volumes.csv file, calculate with my Python model, write a line to another pressures.csv file, read the pressures.csv file, calculate with my Julia model, and finally write to the volumes.csv file.

Do you know of a more suitable way of storing this data and transferring it from one model to another?

Thanks in advance for your reply, and have a nice day,

If you’re fond of NumPy, you can use the NPZ.jl package in Julia to interoperate.

Where I work, we also make extensive use of NetCDF and HDF5, which are both popular and language-agnostic.

2 Likes

You should definitely check out GitHub - cjdoris/PythonCall.jl: Python and Julia in harmony.

3 Likes

Writing a python extension with GitHub - Suzhou-Tongyuan/jnumpy: Writing Python C extensions in Julia within 5 minutes. is very easy, just exchange the numpy array directly.

1 Like

Don’t exchange the data via files. Call between languages directly using PyCall or PythonCall.

1 Like