-
Notifications
You must be signed in to change notification settings - Fork 8
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
Minor bugfixes and automation of PyBind11 bindings #3
Open
vegardjervell
wants to merge
9
commits into
mcfarljm:iso_c_binding
Choose a base branch
from
vegardjervell:iso_c_binding
base: iso_c_binding
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Conversation
This file contains 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
Check if argument names are reserved keywords in C++. If so, prepend an underscore to the name. Specifically, this was the case when using "this" as an argument name on the fortran side. Also added /venv to .gitignore
Moved the fortwrap.py file, and added a setup.py, such that fortwrap can be pip installed. Also moved some code from the __name__ == __main__ clause to the wrap() function, which is now called from the __name__ == __main__ clause. If fortwrap is pip installed, it can be run as python -m fortwrap <ordinary fortwrap options> I could have just made a symlink, but using "pip install -e" feels better, and is also nice if this is ever going out to pypi.
… based on regex match Using the fields %<include/exclude>_files [pattern1 pattern2 ...] and %<include/exclude>_procedures [pattern1 pattern2 ...]. Also added the -d/--directory command line option to the configuration file. Had to change the name sanitizer (see: c8a9711) to prepend "c_", because fortran does not permit leading underscores.
Ensuring that the modules in FortranISOWrappers.f90 are ordered such that they are compiled in the order of required dependencies. Also implemented searching for parent classes, such that the modules in FortranISOWrappers.f90 correctly USE each other. Successfully wrapped test case with multiple inheritance split among several modules.
Wrapper is compiled separately using cmake. The fortran files are included by first compiling the fortran files to an archive, and adding them to target_link_libraries in cmake.
test_py.py can be run to compute pressure, residual helmholtz energy and OPTIONALLY differentials. The pybind wrapping code in pybind11_bindings.cpp has been partially manually written. Specifically, the casting of py::none() to nullptr, the default value of the optional arguments to py::none(), and the casting from py::array_t to float**. Solved: Don't use std::vector for arrays passed to fortran, just use float**.
… modifiable arrays and optional arguments. The handling is done by passing modifiable values as np arrays: Pybind11 can directly access the underlying memory of the arrays in a lambda function and pass these to the internal c++ methods. Optional arguments are also handled by pybind11, rather than in the "plain" c++ wrapper classes. Still needs to be fixed: FortWrap incorrectly generates C++ methods taking e.g. float* as arguments, when they should take float** (see FortWrap thermopack demo). This is likely a quick fix in the c_arg_list function.
… Options class Now all parsing of options happens in one place, and the config file can be used to supply all options.
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.
Edit: We are maintaining a fork at https://github.com/thermotools, and are also automating generation of pybind11 bindings for the C++ wrapper :)
Hi,
It looks like we may be adopting this for our project :) If we do, we will be maintaining a fork at https://github.com/thermotools.
While I was testing it I made some modifications:
setup.py
and moved some files so thatpip
can be easily utilized.FortranISOWrappers.f90
, so that modules are compiled in order of dependency. Also fixed bug where modules did not properly include each other.ConfigFile
parser also read command-line argumentsPyBind11
(still very experimental, may need manual modifications after being generated.)