Skip to content

Latest commit

 

History

History
254 lines (183 loc) · 9.86 KB

CONTRIBUTING.md

File metadata and controls

254 lines (183 loc) · 9.86 KB

Contributing to GridFM

Thank you for your interest in contributing to GridFM. This document explains our contribution process and procedures:

For a description of the roles and responsibilities of the various members of the GridFM community, see the governance policies, and for further details, see the project's Technical Charter. Briefly, Contributors are anyone who submits content to the project, Committers review and approve such submissions, and the Technical Steering Committee provides general project oversight.

If you just need help or have a question, refer to SUPPORT.md.

Scope: What Belongs in This Repository

gridfm-graphkit is a library for training, finetuning, and interacting with a foundation model for the electric power grid. Contributions that extend or improve this core belong here — for example:

  • Model architectures, layers, and loss functions.
  • Training, finetuning, and evaluation logic.
  • Data loading, transforms, and shared utilities.
  • Bug fixes, performance improvements, tests, and documentation for the above.

Application-specific contributions belong in a companion GridFM applications repository, not here. If your contribution is an end-to-end application, a deployment, or a pipeline/notebook/experiment tied to one specific use case or study, please contribute it to the relevant GridFM applications repository instead of adding it to the core library. Keeping application-specific code out of the core keeps this library focused, broadly reusable, and free of use-case-specific dependencies.

If you are unsure whether a contribution is "core" or "application-specific", open an issue to discuss it before starting work.

How to Contribute a Bug Fix or Change

To contribute code to the project, first read over the governance policies page to understand the roles involved.

Each contribution must meet the PEP 8 and include..

GridFM is licensed under the Apache 2.0 license. Contributions should abide by that standard license.

Project committers will review the contribution in a timely manner, and advise of any changes needed to merge the request.

Running the Integration Tests

The integration tests in integrationtests/ assert that training metrics fall within calibrated bounds. These bounds are machine-specific (they depend on your CPU/GPU, CUDA, and library versions), so the baseline (integrationtests/calibration_baseline.json) is not committed — it is git-ignored and you calibrate your own on your machine first.

Prerequisite. The tests train through MLflow; if you don't have an MLflow tracking server, opt into the local file store first:

export MLFLOW_ALLOW_FILE_STORE=true

Calibrate before you change any code. Run the calibration on a clean checkout so the recorded bounds reflect the current behaviour, then make your changes and run the tests to detect any drift they introduce:

  1. On an unchanged checkout, calibrate a baseline on this machine:

    pytest integrationtests --calibrate -s

    This runs training 5 times and writes per-metric bounds (plus a per-test environment fingerprint) to integrationtests/calibration_baseline.json.

  2. Make your code changes.

  3. Run the integration tests (no --calibrate) to assert against the baseline you calibrated in step 1:

    pytest integrationtests -s

If you calibrate after changing the code, the baseline will simply encode your changed behaviour and the tests can no longer catch regressions — always calibrate on the unchanged code first.

Calibration options

Passed to pytest:

Flag When omitted Meaning
--calibrate [N] assert mode (train once, check bounds) --calibrate alone → 5 calibration runs; --calibrate N → N runs. Both write bounds and skip assertions.
--ci C 0.995 Confidence level for the Student-t interval (calibration mode only).
--pad P 0.01 Relative floor on each bound's half-width (`P *

If the environment fingerprint doesn't match

Calibrated bounds depend on your hardware (CPU/GPU), CUDA/cuDNN, and library versions (notably the PyTorch version), so each test's bounds are stamped with their own environment fingerprint under fingerprints in the baseline. When you run the assertion tests, a fingerprint that differs from the one recorded for that test emits a loud warning but does not fail the run — it lists every differing field.

A mismatch means the recorded bounds may not hold in your current environment (for example, after a PyTorch upgrade the metrics can shift). When you see this warning, recalibrate on the unchanged code in your current environment before trusting the assertions:

export MLFLOW_ALLOW_FILE_STORE=true
pytest integrationtests --calibrate -s

Contribution Checklist ✅

Before opening a PR, make sure you complete all steps:

1. Development setup

  • Install dev, test, and torch-scatter dependencies.

    torch-scatter is not on PyPI — it needs a prebuilt wheel from data.pyg.org that matches both your PyTorch version and your compute backend. Pick the right CUDA_TAG from the table below:

    Hardware CUDA_TAG
    CPU only cpu
    CUDA 11.8 cu118
    CUDA 12.1 cu121
    CUDA 12.6 cu126

    Not sure which tag to use? If you don't have an NVIDIA GPU (including Apple Silicon and CPU-only machines), use cpu. For NVIDIA GPUs, check your CUDA version with nvidia-smi (top-right corner) or nvcc --version.

    Replace <CUDA_TAG> in the command below:

    pip does not read [tool.uv] find-links in pyproject.toml. Pass the index yourself, and pin torch==2.12.* in the same command. That matches the package pin torch>=2.10,<2.13 and the wheel index below.

    pip install -e ".[dev,test]" "torch==2.12.*" \
        --find-links https://data.pyg.org/whl/torch-2.12.0+<CUDA_TAG>.html

    For example, CPU-only:

    pip install -e ".[dev,test]" "torch==2.12.*" \
        --find-links https://data.pyg.org/whl/torch-2.12.0+cpu.html

    Or CUDA 12.6:

    pip install -e ".[dev,test]" "torch==2.12.*" \
        --find-links https://data.pyg.org/whl/torch-2.12.0+cu126.html

    Note: The PyTorch version (2.12.0) in the URL must match what is installed. If you change the torch pin in pyproject.toml, update this URL and regenerate the lock file with uv lock.

    No prebuilt wheel for your combination? If data.pyg.org has no prebuilt wheel for your combination, build from source instead. This compiles against the installed torch. Stay inside the package pin torch>=2.10,<2.13, and install torch first:

    pip install torch==2.12.0
    pip install torch-scatter torch-sparse --no-build-isolation

    Building from source requires a C++ compiler (and a matching CUDA toolkit with nvcc for GPU builds).

  • Install the git hooks (this repo runs pre-commit hooks at the pre-push stage):

    pre-commit install
    
  • Create a new branch for your feature from main.

2. Code quality

  • Write clear, readable code with self-explanatory variable names.
  • Comment code where needed.
  • Prefer the clearest implementation if multiple options have similar complexity.

3. Code style & documentation

  • Add Google-style Python docstrings for all functions/classes.
  • Double-check that no debug prints or temporary files are left in the code.
  • Update documentation and README.md whenever relevant.

4. Configuration & dependencies

  • Add any new dependencies to pyproject.toml.

  • If introducing new parameters, update all relevant YAML files:

    • examples/config
    • tests/config

5. Testing

  • Ask your favorite code assistant to identify bugs and edge cases.

  • Add unit tests covering:

    • Core functionality of your changes.
    • Potential edge cases.
  • Run all tests:

    MLFLOW_ALLOW_FILE_STORE=true pytest tests/
  • Run integration tests, see Running the Integration Tests.

6. Pre-commit & linting

The hooks run automatically on git push. To run them manually before pushing:

  • Run the hooks on all files:

    pre-commit run --all-files
  • Fix any issues.

  • Re-run the hooks after any code changes.

7. Documentation build

  • Build docs and check rendering:

    mkdocs build
    mkdocs serve

8. Pull request

  • Rebase your branch onto the latest main before opening a PR.
  • Sign off all commits with the Developer Certificate of Origin (git commit -s). See Developer Certificate of Origin signoff.
  • Open a PR with a short description of your changes.
  • Ensure code, tests, and documentation are clear and complete.