Post · 20 min read· pp. 537–555

Transport Delay

Multiport components as Links and Processes can model time-delayed energy transport via the delay[x] and cyclic_delay[x] attributes where [x] represents the number of the port. This is useful for representing transport delays in pipelines, shipping and other transport modes, or any process where energy withdrawn at bus0 arrives at output ports after a configurable time lag.

Unlike links, processes use the convention to enumerate all delay and cyclic_delay attributes, i.e. delay0, delay1, ..., cyclic_delay0, ... Therefore they allows to have a delay at bus0 in reference to the operation of the process p. Links on the other hand follow the convention on always refering to p at bus0. The delay attributes star with delay affecting p1 at bus1 and continue with delay2. This mirrors the convention of the efficiency attribute.

So how do the attributes work?

  • delay: The delay in units of elapsed time, measured against cumulative n.snapshot_weightings.generators. Energy withdrawn from bus0 at snapshot t arrives at bus1 at the first snapshot where the cumulative weighting since t reaches at least delay. For example, with uniform hourly snapshots (weightings = 1), delay=3 means a 3-hour delay. With 3-hourly snapshots (weightings = 3), the same delay=3 shifts delivery by one snapshot.
  • cyclic_delay: If True (default), energy wraps cyclically from the end of the optimization horizon back to the start — energy sent in the last snapshots arrives at the first snapshots. If False, energy is lost at the tail of the horizon and the first snapshots receive nothing from delayed links.
  • Multi-port delays: Each output port can have its own delay. For additional ports (bus2, bus3, ...), use delay2, delay3, ... and cyclic_delay2, cyclic_delay3, ....

This deep-dive example demonstrates time-delayed energy transport through Link components. Note that the exact same behavior could be reproduced by using the Process component aligning the attributes as described above. For a more basic introduction to delays in the context of chained reservoirs, see the Chained Hydro-Reservoirs example.

Setup

We set up a simple two-bus system: a production site with cheap generation connected to a demand site via a delayed link representing a hydrogen pipeline.

In [2]:

Copied! diagram

ipynb
import matplotlib.pyplot as plt
import pandas as pd

import pypsa

n = pypsa.Network()
n.set_snapshots(range(8))

n.add("Bus", "production")
n.add("Bus", "demand")

n.add("Generator", "wind", bus="production", p_nom=100, marginal_cost=5)
n.add("Generator", "backup", bus="demand", p_nom=100, marginal_cost=80)
n.add("Load", "load", bus="demand", p_set=[10, 30, 50, 20, 40, 60, 25, 15])
n.sanitize()

import matplotlib.pyplot as plt import pandas as pd import pypsa n = pypsa.Network() n.set_snapshots(range(8)) n.add("Bus", "production") n.add("Bus", "demand") n.add("Generator", "wind", bus="production", p_nom=100, marginal_cost=5) n.add("Generator", "backup", bus="demand", p_nom=100, marginal_cost=80) n.add("Load", "load", bus="demand", p_set=[10, 30, 50, 20, 40, 60, 25, 15]) n.sanitize()

text
/tmp/ipykernel_9140/376786051.py:6: PyPSA2Warning: pandas reads strings as `str` dtype since 3.0. PyPSA converts them back to object dtype on import, but keeps `str` from PyPSA 2.0 on. Set `pypsa.options.future.string_dtype` to True to opt in now or to False to keep the current behaviour.
  n = pypsa.Network()
INFO:pypsa.consistency:Sanitizing network...
text
INFO:pypsa.components._types.carriers:Adding 1 missing carriers: ['AC']
text
INFO:pypsa.components._types.carriers:Assigned colors to 1 carriers using 'tab10' palette.
text
INFO:pypsa.consistency:Network sanitization complete.

Cyclic Delay

With cyclic_delay=True (the default), energy wraps around from the end of the optimization horizon to the start. The link has a 2-snapshot delivery delay and 95% efficiency.

In [3]:

Copied! diagram

ipynb
n.add(
    "Link",
    "pipeline",
    bus0="production",
    bus1="demand",
    p_nom=100,
    efficiency=0.95,
    delay=2,
    cyclic_delay=True,
)

n.optimize();

n.add( "Link", "pipeline", bus0="production", bus1="demand", p_nom=100, efficiency=0.95, delay=2, cyclic_delay=True, ) n.optimize();

text
/tmp/ipykernel_9140/753904955.py:12: PyPSA2Warning: From PyPSA 2.0 on, the objective leaves out the capital costs of existing capacity on extendable assets, which improves LP conditioning. Pass `include_objective_constant` to `n.optimize` to choose per call. Set `pypsa.options.future.exclude_objective_constant` to True to opt in now or to False to keep the current behaviour.
  n.optimize();
text
INFO:linopy.model: Solve problem using Gurobi solver
text
INFO:linopy.model:Solver options:
 - log_to_console: False
text
INFO:linopy.io: Writing time: 0.03s
text
Set parameter WLSAccessID
text
Set parameter WLSSecret
text
Set parameter LicenseID to value 2537914
text
Academic license 2537914 - for non-commercial use only - registered to l.___@tu-berlin.de
text
Read LP format model from file /tmp/linopy-problem-pww6b101.lp
text
Reading time = 0.00 seconds
text
obj: 64 rows, 24 columns, 80 nonzeros
text
Set parameter LogToConsole to value 0
text
INFO:linopy.constants: Optimization successful: 
Status: ok
Termination condition: optimal
Solution: 24 primals, 64 duals
Objective: 1.32e+03
Solver: gurobi
Runtime: 0.00s
Dual bound: 1.32e+03
Solver model: available
Solver message: 2
text
INFO:pypsa.optimization.optimize:The shadow-prices of the constraints Generator-fix-p-lower, Generator-fix-p-upper, Link-fix-p-lower, Link-fix-p-upper were not assigned to the network.

The output power p1 is a time-shifted version of the input p0, scaled by the efficiency.

In [4]:

Copied! diagram

ipynb
fig, axes = plt.subplots(1, 2, figsize=(12, 4), sharey=True)
colors = [f"C{i}" for i in range(8)]
delay = 2
p0_colors = colors
p1_colors = colors[-delay:] + colors[:-delay]
n.links_t.p0["pipeline"].plot.bar(
    ax=axes[0], title="Input (p0 at production)", color=p0_colors
)
(-n.links_t.p1["pipeline"]).plot.bar(
    ax=axes[1], title="Output (-p1 at demand)", color=p1_colors
)
for ax in axes:
    ax.set_ylabel("MW")
plt.tight_layout()

fig, axes = plt.subplots(1, 2, figsize=(12, 4), sharey=True) colors = [f"C{i}" for i in range(8)] delay = 2 p0_colors = colors p1_colors = colors[-delay:] + colors[:-delay] n.links_t.p0["pipeline"].plot.bar( ax=axes[0], title="Input (p0 at production)", color=p0_colors ) (-n.links_t.p1["pipeline"]).plot.bar( ax=axes[1], title="Output (-p1 at demand)", color=p1_colors ) for ax in axes: ax.set_ylabel("MW") plt.tight_layout()

No description has been provided for this image

Non-Cyclic Delay

With cyclic_delay=False, the first snapshots receive no flow from the link (nothing was sent early enough to arrive), and energy sent in the last snapshots is lost (it would arrive beyond the horizon).

In [5]:

Copied! diagram

ipynb
n.links.loc["pipeline", "cyclic_delay"] = False

n.optimize();

n.links.loc["pipeline", "cyclic_delay"] = False n.optimize();

text
INFO:linopy.model: Solve problem using Gurobi solver
text
INFO:linopy.model:Solver options:
 - log_to_console: False
text
INFO:linopy.io: Writing time: 0.03s
text
Set parameter WLSAccessID
text
Set parameter WLSSecret
text
Set parameter LicenseID to value 2537914
text
Academic license 2537914 - for non-commercial use only - registered to l.___@tu-berlin.de
text
Read LP format model from file /tmp/linopy-problem-njdd_d9p.lp
text
Reading time = 0.00 seconds
text
obj: 64 rows, 24 columns, 78 nonzeros
text
Set parameter LogToConsole to value 0
text
INFO:linopy.constants: Optimization successful: 
Status: ok
Termination condition: optimal
Solution: 24 primals, 64 duals
Objective: 4.31e+03
Solver: gurobi
Runtime: 0.00s
Dual bound: 4.31e+03
Solver model: available
Solver message: 2
text
INFO:pypsa.optimization.optimize:The shadow-prices of the constraints Generator-fix-p-lower, Generator-fix-p-upper, Link-fix-p-lower, Link-fix-p-upper were not assigned to the network.

In [6]:

Copied! diagram

ipynb
fig, axes = plt.subplots(1, 2, figsize=(12, 4), sharey=True)
colors = [f"C{i}" for i in range(8)]
delay = 2
gray = "lightgray"
p0_colors = colors[: len(colors) - delay] + [gray] * delay
p1_colors = [gray] * delay + colors[: len(colors) - delay]
n.links_t.p0["pipeline"].plot.bar(
    ax=axes[0], title="Input (p0 at production)", color=p0_colors
)
(-n.links_t.p1["pipeline"]).plot.bar(
    ax=axes[1], title="Output (-p1 at demand)", color=p1_colors
)
for ax in axes:
    ax.set_ylabel("MW")
plt.tight_layout()

fig, axes = plt.subplots(1, 2, figsize=(12, 4), sharey=True) colors = [f"C{i}" for i in range(8)] delay = 2 gray = "lightgray" p0_colors = colors[: len(colors) - delay] + [gray] * delay p1_colors = [gray] * delay + colors[: len(colors) - delay] n.links_t.p0["pipeline"].plot.bar( ax=axes[0], title="Input (p0 at production)", color=p0_colors ) (-n.links_t.p1["pipeline"]).plot.bar( ax=axes[1], title="Output (-p1 at demand)", color=p1_colors ) for ax in axes: ax.set_ylabel("MW") plt.tight_layout()

No description has been provided for this image

Notice that p1 is zero for the first 2 snapshots and p0 drops to zero for the last 2 snapshots.

Multi-Port Delay

Each output port can have its own delay. Here we add a third bus representing a branch pipeline with a longer delay.

In [7]:

Copied! diagram

ipynb
n.remove("Link", "pipeline")

n.add("Bus", "demand2")
n.add("Generator", "backup2", bus="demand2", p_nom=100, marginal_cost=80)
n.add("Load", "load2", bus="demand2", p_set=[5, 15, 25, 10, 20, 30, 12, 8])

n.add(
    "Link",
    "pipeline",
    bus0="production",
    bus1="demand",
    bus2="demand2",
    p_nom=100,
    efficiency=0.95,
    efficiency2=0.90,
    delay=2,
    delay2=4,
    cyclic_delay=True,
    cyclic_delay2=True,
)

n.optimize();

n.remove("Link", "pipeline") n.add("Bus", "demand2") n.add("Generator", "backup2", bus="demand2", p_nom=100, marginal_cost=80) n.add("Load", "load2", bus="demand2", p_set=[5, 15, 25, 10, 20, 30, 12, 8]) n.add( "Link", "pipeline", bus0="production", bus1="demand", bus2="demand2", p_nom=100, efficiency=0.95, efficiency2=0.90, delay=2, delay2=4, cyclic_delay=True, cyclic_delay2=True, ) n.optimize();

text
Warning: environment still referenced so free is deferred (Continue to use WLS)
text
INFO:linopy.model: Solve problem using Gurobi solver
text
INFO:linopy.model:Solver options:
 - log_to_console: False
text
INFO:linopy.io: Writing time: 0.02s
text
Set parameter WLSAccessID
text
Set parameter WLSSecret
text
Set parameter LicenseID to value 2537914
text
Academic license 2537914 - for non-commercial use only - registered to l.___@tu-berlin.de
text
Read LP format model from file /tmp/linopy-problem-ek7wg5nu.lp
text
Reading time = 0.00 seconds
text
obj: 88 rows, 32 columns, 112 nonzeros
text
Set parameter LogToConsole to value 0
text
INFO:linopy.constants: Optimization successful: 
Status: ok
Termination condition: optimal
Solution: 32 primals, 88 duals
Objective: 1.45e+04
Solver: gurobi
Runtime: 0.00s
Dual bound: 1.45e+04
Solver model: available
Solver message: 2
text
INFO:pypsa.optimization.optimize:The shadow-prices of the constraints Generator-fix-p-lower, Generator-fix-p-upper, Link-fix-p-lower, Link-fix-p-upper were not assigned to the network.

In [8]:

Copied! diagram

ipynb
fig, axes = plt.subplots(1, 3, figsize=(15, 4), sharey=True)
colors = [f"C{i}" for i in range(8)]
p0_colors = colors
p1_colors = colors[-2:] + colors[:-2]
p2_colors = colors[-4:] + colors[:-4]
n.links_t.p0["pipeline"].plot.bar(ax=axes[0], title="Input (p0)", color=p0_colors)
(-n.links_t.p1["pipeline"]).plot.bar(
    ax=axes[1], title="Output bus1 (-p1, delay=2)", color=p1_colors
)
(-n.links_t.p2["pipeline"]).plot.bar(
    ax=axes[2], title="Output bus2 (-p2, delay=4)", color=p2_colors
)
for ax in axes:
    ax.set_ylabel("MW")
plt.tight_layout()

fig, axes = plt.subplots(1, 3, figsize=(15, 4), sharey=True) colors = [f"C{i}" for i in range(8)] p0_colors = colors p1_colors = colors[-2:] + colors[:-2] p2_colors = colors[-4:] + colors[:-4] n.links_t.p0["pipeline"].plot.bar(ax=axes[0], title="Input (p0)", color=p0_colors) (-n.links_t.p1["pipeline"]).plot.bar( ax=axes[1], title="Output bus1 (-p1, delay=2)", color=p1_colors ) (-n.links_t.p2["pipeline"]).plot.bar( ax=axes[2], title="Output bus2 (-p2, delay=4)", color=p2_colors ) for ax in axes: ax.set_ylabel("MW") plt.tight_layout()

No description has been provided for this image

Non-Uniform Snapshot Weightings

The delay is interpreted in snapshot_weightings.generators time units, not snapshot counts. With non-uniform weightings, the same delay value can shift by different numbers of snapshots.

In [9]:

Copied! diagram

ipynb
n.remove("Link", "pipeline")
n.remove("Bus", "demand2")
n.remove("Generator", "backup2")
n.remove("Load", "load2")

n.snapshot_weightings.loc[:, "generators"] = [1, 2, 1, 2, 1, 2, 1, 2]

n.add(
    "Link",
    "pipeline",
    bus0="production",
    bus1="demand",
    p_nom=100,
    efficiency=0.95,
    delay=3,
    cyclic_delay=True,
)

n.optimize();

n.remove("Link", "pipeline") n.remove("Bus", "demand2") n.remove("Generator", "backup2") n.remove("Load", "load2") n.snapshot_weightings.loc[:, "generators"] = [1, 2, 1, 2, 1, 2, 1, 2] n.add( "Link", "pipeline", bus0="production", bus1="demand", p_nom=100, efficiency=0.95, delay=3, cyclic_delay=True, ) n.optimize();

text
INFO:linopy.model: Solve problem using Gurobi solver
text
INFO:linopy.model:Solver options:
 - log_to_console: False
text
INFO:linopy.io: Writing time: 0.02s
text
Set parameter WLSAccessID
text
Set parameter WLSSecret
text
Set parameter LicenseID to value 2537914
text
Academic license 2537914 - for non-commercial use only - registered to l.___@tu-berlin.de
text
Read LP format model from file /tmp/linopy-problem-ewvjl6dg.lp
text
Reading time = 0.00 seconds
text
obj: 64 rows, 24 columns, 80 nonzeros
text
Set parameter LogToConsole to value 0
text
INFO:linopy.constants: Optimization successful: 
Status: ok
Termination condition: optimal
Solution: 24 primals, 64 duals
Objective: 1.32e+03
Solver: gurobi
Runtime: 0.00s
Dual bound: 1.32e+03
Solver model: available
Solver message: 2
text
INFO:pypsa.optimization.optimize:The shadow-prices of the constraints Generator-fix-p-lower, Generator-fix-p-upper, Link-fix-p-lower, Link-fix-p-upper were not assigned to the network.

In [10]:

Copied! diagram

ipynb
pd.DataFrame(
    {
        "weighting": n.snapshot_weightings.generators,
        "p0": n.links_t.p0["pipeline"],
        "p1": n.links_t.p1["pipeline"],
    }
)

pd.DataFrame( { "weighting": n.snapshot_weightings.generators, "p0": n.links_t.p0["pipeline"], "p1": n.links_t.p1["pipeline"], } )

Out[10]:

weightingp0p1
snapshot
01.052.631579-10.0
12.021.052632-30.0
21.042.105263-50.0
32.063.157895-20.0
41.026.315789-40.0
52.015.789474-60.0
61.010.526316-25.0
72.031.578947-15.0

In [11]:

Copied! diagram

ipynb
from pypsa.components._types.links import Links

src, _ = Links.get_delay_source_indexer(
    n.snapshots, n.snapshot_weightings.generators, delay=3, is_cyclic=True
)

fig, axes = plt.subplots(1, 2, figsize=(12, 4), sharey=True)
colors = [f"C{i}" for i in range(8)]
p1_colors = [colors[s] for s in src]
n.links_t.p0["pipeline"].plot.bar(
    ax=axes[0], title="Input (p0 at production)", color=colors
)
(-n.links_t.p1["pipeline"]).plot.bar(
    ax=axes[1], title="Output (-p1 at demand)", color=p1_colors
)
for ax in axes:
    ax.set_ylabel("MW")
plt.tight_layout()

from pypsa.components._types.links import Links src, _ = Links.get_delay_source_indexer( n.snapshots, n.snapshot_weightings.generators, delay=3, is_cyclic=True ) fig, axes = plt.subplots(1, 2, figsize=(12, 4), sharey=True) colors = [f"C{i}" for i in range(8)] p1_colors = [colors[s] for s in src] n.links_t.p0["pipeline"].plot.bar( ax=axes[0], title="Input (p0 at production)", color=colors ) (-n.links_t.p1["pipeline"]).plot.bar( ax=axes[1], title="Output (-p1 at demand)", color=p1_colors ) for ax in axes: ax.set_ylabel("MW") plt.tight_layout()

No description has been provided for this image

With non-uniform weightings [1, 2, 1, 2, 1, 2, 1, 2] and delay=3, the source-snapshot mapping depends on cumulative weighting sums rather than simple index arithmetic. Here, two snapshots with weights 1+2=3 exactly cover the delay, resulting in a 2-snapshot shift despite the delay value being 3.

Sub-Snapshot Delays

When the delay is shorter than a single snapshot's weighting, the shift still rounds up to one snapshot. Here we use uniform weightings of 4 time units per snapshot with a delay of only 3. Since no snapshot boundary falls within the 3-unit window, the output is shifted by exactly one snapshot — the delay is effectively absorbed within the snapshot duration.

In [12]:

Copied! diagram

ipynb
n.snapshot_weightings.loc[:, "generators"] = 4

n.links.loc["pipeline", "delay"] = 3

n.optimize();

n.snapshot_weightings.loc[:, "generators"] = 4 n.links.loc["pipeline", "delay"] = 3 n.optimize();

text
WARNING:pypsa.components._types.mixin.multiports:Delay 3 does not align exactly with snapshot weighting boundaries and will be rounded to the nearest snapshot boundary.
text
INFO:linopy.model: Solve problem using Gurobi solver
text
INFO:linopy.model:Solver options:
 - log_to_console: False
text
INFO:linopy.io: Writing time: 0.02s
text
Set parameter WLSAccessID
text
Set parameter WLSSecret
text
Set parameter LicenseID to value 2537914
text
Academic license 2537914 - for non-commercial use only - registered to l.___@tu-berlin.de
text
Read LP format model from file /tmp/linopy-problem-mfc_dqb4.lp
text
Reading time = 0.00 seconds
text
obj: 64 rows, 24 columns, 80 nonzeros
text
Set parameter LogToConsole to value 0
text
INFO:linopy.constants: Optimization successful: 
Status: ok
Termination condition: optimal
Solution: 24 primals, 64 duals
Objective: 1.32e+03
Solver: gurobi
Runtime: 0.00s
Dual bound: 1.32e+03
Solver model: available
Solver message: 2
text
WARNING:pypsa.components._types.mixin.multiports:Delay 3 does not align exactly with snapshot weighting boundaries and will be rounded to the nearest snapshot boundary.
text
INFO:pypsa.optimization.optimize:The shadow-prices of the constraints Generator-fix-p-lower, Generator-fix-p-upper, Link-fix-p-lower, Link-fix-p-upper were not assigned to the network.

In [13]:

Copied! diagram

ipynb
src, _ = Links.get_delay_source_indexer(
    n.snapshots, n.snapshot_weightings.generators, delay=3, is_cyclic=True
)

pd.DataFrame(
    {
        "weighting": n.snapshot_weightings.generators,
        "p0": n.links_t.p0["pipeline"],
        "p1": n.links_t.p1["pipeline"],
        "source snapshot": src,
    }
)

src, _ = Links.get_delay_source_indexer( n.snapshots, n.snapshot_weightings.generators, delay=3, is_cyclic=True ) pd.DataFrame( { "weighting": n.snapshot_weightings.generators, "p0": n.links_t.p0["pipeline"], "p1": n.links_t.p1["pipeline"], "source snapshot": src, } )

text
WARNING:pypsa.components._types.mixin.multiports:Delay 3 does not align exactly with snapshot weighting boundaries and will be rounded to the nearest snapshot boundary.

Out[13]:

weightingp0p1source snapshot
snapshot
04.031.578947-10.07
14.052.631579-30.00
24.021.052632-50.01
34.042.105263-20.02
44.063.157895-40.03
54.026.315789-60.04
64.015.789474-25.05
74.010.526316-15.06

In [14]:

Copied! diagram

ipynb
fig, axes = plt.subplots(1, 2, figsize=(12, 4), sharey=True)
colors = [f"C{i}" for i in range(8)]
p1_colors = [colors[s] for s in src]
n.links_t.p0["pipeline"].plot.bar(
    ax=axes[0], title="Input (p0 at production)", color=colors
)
(-n.links_t.p1["pipeline"]).plot.bar(
    ax=axes[1], title="Output (-p1 at demand)", color=p1_colors
)
for ax in axes:
    ax.set_ylabel("MW")
plt.tight_layout()

fig, axes = plt.subplots(1, 2, figsize=(12, 4), sharey=True) colors = [f"C{i}" for i in range(8)] p1_colors = [colors[s] for s in src] n.links_t.p0["pipeline"].plot.bar( ax=axes[0], title="Input (p0 at production)", color=colors ) (-n.links_t.p1["pipeline"]).plot.bar( ax=axes[1], title="Output (-p1 at demand)", color=p1_colors ) for ax in axes: ax.set_ylabel("MW") plt.tight_layout()

No description has been provided for this image

The source-snapshot column confirms that each output snapshot draws from exactly one snapshot earlier (shift of 1), even though delay=3. With weighting=4, the cumulative snapshot starts are [0, 4, 8, ...] — the 3-unit delay never crosses more than one snapshot boundary, so the mapping s(t) = t-1 (cyclically) applies uniformly. Compare this with the previous section where delay=3 with mixed weightings [1, 2, ...] resulted in a 2-snapshot shift. See the user guide for details on how the source-snapshot mapping is computed.

Super-Snapshot Delays

Conversely, when the delay exceeds a single snapshot's weighting, the shift spans multiple snapshots. Here we keep weighting=4 but increase the delay to 5. The delay now crosses one full snapshot boundary, resulting in a 2-snapshot shift.

In [15]:

Copied! diagram

ipynb
n.links.loc["pipeline", "delay"] = 5

n.optimize();

n.links.loc["pipeline", "delay"] = 5 n.optimize();

text
WARNING:pypsa.components._types.mixin.multiports:Delay 5 does not align exactly with snapshot weighting boundaries and will be rounded to the nearest snapshot boundary.
text
INFO:linopy.model: Solve problem using Gurobi solver
text
INFO:linopy.model:Solver options:
 - log_to_console: False
text
INFO:linopy.io: Writing time: 0.02s
text
Set parameter WLSAccessID
text
Set parameter WLSSecret
text
Set parameter LicenseID to value 2537914
text
Academic license 2537914 - for non-commercial use only - registered to l.___@tu-berlin.de
text
Read LP format model from file /tmp/linopy-problem-1qhi7aiw.lp
text
Reading time = 0.00 seconds
text
obj: 64 rows, 24 columns, 80 nonzeros
text
Set parameter LogToConsole to value 0
text
INFO:linopy.constants: Optimization successful: 
Status: ok
Termination condition: optimal
Solution: 24 primals, 64 duals
Objective: 1.32e+03
Solver: gurobi
Runtime: 0.00s
Dual bound: 1.32e+03
Solver model: available
Solver message: 2
text
WARNING:pypsa.components._types.mixin.multiports:Delay 5 does not align exactly with snapshot weighting boundaries and will be rounded to the nearest snapshot boundary.
text
INFO:pypsa.optimization.optimize:The shadow-prices of the constraints Generator-fix-p-lower, Generator-fix-p-upper, Link-fix-p-lower, Link-fix-p-upper were not assigned to the network.

In [16]:

Copied! diagram

ipynb
src, _ = Links.get_delay_source_indexer(
    n.snapshots, n.snapshot_weightings.generators, delay=5, is_cyclic=True
)

pd.DataFrame(
    {
        "weighting": n.snapshot_weightings.generators,
        "p0": n.links_t.p0["pipeline"],
        "p1": n.links_t.p1["pipeline"],
        "source snapshot": src,
    }
)

src, _ = Links.get_delay_source_indexer( n.snapshots, n.snapshot_weightings.generators, delay=5, is_cyclic=True ) pd.DataFrame( { "weighting": n.snapshot_weightings.generators, "p0": n.links_t.p0["pipeline"], "p1": n.links_t.p1["pipeline"], "source snapshot": src, } )

text
WARNING:pypsa.components._types.mixin.multiports:Delay 5 does not align exactly with snapshot weighting boundaries and will be rounded to the nearest snapshot boundary.

Out[16]:

weightingp0p1source snapshot
snapshot
04.052.631579-10.06
14.021.052632-30.07
24.042.105263-50.00
34.063.157895-20.01
44.026.315789-40.02
54.015.789474-60.03
64.010.526316-25.04
74.031.578947-15.05

In [17]:

Copied! diagram

ipynb
fig, axes = plt.subplots(1, 2, figsize=(12, 4), sharey=True)
colors = [f"C{i}" for i in range(8)]
p1_colors = [colors[s] for s in src]
n.links_t.p0["pipeline"].plot.bar(
    ax=axes[0], title="Input (p0 at production)", color=colors
)
(-n.links_t.p1["pipeline"]).plot.bar(
    ax=axes[1], title="Output (-p1 at demand)", color=p1_colors
)
for ax in axes:
    ax.set_ylabel("MW")
plt.tight_layout()

fig, axes = plt.subplots(1, 2, figsize=(12, 4), sharey=True) colors = [f"C{i}" for i in range(8)] p1_colors = [colors[s] for s in src] n.links_t.p0["pipeline"].plot.bar( ax=axes[0], title="Input (p0 at production)", color=colors ) (-n.links_t.p1["pipeline"]).plot.bar( ax=axes[1], title="Output (-p1 at demand)", color=p1_colors ) for ax in axes: ax.set_ylabel("MW") plt.tight_layout()

text
Warning: environment still referenced so free is deferred (Continue to use WLS)

No description has been provided for this image

With delay=5 and weighting=4, each snapshot spans 4 time units, so a 5-unit delay crosses one full snapshot plus 1 unit into the next — yielding a 2-snapshot shift (s(t) = t-2). Compare this with the sub-snapshot case above where delay=3 < weighting=4 produced only a 1-snapshot shift. The general rule: the number of snapshot shifts equals ceil(delay / weighting) for uniform weightings.

diagram 2026-11-05

diagram 2026-02-24