Skip to main content

JAX translation of CLM-ML (Community Land Model with Multi-Layer Canopy)

Project description

CLM-ML-JAX: Community Land Model with Multi-Layer Canopy in JAX

CI codecov Python 3.9+ JAX License: BSD-3

A complete JAX/Python translation of the Community Land Model (CLM) Multi-Layer Canopy physics, enabling GPU acceleration

Reference CLM-ML in Fortran: CLM-ML_v2.CHATS

Features

  • Full Fortran→Python/JAX translation maintaining scientific accuracy
  • Tower-site offline driver for point-scale simulations with prescribed meteorology
  • GPU-accelerated physics through JAX JIT compilation
  • Vectorization with vmap for ensemble and sensitivity analyses
  • Namelist-driven configuration (mirrors Fortran interface)
  • Modular architecture

Installation

# 1. Clone and navigate to repository
git clone https://github.com/AyaLahlou/clm-ml-jax.git
cd clm-ml-jax

# 2. Install package and dependencies
pip install -e .

# 3. Verify installation
clm-ml-offline --help

This installs the clm-ml-offline command and all physics modules (clm_share, clm_src_*, multilayer_canopy, etc.).


Run a Simulation

Execute a 1-day tower-site simulation with the CHATS7 site:

# Or with explicit namelist argument  
clm-ml-offline src/offline_executable/nl.CHATS7.1day

# Or run directly with Python
python -m src.offline_executable.main input_files/nl.CHATS7.1day

Output files are written to the output_files/ directory.


Validation Tests

We compare every JAX routine against golden reference values of the Fortran build:

/path/to/conda/envs/clm-ml-jax/bin/python -m pytest tests/fortran_validation/ -q

Golden JSON files live in tests/fortran_validation/golden_IO/.


Development

Adding a New Physics Module

  1. Create multilayer_canopy/MyPhysicsMod.py mirroring Fortran module structure
  2. Include Fortran source reference in docstring (if applicable).
  3. Use module-level globals from MLclm_varctl.py for configuration
  4. Add tests in tests/multilayer_canopy/test_my_physics.py

Adding a New Tower Site

Edit offline_driver/TowerDataMod.py:

ntower = 16  # Increment from 15

# Extend all arrays by one element
tower_id[16] = 'MYNEWSITE'
tower_lon[16] = -120.5
tower_lat[16] = 38.2
tower_elev[16] = 500.0
# ... (add other fields)

Then create a namelist file: src/offline_executable/nl.MYNEWSITE.date

Configuration & Switches

Global physics switches are in multilayer_canopy/MLclm_varctl.py—change directly, no config object needed:

gs_type = 0              # Stomatal model: 0=Medlyn, 1=Ball-Berry, 2=WUE
flux_profile_type = 1    # Flux-profile: -1=dataset, 0=well-mixed, 1=implicit
runge_kutta_type = 41    # Time integration: 10=Euler, 21=2nd-order, 41=4th-order
dtime_ml = 60.0          # Sub-step interval (s); must divide CLM timestep

Contributing

Contributions are welcome! Here's how you can help:

  1. Report Bugs: Open an issue with reproduction steps
  2. Suggest Features: Open an issue with use case description
  3. Submit PRs: Fork, create feature branch, submit PR
  4. Improve Docs: Documentation improvements are always welcome

Code of Conduct

  • Be respectful and inclusive
  • Provide constructive feedback
  • Focus on improving the project

Citation

@software{clm_ml_jax,
  title={CLM-ML-JAX: Community Land Model with Multi-Layer Canopy in JAX},
  author={Lahlou, Aya},
  year={2024},
  url={https://github.com/AyaLahlou/clm-ml-jax},
  note={JAX translation of CTSM CLM-ML}
}

License

This project is licensed under the BSD-3-Clause License. See LICENSE for details.


If this helps your research, please star the repository!

🐛 Found a bug? Please open an issue

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

clm_ml_jax-0.1.0.tar.gz (428.1 kB view details)

Uploaded Source

Built Distribution

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

clm_ml_jax-0.1.0-py3-none-any.whl (465.6 kB view details)

Uploaded Python 3

File details

Details for the file clm_ml_jax-0.1.0.tar.gz.

File metadata

  • Download URL: clm_ml_jax-0.1.0.tar.gz
  • Upload date:
  • Size: 428.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.15

File hashes

Hashes for clm_ml_jax-0.1.0.tar.gz
Algorithm Hash digest
SHA256 ef2fdcb054f0968a4007acc6a23b4a94736b6e28bb986e9b89c3fc1865952bc1
MD5 d57d2aae61a2fc8a7ea48c5973b03724
BLAKE2b-256 44457c4a74d4037e4dadd93461ed4a4b127dbc3c94fc8fba7dfeba72a4bec9bd

See more details on using hashes here.

File details

Details for the file clm_ml_jax-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: clm_ml_jax-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 465.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.15

File hashes

Hashes for clm_ml_jax-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 f5254e7bad203780f818e7d6e08b65128b35af7187e183406cd52013a1669df9
MD5 ccf68337ae818438b1290b926366782f
BLAKE2b-256 8978c1968dcf6e239d7f1961edadeb51e893717c23bbbb212feef7c22db03818

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