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 working CUDA path in this repo uses the NVIDIA HPC SDK toolchain:

cmake -S . -B build-nvhpc \
  -DBUILD_TESTS=OFF \
  -DCUDA=ON \
  -DCMAKE_C_COMPILER=nvc \
  -DCMAKE_CXX_COMPILER=nvc++ \
  -DCMAKE_Fortran_COMPILER=nvfortran

cmake --build build-nvhpc -j

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 .

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.1.1-cp313-cp313-manylinux_2_27_x86_64.whl (10.5 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.27+ x86-64

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

Uploaded CPython 3.13macOS 15.0+ ARM64

pyminichem-0.1.1-cp312-cp312-manylinux_2_27_x86_64.whl (10.5 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.27+ x86-64

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

Uploaded CPython 3.12macOS 15.0+ ARM64

pyminichem-0.1.1-cp311-cp311-manylinux_2_27_x86_64.whl (10.5 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.27+ x86-64

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

Uploaded CPython 3.11macOS 15.0+ ARM64

pyminichem-0.1.1-cp310-cp310-manylinux_2_27_x86_64.whl (10.5 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.27+ x86-64

pyminichem-0.1.1-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.1.1-cp313-cp313-manylinux_2_27_x86_64.whl.

File metadata

File hashes

Hashes for pyminichem-0.1.1-cp313-cp313-manylinux_2_27_x86_64.whl
Algorithm Hash digest
SHA256 c5e19ca722135e6b06dea9736376c560fc55698453d91bd8b401f824d8c98f35
MD5 25ff355ef56d9f176522d73a6490be52
BLAKE2b-256 d681f193a698503391160467cc1082e3fdc54ca0e4c0e752045651be3ef3e8d2

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyminichem-0.1.1-cp313-cp313-macosx_15_0_arm64.whl
Algorithm Hash digest
SHA256 0717d4a5ae43e8c00be0242a9b661385aebf018589b0df9e243a42fdcabce8c0
MD5 07c100c0bc2eb073cdfddbcc9348e12c
BLAKE2b-256 eb9fdcd32a8cd19985b018e5a28cb1a87b81597bd460cc0e4dd116090354cbb0

See more details on using hashes here.

File details

Details for the file pyminichem-0.1.1-cp312-cp312-manylinux_2_27_x86_64.whl.

File metadata

File hashes

Hashes for pyminichem-0.1.1-cp312-cp312-manylinux_2_27_x86_64.whl
Algorithm Hash digest
SHA256 2b5283b193d3ee4ddeda4f2562016274fa06d7b1f5a0e3e30e04291ce0a67bbe
MD5 60d5f9877870b66fba3334eacabc9fb4
BLAKE2b-256 805a6975b233e46c347a120a7d2554c1e9a1bb04044a46dab8a8a9ba7ddd7d87

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyminichem-0.1.1-cp312-cp312-macosx_15_0_arm64.whl
Algorithm Hash digest
SHA256 cf704b6ef53d78eb235f06bcc94954021269b32eae825abc3c62b48cb88105e7
MD5 597991745ac6905805089a199927550b
BLAKE2b-256 7333b47ad6830c88a32e6050711f5ff80854da48c97ccbf56390a8b26e9a8227

See more details on using hashes here.

File details

Details for the file pyminichem-0.1.1-cp311-cp311-manylinux_2_27_x86_64.whl.

File metadata

File hashes

Hashes for pyminichem-0.1.1-cp311-cp311-manylinux_2_27_x86_64.whl
Algorithm Hash digest
SHA256 4269d8ccd2a152229c2173a3f9ef830cec608e7b78392b1fdc3b2575900d85f1
MD5 8243220f5cc8fe871200d07df76f66e8
BLAKE2b-256 8b62e9f4f49122c8f8e5820aad37e4bf5ca92ad24221ae32ea0693fb40eb03a5

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyminichem-0.1.1-cp311-cp311-macosx_15_0_arm64.whl
Algorithm Hash digest
SHA256 aa201c10c54bdc80d168d53950b7d64a2c0032b6f97543c1cabccce9aa1e325f
MD5 d14c17b39ea912ae3d656312d2714a46
BLAKE2b-256 a32c74ab85d09cc2532fa6e30048f7f3bb24056d21f1cfb9afa1ccc35cd89f34

See more details on using hashes here.

File details

Details for the file pyminichem-0.1.1-cp310-cp310-manylinux_2_27_x86_64.whl.

File metadata

File hashes

Hashes for pyminichem-0.1.1-cp310-cp310-manylinux_2_27_x86_64.whl
Algorithm Hash digest
SHA256 ca6287642111989158d91832ace0265df2cd7fa260a0f8cc0f9cfc3d95d86169
MD5 d8e276d85452c40556a705d61c2e5589
BLAKE2b-256 bf9f66840ed1f927322fd8f03046d16953805bef959128b6974bf7cbf36cb484

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyminichem-0.1.1-cp310-cp310-macosx_15_0_arm64.whl
Algorithm Hash digest
SHA256 8218e9796a53521a8e3188b9c0004338a77f84f4a5c7495a8635a173c6d9eaa6
MD5 6f1b22bd023f7072126dcdfc272fee1d
BLAKE2b-256 1b980bd7118e6c337b9ccf8d22ea0d950503cab0bdcc8e851fbd906614db7f79

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