-
Notifications
You must be signed in to change notification settings - Fork 189
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
De-cythonize ESPResSo #4542
Comments
Once the migration is complete, we should no longer be dependent on Cython 0.29. This would give us the opportunity to replace it with Cython 3.0, which breaks API in multiple ways (source), in particular: bytestrings are now unicode strings, |
Cython is deprecating conditional compilation. This is a feature we are still using in the remaining .pyx files. When building ESPResSo with Cython version 3.0.0a11, the terminal is flooded with the following message:
|
You can try out Cython 3.0 in a container or python environment with: python3 -m pip install --user "Cython==3.0.0b2" It is not possible to build ESPResSo. Conditional compilation is deprecated and leads to fatal errors. The |
Description of changes: - bump requirements: CMake >= 3.20 - block CMake at configuration stage when Cython >= 3.0 is found - Cython 3.0 is not supported in ESPResSo, more details in #4542 (comment) - add an extra guard for a known Doxygen bug - use a ScaFaCoS library built for x86_64 architectures - fix implicit type conversions in Lees-Edwards and use a named constant for invalid or uninitialized axes
Description of changes: - encapsulate thermostats and remove their Cython interface - use one C++ `ScriptInterface` class per core class (fixes #3980) - introduce the `ThermostatFlags` enum, allow deactivating a single thermostat, add an `is_active` flag accessible from the Python interface (fixes #4266) - remove 20 MPI callbacks - partial fix for #4614 - remove thermostat and thermalized/rigid bond global variables - partial fix for #2628 - remove a significant amount of historical Cython code that relied on deprecated Cython features - partial fix for #4542 - ESPResSo is now compatible with Cython 3.0 - the `nogil` deprecation warning subsists - improve testing of the thermostats interface - API changes: - thermalized bond parameter `seed` was moved to `system.thermostat.set_thermalized_bond()` - this change better reflects the fact there is only one global seed for all thermalized bonds - until now this global seed was overwritten by any newly created thermalized bond, whether it was added to the system or not - LB thermostat `seed` parameter now gets written to the RNG seed (silent change) - until now, the RNG seed was hardcoded as `0` and the `seed` value was used to set the RNG counter, thus two independent simulations with a different seed would actually get the same particle coupling random noise sequence with a time lag equal to the difference between the two seeds - this is a bugfix for ensemble runs - fixes #4848
tl;dr: Most Cython files in ESPResSo can be rewritten as Python files using the
ScriptInterface
framework.Background and problem statement
The Python interface of ESPResSo was originally designed using Cython, which could access C++ header files from the core and generate all the necessary glue code to connect the C++ shared objects to the Python interpreter. Cython is a convenient solution, and its syntax is easy to understand to contributors who have some Python experience but no C++ experience.
However, this design decision comes with several drawbacks that are not immediately visible to occasional contributors:
Proposed solution
The
ScriptInterface
framework was introduced to automatically generate the glue code between a Python class and a C++ class that holds a shared pointer to the owned resource. Although it requires writing a C++ class, there are many benefits:boost::mpi
code can be used instead of our customMpiCallbacks
frameworkutils.check_type_or_throw_except()
orutils.is_valid_type()
anymore: this information is already encoded in the C++ class when using e.g.auto const value = get_value<Utils::Vector3d>(value)
, and a clear error message is generated automatically if the conversion failed**kwargs
, which reduces the risk of introducing silent API changes__getstate__()
and__setstate__()
methods to checkpoint Python objects: they are generated automaticallyIn principle, only
script_interface.pyx
andscript_interface.pxd
are necessary, and those can probably be replaced by any other Cython-like interface library.Curent situation
In release 4.2.0, many Cython source files were converted to Python using the
ScriptInterface
framework:espresso/NEWS
Lines 766 to 771 in 18d49bf
This allowed for a significant reduction in the complexity of the
MpiCallbacks
framework:espresso/NEWS
Lines 747 to 748 in 18d49bf
Next steps
The following components remain to be converted from Cython to Python:
ScriptInterface
#4541ScriptInterface
-basedcuda_init.pyx
,_init.pyx
,profiler.pyx
,code_info.pyx
(generated file),version.pyx
: unclearThe text was updated successfully, but these errors were encountered: