Python, Optimization, Linopy, Power Systems
pypsa_canada is a workflow-based modeling framework for power system analysis in Canada, built on top of PyPSA (Python for Power System Analysis). This tool enables comprehensive energy system optimization and planning for Canadian electricity grids.
Key Features:
- Scenario-based modeling: Define and run multiple power system scenarios with customizable configurations
- Multi-temporal analysis: Support for both long-term planning and operational dispatch modeling
- Representative days: Efficient modeling using representative time periods to reduce computational complexity
- Flexible network modeling: Model power systems at various spatial scales (national, provincial, regional)
- Component integration: Handle diverse energy system components including generators, storage units, loads, and transmission links
- Cost optimization: Incorporate detailed capital, operational, and fuel cost data with multiple cost scenarios
- Constraint management: Apply custom constraints including capacity limits, emission targets, and policy requirements
- Workflow automation: Snakemake-based pipeline for reproducible and scalable analysis
This framework has been applied to analyze Canadian power system scenarios including the Atlantic Loop initiative and Saskatchewan grid integration.
pypsa_canada provides a command-line interface to run power system optimization workflows. The tool processes scenario configuration files (YAML) and executes a series of automated tasks including network creation, data loading, constraint application, and optimization solving.
The typical workflow involves:
- Prepare input data: Network components (buses, generators, loads, etc.), cost data, and constraints
- Define scenario: Create a YAML configuration file specifying model parameters and assumptions
- Run optimization: Execute the workflow using the CLI
- Analyze results: Review outputs including optimal dispatch, capacity expansion, and system costs
Run a scenario with:
pypsa_canada run -f config/[your-scenario].yamlAvailable example scenarios in the example/scenarios/ directory:
minimal_model.yaml: Minimal network used for testing purposes
- Unlock stale workflows: If a previous run was interrupted, unlock with:
pypsa_canada run -f scenarios/[scenario].yaml --unlock
- View workflow graph: Visualize the computational workflow (requires additional setup by installing graphviz)
pypsa_canada dag -f scenarios/[scenario].yaml
data/: Input data including network components, costs, and constraintsconfig/: YAML configuration files defining model scenariosressources/: Intermediate network files generated during workflowresults/: Optimization results and outputs
Before starting the installation process: 0. Clone the following project/library pypsa_canada: For GitHub users:
$ git clone https://github.com/NRCan/pypsa-canada.gitFor NRCAN internal users:
$ git clone https://nrcan-eets-cev-renouvelable-devops@dev.azure.com/nrcan-eets-cev-renouvelable-devops/Canadian_Scenarios_Analysis/_git/pypsa_canada- Create the virtual environment with either Conda or Python with Python 3.11
1-a) **For Anaconda/Miniconda users only, create a virtual environment with the following command:
$(base) conda create --name pypsa_cad_p312 python=3.12.101-b) **For Python users only, assuming you have a Python 3.12 installed, execute the following command to create a new virtual environment:
$(base) python -m venv pypsa_cad_p3121-b) Proceed to activate the environment
- Go into the project folder
(env) >> cd [PROJECT_DIR]- Install the package/library:
(pypsa-cad_py312) >> pip install -e .[dev]Following these steps, most dependencies should be installed and you should be able to use pypsa_canada
- Go into the project folder
(env) >> cd [ROOT_DIR]/example- To execute an example
(pypsa-cad_py312) >> pypsa_canada run -f scenarios\Canada-National-no-CER.yaml- If the process is stale, you will need to unlock it with the following command
(pypsa-cad_py312) >> pypsa_canada run -f scenarios\Canada-National-no-CER.yaml --unlockPre-commit hooks are used within this project. The pre-commit hooks will be enforced through a pipeline during the pull request (PR). If it fails, the PR will be rejected. To validate if your changes are meeting the minimum standard, you should execute the following. If there are any issues, resolve them and commit again.
(pypsa-canada_py312) >> pre-commit run --all-files --hook-stage manualPyPSA MIT License : https://github.com/PyPSA/PyPSA/blob/master/LICENSE.txt pypsa-eur License: https://github.com/PyPSA/pypsa-eur/tree/master/LICENSES
Copyright CanmetENERGY - Varennes, NRCan, Goverment of Canada
- Steven Wong (Natural Resources Canada - CanmetENERGY)
- Nathan De Matos (Natural Resources Canada - CanmetENERGY)
- Michel Bui (Natural Resources Canada - CanmetENERGY)
- Sophie Pelland (Natural Resources Canada - CanmetENERGY)
- Matheus Zambroni De Souza (Natural Resources Canada - CanmetENERGY)
- Adrien Prigent (Natural Resources Canada - CanmetENERGY)
- Serban Ivanescu (Natural Resources Canada - CanmetENERGY)
- Steven Wong (steven.wong@nrcan-rncan.gc.ca)
- Nathan De Matos (nathan.dematos@nrcan-rncan.gc.ca)
- Michel Bui (michel.bui@nrcan-rncan.gc.ca)
- Sophie Pelland (sophie.pelland@nrcan-rncan.gc.ca)
- Adrien Prigent (adrien.prigent@nrcan-rncan.gc.ca)
- Serban Ivanescu (serban.ivanescu@nrcan-rncan.gc.ca)