Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rewrite integrators script interface as Python code #4713

Merged
merged 2 commits into from
Apr 24, 2023

Conversation

jngrad
Copy link
Member

@jngrad jngrad commented Apr 21, 2023

Fixes #4712

Description of changes:

The nogil attribute is required to make the integrator run smoothly
with threads (e.g. from the visualizer). Functions marked with the
nogil attribute can throw C++ exceptions since Cython 0.19. The
Cython functions that handle signals can be replaced with the
`signal.raise_signal()` function introduced in Python 3.8.
The old test would send the interrupt signal before the script had
a chance to enter the integration loop, and thus the custom signal
handler was never tested. The new version waits for the subprocess
to write it's ready for the interrupt signal, and the traceback is
checked to confirm the signal was re-raised by the script interface.
Copy link
Member Author

@jngrad jngrad left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is no code coverage in the core for the signal handling code, probably because the interrupt signal interferes with the profiler. But the signal error message is actually tested in the python testcase now. Also, another benefit of no longer exposing the integrator internal state to Cython is that we can encapsulate its 9 global variables into a single struct.

For a proof-of-concept, see integrate.cpp in c933b1b. I will not work further on it for now, because it is not entirely satisfactory, e.g. some of the core functionality like ICC cannot get a pointer to it via function arguments without a significant refactoring. Also, we need to define what is supposed to go in the integrator struct once we enable per-particle integration. And more urgently, we need to get the observable framework to run in parallel to help further simplify the integrator code.

@jngrad jngrad marked this pull request as ready for review April 24, 2023 13:15
@jngrad jngrad added the Core label Apr 24, 2023
@jngrad jngrad requested a review from reinaual April 24, 2023 13:15
Comment on lines +122 to +124
cdef extern from "integrate.hpp":
double get_time_step()

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this necessary, because integrate.pyx is no longer a cython file? Don't we have a better place to access the time_step?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunately, it is still necessary in the python branch, because the old LB implementation needs it. That's the last consumer, so this will be gone in the walberla branch.

@jngrad jngrad added the automerge Merge with kodiak label Apr 24, 2023
@kodiakhq kodiakhq bot merged commit 8b0c0bf into espressomd:python Apr 24, 2023
@jngrad jngrad deleted the nogil branch April 24, 2023 15:50
@jngrad jngrad added this to the Espresso 4.3.0 milestone Apr 26, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

On releasing the GIL in ESPResSo
2 participants