tokenfabrikker/tests/conftest.py
Kjell Tore Guttormsen e216702d69
feat(kode): first coding of business economics, ownership, scale, environment and verdicts
Chapters 7 to 11 of the specification, on the made-up set only:

- nivaaisert: the power cost per facility, year and vintage on levelised
  form (S9, S11 with clarifications 2, 11, 13 and 15), S15, S19, S27, S42
- eierskap: the business cash flow with every asset booked, tax, S28, S29
  and S30 for the four ownership forms, the criteria over the draws
- skala: S31 year by year, the first year with stable operation, M6
- miljo: S32 year by year, the rules of M5 (i) and (ii)
- dommer: S37, the verdict per target, the step of the ladder, the overall
  verdicts; tested on invented outcomes
- kontantstrom: each asset is recorded as it is paid, and the price of
  compute exposes the competitor's cost and the markup

This is an intermediate step. The readings are not settled: an independent
reader is coding the same from the specification alone, a first comparison
agrees on the levelised cost, S19, S42, the cash flows, M3 and M4 and
differs on depreciation at the final year, tax, debt and two definitions.
Chapter 16 gets the clarifications before any result is computed.
Nothing is computed for the hypothesis; the parameter file is unchanged.

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

200 lines
5.5 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,
}
"""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,
)
@pytest.fixture
def oppdiktet() -> LagInndata:
"""The builder of the made-up set of parameter values."""
return lag_inndata