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

[WIP] Automatic python bindings with cppyy #145

Draft
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

JosephThomasParker
Copy link
Contributor

Description

cppyy provides automatic python bindings for C++ functions. This allows us to call NESO functions from python scripts, which has the following advantages:

  • Allows quick prototyping of different models (changing the python script doesn't require recompiling the C++)
  • Easier to integrate NESO into python workflows (e.g. VVUQ, or ML type workflows)
  • Makes NESO more user-friendly
  • Allows currently hard-coded parameters to be changed in the python script without requiring a recompile

This PR adds:

  • Changes to spack.yaml and requirements.txt to add dependencies
  • A blurb in the CMakeLists.txt to build the python bindings
  • The python script cppyy_run.py which executes the same program as src/main.cpp, but from python
  • README_cppyy.md that gives instructions on how to build and run, and outlines problems I'm having with the build system

Type of change

  • New feature (non-breaking change which adds functionality)
  • Requires documentation updates

Testing

Please describe the tests that you ran to verify your changes and provide instructions for reproducibility. Please also list any relevant details for your test configuration.

  • cppyy_run.py replicates the output of src/main.cpp
  • Test can be automated, but isn't yet.

Test Configuration:

Checklist:

  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • Any new dependencies are automatically built for users via cmake
  • I have used understandable variable names
  • I have run clang-format against my *.hpp and *.cpp changes
  • I have run cmake-format against my changes to CMakeLists.txt
  • I have run black against changes to *.py
  • I have made corresponding changes to the documentation
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • My changes generate no new warnings

@JosephThomasParker JosephThomasParker marked this pull request as draft February 3, 2023 10:36
@JosephThomasParker
Copy link
Contributor Author

So the main problem with this PR is that the code doesn't build automatically... I get build errors when I install through spack, but when I just copy and paste the failed commands into command line, the code compiles and the python bindings work. I've put detailed instructions of the process I go through to get it to build in README_cppyy.md. @jwscook and I have looked at the errors, but couldn't get anywhere. @cmacmackin is this something you can help with?

```
spack:
specs:
- neso%[email protected] ^openblas ^hipsycl ^scotch@6 ^[email protected] ^[email protected]%[email protected]
Copy link
Member

Choose a reason for hiding this comment

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

In the end we'll want to have a spec per build, so something like

Preferably with a set of allowable clangs and gccs.

@cmacmackin
Copy link
Contributor

Wayne has told me this needs review. It's still marked as WIP. Should that label be removed? Or are there a few final changes needed prior to review?

@JosephThomasParker
Copy link
Contributor Author

Hi @cmacmackin, I've stopped making changes and I'd like someone to have a look at it, but I know it's not in a state to get merged. Like I describe above, the actual build commands seem to work in isolation, but not when executed via the cmake script. To get some input on fixing the cmake would be great!

@cmacmackin
Copy link
Contributor

OK, I can give it a go. I've never used cppyy before, so might take a bit of trial and error for me to figure it out and get the hang of it.

@cmacmackin
Copy link
Contributor

cmacmackin commented Mar 6, 2023

Before I tried building the bindings I wanted to ensure I could build NESO properly with Clang. In the process of this I discovered that a regressions have been introduced and the test suite no longer passes for any of the compilers.

@@ -17,7 +17,8 @@ class Mesh;

class Mesh {
public:
Mesh(int nintervals = 10, double dt = 0.1, int nt = 1000);
Mesh();
Mesh(int nintervals, double dt = 0.1, int nt = 1000);
Copy link
Contributor

Choose a reason for hiding this comment

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

This causes regressions. There were previously calls made to the Mesh() constructor with no arguments, expecting it to be equivalent to a call of Mesh(10, 0.1, 1000). However, now it will call your newly-defined default constructor, which uses a different value for nintervals_in and doesn't perform any of the setup done in the body of the original constructor.

@@ -14,6 +14,8 @@ class Species;

class Species {
public:
Species(); // unused but required by cppyy python bindings
Copy link
Contributor

Choose a reason for hiding this comment

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

This seems to be causing the integration test Electrostatic2D3V.TwoStream to fail. Not entirely sure why that would happen, but when I comment it out the test passes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants