feat(kode): add the build-out, the power system and the cash flow
- utbygging.py: when each facility starts and which vintages of IT hardware it gets (S22, S33), with chips as a stock, replacement before new facilities and the export rule. - kraftsystem.py: the fitted price lines and the power and capacity balances year by year (S23, S24, S25, S38). - kontantstrom.py: the yearly cash flows per facility, the additionality rule by iteration, the residual value and the net present value for Norway (S26, S34, S35, S40, S45), for the solutions A, B, B', C and R. - hendelser.py and data/aarshendelser.npy: the stream of random numbers for the export rule, one uniform number per draw and year 2028-2100, from its own seed. - inndata.py: one set of values in the units of the equations. - ligninger.py: one function per equation for chapters 4 to 6. Tested on a made-up set of values only (tests/conftest.py); no result for the hypothesis has been computed. 271 tests pass. Seven are documented misses against a source: the five from before, and the price lines for NO3 and NO4, which miss one of NVE's twelve scenarios by 6.0 and 7.7 per cent. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
This commit is contained in:
parent
fd0db8b3d3
commit
5c91cadf4c
15 changed files with 3807 additions and 10 deletions
174
tests/conftest.py
Normal file
174
tests/conftest.py
Normal file
|
|
@ -0,0 +1,174 @@
|
|||
"""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 Inndata, Prislinje
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from collections.abc import Mapping
|
||||
|
||||
OMRAADER = ("NO1", "NO2", "NO3", "NO4", "NO5", "Norge")
|
||||
|
||||
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,
|
||||
}
|
||||
"""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,
|
||||
)
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def oppdiktet() -> LagInndata:
|
||||
"""The builder of the made-up set of parameter values."""
|
||||
return lag_inndata
|
||||
Loading…
Add table
Add a link
Reference in a new issue