TEMOA (Tools for Energy Model Optimization and Analysis) is a sophisticated energy systems optimization framework that supports various modeling approaches including perfect foresight, myopic planning, uncertainty analysis, and alternative generation.
# Install from PyPI in a virtual environment
python -m venv .venv
# Activate virtual environment
# On Linux/Mac:
source .venv/bin/activate
# On Windows:
.venv\Scripts\activate
# Install temoa
pip install temoaIn a virtual env with temoa installed, run:
# Create tutorial files in the current directory
# Creates tutorial_config.toml and tutorial_database.sqlite
temoa tutorial
# Run the model
temoa run tutorial_config.tomlThe Temoa package is organized into clear modules:
temoa.core- Public API for end users (TemoaModel, TemoaConfig, TemoaMode)temoa.cli- Command-line interface and utilitiestemoa.components- Model components and constraintstemoa.data_io- Data loading and validationtemoa.extensions- Optional extensions for different modeling approachesmodeling_to_generate_alternatives- MGA analysismethod_of_morris- Sensitivity analysismonte_carlo- Uncertainty quantificationmyopic- Sequential decision making
temoa.model_checking- Model validation and integrity checkingtemoa.data_processing- Output analysis and visualizationtemoa.utilities- Helper scripts and migration tools
For users who want to contribute to or modify Temoa should install in development mode using uv:
# Install uv if you haven't already
curl -LsSf https://astral.sh/uv/install.sh | sh
# Clone repository
git clone https://github.com/TemoaProject/temoa.git
cd temoa
# Setup development environment with uv
uv sync --all-extras --dev
# Install pre-commit hooks
uv run pre-commit install
# Run tests
uv run pytest
# Run type checking
uv run mypyTemoa provides a modern, user-friendly CLI built with Typer:
Run a model:
temoa run tutorial_config.toml
temoa run tutorial_config.toml --output results/
temoa run tutorial_config.toml --build-only # Build without solvingValidate configuration:
temoa validate tutorial_config.toml
temoa validate tutorial_config.toml --debugDatabase migration:
temoa migrate old_database.sql --output new_database.sql
temoa migrate old_database.db --type db
temoa migrate old_database.sqlite --output migrated_v4.sqliteGenerate tutorial files:
temoa tutorial # Creates tutorial_config.toml and tutorial_database.sqlite
temoa tutorial my_model my_db # Custom namestemoa --version # Show version information
temoa --how-to-cite # Show citation information
temoa --help # Full helpWhen working with the source code, use uv run to ensure you're using the correct dependencies:
uv run temoa run tutorial_config.toml # Run with project dependencies
uv run temoa validate tutorial_config.toml # Validate configuration
uv run temoa tutorial # Create tutorial filesYou can use Temoa as a Python library:
from logging import getLogger
from pathlib import Path
from temoa._internal.temoa_sequencer import TemoaSequencer
from temoa.core.config import TemoaConfig
from temoa.core.modes import TemoaMode
from temoa.cli import setup_logging
from pyomo.environ import value, check_optimal_termination
output_path = Path('output_files/my_run')
output_path.mkdir(parents=True, exist_ok=True)
setup_logging(output_path, debug=False, silent=False)
logger = getLogger(__name__)
# ======================================================================
# Choose ONE of the following two options for configuring the model run:
# ======================================================================
# OPTION 1: build the config in code
config = TemoaConfig(
scenario='zulu',
scenario_mode=TemoaMode.PERFECT_FORESIGHT,
time_sequencing='seasonal_timeslices',
input_database='tutorial_database.sqlite',
output_database='tutorial_database.sqlite',
solver='appsi_highs',
output_path=output_path,
silent=False,
)
# OPTION 2: load the config from a file
config = TemoaConfig.build_config(
config_file=Path('tutorial_config.toml'),
output_path=output_path,
silent=False,
)
ts = TemoaSequencer(config=config)
ts.start() # TemoaSequencer runs the model and handles results
# Results are saved to your output_database but can also be accessed in code, here
solved_instance = ts.pf_solved_instance # solved Temoa instance with solution values
solver_results = ts.pf_results # information from the solver
# Example code usage of the solved instance and solver results
logger.info(f'Solver results: {solver_results["solver"]}')
if check_optimal_termination(solver_results):
logger.info(f'Model solved! Objective value: {value(solved_instance.total_cost):.2f}')
built_capacity = value(solved_instance.v_new_capacity['utopia', 'E51', 2010])
logger.info(f'Built {built_capacity:.2f} GW of storage in 2010')The fastest way to get started:
temoa tutorialThis creates:
tutorial_config.toml- Configuration file with example settingstutorial_database.sqlite- Sample database for learning
Migration from older versions:
# Migrate from v3.1 to v4
temoa migrate old_database_v3.1.sql --output new_database_v4.sql
# or for SQLite databases
temoa migrate old_database_v4.sqlite --output new_database_v4.sqliteA configuration file is required to run the model. The tutorial command creates a complete example:
scenario = "tutorial"
scenario_mode = "perfect_foresight"
input_database = "tutorial_database.sqlite"
output_database = "tutorial_database.sqlite"
solver = "appsi_highs"| Field | Notes |
|---|---|
| Scenario Name | Name used in output tables (cannot contain '-' symbol) |
| Temoa Mode | Execution mode (PERFECT_FORESIGHT, MYOPIC, MGA, etc.) |
| Input/Output DB | Source and output database paths |
| Price Checking | Run pricing analysis on built model |
| Source Tracing | Verify commodity flow network integrity |
| Plot Network | Generate HTML network visualizations |
| Solver | Solver executable name (appsi_highs, cbc, gurobi, cplex, etc.) |
| Save Excel | Export core output to Excel files |
| Save LP | Save LP model files for external solving |
Solves the entire model at once. Most common mode for optimization.
Sequential solving through iterative builds. Required for stepwise decision analysis.
Explores near cost-optimal solutions for robustness analysis.
Two-solve process focusing on specific variables in the objective.
Limited sensitivity analysis of user-selected variables.
Builds model without solving. Useful for validation and troubleshooting.
-
Setup: Create configuration and database files:
temoa tutorial
-
Configure: Edit the configuration file to match your scenario
-
Validate: Check configuration before running:
temoa validate tutorial_config.toml
-
Run: Execute the model:
temoa run tutorial_config.toml
-
Review: Check results in
output_files/YYYY-MM-DD_HHMMSS/ -
Iterate: Modify configuration and run again
Temoa includes optional extensions for advanced analysis:
- Monte Carlo: Uncertainty quantification
- Stochastic Programming: Scenario-based optimization
- Method of Morris: Sensitivity analysis
- Excel output generation
- Graphviz network visualization
- Interactive network diagrams
- Built-in validation checks
- Commodity flow verification
- Price consistency analysis
TEMOA requires at least one optimization solver:
-
Free: HiGHS
- Included via the
highspyPython package (automatically installed with Temoa) - Default solver for tutorial and testing
- Included via the
-
Free: CBC
- Requires separate installation (see CBC documentation)
- Alternative free solver option
-
Commercial: Gurobi, CPLEX, or Xpress
- Requires separate license and installation
- See individual solver documentation
If you encounter solver errors:
# For commercial solvers (Gurobi, CPLEX)
pip install ".[solver]" # Include specific solver packages
# For free solver
temoa run tutorial_config.toml --debug # Get detailed error information- Full Documentation: Built by following docs/README.md
- API Reference: See
temoa.coremodule for public API - GitHub Issues: Report bugs and request features
- Tutorials: Run
temoa tutorialfor guided examples
For contributors:
- Ruff: Code formatting and linting
- mypy: Type checking
- pytest: Testing framework
- Pre-commit: Automated quality checks
See CONTRIBUTING.md for detailed development guidelines.
If you use Temoa in your research, please cite:
@article{hunter2013modeling,
title={Modeling for insight using Tools for Energy Model Optimization and Analysis (Temoa)},
journal={Energy Economics},
volume={40},
pages={339--349},
year={2013},
doi={10.1016/j.eneco.2013.07.014}
}Or use: temoa --how-to-cite