Add PETSc version switching infrastructure - #117
Conversation
PETSc arch names now encode the version: petsc-324-uw-openmpi instead of petsc-4-uw-openmpi. Multiple PETSc versions can coexist under the same PETSC_DIR, each with its own arch directory. Switching versions is: ./uw petsc switch v3.25.0 # checkout tag, set active version ./uw petsc build # build PETSc (if not already built) ./uw build # rebuild petsc4py + UW3 The active version is stored in petsc-custom/.petsc-version (gitignored). Legacy unversioned arch directories (petsc-4-uw-*) are detected and used as fallback when no versioned build exists. New commands: ./uw petsc versions — list available builds ./uw petsc switch — checkout a version tag ./uw petsc active — show active version and arch ./uw petsc build — build PETSc for the active version Underworld development team with AI support from Claude Code
There was a problem hiding this comment.
Pull request overview
Adds infrastructure to let multiple PETSc builds (different versions) coexist under petsc-custom/petsc/ and introduces CLI commands to list/switch the active PETSc version without requiring a full PETSc rebuild-from-scratch workflow.
Changes:
- Add PETSc version detection (
.petsc-versionor git tag) and versionedPETSC_ARCHnaming (petsc-{ver}-uw-{mpi}) with legacy fallback. - Introduce
./uw petsc ...subcommand for version listing, switching, reporting active version, and building. - Persist the active PETSc version in a gitignored
petsc-custom/.petsc-version.
Reviewed changes
Copilot reviewed 2 out of 3 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
uw |
Adds version detection + versioned arch selection; introduces ./uw petsc command routing. |
petsc-custom/build-petsc.sh |
Adds .petsc-version handling, versioned PETSC_ARCH, and new checkout/versions commands. |
.gitignore |
Ignores petsc-custom/.petsc-version local config file. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| petsc_arch_for_env() { | ||
| # Derive the PETSC_ARCH from the environment name. | ||
| # Primary AMR envs (amr, amr-runtime, amr-dev) use platform-default MPI. | ||
| # Override envs (amr-mpich*, amr-openmpi*) force a specific MPI. | ||
| # Derive the PETSC_ARCH from the environment name and active PETSc version. | ||
| # Format: petsc-{version}-uw-{mpi} (e.g. petsc-324-uw-openmpi) | ||
| local env="$1" | ||
| local ver=$(petsc_version_short) | ||
| local mpi="" |
There was a problem hiding this comment.
petsc_arch_for_env() now selects a versioned arch (e.g. petsc-325-uw-openmpi), but this wrapper never exports/overrides PETSC_ARCH (and PETSC_DIR) when running pixi run for the AMR build steps (notably the pip install of petsc4py). Since the pixi environments still set legacy PETSC_ARCH=petsc-4-uw-*, switching versions can leave petsc4py/UW3 building against the wrong arch (or failing to find the new one). Consider explicitly setting PETSC_ARCH=$(petsc_arch_for_env "$env") (and PETSC_DIR=$PETSC_CUSTOM) in the environment for relevant pixi run invocations so the selected version is actually used.
| echo "Checking out PETSc ${tag}..." | ||
| git checkout "${tag}" | ||
|
|
||
| # Update .petsc-version file | ||
| local ver_short | ||
| ver_short=$(echo "${tag}" | sed -E 's/^v([0-9]+)\.([0-9]+).*/\1\2/') | ||
| echo "${ver_short}" > "${VERSION_FILE}" | ||
| echo "Active PETSc version: ${ver_short} (${tag})" |
There was a problem hiding this comment.
checkout_version() runs git checkout <tag> but the PETSc working tree is typically left dirty after apply_patches() (it uses git apply without committing). In that common case, git checkout will fail and version switching won’t work. Consider making checkout resilient by detecting a dirty tree and either stashing/resetting (with an explicit warning) or forcing checkout and then re-running apply_patches() for the new tag.
| cd "${PETSC_DIR}" | ||
|
|
||
| # Fetch latest tags | ||
| git fetch --tags 2>/dev/null |
There was a problem hiding this comment.
checkout_version() assumes ${PETSC_DIR} already exists and is a git repo (cd "${PETSC_DIR}"), so ./uw petsc switch ... will hard-fail on a fresh clone before any PETSc build/clone has happened. Consider checking for ${PETSC_DIR}/.git (or ${PETSC_DIR}/configure) up front and either running clone_petsc automatically or printing a clear instruction to run the build/clone step first.
Summary
Adds the ability to have multiple PETSc versions coexist and switch between them without rebuilding PETSc from scratch.
petsc-324-uw-openmpiinstead ofpetsc-4-uw-openmpiPETSC_DIRin separate arch directoriespetsc-4-uw-*) are detected as fallbackpetsc-custom/.petsc-version(gitignored, local config)New
./uw petscsubcommand:After switching,
./uw buildrebuilds petsc4py + UW3 against the new version.Motivation: jcgraciosa reported issues on PETSc 3.25.0 (#115) that we need to investigate. This lets us test against 3.25 without losing the 3.24 build.
Test plan
./uw petsc activecorrectly reports version 324 and falls back to legacy arch./uw petsc versionslists existing builds with correct legacy labellingUnderworld development team with AI support from Claude Code