Skip to main content

Differentiable FUSE hydrological model with Enzyme AD

Project description

cFUSE - Differentiable FUSE

CI Python Tests

A differentiable implementation of the FUSE hydrological model framework with Enzyme automatic differentiation.

Note cFUSE is in active development

Features

  • Differentiable physics: Full gradient computation via Enzyme AD
  • PyTorch integration: Custom autograd function for gradient-based calibration

Quick Start

1. Install Dependencies

# Python dependencies
pip install numpy torch netCDF4 tqdm matplotlib

# macOS: Install LLVM 19 for Enzyme
brew install llvm@19

2. Build Enzyme (one-time setup)

git clone https://github.com/EnzymeAD/Enzyme.git
cd Enzyme && mkdir build && cd build
cmake ../enzyme -DLLVM_DIR=$(brew --prefix llvm@19)/lib/cmake/llvm
make -j
sudo cp Enzyme/ClangEnzyme-19.dylib /opt/homebrew/lib/

3. Build cFUSE

cd cFUSE
mkdir build && cd build
cmake .. -DCMAKE_BUILD_TYPE=Release \
    -DDFUSE_BUILD_PYTHON=ON \
    -DDFUSE_USE_NETCDF=ON \
    -DDFUSE_USE_ENZYME=ON \
    -DCMAKE_CXX_COMPILER=$(brew --prefix llvm@19)/bin/clang++
make -j
cp cfuse_core*.so ../python/

3b. Build Python package with Enzyme + NetCDF (optional)

# Use local Enzyme plugin and enable NetCDF in the build
CMAKE_ARGS="-DDFUSE_USE_ENZYME=ON -DDFUSE_USE_NETCDF=ON -DENZYME_PLUGIN=/path/to/ClangEnzyme-19.dylib" \
    python -m build --no-isolation --skip-dependency-check

4. Run Example Optimization

cd path/to/cFUSE/python
python optimize_basin.py

Command Line Options

python optimize_basin.py --help

# Examples:
python optimize_basin.py --iterations 700          # More iterations
python optimize_basin.py --lr 0.05                 # Lower learning rate
python optimize_basin.py --loss nse                # Optimize NSE instead of KGE
python optimize_basin.py --spinup-days 730         # 2-year spinup

Test Data

Example data is distributed as a release asset starting with v0.4.0. Download the Bow-at-Banff dataset from https://github.com/DarriEy/cFUSE/releases/tag/v0.4.0 and extract it so the path is data/domain_Bow_at_Banff_lumped_era5/ before running examples.

  • Basin: Bow River at Banff (2210 km²)
  • Forcing: ERA5 reanalysis (precipitation, temperature, PET)
  • Observations: Streamflow for validation

Project Structure

cFUSE/
├── data/                    # Downloaded example data (release asset)
├── include/cfuse/          # C++ headers
├── python/
│   ├── optimize_basin.py   # Example optimization script
│   └── cfuse/              # Python package
├── build/                  # Build output
└── README.md

License

MIT License

Acknowledgments

  • Original FUSE: Clark et al. (2008), Water Resources Research
  • Enzyme AD: Moses & Churavy (2020), NeurIPS

Project details


Download files

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

Source Distribution

cfuse-0.4.1.tar.gz (111.5 kB view details)

Uploaded Source

Built Distribution

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

cfuse-0.4.1-cp311-cp311-macosx_14_0_arm64.whl (111.8 kB view details)

Uploaded CPython 3.11macOS 14.0+ ARM64

File details

Details for the file cfuse-0.4.1.tar.gz.

File metadata

  • Download URL: cfuse-0.4.1.tar.gz
  • Upload date:
  • Size: 111.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.14

File hashes

Hashes for cfuse-0.4.1.tar.gz
Algorithm Hash digest
SHA256 09cca078a3fdd8dbc6e5678a2aa0a92fd997b111834ca802ca314f5e8b762813
MD5 0d91d2ee255599716cd624b76c5bd357
BLAKE2b-256 f5bbe156d038329a1df8f8ed7de2d9dd2cd181427d41b08489c961cff69ee59a

See more details on using hashes here.

File details

Details for the file cfuse-0.4.1-cp311-cp311-macosx_14_0_arm64.whl.

File metadata

File hashes

Hashes for cfuse-0.4.1-cp311-cp311-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 69e13787944832dd233b19c7448daee591e1cb5e2989b7e4f12e1bc049986c50
MD5 0329d5fb29d9e5acb6821545f16dd84e
BLAKE2b-256 c6d93f8a58442785e4be9a4e35dd8061d9208bce832f3ce6485c8eb8ead66f04

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