Building an Image
Goal
Build a Docker/Apptainer/Enroot image for distributed computing with Qrunch’s MPI-enabled tensor network simulator.
The image is based on NVIDIA’s cuQuantum appliance (Ubuntu 24.04 with CUDA 12.9.1) and includes Python 3.12 with Qrunch and its MPI dependencies.
Prerequisites
Docker installed and running
Python environment with Qrunch installed
(Optional) Pre-downloaded wheels for
qrunchwith CUDA and MPI support(Optional) Apptainer installed (required only if using
--apptainerflag)(Optional) Enroot installed (required only if using
--enrootflag)
Quick Start
To create a Docker image with Qrunch MPI support, specify the platform (aarch64 or x86_64):
Option 1 (recommended): Download wheels automatically (requires KVANTIFY_INDEX_URL)
qrunch.image \
--qrunch-version 1.5.0 \
--platform x86_64
Option 2: Use local wheels
qrunch.image \
--qrunch-wheel /path/to/qrunch-1.5.0-cp312-none-linux_x86_64.whl \
--platform x86_64
Note
The Qrunch wheel must be built with CUDA and MPI support for distributed computing. When downloading automatically (Option 1), the correct wheel variant is fetched. When using local wheels (Option 2), ensure your wheel includes these features.
Note
When downloading automatically (Option 1), the wheel variant only includes CUDA and MPI support. If you need support for IBM, IQM, OQC or Quantinuum in the wheel, then use Option 2 with the wheel you need.
The Docker image remains available in your local Docker daemon after building. Use docker images to see it, or push to a registry for remote use.
Verify the build:
To verify that Qrunch is installed correctly in the image:
docker run -it --entrypoint uv qrunch-mpi run --python 3.12 python -c "import qrunch; print(qrunch.__version__)"
Command Reference
The image builder always creates a Docker image first, then optionally converts it to Apptainer (.sif) or Enroot (.sqsh) format.
Note
Apptainer and Enroot conversions can fail on some systems due to Docker daemon connectivity or mksquashfs issues. The tool uses conservative defaults (slower but more stable). If conversion fails, the Docker image is preserved and you can convert manually (see Troubleshooting).
Command-line Options
qrunch.image should be called with either –qrunch-version (Option 1) or –qrunch-wheel (Option 2) as above, but the following optional flags are all available.
--qrunch-versionQrunch version to download (e.g.,
1.5.0). Required when downloading wheels automatically. The tool downloads wheels with CUDA and MPI support. Mutually exclusive with--qrunch-wheel.--qrunch-wheelPath to a local Qrunch wheel with CUDA and MPI support. When using local wheels,
KVANTIFY_INDEX_URLis not required.--platformTarget platform architecture:
aarch64orx86_64. Default:x86_64. Choose the platform matching your HPC cluster or target execution environment.--apptainerGenerate an Apptainer image (
.siffile) after building the Docker image. Uses-processors 1for mksquashfs stability (slower but safer).--enrootGenerate an Enroot image (
.sqshfile) after building the Docker image.--tagDocker tag for the image. Default:
qrunch-mpi.--output-dirDirectory to save
.sifor.sqshfiles. Default: current working directory.
Environment Variables
KVANTIFY_INDEX_URLRequired when using
--qrunch-versionto download wheels automatically. Points to the Cloudsmith Python index with authentication token. Not needed when using local wheels (--qrunch-wheel).
Examples
Build Docker image with Apptainer conversion
qrunch.image \
--qrunch-version 1.5.0 \
--platform x86_64 \
--apptainer \
--output-dir ./containers
Build ARM64 image with custom tag
qrunch.image \
--qrunch-version 1.5.0 \
--platform aarch64 \
--tag qrunch-mpi-arm \
--apptainer
Build with both Apptainer and Enroot
qrunch.image \
--qrunch-version 1.5.0 \
--platform x86_64 \
--apptainer \
--enroot \
--output-dir ./containers
Troubleshooting
Conversion failures
If Apptainer or Enroot conversion fails, you can work with a Docker archive (.tar file) instead of the Docker daemon directly:
docker save qrunch-mpi -o qrunch-mpi.tar
Then convert manually:
# For Apptainer
apptainer build --mksquashfs-args "-processors 1" --force qrunch-mpi.sif docker-archive://qrunch-mpi.tar
# For Enroot (from Docker daemon)
enroot import --arch x86_64 --output qrunch-mpi.sqsh dockerd://qrunch-mpi
# For Enroot (from Docker registry) - useful if dockerd:// has issues
enroot import --arch x86_64 --output qrunch-mpi.sqsh docker://qrunch-mpi
Note
For Enroot, dockerd:// reads from the local Docker daemon, while docker:// pulls from a Docker registry. Use docker:// if you’ve pushed the image to a registry or if dockerd:// has connection issues.
Missing KVANTIFY_INDEX_URL
If you see an error about KVANTIFY_INDEX_URL not being set, either:
Set the environment variable with your Cloudsmith token URL:
export KVANTIFY_INDEX_URL="https://dl.cloudsmith.io/YOUR-TOKEN/kvantify/qrunch/python/simple/"
Or use local wheels with
--qrunch-wheelflags (no environment variable needed)
Next Steps
After building your image:
See Using the MPI cuTensorNet Calculator for writing MPI-enabled scripts with the cuTensorNet calculator
See Running MPI Calculations for deploying and running on HPC clusters with mpirun or Slurm
Test the image locally:
docker run -it --entrypoint uv qrunch-mpi run --python 3.12 python -c "import qrunch; print(qrunch.__version__)"
Consult your cluster’s documentation for cluster-specific requirements and best practices