Global Sensitivity Analysis
This example demonstrates how PyPSA can be combined with Global Sensitivity Analysis (GSA) methods using Sobol indices to understand how capital cost uncertainties affect system design and costs. The third-party tool SALib is used for this example. It makes sense to first read the basic SALib tutorial to understand the concepts before diving into this example.
Import Required Libraries
We'll need PyPSA for energy system modelling and SALib for global sensitivity analysis functions. We'll also use a thread pool to evaluate scenarios in parallel — threads work reliably in notebooks on every operating system, and the solver still runs in parallel because it releases the GIL during optimisation.
In [2]:
Copied!
import logging
import warnings
from functools import partial
from multiprocessing import cpu_count
from multiprocessing.pool import ThreadPool
import matplotlib.pyplot as plt
import numpy as np
from SALib.analyze.sobol import analyze as sobol_analyze
from SALib.sample.sobol import sample as sobol_sample
import pypsa
THREADS = min(cpu_count(), 15)
# Set to True for interaction effects
SECOND = False
# Small number of samples for demo; use 64+ for real analysis
SAMPLES = 8
logging.basicConfig(level=logging.ERROR)
logging.getLogger("linopy").setLevel(logging.ERROR)
warnings.simplefilter(action="ignore", category=FutureWarning)import logging import warnings from functools import partial from multiprocessing import cpu_count from multiprocessing.pool import ThreadPool import matplotlib.pyplot as plt import numpy as np from SALib.analyze.sobol import analyze as sobol_analyze from SALib.sample.sobol import sample as sobol_sample import pypsa THREADS = min(cpu_count(), 15)
Set to True for interaction effects
SECOND = False
Small number of samples for demo; use 64+ for real analysis
SAMPLES = 8 logging.basicConfig(level=logging.ERROR) logging.getLogger("linopy").setLevel(logging.ERROR) warnings.simplefilter(action="ignore", category=FutureWarning)
Create Base PyPSA Model
We will re-use the model.energy style example network. The model is a single-node capacity expansion model with only wind, solar, battery and hydrogen storage to cover a year of hourly demand. To save some computation time, we will sample just every fifth day of the year. Each day is considered at 3-hourly resolution, so we will have 8 snapshots per representative day.
In [3]:
Copied!
n = pypsa.examples.model_energy()
selected = n.snapshots.normalize().unique()[::5]
snapshots = n.snapshots[n.snapshots.normalize().isin(selected)]
n.set_snapshots(snapshots)
n.snapshot_weightings[["objective", "generators"]] *= 5n = pypsa.examples.model_energy() selected = n.snapshots.normalize().unique()[::5] snapshots = n.snapshots[n.snapshots.normalize().isin(selected)] n.set_snapshots(snapshots) n.snapshot_weightings[["objective", "generators"]] *= 5
Define Uncertainty Parameters
We specify which technology costs are uncertain, how much they can vary and what distribution to use for sampling. The uncertainties are defined as scaling factors relative to the base investment costs for solar, wind, batteries and electrolysers.
In [4]:
Copied!
uncertainty_space = {
"num_vars": 4,
"names": ["solar", "wind", "battery", "electrolysis"],
"bounds": [
[0.6, 1],
[0.8, 1],
[0.6, 1],
[0.6, 1],
],
"dists": ["unif"] * 4,
}uncertainty_space = { "num_vars": 4, "names": ["solar", "wind", "battery", "electrolysis"], "bounds": [ [0.6, 1], [0.8, 1], [0.6, 1], [0.6, 1], ], "dists": ["unif"] * 4, }
Generate Sample Points
Sobol sampling creates a systematic set of parameter combinations that efficiently explores the uncertainty space (low-discrepancy series). Each row represents one scenario to simulate.
In [5]:
Copied!
samples = sobol_sample(uncertainty_space, SAMPLES, calc_second_order=SECOND)
display(samples[:4])
display(len(samples))samples = sobol_sample(uncertainty_space, SAMPLES, calc_second_order=SECOND) display(samples[:4]) display(len(samples))
array([[0.80025365, 0.88202516, 0.72455177, 0.9160872 ],
[0.62382879, 0.88202516, 0.72455177, 0.9160872 ],
[0.80025365, 0.89967042, 0.72455177, 0.9160872 ],
[0.80025365, 0.88202516, 0.98439865, 0.9160872 ]])48Define Evaluation Function
This function takes the sampled cost scaling factors, applies them to the network, runs optimization, and extracts the total system cost and optimal capacities.
In [6]:
Copied!
def evaluate(
s: np.ndarray, n: pypsa.Network
) -> tuple[float, float, float, float, float]:
"""Optimize with given scaling factors and evaluate system costs and capacities."""
n_sim = n.copy()
attr = "capital_cost"
n_sim.generators.loc["solar", attr] = s[0] * n.generators.loc["solar", attr]
n_sim.generators.loc["wind", attr] = s[1] * n.generators.loc["wind", attr]
n_sim.storage_units.loc["battery storage", attr] = (
s[2] * n.storage_units.loc["battery storage", attr]
)
n_sim.links.loc["electrolysis", attr] = s[3] * n.links.loc["electrolysis", attr]
n_sim.optimize(solver_name="gurobi")
tsc = (n_sim.statistics.opex().sum() + n_sim.statistics.capex().sum()) / 1e9
solar = n_sim.generators.p_nom_opt["solar"] / 1e3
wind = n_sim.generators.p_nom_opt["wind"] / 1e3
battery = n_sim.storage_units.p_nom_opt["battery storage"] / 1e3
electrolysis = n_sim.links.p_nom_opt["electrolysis"] / 1e3
return tsc, solar, wind, battery, electrolysisdef evaluate( s: np.ndarray, n: pypsa.Network ) -> tuple[float, float, float, float, float]: """Optimize with given scaling factors and evaluate system costs and capacities.""" n_sim = n.copy() attr = "capital_cost" n_sim.generators.loc["solar", attr] = s[0] * n.generators.loc["solar", attr] n_sim.generators.loc["wind", attr] = s[1] * n.generators.loc["wind", attr] n_sim.storage_units.loc["battery storage", attr] = ( s[2] * n.storage_units.loc["battery storage", attr] ) n_sim.links.loc["electrolysis", attr] = s[3] * n.links.loc["electrolysis", attr] n_sim.optimize(solver_name="gurobi") tsc = (n_sim.statistics.opex().sum() + n_sim.statistics.capex().sum()) / 1e9 solar = n_sim.generators.p_nom_opt["solar"] / 1e3 wind = n_sim.generators.p_nom_opt["wind"] / 1e3 battery = n_sim.storage_units.p_nom_opt["battery storage"] / 1e3 electrolysis = n_sim.links.p_nom_opt["electrolysis"] / 1e3 return tsc, solar, wind, battery, electrolysis
Run Sensitivity Analysis
We use parallel processing to evaluate all sample scenarios simultaneously, significantly reducing computation time. Each simulation optimizes the energy system with different cost assumptions and returns the total system cost and optimal capacities.
In [7]:
Copied!
with ThreadPool(processes=THREADS) as pool:
func = partial(evaluate, n=n)
results = np.array(pool.map(func, samples))
display(results[:4])with ThreadPool(processes=THREADS) as pool: func = partial(evaluate, n=n) results = np.array(pool.map(func, samples)) display(results[:4])
Set parameter WLSAccessID
Set parameter WLSAccessIDSet parameter WLSSecret
Set parameter WLSSecretSet parameter LicenseID to value 2537914
Set parameter WLSAccessID
Set parameter LicenseID to value 2537914Set parameter WLSSecretSet parameter LicenseID to value 2537914
Academic license 2537914 - for non-commercial use only - registered to l.___@tu-berlin.deAcademic license 2537914 - for non-commercial use only - registered to l.___@tu-berlin.deSet parameter WLSAccessID
Academic license 2537914 - for non-commercial use only - registered to l.___@tu-berlin.deRead LP format model from file /tmp/linopy-problem-pkbldcn1.lp
Read LP format model from file /tmp/linopy-problem-8so1iscq.lp
Set parameter WLSSecretSet parameter LicenseID to value 2537914
Read LP format model from file /tmp/linopy-problem-7onreuiq.lp
Reading time = 0.05 seconds
Reading time = 0.03 secondsobj: 14022 rows, 6430 columns, 26000 nonzeros
obj: 14022 rows, 6430 columns, 26000 nonzeros
Reading time = 0.02 secondsSet parameter LogToConsole to value 0
obj: 14022 rows, 6430 columns, 26000 nonzerosSet parameter LogToConsole to value 0
Set parameter LogToConsole to value 0Academic license 2537914 - for non-commercial use only - registered to l.___@tu-berlin.deRead LP format model from file /tmp/linopy-problem-_z401ex0.lpReading time = 0.02 secondsobj: 14022 rows, 6430 columns, 26000 nonzerosSet parameter LogToConsole to value 0Set parameter WLSAccessIDSet parameter WLSSecretSet parameter LicenseID to value 2537914Academic license 2537914 - for non-commercial use only - registered to l.___@tu-berlin.deRead LP format model from file /tmp/linopy-problem-8v7t336p.lpReading time = 0.02 secondsobj: 14022 rows, 6430 columns, 26000 nonzerosSet parameter LogToConsole to value 0Set parameter WLSAccessIDSet parameter WLSSecretSet parameter LicenseID to value 2537914Academic license 2537914 - for non-commercial use only - registered to l.___@tu-berlin.deRead LP format model from file /tmp/linopy-problem-sk70ktp3.lpReading time = 0.03 secondsobj: 14022 rows, 6430 columns, 26000 nonzerosSet parameter LogToConsole to value 0Set parameter WLSAccessIDSet parameter WLSAccessIDSet parameter WLSSecret
Set parameter WLSSecretSet parameter LicenseID to value 2537914
Set parameter LicenseID to value 2537914Academic license 2537914 - for non-commercial use only - registered to l.___@tu-berlin.deAcademic license 2537914 - for non-commercial use only - registered to l.___@tu-berlin.de
Read LP format model from file /tmp/linopy-problem-nnyte47a.lpReading time = 0.03 secondsobj: 14022 rows, 6430 columns, 26000 nonzerosSet parameter LogToConsole to value 0Read LP format model from file /tmp/linopy-problem-z3gzrqcx.lpReading time = 0.04 secondsobj: 14022 rows, 6430 columns, 26000 nonzerosSet parameter LogToConsole to value 0Set parameter WLSAccessIDSet parameter WLSSecretSet parameter LicenseID to value 2537914Academic license 2537914 - for non-commercial use only - registered to l.___@tu-berlin.deRead LP format model from file /tmp/linopy-problem-lkkxokyi.lpReading time = 0.02 secondsobj: 14022 rows, 6430 columns, 26000 nonzerosSet parameter LogToConsole to value 0Set parameter WLSAccessIDSet parameter WLSSecretSet parameter LicenseID to value 2537914Academic license 2537914 - for non-commercial use only - registered to l.___@tu-berlin.deRead LP format model from file /tmp/linopy-problem-80e6id8l.lpReading time = 0.02 secondsobj: 14022 rows, 6430 columns, 26000 nonzerosSet parameter LogToConsole to value 0Set parameter WLSAccessIDSet parameter WLSSecretSet parameter LicenseID to value 2537914Academic license 2537914 - for non-commercial use only - registered to l.___@tu-berlin.deRead LP format model from file /tmp/linopy-problem-rua7z1tr.lpReading time = 0.02 secondsobj: 14022 rows, 6430 columns, 26000 nonzerosSet parameter LogToConsole to value 0Set parameter WLSAccessIDSet parameter WLSSecretSet parameter LicenseID to value 2537914Academic license 2537914 - for non-commercial use only - registered to l.___@tu-berlin.deRead LP format model from file /tmp/linopy-problem-3p5bqplq.lpReading time = 0.02 secondsobj: 14022 rows, 6430 columns, 26000 nonzerosSet parameter LogToConsole to value 0Warning: environment still referenced so free is deferred (Continue to use WLS)Warning: environment still referenced so free is deferred (Continue to use WLS)Warning: environment still referenced so free is deferred (Continue to use WLS)Warning: environment still referenced so free is deferred (Continue to use WLS)Warning: environment still referenced so free is deferred (Continue to use WLS)Warning: environment still referenced so free is deferred (Continue to use WLS)Warning: environment still referenced so free is deferred (Continue to use WLS)Warning: environment still referenced so free is deferred (Continue to use WLS)Warning: environment still referenced so free is deferred (Continue to use WLS)Warning: environment still referenced so free is deferred (Continue to use WLS)Warning: environment still referenced so free is deferred (Continue to use WLS)Warning: environment still referenced so free is deferred (Continue to use WLS)Set parameter WLSAccessIDSet parameter WLSSecretSet parameter WLSAccessID
Set parameter LicenseID to value 2537914Set parameter WLSSecretSet parameter LicenseID to value 2537914Academic license 2537914 - for non-commercial use only - registered to l.___@tu-berlin.de
Academic license 2537914 - for non-commercial use only - registered to l.___@tu-berlin.deRead LP format model from file /tmp/linopy-problem-4xxgy4g6.lpReading time = 0.03 seconds
Read LP format model from file /tmp/linopy-problem-rpx2qyf1.lpobj: 14022 rows, 6430 columns, 26000 nonzeros
Reading time = 0.02 secondsobj: 14022 rows, 6430 columns, 26000 nonzerosSet parameter LogToConsole to value 0Set parameter LogToConsole to value 0Set parameter WLSAccessID
Set parameter WLSAccessIDSet parameter WLSSecret
Set parameter WLSSecretSet parameter LicenseID to value 2537914
Set parameter LicenseID to value 2537914Academic license 2537914 - for non-commercial use only - registered to l.___@tu-berlin.de
Academic license 2537914 - for non-commercial use only - registered to l.___@tu-berlin.deRead LP format model from file /tmp/linopy-problem-6k2bx70c.lp
Read LP format model from file /tmp/linopy-problem-9zutyqru.lpReading time = 0.02 seconds
Reading time = 0.04 secondsobj: 14022 rows, 6430 columns, 26000 nonzeros
obj: 14022 rows, 6430 columns, 26000 nonzerosSet parameter LogToConsole to value 0
Set parameter LogToConsole to value 0Set parameter WLSAccessIDSet parameter WLSSecretSet parameter LicenseID to value 2537914Academic license 2537914 - for non-commercial use only - registered to l.___@tu-berlin.deRead LP format model from file /tmp/linopy-problem-25mpem3p.lpReading time = 0.02 secondsobj: 14022 rows, 6430 columns, 26000 nonzerosSet parameter LogToConsole to value 0Set parameter WLSAccessIDSet parameter WLSAccessID
Set parameter WLSSecretSet parameter WLSSecret
Set parameter LicenseID to value 2537914Set parameter LicenseID to value 2537914
Academic license 2537914 - for non-commercial use only - registered to l.___@tu-berlin.deAcademic license 2537914 - for non-commercial use only - registered to l.___@tu-berlin.deRead LP format model from file /tmp/linopy-problem-ebwe7hct.lp
Read LP format model from file /tmp/linopy-problem-o_t2w01m.lpReading time = 0.03 secondsobj: 14022 rows, 6430 columns, 26000 nonzeros
Reading time = 0.02 secondsobj: 14022 rows, 6430 columns, 26000 nonzeros
Set parameter LogToConsole to value 0
Set parameter WLSAccessIDSet parameter LogToConsole to value 0
Set parameter WLSSecretSet parameter LicenseID to value 2537914Academic license 2537914 - for non-commercial use only - registered to l.___@tu-berlin.deRead LP format model from file /tmp/linopy-problem-xswyba_b.lpReading time = 0.02 secondsobj: 14022 rows, 6430 columns, 26000 nonzerosSet parameter LogToConsole to value 0Set parameter WLSAccessIDSet parameter WLSSecretSet parameter LicenseID to value 2537914Academic license 2537914 - for non-commercial use only - registered to l.___@tu-berlin.deRead LP format model from file /tmp/linopy-problem-inuid4um.lpReading time = 0.02 secondsobj: 14022 rows, 6430 columns, 26000 nonzerosSet parameter LogToConsole to value 0Set parameter WLSAccessIDSet parameter WLSSecretSet parameter LicenseID to value 2537914Set parameter WLSAccessIDSet parameter WLSSecretSet parameter LicenseID to value 2537914
Academic license 2537914 - for non-commercial use only - registered to l.___@tu-berlin.deRead LP format model from file /tmp/linopy-problem-hkx7b0tk.lp
Academic license 2537914 - for non-commercial use only - registered to l.___@tu-berlin.deReading time = 0.02 seconds
Set parameter WLSAccessIDobj: 14022 rows, 6430 columns, 26000 nonzerosSet parameter LogToConsole to value 0Read LP format model from file /tmp/linopy-problem-cq_uj7x2.lpSet parameter WLSSecret
Reading time = 0.02 secondsobj: 14022 rows, 6430 columns, 26000 nonzeros
Set parameter LicenseID to value 2537914Set parameter LogToConsole to value 0Academic license 2537914 - for non-commercial use only - registered to l.___@tu-berlin.deRead LP format model from file /tmp/linopy-problem-cw02gbm5.lpReading time = 0.02 secondsobj: 14022 rows, 6430 columns, 26000 nonzerosSet parameter LogToConsole to value 0Set parameter WLSAccessIDSet parameter WLSSecretSet parameter LicenseID to value 2537914Academic license 2537914 - for non-commercial use only - registered to l.___@tu-berlin.deRead LP format model from file /tmp/linopy-problem-7i7z1_f6.lpReading time = 0.02 secondsobj: 14022 rows, 6430 columns, 26000 nonzerosSet parameter LogToConsole to value 0Set parameter WLSAccessIDSet parameter WLSSecretSet parameter LicenseID to value 2537914Academic license 2537914 - for non-commercial use only - registered to l.___@tu-berlin.deRead LP format model from file /tmp/linopy-problem-2jb0faro.lpReading time = 0.02 secondsobj: 14022 rows, 6430 columns, 26000 nonzeros
Set parameter WLSAccessIDSet parameter WLSSecret
Set parameter LogToConsole to value 0Set parameter LicenseID to value 2537914Academic license 2537914 - for non-commercial use only - registered to l.___@tu-berlin.deRead LP format model from file /tmp/linopy-problem-h6w_t7n9.lpReading time = 0.02 secondsobj: 14022 rows, 6430 columns, 26000 nonzerosSet parameter LogToConsole to value 0Set parameter WLSAccessIDSet parameter WLSSecretSet parameter LicenseID to value 2537914Academic license 2537914 - for non-commercial use only - registered to l.___@tu-berlin.deRead LP format model from file /tmp/linopy-problem-v8rfw3e_.lpReading time = 0.02 secondsobj: 14022 rows, 6430 columns, 26000 nonzerosSet parameter LogToConsole to value 0Warning: environment still referenced so free is deferred (Continue to use WLS)Warning: environment still referenced so free is deferred (Continue to use WLS)Warning: environment still referenced so free is deferred (Continue to use WLS)Warning: environment still referenced so free is deferred (Continue to use WLS)Warning: environment still referenced so free is deferred (Continue to use WLS)Warning: environment still referenced so free is deferred (Continue to use WLS)Warning: environment still referenced so free is deferred (Continue to use WLS)Warning: environment still referenced so free is deferred (Continue to use WLS)Warning: environment still referenced so free is deferred (Continue to use WLS)Warning: environment still referenced so free is deferred (Continue to use WLS)Warning: environment still referenced so free is deferred (Continue to use WLS)Warning: environment still referenced so free is deferred (Continue to use WLS)Warning: environment still referenced so free is deferred (Continue to use WLS)Warning: environment still referenced so free is deferred (Continue to use WLS)Warning: environment still referenced so free is deferred (Continue to use WLS)Warning: environment still referenced so free is deferred (Continue to use WLS)Set parameter WLSAccessIDSet parameter WLSSecretSet parameter LicenseID to value 2537914Academic license 2537914 - for non-commercial use only - registered to l.___@tu-berlin.deRead LP format model from file /tmp/linopy-problem-u52ei2la.lpReading time = 0.02 secondsobj: 14022 rows, 6430 columns, 26000 nonzerosSet parameter LogToConsole to value 0Set parameter WLSAccessIDSet parameter WLSSecretSet parameter LicenseID to value 2537914Academic license 2537914 - for non-commercial use only - registered to l.___@tu-berlin.deRead LP format model from file /tmp/linopy-problem-7p5zyben.lpReading time = 0.02 secondsobj: 14022 rows, 6430 columns, 26000 nonzerosSet parameter LogToConsole to value 0Set parameter WLSAccessIDSet parameter WLSSecretSet parameter LicenseID to value 2537914Academic license 2537914 - for non-commercial use only - registered to l.___@tu-berlin.deRead LP format model from file /tmp/linopy-problem-2xn7z1da.lpReading time = 0.02 secondsobj: 14022 rows, 6430 columns, 26000 nonzerosSet parameter LogToConsole to value 0Set parameter WLSAccessIDSet parameter WLSSecretSet parameter LicenseID to value 2537914Academic license 2537914 - for non-commercial use only - registered to l.___@tu-berlin.deRead LP format model from file /tmp/linopy-problem-gzry0my2.lpReading time = 0.03 secondsobj: 14022 rows, 6430 columns, 26000 nonzerosSet parameter LogToConsole to value 0Set parameter WLSAccessIDSet parameter WLSSecretSet parameter LicenseID to value 2537914Academic license 2537914 - for non-commercial use only - registered to l.___@tu-berlin.deRead LP format model from file /tmp/linopy-problem-p4o50vab.lpReading time = 0.02 secondsobj: 14022 rows, 6430 columns, 26000 nonzerosSet parameter LogToConsole to value 0Set parameter WLSAccessIDSet parameter WLSSecretSet parameter LicenseID to value 2537914Academic license 2537914 - for non-commercial use only - registered to l.___@tu-berlin.deRead LP format model from file /tmp/linopy-problem-cmt7vh5y.lpReading time = 0.02 secondsobj: 14022 rows, 6430 columns, 26000 nonzerosSet parameter LogToConsole to value 0Set parameter WLSAccessIDSet parameter WLSSecretSet parameter LicenseID to value 2537914Academic license 2537914 - for non-commercial use only - registered to l.___@tu-berlin.deRead LP format model from file /tmp/linopy-problem-yjjqztg9.lpReading time = 0.02 secondsobj: 14022 rows, 6430 columns, 26000 nonzerosSet parameter LogToConsole to value 0Set parameter WLSAccessIDSet parameter WLSSecretSet parameter LicenseID to value 2537914Academic license 2537914 - for non-commercial use only - registered to l.___@tu-berlin.deRead LP format model from file /tmp/linopy-problem-os03ndf0.lpReading time = 0.02 secondsobj: 14022 rows, 6430 columns, 26000 nonzerosSet parameter LogToConsole to value 0Set parameter WLSAccessIDSet parameter WLSSecret
Set parameter WLSAccessIDSet parameter LicenseID to value 2537914
Set parameter WLSSecretSet parameter LicenseID to value 2537914Academic license 2537914 - for non-commercial use only - registered to l.___@tu-berlin.deAcademic license 2537914 - for non-commercial use only - registered to l.___@tu-berlin.deRead LP format model from file /tmp/linopy-problem-pb6wzwyg.lpReading time = 0.03 secondsRead LP format model from file /tmp/linopy-problem-9hnlek6a.lp
obj: 14022 rows, 6430 columns, 26000 nonzerosReading time = 0.02 secondsSet parameter LogToConsole to value 0
obj: 14022 rows, 6430 columns, 26000 nonzerosSet parameter LogToConsole to value 0Set parameter WLSAccessIDSet parameter WLSSecretSet parameter LicenseID to value 2537914Academic license 2537914 - for non-commercial use only - registered to l.___@tu-berlin.deRead LP format model from file /tmp/linopy-problem-s98094_2.lpReading time = 0.02 secondsobj: 14022 rows, 6430 columns, 26000 nonzerosSet parameter LogToConsole to value 0Set parameter WLSAccessIDSet parameter WLSSecretSet parameter LicenseID to value 2537914Academic license 2537914 - for non-commercial use only - registered to l.___@tu-berlin.deRead LP format model from file /tmp/linopy-problem-subugisa.lpReading time = 0.03 secondsobj: 14022 rows, 6430 columns, 26000 nonzerosSet parameter LogToConsole to value 0Set parameter WLSAccessIDSet parameter WLSSecretSet parameter LicenseID to value 2537914Academic license 2537914 - for non-commercial use only - registered to l.___@tu-berlin.deRead LP format model from file /tmp/linopy-problem-zu0k_h2n.lpReading time = 0.02 secondsobj: 14022 rows, 6430 columns, 26000 nonzerosSet parameter LogToConsole to value 0Set parameter WLSAccessIDSet parameter WLSSecretSet parameter LicenseID to value 2537914Academic license 2537914 - for non-commercial use only - registered to l.___@tu-berlin.deRead LP format model from file /tmp/linopy-problem-fhv_r5r7.lpReading time = 0.03 secondsobj: 14022 rows, 6430 columns, 26000 nonzerosSet parameter LogToConsole to value 0Set parameter WLSAccessIDSet parameter WLSAccessID
Set parameter WLSSecretSet parameter LicenseID to value 2537914
Set parameter WLSSecretSet parameter LicenseID to value 2537914Academic license 2537914 - for non-commercial use only - registered to l.___@tu-berlin.de
Academic license 2537914 - for non-commercial use only - registered to l.___@tu-berlin.deRead LP format model from file /tmp/linopy-problem-mr3_u7pz.lpReading time = 0.05 seconds
Read LP format model from file /tmp/linopy-problem-s1b4nqut.lpobj: 14022 rows, 6430 columns, 26000 nonzeros
Reading time = 0.03 secondsobj: 14022 rows, 6430 columns, 26000 nonzeros
Set parameter LogToConsole to value 0Set parameter LogToConsole to value 0Warning: environment still referenced so free is deferred (Continue to use WLS)Warning: environment still referenced so free is deferred (Continue to use WLS)Warning: environment still referenced so free is deferred (Continue to use WLS)Warning: environment still referenced so free is deferred (Continue to use WLS)Warning: environment still referenced so free is deferred (Continue to use WLS)Warning: environment still referenced so free is deferred (Continue to use WLS)Warning: environment still referenced so free is deferred (Continue to use WLS)Warning: environment still referenced so free is deferred (Continue to use WLS)Warning: environment still referenced so free is deferred (Continue to use WLS)Warning: environment still referenced so free is deferred (Continue to use WLS)Warning: environment still referenced so free is deferred (Continue to use WLS)Warning: environment still referenced so free is deferred (Continue to use WLS)Warning: environment still referenced so free is deferred (Continue to use WLS)Warning: environment still referenced so free is deferred (Continue to use WLS)Warning: environment still referenced so free is deferred (Continue to use WLS)Warning: environment still referenced so free is deferred (Continue to use WLS)Set parameter WLSAccessIDSet parameter WLSSecretSet parameter LicenseID to value 2537914Academic license 2537914 - for non-commercial use only - registered to l.___@tu-berlin.deRead LP format model from file /tmp/linopy-problem-wfw_s40b.lpReading time = 0.02 secondsobj: 14022 rows, 6430 columns, 26000 nonzerosSet parameter LogToConsole to value 0Set parameter WLSAccessIDSet parameter WLSSecretSet parameter LicenseID to value 2537914Set parameter WLSAccessIDSet parameter WLSSecretAcademic license 2537914 - for non-commercial use only - registered to l.___@tu-berlin.deSet parameter LicenseID to value 2537914Read LP format model from file /tmp/linopy-problem-eojj0jz0.lp
Academic license 2537914 - for non-commercial use only - registered to l.___@tu-berlin.deReading time = 0.02 secondsRead LP format model from file /tmp/linopy-problem-2y5jux0t.lpReading time = 0.02 seconds
obj: 14022 rows, 6430 columns, 26000 nonzerosobj: 14022 rows, 6430 columns, 26000 nonzeros
Set parameter LogToConsole to value 0Set parameter LogToConsole to value 0Set parameter WLSAccessIDSet parameter WLSSecretSet parameter LicenseID to value 2537914Academic license 2537914 - for non-commercial use only - registered to l.___@tu-berlin.deRead LP format model from file /tmp/linopy-problem-y_l72d_0.lpReading time = 0.03 secondsobj: 14022 rows, 6430 columns, 26000 nonzerosSet parameter LogToConsole to value 0array([[ 5.8731752 , 34.54541324, 26.63417458, 23.60574103, 1.42527402],
[ 5.55109025, 36.2027921 , 26.58674166, 21.87256598, 1.46763697],
[ 5.92090852, 34.57342403, 26.58805152, 23.50993779, 1.44620469],
[ 6.22773083, 35.77581909, 26.58818519, 20.18074455, 1.71270911]])Visualize Sensitivity Indices
Sobol analysis calculates sensitivity indices showing how much each technology's cost uncertainty contributes to variability in system outcomes (i.e. total system cost and expanded capacities). The larger the index, the more impact that technology's cost has on the outcome. First-order indices show direct effects. Error bars indicate 95% confidence intervals. Note that for SAMPLES = 16, the confidence intervals may be quite large, so larger sample sizes are recommended for more reliable results.
In [8]:
Copied!
outputs = ["Total Cost", "Solar", "Wind", "Battery", "Electrolysis"]
for i, output in enumerate(outputs):
sobol_analyze(uncertainty_space, results[:, i], calc_second_order=SECOND).plot()
plt.gcf().suptitle(f"{output} Sensitivity")outputs = ["Total Cost", "Solar", "Wind", "Battery", "Electrolysis"] for i, output in enumerate(outputs): sobol_analyze(uncertainty_space, results[:, i], calc_second_order=SECOND).plot() plt.gcf().suptitle(f"{output} Sensitivity")





These illustrative results show that solar and battery costs have the largest impact on total system cost. The deployment of solar also substantially depends on the cost of batteries (next to its own cost).
For more global sensitivity analysis functions, like the Method of Morris, see the SALib documentation.
References
- Herman and Usher (2017). SALib: An open-source Python library for Sensitivity Analysis, Journal of Open Source Software (JOSS).
- Usher et al. (2023), Global sensitivity analysis to enhance the transparency and rigour of energy system optimisation modelling, Open Research Europe.
- Tröndle et al. (2020), Trade-Offs between Geographic Scale, Cost, and Infrastructure Requirements for Fully Renewable Electricity in Europe, Joule.
- Neumann et al. (2023), Broad ranges of investment configurations for renewable power systems, robust to cost uncertainty and near-optimality, iScience.
2026-08-05
2026-02-05