Contributing to GTOpt
Thank you for your interest in contributing to GTOpt! This document provides guidelines and instructions for contributing.
The best way to contribute: join the community
You do not need to write C++ to help GTOpt. The most valuable contributions come from people who use it:
- Join the community. Ask questions, share results and propose ideas in Discussions, in English or Spanish, and follow the GTOpt Community organization for new modules.
- Use GTOpt and its modules in your own studies (the
gtoptcore today, and the observatory, market and regional modules as they are published) and tell us what worked, what was missing and what broke. Bug reports with a small case attached are the fastest way to get something fixed. - Contribute networks for validation, ideally networks of real power systems, with their published results when available. Every real system we can reproduce makes GTOpt more reliable for everyone.
- Share case studies. Expansion plans, hydrothermal studies, storage, emissions or market questions are always welcome, as examples in
cases/or as write-ups in Discussions. - Tell us you use it. Add your organization, group or yourself to
USERS.md.
Code, documentation and tool contributions are of course welcome too; the rest of this guide explains how to make them.
Companies and institutions
Utilities, system operators, regulators, consultancies, universities and research centres can contribute in several ways:
- sharing network models and historical results for validation (confidential data can be handled under a non-disclosure agreement);
- co-developing modules, models or features for their own needs;
- funding development, studies, theses or training;
- piloting GTOpt in their planning or operation processes.
To discuss any of these privately, write to Marcelo Matus at marcelomatusacuna@gmail.com.
Getting Started
- Fork the repository and clone your fork
- Follow the build instructions in BUILDING.md
- Create a feature branch from
master
Development Setup
Prerequisites
- Clang 21 (preferred) or GCC 14+ for C++26 support
- CMake 3.31.6+
- Dependencies listed in BUILDING.md
See BUILDING.md for full dependency installation instructions, including Apache Arrow (APT or conda) and the Clang 21 install script.
Building and Testing
The primary build target is the all/ super-project (library, gtopt binary and tests; not the root CMakeLists.txt):
# Configure and build tests (Clang 21 preferred) cmake -S all -B build \ -DCMAKE_BUILD_TYPE=Debug \ -DCMAKE_C_COMPILER=clang \ -DCMAKE_CXX_COMPILER=clang++ cmake --build build -j$(nproc) # Run all tests cd build && ctest --output-on-failure # Run a specific test (doctest filter syntax) ./build/test/gtoptTests -tc="test name pattern" # Check code formatting cmake --build build --target check-format # Auto-format code cmake --build build --target format
Alternative with GCC 14:
CC=gcc-14 CXX=g++-14 cmake -S all -B build -DCMAKE_BUILD_TYPE=Debug cmake --build build -j$(nproc)
Code Coverage
cmake -S all -B build \ -DENABLE_TEST_COVERAGE=ON \ -DCMAKE_BUILD_TYPE=Debug cmake --build build -j$(nproc) cd build && ctest
Code Style
C++
- Standard: C++26 (
CMAKE_CXX_STANDARD 26). C++23 features are used throughout; adopt C++26 features as Clang 21 / GCC 14 support matures. - Compiler flags:
-Wall -Wpedantic -Wextra -Werror— all warnings are errors. - Formatting: Enforced by
.clang-format(80-char column limit, 2-space indent). The CI reports formatting differences on every pull request. - Linting: Configured via
.clang-tidywith extensive checks enabled. - Naming conventions:
- Classes/Structs:
PascalCase(e.g.LinearProblem,SimulationLP) - Free functions and methods:
snake_case(e.g.add_col,get_optvalue,resolve,annual_discount_factor) - Local variables and public data members:
snake_case - Private class members:
m_prefix +_suffix (e.g.m_simulation_,m_options_) - Macros:
UPPER_CASE
- Classes/Structs:
- Include guards: Use
#pragma once - File headers: Doxygen-style (
@file,@brief,@date,@author,@copyright) - Includes: Three sorted groups —
<std>, external<pkg/header>, project<gtopt/...> - Trailing commas: always on the last element of a brace-initializer list (
Size first_block {0,};) - Error handling: Prefer
std::optionaland return values over exceptions - Modern C++: Use concepts (
requires), ranges,std::format, structured bindings, designated initializers,[[nodiscard]],noexceptwhere appropriate
Python
- Version: Python ≥ 3.10 (CI uses 3.12)
- Formatting:
ruff format(88-char line length, configured inpyproject.toml) - Linting:
ruff check+pylint; see.pylintrc - Type checking:
mypy
cd scripts pip install -e ".[dev]" # install dev dependencies ruff format . && ruff check . pylint --jobs=0 <package> ... # the packages you changed; CI's full list mypy <package> ... --ignore-missing-imports # is in .github/workflows/scripts.yml pytest -n auto
Pre-commit Hooks
The project uses pre-commit hooks for automated checks. Install them with:
pip install pre-commit pre-commit install
Hooks include: trailing whitespace, YAML validation, ruff (lint + format), Pylint, ShellCheck, yamllint, markdownlint, and clang-format (v21).
A separate git hook (.githooks/pre-commit, auto-installed by CMake) also runs clang-format on staged C/C++ files and re-stages them automatically.
CI format check: the
style.ymlworkflow reportsclang-formatandruff formatdifferences as warnings on every pull request. Please run the formatters locally before pushing.
Pull Request Process
- Ensure your changes build and all tests pass
- Run
cmake --build build --target check-formatto verify C++ formatting - Add tests for new functionality in
test/source/test_<topic>.cpp - Update documentation if your changes affect user-facing behavior
- Write clear, descriptive commit messages
- Open a pull request against
masterwith a description of your changes - User-visible changes get a bullet under
## [Unreleased]inCHANGELOG.md; maintainers cut releases as described in docs/releasing.md
Testing Guidelines
- Framework: doctest 2.4.12 for C++ tests
- Place test files in
test/source/(ortest/source/json/for JSON tests); theCONFIGURE_DEPENDSglob picks them up automatically - Use
REQUIREfor fatal assertions andCHECKfor non-fatal ones - Use
doctest::Approxfor all floating-point comparisons - Name test cases and sub-cases descriptively
- Add
// NOLINT(...)inline suppressions for intentional clang-tidy false-positives (e.g.use-after-move,unchecked-optional-access) - Do not add
#define DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN(already intest/source/main.cpp) - When modifying LP assembly code (
*_lp.cpp), run the LP Fingerprint comparison against golden references to verify no variables or constraints were accidentally added, removed, or renamed:gtopt_check_fingerprint compare --actual actual.json --expected golden.json
See the existing tests under test/source/ for the test template and conventions.
Project Structure
gtopt/ ├── include/gtopt/ # Public C++ headers (library API) ├── source/ # C++ implementation files ├── test/source/ # C++ unit tests (doctest) │ └── json/ # JSON-specific tests ├── standalone/source/ # main() for the gtopt binary ├── integration_test/ # CMake helpers for e2e tests ├── cases/ # Sample optimization cases (JSON + Parquet) ├── webservice/ # Next.js web UI + REST API ├── guiservice/ # Python/Flask GUI service ├── scripts/ # Python conversion utilities ├── cmake/ # Upstream CMake modules (CPM, tools) ├── cmake_local/ # Project-specific CMake modules └── documentation/ # Doxygen setup
Domain Context
GTOpt (Generation, Transmission and storage Optimization) optimizes and analyses power-system generation, transmission and storage. Its core problem is Generation and Transmission Expansion Planning (GTEP) with storage, plus hydrothermal scheduling (SDDP/cascade) and unit commitment / dispatch — minimizing total discounted OPEX + CAPEX for a multi-stage, multi-scenario power system model. The solver uses DC power flow (Kirchhoff's voltage law) or a transport model, and is validated against standard IEEE benchmark networks (4-bus, 9-bus, 14-bus).
See docs/formulation/mathematical-formulation.md for the full formulation.
License and Contributor License Agreement
The GTOpt core is dual-licensed (AGPL-3.0-or-later with a solver plugin exception, or a commercial license), and the Extension SDK headers are Apache-2.0; see LICENSING.md. To keep all these options available, every contributor must sign the Contributor License Agreement before a pull request can be merged. You keep the copyright of your contribution; the CLA Assistant bot asks you to sign on your first pull request.
All changes go through a pull request and are reviewed by the maintainer (see .github/CODEOWNERS).