tokenfabrikker/tests/conftest.py
Kjell Tore Guttormsen bca6496c0a
feat(utbygging): build out solution T in modules and add S48-S54
utbyggingsplan_trinnvis follows chapter 17.1: the grid balance of the
first stage, the payment condition for a module's power plants, S49,
and in T-K the two stocks of chips and the queue for replacements.
tidslinje gives MW IT in operation per type of power (S50). S48-S54
are pure functions in ligninger.py, and Inndata carries the new
quantities, the scenarios for the loss of demand and the paths of
u_alt. lag_plan returns a Trinnvisplan for T-F and T-K; regn_program
refuses T until it is taken through the cash flow.

Tested on made-up numbers only (59 new tests, hand-computed build-outs).
Nothing is computed for the hypothesis.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
2026-11-12 23:55:57 +01:00

216 lines
6.1 KiB
Python

"""A made-up set of parameter values for the tests of build-out, power system and cash flow.
Every number is round and invented. Nothing here comes from the frozen
parameter file, and no test that uses this set says anything about the
hypothesis.
"""
from __future__ import annotations
from typing import TYPE_CHECKING, Protocol
import pytest
from tokenfabrikker.inndata import Eierform, Inndata, Prislinje
if TYPE_CHECKING:
from collections.abc import Mapping
OMRAADER = ("NO1", "NO2", "NO3", "NO4", "NO5", "Norge")
EIERFORMER: Mapping[str, Eierform] = {
"direkte": Eierform("direkte", 1.0, 0.0, 0.0, 1.0, 0.04, None, 1.0, skatt=False),
"heleid_selskap": Eierform("heleid_selskap", 1.0, 0.0, 0.0, 0.5, 0.05, 0.10, 1.0, skatt=True),
"majoritet_boers": Eierform("majoritet_boers", 0.6, 0.0, 0.0, 0.5, 0.05, 0.12, 1.0, skatt=True),
"petroleumsmodell": Eierform(
"petroleumsmodell", 0.6, 0.25, 0.5, 0.5, 0.05, 0.12, 1.0, skatt=True
),
}
"""Made-up ownership forms with round numbers, in the layout of the parameter file."""
GRUNNVERDIER: Mapping[str, float] = {
# time and size
"T0": 2027,
"T_slutt": 2060,
"P_IT": 1000.0,
# nuclear power: investment (kr/MW), construction and operation
"c_N_ref": 100e6,
"P_ref": 1000.0,
"nu": 1.0,
"ell": 0.0,
"n_0": 5,
"u_xi": 0.9,
"w_xi": 0.5,
"o_xi": 0.5,
"tau_F": 8.0,
"tau_reg_min": 2.0,
"tau_N": 4.0,
"KF": 0.8,
"o_p": 0.05,
"o_f_stor": 0.02,
"o_f_liten": 0.04,
"beta_F": 0.1,
"chi": 0.1,
"A_krav": 0.99,
"L_N": 20.0,
"f_N": 1e6,
"nu_f": 0.0,
"v_N": 50.0,
"u_N": 70.0,
"u_N_liten": 100.0,
"d_N": 30.0,
"D_avv": 5e6,
"phi_U": 1e-5,
"K_U": 1e12,
"D_fors": 8e9,
"aarsverk_prog": 1000.0,
"andel_myndighet": 0.2,
"c_aarsverk": 1e6,
"n_reaktor": 1000.0,
# the plant without a grid: buffer and external supply
"delta_L": 0.5,
"c_buf": 10e6,
"f_buf": 0.4e6,
"L_buf": 20,
"s_g": 0.02,
"c_gen": 10e6,
"D_linje": 50.0,
"c_linje": 10e6,
# the data centre
"c_H0": 200e6,
"gamma_H": 0.0,
"c_bygg": 100e6,
"d_bygg": 0.1,
"L_H": 5,
"L_B": 15.0,
"tau_D": 2.0,
"PUE": 1.2,
"PUE_v": 1.2,
"lambda": 0.75,
"o_D_v": 3e6,
"o_D": 2e6,
"d_o_D": 0.5e6,
"mu_rel": 1.0,
"h_knapp": 100.0,
# the price of compute
"p_v": 800.0,
"y_obs": 150e6,
"T_knapp": 10,
"pi_neg": -0.3,
# the power system
"S0": 10e6,
"b_ut": 2.0,
"m_tort": 1.5,
"s_tort": 1.2,
"w_tort_vann": 0.8,
"psi_N": 1.0,
"kappa_vind": 0.05,
"c_fast": 1.4e6,
"c_res": 1.0e6,
"I_nett": 5e6,
"L_nett": 40,
"tau_nett": 3.0,
"n_tap": 0.05,
"t_el": 70.0,
"delta_V": 0.5,
# renewable power
"vind.investering": 14e6,
"vind.drift": 120.0,
"vind.fullasttimer": 3000.0,
"vind.levetid": 30,
"vind.byggetid": 2,
"vann.investering": 20e6,
"vann.drift": 70.0,
"vann.fullasttimer": 3000.0,
"vann.levetid": 40,
"vann.byggetid": 3,
"havvind.investering": 50e6,
"havvind.drift": 0.9e6,
"havvind.fullasttimer": 4500.0,
"havvind.levetid": 30,
"havvind.byggetid": 3,
"E_vann_rest": 2e6,
"E_vind_rest": 3e6,
"g_fornybar": 4e6,
# discounting, emissions, chips
"rho_N": 0.06,
"rho_D": 0.08,
"varphi": 0.2,
"s_B_NO": 0.5,
"u_B": 2000.0,
"phi_X": 0.0,
"D_X": 2.0,
"s_brikker": 0.04,
"G_server": 25_000.0,
# business economics and ownership
"t_nett": 0.3e6,
"tau_s": 0.2,
"iota": 0.02,
"r_stat": 0.02,
# scale and environment (emissions in tonnes per MWh and per MW IT)
"SNKS_snitt": 500e9,
"u_kjerne": 0.012,
"u_vind": 0.011,
"u_havvind": 0.012,
"u_vann": 0.004,
"u_H": 1000.0,
"eta_N": 3e-6,
# the addition to the direction (chapter 17): modules, first stage, own machines, water
"P_m": 100.0,
"tau_1": 2.0,
"n_1": 150.0,
"eps_d": 1.0,
"w_D_uttak": 0.1,
"w_N_uttak": 150.0,
"w_N_forbruk": 0.0,
"w_D_sjo": 100.0,
}
"""Round, invented values in the units of the equations (kr, MW, MWh, kr/MWh, years)."""
class LagInndata(Protocol):
"""Builds the made-up set, with the named values replaced."""
def __call__(
self, *, u_eksport: tuple[float, ...] | None = None, **endringer: float
) -> Inndata:
"""Return the set; ``vind__levetid`` replaces ``vind.levetid`` and ``lam`` ``lambda``."""
...
def lag_inndata(*, u_eksport: tuple[float, ...] | None = None, **endringer: float) -> Inndata:
"""The made-up set; ``vind__drift`` replaces ``vind.drift`` and ``lam`` replaces ``lambda``."""
verdier = dict(GRUNNVERDIER)
for navn, verdi in endringer.items():
noekkel = "lambda" if navn == "lam" else navn.replace("__", ".")
if noekkel not in verdier:
msg = f"unknown made-up quantity {noekkel!r}"
raise KeyError(msg)
verdier[noekkel] = verdi
antall_aar = round(verdier["T_slutt"] - verdier["T0"])
return Inndata(
v=verdier,
design={"o_f_liten": 0.04, "o_f_stor": 0.02, "o_p": 0.05, "beta_F": 0.1},
P_u_sett=(5.0, 10.0, 20.0, 50.0, 100.0, 200.0, 300.0, 400.0, 500.0, 1000.0),
psi={"vind": 0.9, "vann": 1.2, "havvind": 1.0},
kappa={"vann": 0.9, "havvind": 0.0},
linjer={omraade: Prislinje(alpha=700.0, b=-10e-6) for omraade in OMRAADER},
karbonpris={2026: 1000.0, 2100: 1000.0},
u_eksport=(0.5,) * antall_aar if u_eksport is None else u_eksport,
eierformer=EIERFORMER,
areal={"kjernekraft": 0.1e-6, "vind_direkte": 1.5e-6, "vind_plan": 30e-6, "tomt": 0.001},
petroleum_median=250e9,
bortfall={"lavt": (0.1, 0.2), "hoyt": (0.3, 0.6)},
u_alt={
"hoved": {2025: 0.4, 2035: 0.2, 2045: 0.1},
"fast": {2025: 0.5},
"null": {2025: 0.0},
},
kjoletaarn={"forbruk": (2.0, 2.5, 3.0), "uttak": (3.0, 4.0, 10.0)},
)
@pytest.fixture
def oppdiktet() -> LagInndata:
"""The builder of the made-up set of parameter values."""
return lag_inndata