Closed g-bauer closed 1 year ago
Since we have to deal with this problem now anyways: Is there any way we can make the implementation of the Python FFI for the dual numbers more ergonomic? It's virtually impossible to make a Box<dyn DualNum<f64>>
using a PyDualNumber<PyObject>
and doing a (manually implemented) type check for every operation we have also seems unfeasible.
Aside from that the steps that you outline seem doable. Maybe expose ALL dual numbers that are created in the num-dual Python FFI and then in feos we can just build the States that we need. E.g., currently num-dual builds dual numbers with up to 10 derivatives but we would only need them for up to 2 in feos.
(For more than 10 derivatives backward AD should be seriously considered anyways)
These are things to consider:
num-dual
module (the Python package)For feos
we just have to make sure that all variants we need in HelmholtzEnergy
are build and public in the python
(Rust) module. But I agree, we should investigate if any improvements to the way we build the bindings can be made. This is, however, an issue for num-dual
.
In feos
, currently two macros are used. One implements the getters for the states that are at the moment defined manually, the second one implements the HelmholtzEnergy
trait. It should be possible to do that all automatically given a list of dual numbers.
For the
python
equation of state, users can define their ownhelmholtz_energy
function that takes aStateHD
object as input. In the function, properties of the state can be accessed, e.g. one can writestate.moles
. To make this work, there has to be a non-generic state object for each (hyper) dual number.Currently, missing dual numbers are simply defined in
feos-core
. Using these definitions, for each a non-genericStateHD
version is built. There are currently two issues:num-dual
(which currently does not export all variants we need to Python)impl_state_hd!
(which implement the getters) for all states that are built. Hence, there will be errors in Python when one tries to call the getters.To fix this, we
num-dual
. (Check class names in macros!)HelmholtzEnergyDual
in single macro?