Skip to main content

Torch-based Python bindings for the minichem Fortran chemistry solver.

Project description

pyminichem

pyminichem is a standalone Python package and Torch-based C++ wrapper around the Fortran mini_chem code base. The repository follows the same broad layout used by pydisort, pyharp, and kintera:

  • src/: native C, C++, and wrapper code
  • python/: Python package, pybind11 bindings, and packaged resources
  • patches/: upstream minichem patch set
  • tests/: C++ and Python validation

The build flow is:

  1. Fetch upstream mini_chem with CMake.
  2. Apply the same mini_ch_i_dlsode.f90 patch used by canoe.
  3. Link the patched Fortran implementation into a thin C shim.
  4. Wrap that shim in a Torch-based C++ API.
  5. Expose the C++ API to Python with pybind11.

Build

CPU build

Use the default GNU toolchain for the CPU-only path:

cmake -S . -B build-cpu -DBUILD_TESTS=ON
cmake --build build-cpu -j
ctest --test-dir build-cpu -R '^test_minichem.release$' --output-on-failure

If you want the editable Python package to use the CPU build, copy the native library into the package locations and reinstall:

cp build-cpu/lib/libpyminichem_release.so build/lib/libpyminichem_release.so
cp build-cpu/lib/libpyminichem_release.so python/lib/libpyminichem_release.so
python -m pip install -e .

CUDA/OpenACC build with NVHPC

The CUDA path in this repo uses GNU C/C++ for the Torch wrapper and the NVIDIA HPC SDK Fortran compiler for the OpenACC minichem backend. Do not use GNU Fortran with -DCUDA=ON: it can link through libgomp, but the resulting build fails at runtime on NVIDIA GPUs with device type nvidia not supported.

First put the NVIDIA HPC SDK compilers on PATH:

export NVHPC=/opt/nvidia/hpc_sdk
export NVHPC_BIN=$(find "$NVHPC/Linux_x86_64" \
  -mindepth 3 -maxdepth 3 -path '*/compilers/bin' -type d \
  | sort -V | tail -n 1)
export PATH="$NVHPC_BIN:$PATH"

gcc --version
g++ --version
nvfortran --version

Then configure CMake with CUDA enabled. When -DCUDA=ON, CMake defaults to gcc, g++, and nvfortran unless compilers are explicitly provided with -DCMAKE_*_COMPILER=....

cmake -S . -B build-nvhpc \
  -DBUILD_TESTS=OFF \
  -DCUDA=ON

cmake --build build-nvhpc -j

For a test-enabled local CUDA build:

cmake -S . -B build-nvhpc \
  -DBUILD_TESTS=ON \
  -DCUDA=ON

cmake --build build-nvhpc -j
ctest --test-dir build-nvhpc -R '^test_minichem.release$' --output-on-failure

To make the editable Python package use the NVHPC/CUDA build:

cp build-nvhpc/lib/libpyminichem_release.so build/lib/libpyminichem_release.so
cp build-nvhpc/lib/libpyminichem_release.so python/lib/libpyminichem_release.so
python -m pip install -e .

After installing the editable package, the CUDA example should run with CUDA tensors:

python examples/minichem.py

For PyPI/release wheels, the Linux cibuildwheel job uses docker.io/luminoctum/manylinux2_28-cuda12.8-nvhpc:2026-04-28. That image already provides CUDA Toolkit and NVIDIA HPC SDK. The release workflow discovers /opt/nvidia/hpc_sdk/Linux_x86_64/<version>/compilers/bin, exports CC=gcc, CXX=g++, FC=nvfortran, and passes those compilers to CMake.

To avoid installing CUDA/NVHPC during every release build, see docs/nvhpc-cuda-manylinux-image.md for instructions to build a manylinux_2_28 image with CUDA Toolkit and NVHPC, then push it to Docker Hub.

Test

Python tests

After installing the editable package:

pytest tests

GPU smoke test

Run the live CUDA test from a directory outside the repo root, so Python imports the editable package instead of treating the top-level pyminichem/ repo directory as a namespace package:

cd /tmp
python - <<'PY'
import torch
import pyminichem

print('cuda_enabled', pyminichem.cuda_enabled())
print('torch_cuda_available', torch.cuda.is_available())
print('device_count', torch.cuda.device_count())

base_vmr = torch.tensor(
    [[0.0, 0.9975, 0.001074, 0.0, 0.0, 0.0, 0.0, 0.00059024, 0.0, 0.00014159, 0.0, 0.0]],
    dtype=torch.float64,
)

outputs = []
for dev in [0, 1]:
    device = f'cuda:{dev}'
    mc = pyminichem.MiniChem()
    mc.initialize()
    temp = torch.tensor([1500.0], dtype=torch.float64, device=device)
    pres = torch.tensor([1.0e5], dtype=torch.float64, device=device)
    vmr = base_vmr.to(device)
    out = mc.forward(temp, pres, vmr, 60.0)
    torch.cuda.synchronize(dev)
    out_cpu = out.detach().cpu()
    outputs.append(out_cpu)
    print('device', dev, 'out_device', out.device, 'shape', tuple(out.shape))
    print('finite', bool(torch.isfinite(out).all().item()), 'sum', float(out_cpu.sum().item()))

if len(outputs) == 2:
    diff = (outputs[0] - outputs[1]).abs().max().item()
    print('max_abs_diff_between_gpu0_gpu1', diff)
PY

Expected behavior for the current working NVHPC build:

  • cuda_enabled True
  • torch_cuda_available True
  • device_count 2 on this machine
  • finite output tensors on both cuda:0 and cuda:1
  • max_abs_diff_between_gpu0_gpu1 0.0 for the smoke test above

NVIDIA HPC SDK

For the CUDA/OpenACC build, install the NVIDIA HPC SDK from NVIDIA's official Linux x86_64 packages:

  1. Download the SDK tarball from the NVIDIA HPC SDK download page.
  2. Extract the archive.
  3. Run the installer.
  4. Add the compiler bin directory to PATH.

Official references:

  • OpenACC getting started guide: https://docs.nvidia.com/hpc-sdk/archive/25.3/compilers/openacc-gs/index.html
  • NVIDIA HPC SDK download page: https://developer.nvidia.com/hpc-sdk

Typical installation flow:

wget <official-nvhpc-tarball-url>
tar -xpf nvhpc_<version>_Linux_x86_64_cuda_multi.tar.gz
cd nvhpc_<version>_Linux_x86_64_cuda_multi
sudo ./install

The default install location is typically:

/opt/nvidia/hpc_sdk/Linux_x86_64/<version>/compilers/bin

Add the compilers to your shell environment:

export NVHPC=/opt/nvidia/hpc_sdk
export PATH=$NVHPC/Linux_x86_64/<version>/compilers/bin:$PATH

Verify the installation with:

nvfortran --version
nvc++ --version
nvaccelinfo

Notes:

  • Replace <version> with the installed SDK version, for example 25.3.
  • nvaccelinfo is NVIDIA's recommended check that the driver and GPU-facing toolchain are visible.
  • The default /opt installation path usually requires sudo.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

pyminichem-0.2.2-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (31.2 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.27+ x86-64manylinux: glibc 2.28+ x86-64

pyminichem-0.2.2-cp313-cp313-macosx_15_0_arm64.whl (5.9 MB view details)

Uploaded CPython 3.13macOS 15.0+ ARM64

pyminichem-0.2.2-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (31.2 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.27+ x86-64manylinux: glibc 2.28+ x86-64

pyminichem-0.2.2-cp312-cp312-macosx_15_0_arm64.whl (5.9 MB view details)

Uploaded CPython 3.12macOS 15.0+ ARM64

pyminichem-0.2.2-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (31.2 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.27+ x86-64manylinux: glibc 2.28+ x86-64

pyminichem-0.2.2-cp311-cp311-macosx_15_0_arm64.whl (5.9 MB view details)

Uploaded CPython 3.11macOS 15.0+ ARM64

pyminichem-0.2.2-cp310-cp310-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (31.1 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.27+ x86-64manylinux: glibc 2.28+ x86-64

pyminichem-0.2.2-cp310-cp310-macosx_15_0_arm64.whl (5.9 MB view details)

Uploaded CPython 3.10macOS 15.0+ ARM64

File details

Details for the file pyminichem-0.2.2-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for pyminichem-0.2.2-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 8447368d56ce5db98bbf05dc1764c103e2acb38667e6fb53f02bcf2c2cc6a2e8
MD5 b2015e82ccf56b17b936b10f35c4c4d7
BLAKE2b-256 85dbd365b3e175188ddd31edc83dde9cdd37a9126ea36ee43c3497e650831f5c

See more details on using hashes here.

File details

Details for the file pyminichem-0.2.2-cp313-cp313-macosx_15_0_arm64.whl.

File metadata

File hashes

Hashes for pyminichem-0.2.2-cp313-cp313-macosx_15_0_arm64.whl
Algorithm Hash digest
SHA256 35138f3e93c1405c36ca5e7e127a79475532c13bb96e2ce5c1cf7d0651b07cd0
MD5 cfe8052a4f17154536cae337ca6502eb
BLAKE2b-256 45b4a4547807f92651b52a9bf54a05e40689514d2ec16da6cb59c8c4fef4b9b3

See more details on using hashes here.

File details

Details for the file pyminichem-0.2.2-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for pyminichem-0.2.2-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 434085b1eb4a797f205ef8b67514c4eb0ecd588f46aa657e2c547bba0c7d5938
MD5 4860f33eba446a9fdf796e6dda0ef1b4
BLAKE2b-256 c23c01f55c3419e92b6c0a522d7c8eb66161a44c8b56f5ef829a35cf8848dd45

See more details on using hashes here.

File details

Details for the file pyminichem-0.2.2-cp312-cp312-macosx_15_0_arm64.whl.

File metadata

File hashes

Hashes for pyminichem-0.2.2-cp312-cp312-macosx_15_0_arm64.whl
Algorithm Hash digest
SHA256 5247b780e2a33e3613d5ee10c946b1116b3106535d97da60f0bdec0f7ae9f98a
MD5 18c99e954e46093ff905ea87bbdfdbad
BLAKE2b-256 92e01485697ee6bd1faf9bac1c5f9d46d2a2d363105d9b17e5079b90f44b6e8b

See more details on using hashes here.

File details

Details for the file pyminichem-0.2.2-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for pyminichem-0.2.2-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 4a5f58ca607154b0d6683f97f3cfa800f9515b22de45192802a8427f746ba8df
MD5 7fe5b3ac2458ae5a9d29fe5ab4b538e4
BLAKE2b-256 2117cac007e278e5de968e2e4ba084c1598b1fd05d5ebfdd879162c2b570f1c0

See more details on using hashes here.

File details

Details for the file pyminichem-0.2.2-cp311-cp311-macosx_15_0_arm64.whl.

File metadata

File hashes

Hashes for pyminichem-0.2.2-cp311-cp311-macosx_15_0_arm64.whl
Algorithm Hash digest
SHA256 65cdbed146fca42051232ddd0b334b642bb6f5cca2f37d5f0811788d6585a66d
MD5 3805d3c454218c7d26bb7468b52dfbdc
BLAKE2b-256 db48487511e3eba9c360087d956f57a9fb7977e8ccc8dac1638351ef9869cc27

See more details on using hashes here.

File details

Details for the file pyminichem-0.2.2-cp310-cp310-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for pyminichem-0.2.2-cp310-cp310-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 97c12c2eebae78f020a9528b5b4f60e99ea1b27e1abdf9e92b6aaeb64aed0f64
MD5 6e1d967213754877fb442cedae5fcdb3
BLAKE2b-256 131a30c632baa944ee079a83bf0b3c948e2b90bba7ab9e08fba29acad900009a

See more details on using hashes here.

File details

Details for the file pyminichem-0.2.2-cp310-cp310-macosx_15_0_arm64.whl.

File metadata

File hashes

Hashes for pyminichem-0.2.2-cp310-cp310-macosx_15_0_arm64.whl
Algorithm Hash digest
SHA256 3e8f82b8dca1515d49a164e78c6051acc589c86253d038935aeba7ea9f1d2ca1
MD5 8b778c1584f531683c96a8b3e12eddd4
BLAKE2b-256 363da8e063ef462a365a40f3e2e0729044165f3cba029142fbf5be89e9d014ec

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page