modsim / CADET

A modular, fast, and accurate simulation framework for (column) liquid chromatography
GNU General Public License v3.0
50 stars 24 forks source link

In-memory Python interface #12

Open sleweke opened 5 years ago

sleweke commented 5 years ago

CADET already provides a MATLAB interface via MEX-functions. A similar in-memory interface can be done in Python. Such an interface reduces the overhead of reading input files, allocating memory, configuring and initializing the simulation. This is especially interesting when doing optimization or repeated simulations (e.g., parameter studies).

There are basically two approaches to build an in-memory interface:

Generally, the file format should be recreated on the Python side using nested dictionaries.

Attention: Due to the handling of AD directions, whose active number is reset when starting time integration, running simulations concurrently in the same (Python) process / libcadet instance might produce wrong sensitivities or results (when using AD for Jacobians) under specific circumstances. This is the case when the simulations use a different number of active AD directions and the one with less directions is started last. The global active-AD-directions-variable is then reset to the lower number, which causes the other simulation to use the same number of directions.

Intrusive approach

Pros / cons:

Nonintrusive approach

Pros / cons:

Proposal: Nonintrusive approach using callbacks

A minimal working setup:

Details on the callback-based ParameterProvider:

Estimated timeframe for a working prototype: 1.5 months.

schmoelder commented 3 years ago

Work in progress for CADET-Python can be found here.