deepdesk-bench / shared /scripts /generate_cases.py
qrlow's picture
feat: publish SnD Floaters benchmark (part 2)
23883dd verified
Raw History Blame Contribute Delete
60.6 kB
#!/usr/bin/env python3
"""Generate the synthetic SnD Floaters evaluation cases and answer keys."""
from __future__ import annotations
import json
from collections import defaultdict
from copy import deepcopy
from datetime import date, datetime, time, timedelta
from pathlib import Path
from typing import Any, Optional
from zoneinfo import ZoneInfo
ROOT = Path(__file__).resolve().parents[1]
CASES_ROOT = ROOT / "cases"
SCHEMAS_ROOT = ROOT / "schemas"
TERMINALS = [
{
"terminal_id": "FR-DKK",
"name": "Dunkerque LNG",
"timezone": "Europe/Paris",
"in_scope": True,
},
{
"terminal_id": "BE-ZEE",
"name": "Zeebrugge LNG",
"timezone": "Europe/Brussels",
"in_scope": True,
},
{
"terminal_id": "GB-SOU",
"name": "South Hook LNG",
"timezone": "Europe/London",
"in_scope": True,
},
{
"terminal_id": "NL-GATE",
"name": "Gate LNG",
"timezone": "Europe/Amsterdam",
"in_scope": True,
},
{
"terminal_id": "TR-ALI",
"name": "Aliaga LNG",
"timezone": "Europe/Istanbul",
"in_scope": False,
},
]
BASE_RULES = [
{
"rule_id": "R-CUTOFF",
"description": "Use an observation only when received_at is at or before as_of and retracted is false.",
},
{
"rule_id": "R-SOURCE-PRECEDENCE",
"description": "For destination and arrival, terminal_nomination outranks port_call, which outranks AIS. Equal-priority conflicts remain unresolved.",
},
{
"rule_id": "R-AIS-DESTINATION-STALENESS",
"description": "An AIS destination older than 24 hours at as_of is stale and cannot override a non-stale higher-priority source.",
"stale_after_hours": 24,
},
{
"rule_id": "R-STATE-LADEN",
"description": "A recent AIS observation explicitly marked laden and underway supports the inferred state laden_underway.",
},
{
"rule_id": "R-GAS-DAY",
"description": "Assign arrival to the gas day containing it in the case timezone. Gas days begin at 06:00 local time.",
},
{
"rule_id": "R-SENDOUT-STANDARD-3D",
"description": "Allocate an in-scope discharge over three gas days from its start day using fractions 0.20, 0.50, and 0.30.",
"fractions": [0.2, 0.5, 0.3],
},
{
"rule_id": "R-OUTAGE-PUSH",
"description": "If sendout would start on a zero-capacity gas day, shift the whole three-day profile to the first open gas day.",
},
{
"rule_id": "R-DUPLICATE",
"description": "Records for the same IMO, voyage_id, event, time, and value describe one cargo event, even when supplied by multiple feeds.",
},
{
"rule_id": "R-SPLIT",
"description": "When explicit discharge fractions sum to one, keep one cargo identity and create one discharge leg per terminal.",
},
{
"rule_id": "R-SCOPE",
"description": "An out-of-scope discharge contributes zero to European LNG sendout; retain its energy as unallocated_gwh for auditability.",
},
{
"rule_id": "R-UNKNOWN",
"description": "Return null and an exception when the supplied evidence and rules cannot resolve a material value. Do not invent conversions or tie-breakers.",
},
{
"rule_id": "R-CARGO-DIFF",
"description": "LNG balance delta equals updated in-scope cargo sendout minus the matched prior cargo sendout for each gas day.",
},
{
"rule_id": "R-BALANCE-ARITHMETIC",
"description": "For every balance row, updated_contribution_gwh equals prior_contribution_gwh plus delta_contribution_gwh.",
},
{
"rule_id": "R-BALANCER",
"description": "Offset the LNG sendout delta in storage_net with the opposite sign so the daily residual stays zero.",
},
]
def write_json(path: Path, value: Any) -> None:
path.parent.mkdir(parents=True, exist_ok=True)
path.write_text(json.dumps(value, indent=2, ensure_ascii=False) + "\n", encoding="utf-8")
def write_text(path: Path, value: str) -> None:
path.parent.mkdir(parents=True, exist_ok=True)
path.write_text(value.rstrip() + "\n", encoding="utf-8")
def gas_days(start: str, count: int = 3) -> list[str]:
first = date.fromisoformat(start)
return [(first + timedelta(days=i)).isoformat() for i in range(count)]
def gas_day_for(arrival: str, timezone: str = "Europe/Brussels") -> str:
instant = datetime.fromisoformat(arrival.replace("Z", "+00:00"))
local = instant.astimezone(ZoneInfo(timezone))
label = local.date()
if local.timetz().replace(tzinfo=None) < time(6, 0):
label -= timedelta(days=1)
return label.isoformat()
def standard_profile(quantity_gwh: float, fraction: float, start_day: str) -> list[dict[str, Any]]:
start = date.fromisoformat(start_day)
weights = [0.2, 0.5, 0.3]
return [
{
"gas_day": (start + timedelta(days=i)).isoformat(),
"gwh": round(quantity_gwh * fraction * weight, 3),
}
for i, weight in enumerate(weights)
]
def make_prior_balance(days: list[str]) -> list[dict[str, Any]]:
production = [480.0, 475.0, 470.0, 465.0]
pipeline = [2600.0, 2580.0, 2550.0, 2540.0]
lng = [1000.0, 1020.0, 980.0, 990.0]
demand = [-3650.0, -3620.0, -3600.0, -3580.0]
exports = [-120.0, -115.0, -110.0, -105.0]
records: list[dict[str, Any]] = []
for i, day in enumerate(days):
idx = i % len(production)
non_storage = {
"domestic_production": production[idx],
"pipeline_imports": pipeline[idx],
"lng_sendout": lng[idx],
"demand": demand[idx],
"exports": exports[idx],
}
storage = -sum(non_storage.values())
components = {**non_storage, "storage_net": round(storage, 3)}
for component_id, contribution in components.items():
records.append(
{
"record_id": f"bal-{day}-{component_id}",
"gas_day": day,
"component_id": component_id,
"contribution_gwh": contribution,
}
)
return records
def observation(
observation_id: str,
event_time: str,
received_at: str,
source: str,
kind: str,
imo: str,
voyage_id: str,
value: dict[str, Any],
*,
supersedes: Optional[str] = None,
retracted: bool = False,
) -> dict[str, Any]:
return {
"observation_id": observation_id,
"event_time": event_time,
"received_at": received_at,
"source": source,
"kind": kind,
"subject": {"imo": imo, "voyage_id": voyage_id},
"value": value,
"supersedes_observation_id": supersedes,
"retracted": retracted,
}
def prior_cargo(
cargo_id: str,
imo: str,
voyage_id: str,
quantity_gwh: float,
legs: list[dict[str, Any]],
) -> dict[str, Any]:
return {
"cargo_id": cargo_id,
"imo": imo,
"voyage_id": voyage_id,
"quantity_gwh": quantity_gwh,
"included_in_prior_balance": True,
"discharge_legs": legs,
}
def prior_leg(
leg_id: str,
terminal_id: str,
arrival_time: str,
discharge_fraction: float,
profile: list[dict[str, Any]],
*,
included_in_scope: bool = True,
) -> dict[str, Any]:
return {
"leg_id": leg_id,
"terminal_id": terminal_id,
"included_in_scope": included_in_scope,
"arrival_time": arrival_time,
"discharge_fraction": discharge_fraction,
"sendout_profile": profile,
}
def basis(
kind: str,
evidence_ids: Optional[list[str]] = None,
rule_id: Optional[Any] = None,
assumption_id: Optional[str] = None,
) -> dict[str, Any]:
rule_ids = [] if rule_id is None else (rule_id if isinstance(rule_id, list) else [rule_id])
return {
"kind": kind,
"evidence_ids": evidence_ids or [],
"rule_ids": rule_ids,
"assumption_id": assumption_id,
}
def decision(value: Any, item_basis: dict[str, Any]) -> dict[str, Any]:
return {"value": value, "basis": item_basis}
def estimate(
central: Optional[float],
item_basis: dict[str, Any],
lower: Optional[float] = None,
upper: Optional[float] = None,
) -> dict[str, Any]:
if central is not None:
lower = central if lower is None else lower
upper = central if upper is None else upper
return {"lower": lower, "central": central, "upper": upper, "basis": item_basis}
def time_estimate(value: Optional[str], item_basis: dict[str, Any]) -> dict[str, Any]:
return {"earliest": value, "central": value, "latest": value, "basis": item_basis}
def answer_leg(
leg_id: str,
terminal_id: str,
included_in_scope: bool,
arrival_time: str,
discharge_fraction: float,
profile: list[dict[str, Any]],
quantity_gwh: float,
*,
terminal_basis: dict[str, Any],
arrival_basis: dict[str, Any],
fraction_basis: dict[str, Any],
profile_basis: dict[str, Any],
unallocated_gwh: float = 0.0,
) -> dict[str, Any]:
return {
"leg_id": leg_id,
"terminal_id": decision(terminal_id, terminal_basis),
"included_in_scope": included_in_scope,
"arrival_time": time_estimate(arrival_time, arrival_basis),
"discharge_fraction": estimate(discharge_fraction, fraction_basis),
"sendout_profile": {
"points": profile,
"unallocated_gwh": round(unallocated_gwh, 3),
"basis": profile_basis,
},
}
def cargo_update(
update_id: str,
matched_prior_cargo_id: Optional[str],
source_observation_ids: list[str],
action: str,
state: Optional[str],
quantity_gwh: Optional[float],
legs: list[dict[str, Any]],
*,
action_basis: dict[str, Any],
state_basis: dict[str, Any],
quantity_basis: dict[str, Any],
risk_flags: Optional[list[str]] = None,
) -> dict[str, Any]:
return {
"update_id": update_id,
"matched_prior_cargo_id": matched_prior_cargo_id,
"source_observation_ids": source_observation_ids,
"action": decision(action, action_basis),
"operational_state": decision(state, state_basis),
"quantity_gwh": estimate(quantity_gwh, quantity_basis),
"discharge_legs": legs,
"risk_flags": risk_flags or [],
}
def profile_map(legs: list[dict[str, Any]], answer_format: bool) -> dict[str, float]:
result: defaultdict[str, float] = defaultdict(float)
for leg in legs:
if not leg["included_in_scope"]:
continue
profile = leg["sendout_profile"]
points = profile["points"] if answer_format else profile
for point in points:
result[point["gas_day"]] += point["gwh"]
return {day: round(value, 3) for day, value in result.items()}
def cargo_delta_from_answer(
days: list[str],
prior_book: list[dict[str, Any]],
updates: list[dict[str, Any]],
) -> dict[str, float]:
prior_by_id = {cargo["cargo_id"]: cargo for cargo in prior_book}
delta: defaultdict[str, float] = defaultdict(float)
for update in updates:
prior_id = update["matched_prior_cargo_id"]
if prior_id is not None:
prior_profile = profile_map(prior_by_id[prior_id]["discharge_legs"], answer_format=False)
for day, amount in prior_profile.items():
delta[day] -= amount
updated_profile = profile_map(update["discharge_legs"], answer_format=True)
for day, amount in updated_profile.items():
delta[day] += amount
return {day: round(delta.get(day, 0.0), 3) for day in days}
def build_daily_balance(
prior_balance: list[dict[str, Any]],
days: list[str],
lng_delta: dict[str, float],
change_evidence: list[str],
) -> list[dict[str, Any]]:
prior_by_day: defaultdict[str, dict[str, dict[str, Any]]] = defaultdict(dict)
for row in prior_balance:
prior_by_day[row["gas_day"]][row["component_id"]] = row
output: list[dict[str, Any]] = []
order = [
"domestic_production",
"pipeline_imports",
"lng_sendout",
"demand",
"exports",
"storage_net",
]
for day in days:
components: list[dict[str, Any]] = []
for component_id in order:
prior_row = prior_by_day[day][component_id]
delta = 0.0
evidence = [prior_row["record_id"]]
rule_id = "R-BALANCE-ARITHMETIC"
if component_id == "lng_sendout":
delta = lng_delta[day]
evidence += change_evidence
rule_id = "R-CARGO-DIFF"
elif component_id == "storage_net":
delta = -lng_delta[day]
evidence += change_evidence
rule_id = "R-BALANCER"
updated = round(prior_row["contribution_gwh"] + delta, 3)
components.append(
{
"component_id": component_id,
"prior_contribution_gwh": prior_row["contribution_gwh"],
"delta_contribution_gwh": round(delta, 3),
"updated_contribution_gwh": updated,
"basis": basis("calculated", evidence, rule_id),
}
)
residual = round(sum(row["updated_contribution_gwh"] for row in components), 3)
output.append({"gas_day": day, "components": components, "residual_gwh": residual})
return output
def input_document(
case_id: str,
title: str,
difficulty: str,
as_of: str,
days: list[str],
prior_book: list[dict[str, Any]],
observations: list[dict[str, Any]],
*,
timezone: str = "Europe/Brussels",
capacity_schedule: Optional[list[dict[str, Any]]] = None,
unit_conversions: Optional[list[dict[str, Any]]] = None,
) -> dict[str, Any]:
return {
"schema_version": "1.0",
"case_id": case_id,
"title": title,
"difficulty": difficulty,
"task": "Update the synthetic European gas balance from the supplied LNG floater observations. Use only this case and return JSON matching schemas/answer.schema.json.",
"as_of": as_of,
"scope": {
"market_area": "EU27+UK",
"included_terminal_ids": ["FR-DKK", "BE-ZEE", "GB-SOU", "NL-GATE"],
"balance_gas_days": days,
"cargo_lookahead_end": (date.fromisoformat(days[-1]) + timedelta(days=3)).isoformat(),
},
"conventions": {
"unit": "GWh",
"timezone": timezone,
"gas_day_start_local": "06:00",
"balance_representation": "signed_contribution",
"balancing_component_id": "storage_net",
"must_balance": True,
"rounding_gwh": 0.001,
"unknown_policy": "emit_null",
},
"rules": deepcopy(BASE_RULES),
"reference_data": {
"terminals": deepcopy(TERMINALS),
"sendout_profiles": {
"standard-3d": {"fractions": [0.2, 0.5, 0.3]}
},
"capacity_schedule": capacity_schedule or [],
"unit_conversions": unit_conversions or [],
},
"prior_balance": make_prior_balance(days),
"prior_cargo_book": prior_book,
"observations": observations,
}
def answer_document(
case_input: dict[str, Any],
updates: list[dict[str, Any]],
change_evidence: list[str],
*,
exceptions: Optional[list[dict[str, Any]]] = None,
quality_overrides: Optional[dict[str, str]] = None,
) -> dict[str, Any]:
days = case_input["scope"]["balance_gas_days"]
lng_delta = cargo_delta_from_answer(days, case_input["prior_cargo_book"], updates)
quality = {
"cutoff_respected": "pass",
"no_duplicate_cargo": "pass",
"profile_mass_conserved": "pass",
"terminal_constraints_respected": "pass",
"component_arithmetic_reconciled": "pass",
"balance_reconciled": "pass",
}
quality.update(quality_overrides or {})
return {
"schema_version": "1.0",
"case_id": case_input["case_id"],
"as_of": case_input["as_of"],
"unit": "GWh",
"cargo_updates": updates,
"daily_balance": build_daily_balance(
case_input["prior_balance"], days, lng_delta, change_evidence
),
"assumptions": [],
"exceptions": exceptions or [],
"quality_checks": quality,
}
def exception(code: str, severity: str, entity_ids: list[str], action: str) -> dict[str, Any]:
return {
"code": code,
"severity": severity,
"entity_ids": entity_ids,
"action": action,
}
def build_cases() -> list[dict[str, Any]]:
cases: list[dict[str, Any]] = []
# 01: New cargo added to the balance.
days = gas_days("2026-01-15")
obs = [
observation(
"obs-101",
"2026-01-14T09:00:00Z",
"2026-01-14T09:02:00Z",
"ais",
"position",
"9100001",
"voyage-101",
{"navigation_state": "underway", "load_state": "laden"},
),
observation(
"obs-102",
"2026-01-14T10:00:00Z",
"2026-01-14T10:05:00Z",
"terminal_nomination",
"scheduled_discharge",
"9100001",
"voyage-101",
{
"terminal_id": "FR-DKK",
"arrival_time": "2026-01-15T08:00:00Z",
"quantity": 600.0,
"unit": "GWh",
"discharge_fraction": 1.0,
},
),
]
case_input = input_document(
"floater-001", "New in-scope cargo", "easy", "2026-01-14T12:00:00Z", days, [], obs
)
profile = standard_profile(600.0, 1.0, gas_day_for("2026-01-15T08:00:00Z"))
leg = answer_leg(
"leg-101-a",
"FR-DKK",
True,
"2026-01-15T08:00:00Z",
1.0,
profile,
600.0,
terminal_basis=basis("observed", ["obs-102"]),
arrival_basis=basis("observed", ["obs-102"]),
fraction_basis=basis("observed", ["obs-102"]),
profile_basis=basis("calculated", ["obs-102"], "R-SENDOUT-STANDARD-3D"),
)
update = cargo_update(
"update-101",
None,
["obs-101", "obs-102"],
"add",
"laden_underway",
600.0,
[leg],
action_basis=basis("inferred", ["obs-101", "obs-102"], "R-CARGO-DIFF"),
state_basis=basis("inferred", ["obs-101"], "R-STATE-LADEN"),
quantity_basis=basis("observed", ["obs-102"]),
)
answer = answer_document(case_input, [update], ["obs-101", "obs-102"])
cases.append(
{
"slug": "01_new_cargo",
"input": case_input,
"answer": answer,
"primary_test": "Add a previously unbooked cargo and translate arrival into terminal sendout.",
"review_points": [
"The cargo adds 120, 300, and 180 GWh of LNG sendout.",
"storage_net moves by the opposite amount on each gas day.",
"The AIS state is inferred, while nomination fields are observed.",
],
}
)
# 02: Existing cargo delayed by two gas days.
days = gas_days("2026-01-15")
prior_profile = standard_profile(900.0, 1.0, "2026-01-15")
book = [
prior_cargo(
"cargo-201",
"9100002",
"voyage-201",
900.0,
[prior_leg("prior-leg-201", "BE-ZEE", "2026-01-15T08:00:00Z", 1.0, prior_profile)],
)
]
obs = [
observation(
"obs-201",
"2026-01-14T09:30:00Z",
"2026-01-14T09:31:00Z",
"ais",
"position",
"9100002",
"voyage-201",
{"navigation_state": "underway", "load_state": "laden"},
),
observation(
"obs-202",
"2026-01-14T10:15:00Z",
"2026-01-14T10:16:00Z",
"terminal_nomination",
"schedule_change",
"9100002",
"voyage-201",
{
"terminal_id": "BE-ZEE",
"arrival_time": "2026-01-17T08:00:00Z",
"discharge_fraction": 1.0,
"reason": "berth delay"
},
),
]
case_input = input_document(
"floater-002", "Existing cargo delayed", "medium", "2026-01-14T12:00:00Z", days, book, obs
)
new_profile = standard_profile(900.0, 1.0, "2026-01-17")
leg = answer_leg(
"leg-201-a",
"BE-ZEE",
True,
"2026-01-17T08:00:00Z",
1.0,
new_profile,
900.0,
terminal_basis=basis("observed", ["obs-202"]),
arrival_basis=basis("observed", ["obs-202"]),
fraction_basis=basis("observed", ["obs-202"]),
profile_basis=basis("calculated", ["cargo-201", "obs-202"], "R-SENDOUT-STANDARD-3D"),
)
update = cargo_update(
"update-201",
"cargo-201",
["obs-201", "obs-202"],
"reschedule",
"laden_underway",
900.0,
[leg],
action_basis=basis("inferred", ["cargo-201", "obs-202"], "R-CARGO-DIFF"),
state_basis=basis("inferred", ["obs-201"], "R-STATE-LADEN"),
quantity_basis=basis("observed", ["cargo-201"]),
)
answer = answer_document(case_input, [update], ["cargo-201", "obs-202"])
cases.append(
{
"slug": "02_delayed_existing_cargo",
"input": case_input,
"answer": answer,
"primary_test": "Subtract the prior profile before adding the delayed profile.",
"review_points": [
"The LNG deltas for the visible horizon are -180, -450, and -90 GWh.",
"The cargo is rescheduled, not added as a second cargo.",
"Sendout on 18 and 19 January remains in the cargo profile even though it is outside the balance horizon.",
],
}
)
# 03: Existing European cargo diverts outside scope.
days = gas_days("2026-01-15")
prior_profile = standard_profile(750.0, 1.0, "2026-01-15")
book = [
prior_cargo(
"cargo-301",
"9100003",
"voyage-301",
750.0,
[prior_leg("prior-leg-301", "FR-DKK", "2026-01-15T08:00:00Z", 1.0, prior_profile)],
)
]
obs = [
observation(
"obs-301",
"2026-01-14T10:00:00Z",
"2026-01-14T10:01:00Z",
"port_call",
"diversion",
"9100003",
"voyage-301",
{
"terminal_id": "TR-ALI",
"arrival_time": "2026-01-16T10:00:00Z",
"discharge_fraction": 1.0,
},
)
]
case_input = input_document(
"floater-003", "Cargo diverted outside scope", "medium", "2026-01-14T12:00:00Z", days, book, obs
)
leg = answer_leg(
"leg-301-a",
"TR-ALI",
False,
"2026-01-16T10:00:00Z",
1.0,
[],
750.0,
terminal_basis=basis("observed", ["obs-301"]),
arrival_basis=basis("observed", ["obs-301"]),
fraction_basis=basis("observed", ["obs-301"]),
profile_basis=basis("calculated", ["cargo-301", "obs-301"], "R-SCOPE"),
unallocated_gwh=750.0,
)
update = cargo_update(
"update-301",
"cargo-301",
["obs-301"],
"remove",
"laden_underway",
750.0,
[leg],
action_basis=basis("inferred", ["cargo-301", "obs-301"], "R-SCOPE"),
state_basis=basis("inferred", ["obs-301"], "R-SOURCE-PRECEDENCE"),
quantity_basis=basis("observed", ["cargo-301"]),
risk_flags=["diverted_outside_scope"],
)
answer = answer_document(
case_input,
[update],
["cargo-301", "obs-301"],
exceptions=[exception("DIVERTED_OUTSIDE_SCOPE", "info", ["cargo-301", "obs-301"], "exclude")],
)
cases.append(
{
"slug": "03_diverted_outside_scope",
"input": case_input,
"answer": answer,
"primary_test": "Remove a previously booked European cargo after an out-of-scope diversion.",
"review_points": [
"All three prior LNG sendout contributions are removed.",
"The cargo energy remains visible as unallocated_gwh rather than disappearing.",
"No Turkish terminal sendout is added to the European balance.",
],
}
)
# 04: Stale AIS destination conflicts with a current terminal nomination.
days = gas_days("2026-01-15")
prior_profile = standard_profile(600.0, 1.0, "2026-01-15")
book = [
prior_cargo(
"cargo-401",
"9100004",
"voyage-401",
600.0,
[prior_leg("prior-leg-401", "BE-ZEE", "2026-01-15T08:00:00Z", 1.0, prior_profile)],
)
]
obs = [
observation(
"obs-401",
"2026-01-12T02:00:00Z",
"2026-01-12T02:01:00Z",
"ais",
"declared_destination",
"9100004",
"voyage-401",
{"destination_text": "SOUTHAMPTON", "navigation_state": "underway", "load_state": "laden"},
),
observation(
"obs-402",
"2026-01-14T10:30:00Z",
"2026-01-14T10:31:00Z",
"terminal_nomination",
"scheduled_discharge",
"9100004",
"voyage-401",
{
"terminal_id": "BE-ZEE",
"arrival_time": "2026-01-15T08:00:00Z",
"quantity": 600.0,
"unit": "GWh",
"discharge_fraction": 1.0,
},
),
]
case_input = input_document(
"floater-004", "Stale AIS destination conflict", "medium", "2026-01-14T12:00:00Z", days, book, obs
)
leg = answer_leg(
"leg-401-a",
"BE-ZEE",
True,
"2026-01-15T08:00:00Z",
1.0,
prior_profile,
600.0,
terminal_basis=basis("observed", ["obs-402"]),
arrival_basis=basis("observed", ["obs-402"]),
fraction_basis=basis("observed", ["obs-402"]),
profile_basis=basis("calculated", ["cargo-401", "obs-402"], "R-SENDOUT-STANDARD-3D"),
)
update = cargo_update(
"update-401",
"cargo-401",
["obs-401", "obs-402"],
"unchanged",
"laden_underway",
600.0,
[leg],
action_basis=basis(
"inferred",
["cargo-401", "obs-401", "obs-402"],
["R-SOURCE-PRECEDENCE", "R-AIS-DESTINATION-STALENESS"],
),
state_basis=basis("inferred", ["obs-401"], "R-STATE-LADEN"),
quantity_basis=basis("observed", ["obs-402"]),
risk_flags=["stale_ais_destination_ignored"],
)
answer = answer_document(
case_input,
[update],
["cargo-401", "obs-402"],
exceptions=[exception("STALE_LOWER_PRIORITY_DESTINATION", "warning", ["obs-401", "obs-402"], "none")],
)
cases.append(
{
"slug": "04_stale_destination_conflict",
"input": case_input,
"answer": answer,
"primary_test": "Prefer a current terminal nomination over stale AIS text.",
"review_points": [
"The cargo and balance remain unchanged.",
"The old SOUTHAMPTON text is retained as a warning, not used as the destination.",
"The answer cites the nomination as direct evidence for the terminal.",
],
}
)
# 05: A cargo changes from one full discharge to two explicit discharge legs.
days = gas_days("2026-01-15")
prior_profile = standard_profile(1000.0, 1.0, "2026-01-15")
book = [
prior_cargo(
"cargo-501",
"9100005",
"voyage-501",
1000.0,
[prior_leg("prior-leg-501", "FR-DKK", "2026-01-15T08:00:00Z", 1.0, prior_profile)],
)
]
obs = [
observation(
"obs-501",
"2026-01-14T10:00:00Z",
"2026-01-14T10:01:00Z",
"terminal_nomination",
"split_discharge",
"9100005",
"voyage-501",
{"terminal_id": "FR-DKK", "arrival_time": "2026-01-15T08:00:00Z", "discharge_fraction": 0.4},
),
observation(
"obs-502",
"2026-01-14T10:05:00Z",
"2026-01-14T10:06:00Z",
"terminal_nomination",
"split_discharge",
"9100005",
"voyage-501",
{"terminal_id": "GB-SOU", "arrival_time": "2026-01-17T08:00:00Z", "discharge_fraction": 0.6},
),
observation(
"obs-503",
"2026-01-14T09:30:00Z",
"2026-01-14T09:31:00Z",
"ais",
"position",
"9100005",
"voyage-501",
{"navigation_state": "underway", "load_state": "laden"},
),
]
case_input = input_document(
"floater-005", "Split discharge at two terminals", "hard", "2026-01-14T12:00:00Z", days, book, obs
)
leg_a = answer_leg(
"leg-501-a",
"FR-DKK",
True,
"2026-01-15T08:00:00Z",
0.4,
standard_profile(1000.0, 0.4, "2026-01-15"),
1000.0,
terminal_basis=basis("observed", ["obs-501"]),
arrival_basis=basis("observed", ["obs-501"]),
fraction_basis=basis("observed", ["obs-501"]),
profile_basis=basis("calculated", ["cargo-501", "obs-501"], "R-SENDOUT-STANDARD-3D"),
)
leg_b = answer_leg(
"leg-501-b",
"GB-SOU",
True,
"2026-01-17T08:00:00Z",
0.6,
standard_profile(1000.0, 0.6, "2026-01-17"),
1000.0,
terminal_basis=basis("observed", ["obs-502"]),
arrival_basis=basis("observed", ["obs-502"]),
fraction_basis=basis("observed", ["obs-502"]),
profile_basis=basis("calculated", ["cargo-501", "obs-502"], "R-SENDOUT-STANDARD-3D"),
)
update = cargo_update(
"update-501",
"cargo-501",
["obs-501", "obs-502", "obs-503"],
"split",
"laden_underway",
1000.0,
[leg_a, leg_b],
action_basis=basis("inferred", ["cargo-501", "obs-501", "obs-502"], "R-SPLIT"),
state_basis=basis("inferred", ["obs-503"], "R-STATE-LADEN"),
quantity_basis=basis("observed", ["cargo-501"]),
risk_flags=["multi_terminal_discharge"],
)
answer = answer_document(
case_input,
[update],
["cargo-501", "obs-501", "obs-502"],
exceptions=[exception("SPLIT_DISCHARGE", "info", ["cargo-501", "obs-501", "obs-502"], "none")],
)
cases.append(
{
"slug": "05_split_discharge",
"input": case_input,
"answer": answer,
"primary_test": "Preserve cargo identity while allocating two discharge legs.",
"review_points": [
"The 40% and 60% legs sum to the full 1,000 GWh cargo.",
"The LNG deltas for the visible horizon are -120, -300, and -60 GWh.",
"The second leg continues beyond the three-day balance horizon.",
],
}
)
# 06: Terminal outage pushes the profile one day later.
days = gas_days("2026-01-15")
obs = [
observation(
"obs-601",
"2026-01-14T10:00:00Z",
"2026-01-14T10:01:00Z",
"terminal_nomination",
"scheduled_discharge",
"9100006",
"voyage-601",
{
"terminal_id": "NL-GATE",
"arrival_time": "2026-01-15T08:00:00Z",
"quantity": 800.0,
"unit": "GWh",
"discharge_fraction": 1.0,
},
),
observation(
"obs-602",
"2026-01-14T09:00:00Z",
"2026-01-14T09:01:00Z",
"ais",
"position",
"9100006",
"voyage-601",
{"navigation_state": "underway", "load_state": "laden"},
),
]
capacity = [
{
"record_id": "capacity-NL-GATE-2026-01-15",
"terminal_id": "NL-GATE",
"gas_day": "2026-01-15",
"sendout_capacity_gwh": 0.0,
"reason": "planned outage",
}
]
case_input = input_document(
"floater-006",
"Terminal outage shifts sendout",
"medium",
"2026-01-14T12:00:00Z",
days,
[],
obs,
capacity_schedule=capacity,
)
shifted_profile = standard_profile(800.0, 1.0, "2026-01-16")
leg = answer_leg(
"leg-601-a",
"NL-GATE",
True,
"2026-01-15T08:00:00Z",
1.0,
shifted_profile,
800.0,
terminal_basis=basis("observed", ["obs-601"]),
arrival_basis=basis("observed", ["obs-601"]),
fraction_basis=basis("observed", ["obs-601"]),
profile_basis=basis(
"calculated",
["obs-601", "capacity-NL-GATE-2026-01-15"],
["R-SENDOUT-STANDARD-3D", "R-OUTAGE-PUSH"],
),
)
update = cargo_update(
"update-601",
None,
["obs-601", "obs-602"],
"add",
"laden_underway",
800.0,
[leg],
action_basis=basis("inferred", ["obs-601", "obs-602"], "R-CARGO-DIFF"),
state_basis=basis("inferred", ["obs-602"], "R-STATE-LADEN"),
quantity_basis=basis("observed", ["obs-601"]),
risk_flags=["terminal_outage"],
)
answer = answer_document(
case_input,
[update],
["obs-601", "capacity-NL-GATE-2026-01-15"],
exceptions=[exception("TERMINAL_OUTAGE_PROFILE_SHIFT", "warning", ["obs-601", "capacity-NL-GATE-2026-01-15"], "defer")],
)
cases.append(
{
"slug": "06_terminal_outage",
"input": case_input,
"answer": answer,
"primary_test": "Keep arrival and sendout timing separate during a terminal outage.",
"review_points": [
"The vessel still arrives on 15 January.",
"The zero-capacity day shifts sendout to 16, 17, and 18 January.",
"Only 160 and 400 GWh fall inside the visible balance horizon.",
],
}
)
# 07: Duplicate vendor observations describe one new cargo.
days = gas_days("2026-01-15")
duplicate_value = {"terminal_id": "FR-DKK", "arrival_time": "2026-01-15T09:00:00Z"}
obs = [
observation(
"obs-701",
"2026-01-14T09:00:00Z",
"2026-01-14T09:01:00Z",
"ais_feed_a",
"destination_update",
"9100007",
"voyage-701",
deepcopy(duplicate_value),
),
observation(
"obs-702",
"2026-01-14T09:00:00Z",
"2026-01-14T09:02:00Z",
"ais_feed_b",
"destination_update",
"9100007",
"voyage-701",
deepcopy(duplicate_value),
),
observation(
"obs-703",
"2026-01-14T10:00:00Z",
"2026-01-14T10:01:00Z",
"terminal_nomination",
"scheduled_discharge",
"9100007",
"voyage-701",
{
"terminal_id": "FR-DKK",
"arrival_time": "2026-01-15T09:00:00Z",
"quantity": 500.0,
"unit": "GWh",
"discharge_fraction": 1.0,
},
),
observation(
"obs-704",
"2026-01-14T09:30:00Z",
"2026-01-14T09:31:00Z",
"ais",
"position",
"9100007",
"voyage-701",
{"navigation_state": "underway", "load_state": "laden"},
),
]
case_input = input_document(
"floater-007", "Duplicate feed records", "medium", "2026-01-14T12:00:00Z", days, [], obs
)
profile = standard_profile(500.0, 1.0, "2026-01-15")
leg = answer_leg(
"leg-701-a",
"FR-DKK",
True,
"2026-01-15T09:00:00Z",
1.0,
profile,
500.0,
terminal_basis=basis("observed", ["obs-703"]),
arrival_basis=basis("observed", ["obs-703"]),
fraction_basis=basis("observed", ["obs-703"]),
profile_basis=basis("calculated", ["obs-703"], "R-SENDOUT-STANDARD-3D"),
)
update = cargo_update(
"update-701",
None,
["obs-701", "obs-702", "obs-703", "obs-704"],
"add",
"laden_underway",
500.0,
[leg],
action_basis=basis("inferred", ["obs-701", "obs-702", "obs-703"], "R-DUPLICATE"),
state_basis=basis("inferred", ["obs-704"], "R-STATE-LADEN"),
quantity_basis=basis("observed", ["obs-703"]),
risk_flags=["duplicate_source_records_merged"],
)
answer = answer_document(
case_input,
[update],
["obs-701", "obs-702", "obs-703"],
exceptions=[exception("DUPLICATE_OBSERVATIONS_MERGED", "info", ["obs-701", "obs-702"], "none")],
)
cases.append(
{
"slug": "07_duplicate_records",
"input": case_input,
"answer": answer,
"primary_test": "Merge duplicate feed records without doubling the cargo.",
"review_points": [
"There is one 500 GWh cargo, not two or three cargos.",
"The LNG additions are 100, 250, and 150 GWh.",
"All source records remain cited for auditability.",
],
}
)
# 08: A useful correction arrives after the information cutoff.
days = gas_days("2026-01-15")
prior_profile = standard_profile(700.0, 1.0, "2026-01-15")
book = [
prior_cargo(
"cargo-801",
"9100008",
"voyage-801",
700.0,
[prior_leg("prior-leg-801", "BE-ZEE", "2026-01-15T08:00:00Z", 1.0, prior_profile)],
)
]
obs = [
observation(
"obs-801",
"2026-01-14T10:00:00Z",
"2026-01-14T10:01:00Z",
"terminal_nomination",
"schedule_change",
"9100008",
"voyage-801",
{"terminal_id": "BE-ZEE", "arrival_time": "2026-01-16T08:00:00Z", "discharge_fraction": 1.0},
),
observation(
"obs-802",
"2026-01-14T11:55:00Z",
"2026-01-14T12:30:00Z",
"terminal_nomination",
"schedule_correction",
"9100008",
"voyage-801",
{"terminal_id": "BE-ZEE", "arrival_time": "2026-01-15T08:00:00Z", "discharge_fraction": 1.0},
supersedes="obs-801",
),
observation(
"obs-803",
"2026-01-14T09:00:00Z",
"2026-01-14T09:01:00Z",
"ais",
"position",
"9100008",
"voyage-801",
{"navigation_state": "underway", "load_state": "laden"},
),
]
case_input = input_document(
"floater-008", "Correction received after cutoff", "hard", "2026-01-14T12:00:00Z", days, book, obs
)
delayed_profile = standard_profile(700.0, 1.0, "2026-01-16")
leg = answer_leg(
"leg-801-a",
"BE-ZEE",
True,
"2026-01-16T08:00:00Z",
1.0,
delayed_profile,
700.0,
terminal_basis=basis("observed", ["obs-801"]),
arrival_basis=basis("observed", ["obs-801"]),
fraction_basis=basis("observed", ["obs-801"]),
profile_basis=basis("calculated", ["cargo-801", "obs-801"], "R-SENDOUT-STANDARD-3D"),
)
update = cargo_update(
"update-801",
"cargo-801",
["obs-801", "obs-803"],
"reschedule",
"laden_underway",
700.0,
[leg],
action_basis=basis("inferred", ["cargo-801", "obs-801"], "R-CUTOFF"),
state_basis=basis("inferred", ["obs-803"], "R-STATE-LADEN"),
quantity_basis=basis("observed", ["cargo-801"]),
risk_flags=["post_cutoff_correction_ignored"],
)
answer = answer_document(
case_input,
[update],
["cargo-801", "obs-801"],
exceptions=[exception("POST_CUTOFF_OBSERVATION_IGNORED", "info", ["obs-802"], "none")],
)
cases.append(
{
"slug": "08_cutoff_leak",
"input": case_input,
"answer": answer,
"primary_test": "Ignore a correction received after the stated information cutoff.",
"review_points": [
"obs-802 occurred before cutoff but was received 30 minutes after cutoff, so it is unavailable.",
"The visible LNG deltas are -140, -210, and +140 GWh.",
"The ignored observation appears only in the exception, not as decision evidence.",
],
}
)
# 09: Arrival just before the 06:00 local gas-day boundary on the DST transition.
days = gas_days("2026-03-28")
obs = [
observation(
"obs-901",
"2026-03-28T10:00:00Z",
"2026-03-28T10:01:00Z",
"terminal_nomination",
"scheduled_discharge",
"9100009",
"voyage-901",
{
"terminal_id": "BE-ZEE",
"arrival_time": "2026-03-29T03:30:00Z",
"quantity": 400.0,
"unit": "GWh",
"discharge_fraction": 1.0,
},
),
observation(
"obs-902",
"2026-03-28T09:00:00Z",
"2026-03-28T09:01:00Z",
"ais",
"position",
"9100009",
"voyage-901",
{"navigation_state": "underway", "load_state": "laden"},
),
]
case_input = input_document(
"floater-009",
"DST gas-day boundary",
"hard",
"2026-03-28T12:00:00Z",
days,
[],
obs,
timezone="Europe/Brussels",
)
dst_start_day = gas_day_for("2026-03-29T03:30:00Z", "Europe/Brussels")
profile = standard_profile(400.0, 1.0, dst_start_day)
leg = answer_leg(
"leg-901-a",
"BE-ZEE",
True,
"2026-03-29T03:30:00Z",
1.0,
profile,
400.0,
terminal_basis=basis("observed", ["obs-901"]),
arrival_basis=basis("observed", ["obs-901"]),
fraction_basis=basis("observed", ["obs-901"]),
profile_basis=basis(
"calculated",
["obs-901"],
["R-GAS-DAY", "R-SENDOUT-STANDARD-3D"],
),
)
update = cargo_update(
"update-901",
None,
["obs-901", "obs-902"],
"add",
"laden_underway",
400.0,
[leg],
action_basis=basis("inferred", ["obs-901", "obs-902"], "R-CARGO-DIFF"),
state_basis=basis("inferred", ["obs-902"], "R-STATE-LADEN"),
quantity_basis=basis("observed", ["obs-901"]),
risk_flags=["dst_gas_day_boundary"],
)
answer = answer_document(case_input, [update], ["obs-901", "obs-902"])
cases.append(
{
"slug": "09_dst_gas_day_boundary",
"input": case_input,
"answer": answer,
"primary_test": "Assign an arrival to the correct gas day across the DST change.",
"review_points": [
"03:30Z is 05:30 local after the DST jump, still before the 06:00 gas-day start.",
"The sendout profile therefore begins on gas day 2026-03-28.",
"The LNG additions are 80, 200, and 120 GWh.",
],
}
)
# 10: Equal-priority destination conflict and missing LNG-volume conversion.
days = gas_days("2026-01-15")
obs = [
observation(
"obs-1001",
"2026-01-14T10:00:00Z",
"2026-01-14T10:01:00Z",
"terminal_nomination",
"scheduled_discharge",
"9100010",
"voyage-1001",
{
"terminal_id": "FR-DKK",
"arrival_time": "2026-01-15T08:00:00Z",
"quantity": 170000.0,
"unit": "m3_LNG",
"discharge_fraction": 1.0,
},
),
observation(
"obs-1002",
"2026-01-14T10:00:00Z",
"2026-01-14T10:02:00Z",
"terminal_nomination",
"scheduled_discharge",
"9100010",
"voyage-1001",
{
"terminal_id": "BE-ZEE",
"arrival_time": "2026-01-15T08:00:00Z",
"quantity": 170000.0,
"unit": "m3_LNG",
"discharge_fraction": 1.0,
},
),
observation(
"obs-1003",
"2026-01-14T09:30:00Z",
"2026-01-14T09:31:00Z",
"ais",
"position",
"9100010",
"voyage-1001",
{"navigation_state": "underway", "load_state": "laden"},
),
]
case_input = input_document(
"floater-010",
"Unresolved destination and quantity",
"hard",
"2026-01-14T12:00:00Z",
days,
[],
obs,
unit_conversions=[],
)
update = cargo_update(
"update-1001",
None,
["obs-1001", "obs-1002", "obs-1003"],
"unresolved",
"laden_underway",
None,
[],
action_basis=basis("unknown", ["obs-1001", "obs-1002"], "R-UNKNOWN"),
state_basis=basis("inferred", ["obs-1003"], "R-STATE-LADEN"),
quantity_basis=basis("unknown", ["obs-1001", "obs-1002"], "R-UNKNOWN"),
risk_flags=["equal_priority_destination_conflict", "missing_unit_conversion"],
)
answer = answer_document(
case_input,
[update],
["obs-1001", "obs-1002"],
exceptions=[
exception("CONFLICTING_DESTINATION", "blocking", ["obs-1001", "obs-1002"], "request_data"),
exception("MISSING_UNIT_CONVERSION", "blocking", ["obs-1001", "obs-1002"], "request_data"),
],
quality_overrides={"profile_mass_conserved": "not_applicable"},
)
cases.append(
{
"slug": "10_unresolved_ambiguity",
"input": case_input,
"answer": answer,
"primary_test": "Return unknown rather than inventing a destination tie-breaker or volume conversion.",
"review_points": [
"The two terminal nominations have equal priority and conflict.",
"No m3_LNG-to-GWh conversion is supplied.",
"The correct balance change is zero until both issues are resolved.",
],
}
)
return cases
def make_input_schema() -> dict[str, Any]:
return {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"$id": "https://example.org/snd-floaters/input-1.0.schema.json",
"title": "SnD Floaters synthetic case input",
"type": "object",
"additionalProperties": False,
"required": [
"schema_version",
"case_id",
"title",
"difficulty",
"task",
"as_of",
"scope",
"conventions",
"rules",
"reference_data",
"prior_balance",
"prior_cargo_book",
"observations",
],
"properties": {
"schema_version": {"const": "1.0"},
"case_id": {"type": "string"},
"title": {"type": "string"},
"difficulty": {"enum": ["easy", "medium", "hard"]},
"task": {"type": "string"},
"as_of": {"type": "string", "format": "date-time"},
"scope": {"type": "object"},
"conventions": {"type": "object"},
"rules": {"type": "array", "items": {"type": "object"}},
"reference_data": {"type": "object"},
"prior_balance": {"type": "array", "items": {"type": "object"}},
"prior_cargo_book": {"type": "array", "items": {"type": "object"}},
"observations": {"type": "array", "items": {"type": "object"}},
},
}
def make_answer_schema() -> dict[str, Any]:
basis_schema = {
"type": "object",
"additionalProperties": False,
"required": ["kind", "evidence_ids", "rule_ids", "assumption_id"],
"properties": {
"kind": {"enum": ["observed", "inferred", "calculated", "assumed", "unknown"]},
"evidence_ids": {"type": "array", "items": {"type": "string"}, "uniqueItems": True},
"rule_ids": {
"type": "array",
"items": {"type": "string"},
"uniqueItems": True,
},
"assumption_id": {"type": ["string", "null"]},
},
}
decision_schema = {
"type": "object",
"additionalProperties": False,
"required": ["value", "basis"],
"properties": {
"value": {"type": ["string", "null"]},
"basis": {"$ref": "#/$defs/basis"},
},
}
estimate_schema = {
"type": "object",
"additionalProperties": False,
"required": ["lower", "central", "upper", "basis"],
"properties": {
"lower": {"type": ["number", "null"]},
"central": {"type": ["number", "null"]},
"upper": {"type": ["number", "null"]},
"basis": {"$ref": "#/$defs/basis"},
},
}
time_estimate_schema = {
"type": "object",
"additionalProperties": False,
"required": ["earliest", "central", "latest", "basis"],
"properties": {
"earliest": {
"anyOf": [{"type": "string", "format": "date-time"}, {"type": "null"}]
},
"central": {
"anyOf": [{"type": "string", "format": "date-time"}, {"type": "null"}]
},
"latest": {
"anyOf": [{"type": "string", "format": "date-time"}, {"type": "null"}]
},
"basis": {"$ref": "#/$defs/basis"},
},
}
sendout_profile_schema = {
"type": "object",
"additionalProperties": False,
"required": ["points", "unallocated_gwh", "basis"],
"properties": {
"points": {
"type": "array",
"items": {
"type": "object",
"additionalProperties": False,
"required": ["gas_day", "gwh"],
"properties": {
"gas_day": {"type": "string", "format": "date"},
"gwh": {"type": "number", "minimum": 0},
},
},
},
"unallocated_gwh": {"type": "number", "minimum": 0},
"basis": {"$ref": "#/$defs/basis"},
},
}
leg_schema = {
"type": "object",
"additionalProperties": False,
"required": [
"leg_id",
"terminal_id",
"included_in_scope",
"arrival_time",
"discharge_fraction",
"sendout_profile",
],
"properties": {
"leg_id": {"type": "string"},
"terminal_id": {"$ref": "#/$defs/decision"},
"included_in_scope": {"type": "boolean"},
"arrival_time": {"$ref": "#/$defs/timeEstimate"},
"discharge_fraction": {"$ref": "#/$defs/estimate"},
"sendout_profile": {"$ref": "#/$defs/sendoutProfile"},
},
}
cargo_update_schema = {
"type": "object",
"additionalProperties": False,
"required": [
"update_id",
"matched_prior_cargo_id",
"source_observation_ids",
"action",
"operational_state",
"quantity_gwh",
"discharge_legs",
"risk_flags",
],
"properties": {
"update_id": {"type": "string"},
"matched_prior_cargo_id": {"type": ["string", "null"]},
"source_observation_ids": {
"type": "array",
"items": {"type": "string"},
"minItems": 1,
"uniqueItems": True,
},
"action": {
"type": "object",
"additionalProperties": False,
"required": ["value", "basis"],
"properties": {
"value": {
"enum": ["unchanged", "add", "reschedule", "remove", "split", "unresolved"]
},
"basis": {"$ref": "#/$defs/basis"},
},
},
"operational_state": {"$ref": "#/$defs/decision"},
"quantity_gwh": {"$ref": "#/$defs/estimate"},
"discharge_legs": {"type": "array", "items": {"$ref": "#/$defs/dischargeLeg"}},
"risk_flags": {
"type": "array",
"items": {"type": "string"},
"uniqueItems": True,
},
},
}
component_schema = {
"type": "object",
"additionalProperties": False,
"required": [
"component_id",
"prior_contribution_gwh",
"delta_contribution_gwh",
"updated_contribution_gwh",
"basis",
],
"properties": {
"component_id": {"type": "string"},
"prior_contribution_gwh": {"type": "number"},
"delta_contribution_gwh": {"type": "number"},
"updated_contribution_gwh": {"type": "number"},
"basis": {"$ref": "#/$defs/basis"},
},
}
daily_balance_schema = {
"type": "object",
"additionalProperties": False,
"required": ["gas_day", "components", "residual_gwh"],
"properties": {
"gas_day": {"type": "string", "format": "date"},
"components": {"type": "array", "items": {"$ref": "#/$defs/component"}},
"residual_gwh": {"type": "number"},
},
}
assumption_schema = {
"type": "object",
"additionalProperties": False,
"required": ["assumption_id", "statement", "materiality", "affected_fields"],
"properties": {
"assumption_id": {"type": "string"},
"statement": {"type": "string"},
"materiality": {"enum": ["immaterial", "material"]},
"affected_fields": {"type": "array", "items": {"type": "string"}},
},
}
exception_schema = {
"type": "object",
"additionalProperties": False,
"required": ["code", "severity", "entity_ids", "action"],
"properties": {
"code": {"type": "string"},
"severity": {"enum": ["info", "warning", "blocking"]},
"entity_ids": {"type": "array", "items": {"type": "string"}, "uniqueItems": True},
"action": {"enum": ["none", "request_data", "hold_prior", "exclude", "defer"]},
},
}
return {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"$id": "https://example.org/snd-floaters/answer-1.0.schema.json",
"title": "SnD Floaters benchmark answer",
"type": "object",
"additionalProperties": False,
"required": [
"schema_version",
"case_id",
"as_of",
"unit",
"cargo_updates",
"daily_balance",
"assumptions",
"exceptions",
"quality_checks",
],
"properties": {
"schema_version": {"const": "1.0"},
"case_id": {"type": "string"},
"as_of": {"type": "string", "format": "date-time"},
"unit": {"const": "GWh"},
"cargo_updates": {"type": "array", "items": {"$ref": "#/$defs/cargoUpdate"}},
"daily_balance": {"type": "array", "items": {"$ref": "#/$defs/dailyBalance"}},
"assumptions": {"type": "array", "items": {"$ref": "#/$defs/assumption"}},
"exceptions": {"type": "array", "items": {"$ref": "#/$defs/exception"}},
"quality_checks": {
"type": "object",
"additionalProperties": False,
"required": [
"cutoff_respected",
"no_duplicate_cargo",
"profile_mass_conserved",
"terminal_constraints_respected",
"component_arithmetic_reconciled",
"balance_reconciled",
],
"properties": {
"cutoff_respected": {"enum": ["pass", "fail", "not_applicable"]},
"no_duplicate_cargo": {"enum": ["pass", "fail", "not_applicable"]},
"profile_mass_conserved": {"enum": ["pass", "fail", "not_applicable"]},
"terminal_constraints_respected": {"enum": ["pass", "fail", "not_applicable"]},
"component_arithmetic_reconciled": {"enum": ["pass", "fail", "not_applicable"]},
"balance_reconciled": {"enum": ["pass", "fail", "not_applicable"]},
},
},
},
"$defs": {
"basis": basis_schema,
"decision": decision_schema,
"estimate": estimate_schema,
"timeEstimate": time_estimate_schema,
"sendoutProfile": sendout_profile_schema,
"dischargeLeg": leg_schema,
"cargoUpdate": cargo_update_schema,
"component": component_schema,
"dailyBalance": daily_balance_schema,
"assumption": assumption_schema,
"exception": exception_schema,
},
}
def review_markdown(case: dict[str, Any]) -> str:
answer = case["answer"]
deltas: list[str] = []
for day in answer["daily_balance"]:
lng_row = next(row for row in day["components"] if row["component_id"] == "lng_sendout")
storage_row = next(row for row in day["components"] if row["component_id"] == "storage_net")
deltas.append(
f"- {day['gas_day']}: LNG {lng_row['delta_contribution_gwh']:+.3f} GWh; "
f"storage_net {storage_row['delta_contribution_gwh']:+.3f} GWh"
)
points = "\n".join(f"- {point}" for point in case["review_points"])
return f"""# {case['input']['case_id']}: {case['input']['title']}
## What this case tests
{case['primary_test']}
## Correct balance deltas
{chr(10).join(deltas)}
## Things to review
{points}
The detailed machine-readable answer is in answer.json. Only input.json should be shown to a model during an evaluation run.
"""
def main() -> None:
cases = build_cases()
manifest: dict[str, Any] = {
"suite_id": "snd-floaters-eval",
"suite_version": "0.1.0",
"description": "Synthetic European gas supply-demand balance updates from LNG floater observations.",
"case_count": len(cases),
"cases": [],
}
for case in cases:
directory = CASES_ROOT / case["slug"]
write_json(directory / "input.json", case["input"])
write_json(directory / "answer.json", case["answer"])
write_text(directory / "review.md", review_markdown(case))
manifest["cases"].append(
{
"case_id": case["input"]["case_id"],
"slug": case["slug"],
"title": case["input"]["title"],
"difficulty": case["input"]["difficulty"],
"primary_test": case["primary_test"],
"input_path": f"cases/{case['slug']}/input.json",
"answer_path": f"cases/{case['slug']}/answer.json",
"review_path": f"cases/{case['slug']}/review.md",
}
)
write_json(ROOT / "manifest.json", manifest)
write_json(SCHEMAS_ROOT / "input.schema.json", make_input_schema())
write_json(SCHEMAS_ROOT / "answer.schema.json", make_answer_schema())
print(f"Generated {len(cases)} cases in {CASES_ROOT}")
if __name__ == "__main__":
main()