feat(trekninger): read parameter file 1.1 and store the new draws
The loader knows the new checksum and the units of the new quantities (g CO2 per kWh, cubic metres per MWh). 10 000 draws of 91 quantities with the same seed; the four new ones are the last columns. All columns have new numbers, because the random numbers are laid out row by row. The stream for yearly events is byte for byte the same; only its description records the new checksum. Tests for the counts, the new quantities and the checksum in the pre-registration. README, CHANGELOG and CLAUDE.md updated. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
This commit is contained in:
parent
5be06462ac
commit
ea26cd4226
9 changed files with 100 additions and 25 deletions
|
|
@ -70,3 +70,9 @@ All notable changes to this project will be documented in this file.
|
|||
changed the chip rule and the condition for nuclear power in the second version, the cap on early grid
|
||||
connections and the lead time. The parameter file is unchanged; the new quantities are candidates until the
|
||||
deviation from the freeze.
|
||||
- One deviation from the parameter freeze, before anything is computed (`modell/parametere.json` version 1.1,
|
||||
new checksum in the pre-registration): thirteen new quantities for the addition to the direction, seven new
|
||||
sensitivities and three corrected lines in the list of sensitivities. None of the 124 frozen parameters got a
|
||||
new value, range or distribution. 137 parameters, 91 drawn quantities, new draws in `data/`. Before the
|
||||
deviation the project itself looked up the 30 source entries behind the new quantities in the primary
|
||||
sources; four things changed from the candidates (see chapter 17.8 of the specification).
|
||||
|
|
|
|||
|
|
@ -20,7 +20,8 @@ carousel, Python code, and a Claude plugin (own repo, later).
|
|||
- `FORHANDSREGISTRERING.md`: the approved direction and pre-registered criteria (M1–M7). Committed.
|
||||
- `modell/spesifikasjon.md`: the model specification (equations S1–S54; chapter 17,
|
||||
the addition to the direction, is not coded yet). `modell/parametere.json`: the frozen
|
||||
parameters (value, range, distribution, source entries); its checksum is recorded in the pre-registration.
|
||||
parameters (value, range, distribution, source entries); its checksum is recorded in the pre-registration
|
||||
(version 1.1 after the one deviation of 2026-11-12, which added the quantities of chapter 17.8).
|
||||
The table in chapter 14 of the specification is generated from that file.
|
||||
`modell/fagfellevurdering-*.md`: review findings per draft and what was done.
|
||||
- `PLAN.md` and `STATE.md`: local working files (gitignored). `private/`: working documents, never committed
|
||||
|
|
@ -42,7 +43,7 @@ carousel, Python code, and a Claude plugin (own repo, later).
|
|||
cost of capital before tax), approved by the operator 2026-11-12; 67 lists what remains. Clarification 68
|
||||
holds the sources' figures for M5 (i), mirrored in `miljo.KILDEVERDIER_M5`. The run over the draws, the
|
||||
sensitivities and the tools of chapter 12 are not coded yet.
|
||||
- `data/trekninger.npy` and `data/trekninger.json`: the 10 000 draws of the 87 drawn quantities, in the parameter
|
||||
- `data/trekninger.npy` and `data/trekninger.json`: the 10 000 draws of the 91 drawn quantities, in the parameter
|
||||
file's units. `data/aarshendelser.npy` and `.json`: one uniform number per draw and year 2028–2100 for the
|
||||
export rule (own seed). Committed; every later computation reads them.
|
||||
- `tests/`: unit tests per equation, the loader, the draws, and `test_fasit.py` (known answers from Argonne,
|
||||
|
|
@ -70,7 +71,7 @@ carousel, Python code, and a Claude plugin (own repo, later).
|
|||
chapters 0 to 13 it prevails. A new ambiguity is settled there with a date, never silently in code. Chapter 17
|
||||
holds the addition to the direction (solution T in the versions T-F and T-K, on-device compute, avoided
|
||||
emissions, cooling water; S48–S54). Where it is silent, T follows the rules for C and B. Its new quantities
|
||||
(17.8) are candidates, not parameters, until the deviation from the freeze.
|
||||
(17.8) were frozen in the deviation of 2026-11-12 and stand last in the parameter file.
|
||||
- **Known-answer tests:** nothing is tuned to make one pass. A miss stays in the suite as a strict `xfail` with
|
||||
the measured deviation and the cause if known, and is reported in the review log.
|
||||
- **No results yet:** until part 6, code is only run on made-up numbers or on a source's own assumptions, never on
|
||||
|
|
|
|||
|
|
@ -17,7 +17,8 @@ skal si når satsingen lønner seg, og når den ikke gjør det.
|
|||
retningen: trinnvis oppbygging, AI-bruk på brukernes egne maskiner, utslipp «med fradrag» og kjølevann. Det er
|
||||
ikke kodet ennå.
|
||||
- `modell/parametere.json`: parameterne, frosset før noe er regnet: verdi, spenn, fordeling og poster i
|
||||
kildebanken. Sjekksummen står i forhåndsregistreringen.
|
||||
kildebanken. Fila er endret én gang etter frysen, 12. november 2026, da størrelsene for tillegget til retningen
|
||||
kom inn, også det før noe er regnet. Sjekksummen og hva som ble endret, står i forhåndsregistreringen.
|
||||
- `modell/fagfellevurdering-utkast-1.md` og `modell/fagfellevurdering-utkast-2-og-3.md`: hva uavhengige lesere
|
||||
fant i utkastene, og hva som er gjort med det.
|
||||
- `src/tokenfabrikker/`: koden. Én funksjon per ligning, med samme nummer som i spesifikasjonen: kraftverket,
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
"beskrivelse": "Egen strøm av tilfeldige tall for hendelser som trekkes per år (eksportregelen, kapittel 4 i spesifikasjonen). Én rad per trekning, én kolonne per kalenderår. Tallene er jevnt fordelt mellom 0 og 1; en eksportregel innføres i et år når tallet er lavere enn den trukne phi_X.",
|
||||
"tabell": "aarshendelser.npy",
|
||||
"sha256_tabell": "b2a8c282629fea229e5a114506727dcd592c0b2deef95057f276f32fb0dde5f5",
|
||||
"sha256_parametere": "45828355036bb7fc57974bcb4d886ce13dd67a441b4c548836cc184ac3b3f6cc",
|
||||
"sha256_parametere": "4b8809bc56abdd8b2872b89eecffd8453199eef627110276dd10aecea8307f16",
|
||||
"antall_trekninger": 10000,
|
||||
"froe": 20261112,
|
||||
"generator": "PCG64 (numpy.random.Generator)",
|
||||
|
|
|
|||
|
|
@ -1,8 +1,8 @@
|
|||
{
|
||||
"beskrivelse": "Trekningene av de frosne parameterne i modell/parametere.json. Én rad per trekning, én kolonne per størrelse som trekkes, i parameterfilas enheter.",
|
||||
"tabell": "trekninger.npy",
|
||||
"sha256_tabell": "6eabe71ad4ba55327276803f49bf0ca7c14bd5d29244edd0baadd76edc94595c",
|
||||
"sha256_parametere": "45828355036bb7fc57974bcb4d886ce13dd67a441b4c548836cc184ac3b3f6cc",
|
||||
"sha256_tabell": "0306f838dfbff6eef6a2fdb420d1008dca8159be0d473f7925d65d02da417415",
|
||||
"sha256_parametere": "4b8809bc56abdd8b2872b89eecffd8453199eef627110276dd10aecea8307f16",
|
||||
"antall_trekninger": 10000,
|
||||
"froe": 20261111,
|
||||
"generator": "PCG64 (numpy.random.Generator)",
|
||||
|
|
@ -381,6 +381,22 @@
|
|||
{
|
||||
"navn": "eps_e",
|
||||
"enhet": "–"
|
||||
},
|
||||
{
|
||||
"navn": "tau_1",
|
||||
"enhet": "år"
|
||||
},
|
||||
{
|
||||
"navn": "n_1",
|
||||
"enhet": "MW per år"
|
||||
},
|
||||
{
|
||||
"navn": "w_D_uttak",
|
||||
"enhet": "m³/MWh IT"
|
||||
},
|
||||
{
|
||||
"navn": "w_N_uttak",
|
||||
"enhet": "m³/MWh"
|
||||
}
|
||||
]
|
||||
}
|
||||
|
|
|
|||
Binary file not shown.
|
|
@ -27,8 +27,12 @@ from typing import TYPE_CHECKING, Final, cast
|
|||
if TYPE_CHECKING:
|
||||
from collections.abc import Mapping
|
||||
|
||||
FROSSEN_SHA256: Final = "45828355036bb7fc57974bcb4d886ce13dd67a441b4c548836cc184ac3b3f6cc"
|
||||
"""Checksum of the frozen file (commit 01b27fa), as recorded in the pre-registration."""
|
||||
FROSSEN_SHA256: Final = "4b8809bc56abdd8b2872b89eecffd8453199eef627110276dd10aecea8307f16"
|
||||
"""Checksum of the frozen file, as recorded in the pre-registration.
|
||||
|
||||
Version 1.1 of the file: the deviation from the freeze of 2026-11-12 (the quantities of
|
||||
chapter 17 of the specification). The first freeze (commit 01b27fa) had 4582835...f6cc.
|
||||
"""
|
||||
|
||||
STANDARDSTI: Final = Path(__file__).resolve().parents[2] / "modell" / "parametere.json"
|
||||
|
||||
|
|
@ -107,8 +111,12 @@ ENHETSFAKTOR: Final[dict[str, float]] = {
|
|||
"MW IT": 1.0,
|
||||
# emissions and waste -> tonnes per MWh, tonnes per MW IT
|
||||
"g CO2e/kWh": 1e-3,
|
||||
"g CO2/kWh": 1e-3,
|
||||
"tonn CO2e per MW IT": 1.0,
|
||||
"tonn uran per TWh": 1e-6,
|
||||
# cooling water -> m3 per MWh
|
||||
"m³/MWh": 1.0,
|
||||
"m³/MWh IT": 1.0,
|
||||
# time, counts, shares and rates
|
||||
"år": 1.0,
|
||||
"kalenderår": 1.0,
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ import re
|
|||
import statistics
|
||||
from collections import Counter
|
||||
from pathlib import Path
|
||||
from typing import Any
|
||||
from typing import Any, cast
|
||||
|
||||
import pytest
|
||||
|
||||
|
|
@ -39,10 +39,12 @@ def _endret(raa: dict[str, Any], parameter_id: str) -> tuple[dict[str, Any], dic
|
|||
|
||||
|
||||
def test_sjekksummen_er_den_i_forhaandsregistreringen() -> None:
|
||||
"""The freeze section lists the first checksum, then one per deviation; the last applies."""
|
||||
tekst = (ROT / "FORHANDSREGISTRERING.md").read_text(encoding="utf-8")
|
||||
funnet = re.search(r"SHA-256: `([0-9a-f]{64})`", tekst)
|
||||
assert funnet is not None
|
||||
assert funnet.group(1) == pm.FROSSEN_SHA256
|
||||
avsnitt = tekst.split("## Parameterfrys")[1].split("\n## ")[0]
|
||||
funnet = re.findall(r"SHA-256: `([0-9a-f]{64})`", avsnitt)
|
||||
assert len(funnet) == 2
|
||||
assert funnet[-1] == pm.FROSSEN_SHA256
|
||||
assert pm.sjekksum() == pm.FROSSEN_SHA256
|
||||
|
||||
|
||||
|
|
@ -55,13 +57,13 @@ def test_en_endret_fil_avvises(tmp_path: Path) -> None:
|
|||
|
||||
|
||||
def test_antall_og_status_som_i_forhaandsregistreringen(sett: pm.Parametersett) -> None:
|
||||
"""124 parameters: 80 with source, 1 derived, 35 open assumptions, 8 choices of set-up."""
|
||||
assert len(sett.parametere) == 124
|
||||
"""137 parameters: 87 with source, 1 derived, 40 open assumptions, 9 choices of set-up."""
|
||||
assert len(sett.parametere) == 137
|
||||
assert Counter(p.status for p in sett.parametere) == {
|
||||
"kilde": 80,
|
||||
"kilde": 87,
|
||||
"avledet": 1,
|
||||
"åpen forutsetning": 35,
|
||||
"modellvalg": 8,
|
||||
"åpen forutsetning": 40,
|
||||
"modellvalg": 9,
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -271,15 +273,56 @@ def test_prisene_regnes_om_til_2025_kroner_per_mwh(sett: pm.Parametersett) -> No
|
|||
assert set(svakest.pris) == {"NO1", "NO2", "NO3", "NO4", "NO5", "Norge"}
|
||||
|
||||
|
||||
def test_storrelsene_i_tillegget_til_retningen(sett: pm.Parametersett) -> None:
|
||||
"""The quantities of chapter 17.8, added in the deviation from the freeze of 2026-11-12."""
|
||||
assert [p.id for p in sett.parametere[124:]] == [
|
||||
"P_m", "tau_1", "n_1", "eps_d", "d_kilde", "s_flytt", "s_trening", "u_alt",
|
||||
"w_D_uttak", "w_N_uttak", "w_N_forbruk", "w_N_taarn", "w_D_sjo",
|
||||
] # fmt: skip
|
||||
assert sett.fast("P_m") == 100
|
||||
assert sett.fast("eps_d") == 1
|
||||
assert sett.fast("w_N_forbruk") == 0
|
||||
assert sett.fast("w_D_sjo") == 98
|
||||
spenn = {
|
||||
n: sett.storrelse(n).fordeling.tall for n in ("tau_1", "n_1", "w_D_uttak", "w_N_uttak")
|
||||
}
|
||||
assert spenn == {
|
||||
"tau_1": {"lav": 3, "hoy": 7},
|
||||
"n_1": {"lav": 18, "hoy": 268},
|
||||
"w_D_uttak": {"lav": 0.07, "hoy": 0.10},
|
||||
"w_N_uttak": {"lav": 119, "hoy": 168},
|
||||
}
|
||||
assert sett.tabell("d_kilde") == {"2030": 0.119, "2035": 0.21}
|
||||
flytt = cast("dict[str, float]", sett.tabell("s_flytt"))
|
||||
trening = cast("dict[str, float]", sett.tabell("s_trening"))
|
||||
bortfall = [
|
||||
flytt[aar] * (1 - trening[ende]) for ende in ("hoy", "lav") for aar in ("2030", "2035")
|
||||
]
|
||||
assert bortfall == pytest.approx([0.188, 0.376, 0.32, 0.64])
|
||||
utslipp = cast("dict[str, Any]", sett.tabell("u_alt"))
|
||||
assert utslipp["hoved"] == {"2024": 430, "2030": 340, "2035": 270, "2040": 201.2, "2050": 131.2}
|
||||
assert utslipp["hoved"]["2040"] == pytest.approx(270 * 187 / 251, abs=0.05)
|
||||
assert utslipp["hoved"]["2050"] == pytest.approx(270 * 122 / 251, abs=0.05)
|
||||
assert utslipp["lav"] == {"2025": 170, "2030": 90}
|
||||
assert utslipp["hoy"] == {"lav": 410, "hoy": 626}
|
||||
assert utslipp["null"] == 0
|
||||
assert sett.storrelse("u_alt").faktor == pytest.approx(1e-3) # g per kWh -> tonnes per MWh
|
||||
assert sett.tabell("w_N_taarn") == {"forbruk": [2.2, 2.5, 3.2], "uttak": [3.0, 4.2, 9.8]}
|
||||
assert {
|
||||
sett.parameter(i).status for i in ("tau_1", "n_1", "eps_d", "s_flytt", "w_N_forbruk")
|
||||
} == {"åpen forutsetning"}
|
||||
|
||||
|
||||
def test_alle_storrelser_og_rekkefolgen(sett: pm.Parametersett) -> None:
|
||||
"""136 scalar quantities with the composites split; 87 of them are drawn, in file order."""
|
||||
assert len(sett.storrelser()) == 136
|
||||
"""149 scalar quantities with the composites split; 91 of them are drawn, in file order."""
|
||||
assert len(sett.storrelser()) == 149
|
||||
stokastiske = [s.navn for s in sett.stokastiske()]
|
||||
assert len(stokastiske) == 87
|
||||
assert len(stokastiske) == 91
|
||||
assert stokastiske[:4] == ["c_N_ref", "w_xi", "u_xi", "o_xi"]
|
||||
assert stokastiske[-1] == "eps_e"
|
||||
assert stokastiske[86] == "eps_e"
|
||||
assert stokastiske[87:] == ["tau_1", "n_1", "w_D_uttak", "w_N_uttak"]
|
||||
plass = stokastiske.index("vann.investering")
|
||||
assert stokastiske[plass : plass + 2] == ["vann.investering", "vann.drift"]
|
||||
assert sett.monte_carlo.froe == 20261111
|
||||
assert sett.monte_carlo.antall_trekninger == 10_000
|
||||
assert len(sett.foelsomheter) == 29
|
||||
assert len(sett.foelsomheter) == 37
|
||||
|
|
|
|||
|
|
@ -49,7 +49,7 @@ def _kvantil(sett: pm.Parametersett, navn: str, q: float) -> float:
|
|||
def test_oppsettet_folger_parameterfila(
|
||||
sett: pm.Parametersett, trukket: trekninger.Trekninger
|
||||
) -> None:
|
||||
assert trukket.tabell.shape == (10_000, 87)
|
||||
assert trukket.tabell.shape == (10_000, 91)
|
||||
assert trukket.kolonner == tuple(s.navn for s in sett.stokastiske())
|
||||
assert trukket.tabell.dtype == np.float64
|
||||
assert np.isfinite(trukket.tabell).all()
|
||||
|
|
@ -96,7 +96,7 @@ def test_skriv_og_les(
|
|||
|
||||
def test_kommandolinjen(tmp_path: Path, capsys: pytest.CaptureFixture[str]) -> None:
|
||||
assert trekninger.main(["lag", "--mappe", str(tmp_path)]) == 0
|
||||
assert "10000 trekninger av 87 størrelser" in capsys.readouterr().out
|
||||
assert "10000 trekninger av 91 størrelser" in capsys.readouterr().out
|
||||
assert trekninger.main(["kontroll", "--mappe", str(tmp_path)]) == 0
|
||||
assert capsys.readouterr().out.startswith("identisk")
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue