Add external python predictor#1898
Conversation
mayrmt
left a comment
There was a problem hiding this comment.
@danielwolff1 I left some comments and raised some questions, that I could not answer for myself right away. For me, it looks like this is going into the right direction.
danielwolff1
left a comment
There was a problem hiding this comment.
Thanks for the fast review, I appreciate the input! I still have to look into some of the points you mentioned and will do so next week probably.
isteinbrecher
left a comment
There was a problem hiding this comment.
Thanks for this feature @danielwolff1 ! Nice to see how easy it is to incorporate python within 4C.
|
@danielwolff1 You could squash the commits. |
5064ddd to
78dc93c
Compare
|
@danielwolff1 could you have a look at the failing nightly pipeline? https://github.com/4C-multiphysics/4C/actions/runs/24694150094/job/72223568409 |
|
After a brief look, the tests fail because I'll have to investigate this more closely and will do so as quickly as possible, but unfortunately I'm at a conference this week, so it might take a couple of days. |
That explains why the nightly pipeline if failing. These tests are defined in Edit: I think it makes more sense to just activate the corresponding python environment so that the correct environment is in the path during testing. Then, 4C should pick the correct one and should find all dependencies. |
|
okay perfect, I didn't know that we already have a python environment (or how to activate it). Do you know if I can simply run |
Description and Context
With this PR, I'm proposing a new predictor class which allows to defer the actually implementation of the predictor to python. We need this feature as we want to study the behavior of Neural Network-based structural predictors.
Implementation details
I implemented this feature similarly to what has been done in the context of a python surrogate model for rough surface contact laws as merged in #1735. The general idea of the implementation are:
4Cexecution might happen in parallel, yet the computations in python only happen in a single interpreter, i.e., in a single process.pybind11functionality is completely encapsulated in anImplementationclass so that it does not interfere with the actual predictor.setup()method. That way the user can easily control whether to have this once-per-simulation overhead of communicating the mesh or whether they only need the "regular" information that also the C++ predictors see.Testing
I have implemented two integration tests where I test the two major different control flows, i.e., once the python script has a setup method and the mesh needs to be communicated and once not. In both cases, the python script implements the simple logic of a
ConstDispredictor and the corresponding values in theRESULTS DESCRIPTIONsection have been generated by running the same input scripts however withPREDICT = ConstDis.I'm still planning to look into unit tests for this feature but the general implementation already works and won't change anymore, so I already wanted to put it out for review.
I appreciate any comments and insights for potential improvements 😊