Skip to content

Add PETSc version switching infrastructure - #117

Merged
lmoresi merged 1 commit into
developmentfrom
feature/petsc-version-switch
Apr 17, 2026
Merged

Add PETSc version switching infrastructure#117
lmoresi merged 1 commit into
developmentfrom
feature/petsc-version-switch

Conversation

@lmoresi

@lmoresi lmoresi commented Apr 17, 2026

Copy link
Copy Markdown
Member

Summary

Adds the ability to have multiple PETSc versions coexist and switch between them without rebuilding PETSc from scratch.

  • Arch names now encode the PETSc version: petsc-324-uw-openmpi instead of petsc-4-uw-openmpi
  • Multiple versions coexist under the same PETSC_DIR in separate arch directories
  • Legacy unversioned arch dirs (petsc-4-uw-*) are detected as fallback
  • Active version stored in petsc-custom/.petsc-version (gitignored, local config)

New ./uw petsc subcommand:

./uw petsc versions          # list available builds
./uw petsc switch v3.25.0    # checkout tag + set active
./uw petsc active            # show current version/arch
./uw petsc build             # build PETSc for active version

After switching, ./uw build rebuilds 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 active correctly reports version 324 and falls back to legacy arch
  • ./uw petsc versions lists existing builds with correct legacy labelling
  • Version detection from git tags works
  • Full round-trip: switch to v3.25.0, build, test, switch back (requires ~1 hour PETSc build)

Underworld development team with AI support from Claude Code

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
Copilot AI review requested due to automatic review settings April 17, 2026 16:44

Copilot AI left a comment

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.

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-version or git tag) and versioned PETSC_ARCH naming (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.

Comment thread uw
Comment on lines 64 to +69
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=""

Copilot AI Apr 17, 2026

Copy link

Choose a reason for hiding this comment

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

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.

Copilot uses AI. Check for mistakes.
Comment on lines +437 to +444
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})"

Copilot AI Apr 17, 2026

Copy link

Choose a reason for hiding this comment

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

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.

Copilot uses AI. Check for mistakes.
Comment on lines +425 to +428
cd "${PETSC_DIR}"

# Fetch latest tags
git fetch --tags 2>/dev/null

Copilot AI Apr 17, 2026

Copy link

Choose a reason for hiding this comment

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

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.

Copilot uses AI. Check for mistakes.
@lmoresi
lmoresi merged commit 7d295eb into development Apr 17, 2026
5 checks passed
@lmoresi
lmoresi deleted the feature/petsc-version-switch branch June 13, 2026 00:53
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.

2 participants