Link Python module to Cantera shared library#1429
Merged
ischoegl merged 28 commits intoCantera:mainfrom Feb 3, 2023
Merged
Conversation
8201853 to
1f1d26f
Compare
Codecov Report
@@ Coverage Diff @@
## main #1429 +/- ##
==========================================
+ Coverage 70.73% 70.94% +0.21%
==========================================
Files 378 369 -9
Lines 55141 55201 +60
Branches 18164 18176 +12
==========================================
+ Hits 39006 39165 +159
+ Misses 13626 13574 -52
+ Partials 2509 2462 -47
📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more |
f6080c6 to
1fc2b7a
Compare
5 tasks
8485cb3 to
508967a
Compare
This is a prerequisite to using Boost.DLL with the std::filesystem library.
This eliminates the need to directly link the Cantera shared library or Cantera applications to libpython.
This version properly exports all necessary DLL symbols, eliminating the need to embed it separately in the Cython module.
10.15 or newer is required for C++17 support
This requires copying the relevant MinGW runtime libraries into the Python module.
Trying this to understand why this step can sometimes take upwards of 8 minutes.
This is important because extensions can only be loaded correctly when Cantera is linked as a shared library.
When the Python module is linked to the Cantera shared library, it is possible that a user has multiple incompatible versions of the library installed. This checks that the Cantera version and Git commit are the same when importing the Python module, to avoid crashes or erroneous behavior due to ABI mismatches.
9c05ade to
3dd702d
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Changes proposed in this pull request
The main purpose of this PR is to modify the implementation of
ExtensibleRateso that the core Cantera library (libcantera) does not need to depend on a specific Python installation at compilation / installation time. Achieving this required some fairly far-reaching changes, though I think they will all have long-term benefits.PythonExtensionManagerclass and associated Cython functions have been moved out oflibcanterainto a separate shim,libcantera_pythonthat is loaded on demand. This new library is the one that links tolibpythonand loads the Cantera Python module.libcantera_python) both depend onlibcantera,libcanteraneeds to be loaded as a shared library to avoid having two copies of the library with separate state (which would interfere instantiating user defined types that are only instance with one copy ofReactionRateFactory, for example). Multiple versions of Python are supported (not at the same time!) by having multiple versions oflibcantera_python, e.g.libcantera_python3_11.soandlibcantera_python3_10.so.libcantera_sharedrequires "exporting" the complete C++ interface. Due the the sheer number of methods that need to be exported, rather than the standard approach investigated in Export C++ library symbols for core methods #1298, this PR uses the static library to generate a list of symbols to be exported from the DLL.libcantera_pythonlibrary on-demand are OS-specific. Rather than use these low-level functions, the Boost.DLL library is used for its higher-level, cross-platform capabilities. While Boost.DLL is header-only, by default it depends on Boost.Filesystem, which has a compiled component. However, since C++17 introducedstd::filesystem(derived from Boost.Filesystem), Boost.DLL provides an option to usestd::filesystem. Therefore, in order to avoid introducing a dependence on the compiled components of Boost, this PR bumps Cantera's compiler requirement to the C++17 standard.There are also a few more minor changes that ended up coming along for the ride:
usingdirectives within theCanteranamespace for some of the most-used standard library types:string,vector,map,function,pair,unique_ptr. I figuremap<string, string>is more readable thanstd::map<std::string, std::string>.fmtandEigen.If applicable, fill in the issue number this pull request is fixing
Checklist
scons build&scons test) and unit tests address code coverage