Skip to content

Adds axom module to python interface with axom.sidre#1896

Open
kennyweiss wants to merge 11 commits into
developfrom
feature/kweiss/improve-python-sidre
Open

Adds axom module to python interface with axom.sidre#1896
kennyweiss wants to merge 11 commits into
developfrom
feature/kweiss/improve-python-sidre

Conversation

@kennyweiss

Copy link
Copy Markdown
Member

Summary

  • This PR improves how our python bindings are installed and exposed
  • It provides Sidre's Python module under axom.sidre instead of pysidre
  • It adds the AXOM_PYTHON_MODULE_INSTALL_PREFIX CMake variable for controlling where Axom's python modules get installed, and updates spack to have axom extend python for improved access within spack environments.
    • The run_axom_with_sidre script now allows relative paths to the Axom module in support of this.
  • It also paves the way to being able to install axom's python modules through pip/uv wheels
  • And, it improves the user docs about how to set up and use Axom's python bindings

* Renames the extension module from `pysidre` to `_sidre` so can import `axom.sidre`
* Adds python package scaffolding to `src/python`
* Introduces `AXOM_PYTHON_MODULE_INSTALL_PREFIX` CMake cache variable
* Update pysidre usage to `import axom.sidre as pysidre`
  and adds a shim to warning users that importing `pysidre` is deprecated.
This allows spack environment views to place Axom's installed
Python packages onto the interpreter path automatically.

This commit also emits `AXOM_PYTHON_MODULE_INSTALL_PREFIX`
in the generated host-config.
One can call the macro with either a COMMAND or a SOURCE file.
@kennyweiss kennyweiss self-assigned this Jun 26, 2026
@kennyweiss kennyweiss added Sidre Issues related to Axom's 'sidre' component Build system Issues related to Axom's build system usability Related to code usability Python labels Jun 26, 2026
Misc: Fixes typos and whitespace issues
@kennyweiss kennyweiss force-pushed the feature/kweiss/improve-python-sidre branch from 08306f7 to 06e053d Compare June 26, 2026 03:55

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Question for reviewers -- especially @bmhan12 -- do you think we need this pysidre shim?
I'm not aware of anyone that's currently using this, and the minimal fix in a script that uses this is very straightforward:

- import pysidre
+ import axom.sidre as pysidre

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

do you think we need this pysidre shim?

I think we can get rid of the shim.
Thinking of packages like matplotlib, where it's standard practice to just do: import matplotlib.pyplot as plt as the recommended path (https://matplotlib.org/stable/tutorials/pyplot.html).


if(NANOBIND_FOUND)
nanobind_add_module(pysidre nanobind_sidre.cpp)
# Python bindings for Sidre.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I think most of this logic belongs in the parent directory's CMakeLists.txt,
but I held off on moving it up for now since we only currently have one python submodule (axom.sidre)
Once we have another one, we'll likely have a better sense of what the general pattern should be.

On the other hand, I'm not against refactoring it in this PR.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Leave it for now and refactor when we have another Python module to avoid churn?

Comment thread src/tools/CMakeLists.txt

# gen python helper to build directory
set(_PYEXT_DIR ${PROJECT_BINARY_DIR}/lib)
# gen python helper to build directory.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Similarly here -- the installation logic for Axom's python modules probably doesn't belong in src/tools/CMakeLists.txt

# SPDX-License-Identifier: (BSD-3-Clause)

import pysidre
import axom.sidre as pysidre

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

To minimize the changes in this PR, I only applied

- import pysidre
+ import axom.sidre as pysidre

Should we use the full axom.sidre or perhaps something else instead of pysidre in our examples/tests for sidre's python interface?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Is there an issue with using pysidre?

Comment on lines +760 to +768
if spec.satisfies("+python"):
# Install Axom's Python package(s) so a spack environment view merges them into
# a single site-packages and `import axom.sidre` works without updating PYTHONPATH
entries.append(
cmake_cache_path(
"AXOM_PYTHON_MODULE_INSTALL_PREFIX",
spec["python"].package.platlib,
)
)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Does this PR require updating the host-configs?

parallel_io_concepts
sidre_conduit
mfem_sidre_datacollection
python_interface

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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

Labels

Build system Issues related to Axom's build system Python Sidre Issues related to Axom's 'sidre' component usability Related to code usability

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants