Skip to content

Error with optimize_with_rolling_horizon: KeyError: "not all values found in index 'snapshot'. Try setting the method keyword argument (example: method='nearest')." #1454

@thomgeo

Description

@thomgeo

Version Checks (indicate both or one)

  • I have confirmed this bug exists on the lastest release of PyPSA.

  • I have confirmed this bug exists on the current master branch of PyPSA.

Issue Description

Hi everyone, I have found an issue with the rolling horizon functionality if linearized_unit_commitment is set to True and if ramp rates are exceeding 1. Potentially, this is not even a bug, as one might ask why ramp rates larger than 1 would be needed. This is because we use the data as well to model reserves, where you need to assess what level can be provided within, for example, 15 min. There, it can make a difference whether the hourly pu ramp rate is 1 or 2. Maybe it is possible to simply cap the ramp rate at 1 for the calculations, but allow to include higher ones in the n.generator table?

Reproducible Example

import pypsa 

n = pypsa.examples.scigrid_de()
disp = ['Gas', 'Hard Coal',  'Waste', 'Brown Coal', 'Oil', 'Nuclear']
n.generators.loc[n.generators.carrier.isin(disp), "committable"] = True
n.generators.loc[:, "ramp_limit_up"] = 1
n.generators.loc[n.generators.carrier.isin(disp), "ramp_limit_up"] = 1.5
n.optimize.optimize_with_rolling_horizon(solver_name=solver_name, linearized_unit_commitment=True, horizon=12)

Expected Behavior

Rolling horizon solves all horizons after another without crashing

Installed Versions

Details - unicodedata2=17.0.0=py312h4c3975b_0 - unidecode=1.4.0=pyhcf101f3_1 - uri-template=1.3.0=pyhd8ed1ab_1 - uriparser=0.9.8=hac33072_0 - urllib3=2.5.0=pyhd8ed1ab_0 - validators=0.35.0=pyhd8ed1ab_0 - virtualenv=20.35.4=pyhd8ed1ab_0 - wayland=1.24.0=hd6090a7_1 - wcwidth=0.2.14=pyhd8ed1ab_0 - webcolors=25.10.0=pyhd8ed1ab_0 - webencodings=0.5.1=pyhd8ed1ab_3 - websocket-client=1.9.0=pyhd8ed1ab_0 - wheel=0.45.1=pyhd8ed1ab_1 - widgetsnbextension=3.6.10=pyhd8ed1ab_0 - wrapt=1.17.3=py312h4c3975b_1 - xarray=2025.6.1=pyhd8ed1ab_1 - xcb-util=0.4.1=h4f16b4b_2 - xcb-util-cursor=0.1.5=hb9d3cd8_0 - xcb-util-image=0.4.0=hb711507_2 - xcb-util-keysyms=0.4.1=hb711507_0 - xcb-util-renderutil=0.3.10=hb711507_0 - xcb-util-wm=0.4.2=hb711507_0 - xerces-c=3.2.5=h988505b_2 - xkeyboard-config=2.46=hb03c661_0 - xlrd=2.0.2=pyhd8ed1ab_0 - xorg-libice=1.1.2=hb9d3cd8_0 - xorg-libsm=1.2.6=he73a12e_0 - xorg-libx11=1.8.12=h4f16b4b_0 - xorg-libxau=1.0.12=hb9d3cd8_0 - xorg-libxcomposite=0.4.6=hb9d3cd8_2 - xorg-libxcursor=1.2.3=hb9d3cd8_0 - xorg-libxdamage=1.1.6=hb9d3cd8_0 - xorg-libxdmcp=1.1.5=hb9d3cd8_0 - xorg-libxext=1.3.6=hb9d3cd8_0 - xorg-libxfixes=6.0.2=hb03c661_0 - xorg-libxi=1.8.2=hb9d3cd8_0 - xorg-libxinerama=1.1.5=h5888daf_1 - xorg-libxrandr=1.5.4=hb9d3cd8_0 - xorg-libxrender=0.9.12=hb9d3cd8_0 - xorg-libxtst=1.2.5=hb9d3cd8_3 - xorg-libxxf86vm=1.1.6=hb9d3cd8_0 - xorg-xorgproto=2024.1=hb9d3cd8_1 - xyzservices=2025.10.0=pyhd8ed1ab_0 - xz=5.8.1=hbcc6ac9_2 - xz-gpl-tools=5.8.1=hbcc6ac9_2 - xz-tools=5.8.1=hb9d3cd8_2 - yaml=0.2.5=h280c20c_3 - yarl=1.22.0=py312h8a5da7c_0 - yte=1.8.1=pyha770c72_0 - zeromq=4.3.5=h387f397_9 - zict=3.0.0=pyhd8ed1ab_1 - zipp=3.23.0=pyhd8ed1ab_0 - zlib=1.3.1=hb9d3cd8_2 - zlib-ng=2.2.5=hde8ca8f_0 - zstandard=0.25.0=py312h5253ce2_1 - zstd=1.5.7=hb8e6e7a_2 - pip: - oauthlib==3.3.1 - ply==3.11 - pyomo==6.9.5 - requests-oauthlib==1.3.1 - snakemake-storage-plugin-http==0.3.0 - tsam==2.3.9

Metadata

Metadata

Assignees

Labels

needs triageIssue needs initial review by the maintainers

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions