Skip to content

Conversation

@FlorianDeconinck
Copy link

@FlorianDeconinck FlorianDeconinck commented Feb 6, 2026

Types of change(s)

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Trivial change (affects only documentation or cleanup)
  • Refactor (no functional changes, no api changes)

Checklist

  • Tested this change with a run of GEOSgcm
  • Ran the Unit Tests (make tests)

Description

This PR aims at solving the "90%" case of Python integration has it as been seen lately at GMAO. The main features are:

  • One liner to drop into python, with dynamic package load (with a simple structure for user to hook in)
  • MAPL/ESMF states pass-through with a limited API to pull memory down in Python
  • Tooling for common Python operations (ongoing, more to come)

The entire API is heavily #ifdef by a flag at compile time BUILD_PYTHONBRIDGE - by default the functions are passthroughs.

Review points

@tclune / @atrayano: it was non-trivial for me to find a spot where I could initialize the system with the atmospheric grid. I ended up calling in GEOSAgcm_GridComp (see sister PR). This is only needed because right now the bridge back to MAPL gives me the pointer "blind", without sizes and rank. So I am giving the GRID to users so we can tool down.
A better version would be to augment the "MAPLpy" bridge to get shape and ranks, but I'd like to see that in a subsequent version so we can stress test this bridge first.

@mathomp4: I ended up not feeding the add_definitions upstream like we talked about. I kept it within the MAPL.python_bridge cmakelist and forwarded the API there. This looks cleaner and achieve the "opt-in by default" behavior we wanted.

@pchakraborty: You should find the design quite familiar. It's a CFFI bridge, like we've done before. The trick relies in the _get_code_object_from_package_name where I dynamically load the user given module and search for a CODE object. The README spells it out with some code. The rest is marshalling up & down memory via void*.

@FlorianDeconinck FlorianDeconinck requested a review from a team as a code owner February 6, 2026 16:50
@FlorianDeconinck FlorianDeconinck added 🎁 New Feature This is a new feature 0 Diff Trivial The changes in this pull request are trivially zero-diff (documentation, build failure, &c.) labels Feb 6, 2026
@mathomp4 mathomp4 added 0 Diff The changes in this pull request have verified to be zero-diff with the target branch. and removed 0 Diff Trivial The changes in this pull request are trivially zero-diff (documentation, build failure, &c.) labels Feb 6, 2026
@tclune tclune requested review from pchakraborty and tclune February 6, 2026 18:07
@tclune
Copy link
Collaborator

tclune commented Feb 6, 2026

We will have a meeting this afternoon to take a quick look. A deeper dive will wait until next week.

@FlorianDeconinck
Copy link
Author

Python API updated to simplify retrieving memory. Now you can do

MAPLPy = get_MAPLPy()
T = MAPLPy.get_pointer("T", state=import_state, dtype=np.float32, dims=MAPLPy.grid_dims)

and you get Fortran memory mapping in T, while T is a numpy array.

@mathomp4
Copy link
Member

mathomp4 commented Feb 9, 2026

Well, that coupled CI failure is weird. I'm re-running it.

@FlorianDeconinck
Copy link
Author

With the latest round of Python work I believe we have reached MVP - review away!

@mathomp4
Copy link
Member

mathomp4 commented Feb 9, 2026

I tested with NAG by hand and it's happy too.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

0 Diff The changes in this pull request have verified to be zero-diff with the target branch. 🎁 New Feature This is a new feature

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants