Skip to content

Enable Axom's Python to be installed via uv/pip - #1936

Open
kennyweiss wants to merge 35 commits into
developfrom
feature/kweiss/python-env
Open

Enable Axom's Python to be installed via uv/pip#1936
kennyweiss wants to merge 35 commits into
developfrom
feature/kweiss/python-env

Conversation

@kennyweiss

@kennyweiss kennyweiss commented Aug 1, 2026

Copy link
Copy Markdown
Member

Summary

  • This feature PR packages Axom's Python bindings as a wheel that can be installed via uv or pip
    • Our current Python interface is run through a script (run_python_with_axom.sh) that adds the necessary dependencies to PYTHONPATH
    • This PR adds another option to generate a scikit-build-core project over an installed Axom. The generated Python wheel can be installed into a uv or pip virtual environment
    • It also adds a CI job to build and test the wheel via uv from an already built Axom installation (the gcc docker CI)
  • This PR also improves the Sidre bindings to (a) fix type helpers for better IDE integration and (b) fixes a potential memory leak related to pinning external views into memory already tracked by our interface. It adds several tests for this memory fix

Three steps to a uv installation

Assuming we already have an Axom installation in ${AXOM_INSTALL}

   # 1. create a uv virtual environment
   $ uv venv --python $(which python3)

   # 2. build the wheel against an Axom installation (internal logic adds the Conduit that axom was built against)
   $ uv pip install /path/to/axom/src/python \
       -C cmake.define.AXOM_DIR="$AXOM_INSTALL/lib/cmake"

   # 3. run an axom.sidre Python script through this environment
   $ uv run python -c "import axom.sidre, conduit, numpy; print(axom.__version__)"

Running in Jupyter w/ type hints

   # 1. install Jupyterlab, and optionally, extra language servers
   $ uv pip install jupyterlab ipykernel
   $ uv pip install jupyterlab-lsp 'python-lsp-server[all]'

   # 2. generate an Axom kernel
   $ uv run python -m ipykernel install --user --name axom --display-name "Axom (uv)"

   # 3. run jupyter
   $ uv run jupyter lab
  • Our Axom kernel has tab completion on the API:
image
  • It also has tooltips for the API (via shift+tab)
image
  • Somewhat larger example:
image

Limitations

  • Usage errors in Jupyter currently pipe through cerr (via SLIC_WARNING) and don't show up in the error Jupyter output cell. E.g if you run the cell to create a view or group a second time, it will silently get converted to None.
  • I didn't test this with hip or cuda configs. Let's also handle that in a separate PR

@kennyweiss kennyweiss self-assigned this Aug 1, 2026
@kennyweiss kennyweiss added enhancement New feature or request Sidre Issues related to Axom's 'sidre' component CI Issues related to continuous integration Documentation Issues related to documentation usability Related to code usability Python labels Aug 1, 2026

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.

This user doc about Python will move out of sidre once we have bindings for a second component

//! Erase all pins recorded for \a ds (called when the DataStore is collected).
void releaseDataStoreExternalPins(DataStore* ds) { externalDataOwnerRegistry().erase(ds); }

//! Release the pin recorded for \a view, if any (defined below).

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.

This block contains fixes for pinning memory in blocks we've already pinned


m_sidre.def("indexIsValid", &indexIsValid, "Returns true if idx is valid, else false.");
m_sidre.def("nameIsValid", &nameIsValid, "Returns true if name is valid, else false.");
m_sidre.def("indexIsValid",

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.

The nb::arg() additions help Jupyter and IDEs get the names of functions (instead of just arg1, arg2

"Create an Attribute object with a default string value")
"Create an Attribute object with a default string value",
nb::arg("name"),
nb::arg("default_value").noconvert())

@kennyweiss kennyweiss Aug 1, 2026

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.

The noconvert() prohibits casts like float -> int. (see block comment below in this file)

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.

This file helps us get the conduit that Axom was configured against

Comment thread src/python/CMakeLists.txt

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.

This is the CMake project that uv uses to set up the wheel for uv.

I tried to make it as simple as possible, but there were some necessary complexities.
I'm not sure how thoroughly tests the stable ABI options are, but they seemed worthwhile.

Comment thread src/python/pyproject.toml

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.

This pyproject.toml file sets up the wheel and its dependencies.

Comment thread .github/workflows/ci-tests.yml Outdated
Comment thread src/python/pyproject.toml
# The compiled extension and its generated _sidre.pyi are installed by CMakeLists.txt into axom/sidre/.
wheel.packages = ["src/axom"]

# NOTE on the sdist: the binding translation unit lives with its component (../axom/sidre/nanobind_sidre.cpp), outside this project directory.

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.

is this comment block necessary, or is there setting(s) here that should be made optional?

Comment on lines +114 to +117
$ uv pip install /path/to/axom/src/python \
-C cmake.define.AXOM_DIR="$AXOM_INSTALL/lib/cmake"

$ uv run python -c "import axom.sidre, conduit, numpy; print(axom.__version__)"

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.

Thanks for the documentation!

Here's the ReadTheDocs link for reference:
https://axom.readthedocs.io/en/feature-kweiss-python-env/axom/sidre/docs/sphinx/python_interface.html

I tried following along, just wanted to note that AXOM_DIR needs to be an absolute path.

Also, I tried the uv run python command here, and got a configuration error:

Click for dropdown of error
$ uv run python -c "import axom.sidre, conduit, numpy; print(axom.__version__)"
  × Failed to build `axom-pysidre @ file:///usr/WS1/han12/axom_codex`
  ├─▶ The build backend returned an error
  ╰─▶ Call to `scikit_build_core.build.build_editable` failed (exit status: 1)

      [stdout]
      *** scikit-build-core 1.0.3 using CMake 3.26.5 (editable)
      *** Configuring CMake...
      loading initial cache file build/cp313-cp313-linux_x86_64/CMakeInit.txt
      -- The C compiler identification is GNU 13.3.1
      -- The CXX compiler identification is GNU 13.3.1
      -- Detecting C compiler ABI info
      -- Detecting C compiler ABI info - done
      -- Check for working C compiler: /usr/tce/packages/gcc/gcc-13.3.1/bin/gcc - skipped
      -- Detecting C compile features
      -- Detecting C compile features - done
      -- Detecting CXX compiler ABI info
      -- Detecting CXX compiler ABI info - done
      -- Check for working CXX compiler: /usr/tce/packages/gcc/gcc-13.3.1/bin/g++ - skipped
      -- Detecting CXX compile features
      -- Detecting CXX compile features - done
      -- BLT Version: 0.7.2
      -- CMake Version: 3.26.5
      -- CMake Build Type: Release
      -- CMake Executable: /usr/bin/cmake
      -- Setting CMAKE_CXX_EXTENSIONS to OFF
      -- Standard C++20 selected
      -- BLT MPI support is OFF
      -- BLT OpenMP support is OFF
      -- BLT CUDA support is OFF
      -- BLT HIP support is OFF
      -- Found Git: /usr/tce/bin/git (found version "2.29.1")
      -- Git Support is ON
      -- Git Executable: /usr/tce/bin/git
      -- Git Version: 2.29.1
      -- Sphinx support is OFF
      -- Valgrind support is OFF
      -- AStyle support is OFF
      -- ClangFormat support is OFF
      -- Uncrustify support is OFF
      -- Yapf support is OFF
      -- CMakeFormat support is OFF
      -- Cppcheck support is OFF
      -- ClangQuery support is OFF
      -- ClangTidy support is OFF
      -- ClangApplyReplacements support is OFF
      -- C Compiler family is GNU
      -- Adding optional BLT definitions and compiler flags
      -- Enabling all compiler warnings on all targets.
      -- Fortran support disabled.
      -- CMAKE_C_FLAGS flags are:   -Wall -Wextra
      -- CMAKE_CXX_FLAGS flags are:   -Wall -Wextra
      -- CMAKE_EXE_LINKER_FLAGS flags are:
      -- CMake's C implicit link directories:
      /collab/usr/global/tools/tce4/packages/gcc/gcc-13.3.1/lib/gcc/x86_64-redhat-linux/13;/collab/usr/global/tools/tce4/packages/gcc/gcc-13.3.1/lib/gcc;/collab/usr/global/tools/tce4/packages/gcc/gcc-13.3.1/lib64;/lib64;/usr/lib64;/collab/usr/global/tools/tce4/packages/gcc/gcc-13.3.1/lib
      -- CMake's CXX implicit link directories:
      /collab/usr/global/tools/tce4/packages/gcc/gcc-13.3.1/lib/gcc/x86_64-redhat-linux/13;/collab/usr/global/tools/tce4/packages/gcc/gcc-13.3.1/lib/gcc;/collab/usr/global/tools/tce4/packages/gcc/gcc-13.3.1/lib64;/lib64;/usr/lib64;/collab/usr/global/tools/tce4/packages/gcc/gcc-13.3.1/lib
      -- CMake's C implicit link libraries: gcc;gcc_s;c;gcc;gcc_s
      -- CMake's CXX implicit link libraries: stdc++;m;gcc_s;gcc;c;gcc_s;gcc
      -- Umpire support is OFF
      -- RAJA support is OFF
      -- Conduit support is OFF
      -- HDF5 support is OFF
      -- MFEM support is OFF
      -- Adiak support is OFF
      -- Caliper support is OFF
      -- Shroud support is OFF
      -- Found Python: /g/g12/han12/.cache/uv/builds-v0/.tmptcFZjg/bin/python (found suitable version "3.13.11", minimum
      required is "3.8") found components: Interpreter Development.Module
      -- Python version: 3.13.11
      -- Python executable: /g/g12/han12/.cache/uv/builds-v0/.tmptcFZjg/bin/python
      -- Python include dir:
      /collab/usr/gapps/axom/devtools/toss_4_x86_64_ib/2026_02_17_14_42_14/gcc-13.3.1/python-3.13.11-unvqpdaz447knce6gej3tdldeqqsdssl/include/python3.13
      -- Python library:
      -- Configuring incomplete, errors occurred!

      [stderr]
      WARNING: Minimum CMake version not found in CMakeLists.txt. If the CMakeLists.txt is valid, this might be a bug in
      our search algorithm. Report this or (and) set manually to avoid this warning.
      CMake Error at cmake/thirdparty/SetupAxomThirdParty.cmake:409 (message):
        Axom's python extensions require conduit and numpy at runtime.

        The python library installation paths can be specified with CMake
        variables: CONDUIT_PYTHON_MODULE_DIR, PY_NUMPY_DIR
      Call Stack (most recent call first):
        cmake/CMakeBasics.cmake:21 (include)
        CMakeLists.txt:128 (include)



      *** CMake configuration failed

I was able to resolve it by adding --no-sync flag, not sure if that's expected.

This directory is used by the Python installation (e.g. for wheels).
Also deemphasizes the discussion of platform-dependent wheelhouses.
And about better IDE integration with Jupyter.
Only export variables with content, and clarify the intent of the two variable groups.
Do not pin pointers within blocks that are already pinned.
Allow for the possibility of some generated config files not being present and return a proper error message.
@kennyweiss
kennyweiss force-pushed the feature/kweiss/python-env branch from f0f3639 to 8f67e36 Compare August 28, 2026 01:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CI Issues related to continuous integration Documentation Issues related to documentation enhancement New feature or request 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