Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
{
"date": "2026-10-16",
"parent_commit": "feccf32cc34c534ce24c76863313c8f762dfdf8b",
"source_commit": "0c4ac962fdbf1c937f836197e69b2ab04bf229f2",
"source_tree": "562bfd0a63e6888d3341029a1c768ddcb6ce34a6",
"source_sha256": {
"rust/catalogue-geometry/src/main.rs": "0efccf78a1e5223d4ecea19d5fd93f300cbe7d93e5da87b37a1817e5b710b668",
"rust/catalogue-geometry/src/model_complete.rs": "5fb6d8d77c3c59fc884e5afccf3c6aa4d6d289d0db3758fe15f01e32f64a8a66",
"rust/catalogue-geometry/src/worker_protocol.rs": "0caa9482bcebee8461ffc75317ebdb9f1456c3635bd43e7c1b648222d5ea1139",
"src/riverfahrplan/worker_session.py": "2ef7f1e877dc151d3aded8b0940a8e6d691d662cbbe2c84abf46cd8615593a2a",
"tests/test_model_complete_rust.py": "7da3f312cc5976eaed85a5b5d85e228fba873c83ec258833460aabc12c2bf86d"
},
"release_worker_sha256": "73f69daffb57b8907b8c5db288f82283a66ea3da83c9baa93d55c0852a04861d",
"composition": [
"named source formations and consumed branches",
"terminal parent and full-span side-network donors",
"directed source continuation with final identity mapping",
"source description and precedence",
"stable events and branches",
"identity enrichment and complete neutral model metadata"
],
"limits": [
"Python remains default; normal driver still uses existing adapters.",
"Public native entrypoint and model/regional/CLI integration remain open.",
"Internal JSON copies remain; no performance or hard RSS guarantee.",
"Large real-world PBF/time/RSS acceptance remains outstanding."
],
"github_ci": {
"run": 38872738687,
"result": "failed before runner allocation",
"all_runner_ids": 0,
"executed_steps": 0
},
"validation": {
"full_python_integration_tests": 9378,
"full_suite_worker_profile": "debug",
"full_suite_seconds": 280.22,
"release_targeted_tests": 1290,
"release_targeted_seconds": 81.55,
"new_retained_complete_model_cases": 132,
"rust_tests": 35,
"rustfmt": true,
"clippy_deny_warnings_all_targets": true,
"debug_build": true,
"release_build": true,
"installed_wheel_four_full_models_debug_and_release": true
}
}
60 changes: 60 additions & 0 deletions docs/native-model-finalization-migration.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
# Quellen und vollständiges Modell aus gehaltenem Zustand

`dataset_model_finalize(dataset_key, model_key, save_as=..., way_river_ids=...)`
setzt nach `dataset_model_branches` fort. Der Aufruf liefert ausschließlich
ein Handle; `/model` enthält das vollständige neutrale `RiverModel.as_dict()`-
Format. Auch synthetische R-/W-Identitäten erhalten die bisherige Darstellung
mit `river_id` und leerem `wikidata_id`.

Rust komponiert benannte Quellzuflüsse, verbrauchte Quellzweige, das
Formationsereignis, bewiesene Terminal-Spender, eindeutige vollständige
Seitennetz-Spender und gerichtete Quellfortsetzungen. Darauf folgen die
Quellbeschreibung, Quellpriorität, Identitätsanreicherung, stabile Ereignis-
und Zweigsortierung sowie sämtliche Modellmetadaten. Bestehende Fachkerne
bleiben für diese Entscheidungen verantwortlich. Python übergibt nur Handles,
Unicode-Faltung und die optionale deklarative Way-/Fluss-ID-Zuordnung.

Endpunktkandidaten werden mit der final übergebenen ID-Zuordnung nativ erneut
ermittelt. Dadurch können spätere IDs keine veraltete Fortsetzung aus einem
früheren Aufruf übernehmen. Bei Formation werden nur die verbrauchten
repräsentativen Zweige entfernt; bei einem Spender nur dessen ausgewählter
Listenplatz. Untergeordnete Ereignisse und Zweige bleiben unverändert.
Kompakte Hauptlaufereignisse erhalten vor der finalen Sortierung wieder ihre
vollständigen Modellfelder einschließlich der OSM-Knoten-ID.

Das fertige Modell wird unter einem eigenen Feld gehalten. Die bisherigen
Zwischenfelder bleiben als reproduzierbare Eingabe erhalten, sodass dieselbe
Fortsetzung auch auf ihrem eigenen Ergebnis wiederholbar bleibt. Datensatz-
revisionen und atomare Ergebnisablage nutzen den vorhandenen Worker-Vertrag.

132 neue PBF-Vergleichsfälle prüfen das gesamte Modell gegen den normalen
Python-Treiber, einschließlich Quellbildung und -veto, Wasserflächen-/Quell-
Priorität, Quellen und benannten Punkten, Spenderauswahl,
Fortsetzungsrichtungen, Relationsrang, leeren und nachgereichten IDs,
synthetischen Identitäten, Alternativrouten, Zufallsgraphen und Fehlerfällen.
Während der nativen Verkettung sind der Python-Modelltreiber,
Quell-/Spender-/Finalisierungsalgorithmen und `GEOD.inv` gesperrt. Die
Modellwiederherstellung mit `RiverModel.from_dict` wird ebenfalls geprüft.

Python bleibt Standard; der normale Modell-/Regional-/CLI-Treiber verwendet
weiter seine bisherigen Adapter. Ein öffentlicher nativer Gesamteinstieg und
dessen Integration bleiben weitere Arbeit. Interne JSON-Kopien bestehen;
keine Leistungszusage oder harte RSS-Grenze. Große reale PBF-/Zeit-/RSS-Abnahmen
stehen weiter aus.

## Prüfstand

9.378 vollständige Python-/Integrationstests mit frischem Debug-Worker und
osmium sowie 1.290 gezielte Tests mit frischem Release-Worker bestehen.
35 Rust-Tests, rustfmt und Clippy mit `-D warnings` für alle Targets bestehen.
Ein separat installiertes Wheel vergleicht vier vollständige Modelle nach der
gesamten nativen Verkettung: Quellzusammenfluss, Speisekanal-Spender,
Seitenmerkmale/Alternativroute und synthetische Relationsidentität. Diese
Vergleiche bestehen mit Debug- und Release-Worker.

Der Quellnachweis steht unter
`migration-proofs/native-model-finalization-reference-20261016.json`.
GitHub-CI scheitert erneut vor Runnerzuweisung: Im Lauf 38872738687 haben
alle fünf Jobs `runner_id=0` und keine ausgeführten Schritte. Die Ursache ist
aus diesen Jobdaten nicht bestimmbar. Lokale Prüfungen ersetzen keine
erfolgreiche GitHub-CI; der PR bleibt Draft.
6 changes: 6 additions & 0 deletions docs/rust-migration-worklist-20261015.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,9 @@ Hauptlaufzweige sowie Untergrund- und Seitenmerkmalsmontage laufen nun aus dem
gehaltenen Zustand; siehe native-model-branches-migration.md. Nächste Grenze
sind Quellbildung, Spenderentscheidungen und Modellfinalisierung, anschließend
Regional-/CLI-Komposition. Python bleibt weiterhin Standard.

Quellbildung, Spenderauswahl, Quellbeschreibung, Sortierung und vollständige
neutrale Modellmontage laufen nun ebenfalls aus gehaltenem Zustand;
siehe native-model-finalization-migration.md. Offen bleiben der öffentliche
native Gesamteinstieg, die Integration in Modell-/Regional-/CLI-Treiber und
die große reale PBF-/Zeit-/RSS-Abnahme. Python bleibt Standard.
1 change: 1 addition & 0 deletions rust/catalogue-geometry/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ mod manifest;
mod metro_render_plan;
mod model_branches;
mod model_canals;
mod model_complete;
mod model_connections;
mod model_features;
mod model_finalize;
Expand Down
240 changes: 240 additions & 0 deletions rust/catalogue-geometry/src/model_complete.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,240 @@
//! Source decisions and neutral RiverModel assembly from retained branches.
use crate::{
model_branches::{array, id, number},
pbf,
worker_protocol::execute,
};
use serde::Deserialize;
use serde_json::{json, Value};
#[derive(Deserialize)]
#[serde(deny_unknown_fields)]
pub(crate) struct Configuration {
schema_version: u32,
casefold: Value,
way_river_ids: Value,
}
fn fields(value: &Value, names: &[&str]) -> Value {
Value::Object(
names
.iter()
.map(|k| ((*k).to_string(), value[*k].clone()))
.collect(),
)
}
fn receiver(mut value: Value) -> Value {
if !value.is_null() {
for key in ["bank", "flow_direction", "connection_kind", "river_id"] {
if value.get(key).is_none() {
value[key] = Value::Null;
}
}
}
value
}
fn ordered(values: &[Value], order: &Value) -> Result<Vec<Value>, String> {
array(order)?
.iter()
.map(|i| {
values
.get(
i.as_u64()
.and_then(|n| usize::try_from(n).ok())
.ok_or("invalid model permutation")?,
)
.cloned()
.ok_or_else(|| "unknown model permutation index".into())
})
.collect()
}
fn prune(branches: &mut Vec<Value>, consumed: Value, donor: Option<usize>) -> Result<(), String> {
let plan = execute(
"--model-finalize",
json!({"schema_version":35,"mode":"prune","consumed_way_ids":consumed,"donor_owner":donor,
"branches":branches.iter().enumerate().map(|(i,b)|json!({"way_id":b["way_id"],"owner":i})).collect::<Vec<_>>()}),
)?;
*branches = ordered(branches, &plan["keep_indices"])?;
Ok(())
}
pub(crate) fn build(data: &pbf::Imported, state: Value, c: Configuration) -> Result<Value, String> {
if c.schema_version != 81 || state["schema_version"] != 1 {
return Err("model finalization requires schema_version 81 and native model state".into());
}
// Require the complete prefix before recomputing endpoint candidates with
// the final identity mapping. This also prevents stale mapping candidates.
let mut branches = array(&state["branches"])?.clone();
array(&state["underground_main_sections"])?;
array(&state["passages"])?;
let mut state = crate::model_connections::build(
data,
state,
serde_json::from_value(json!({"schema_version":77,"way_river_ids":c.way_river_ids}))
.map_err(|e| e.to_string())?,
)?;
let path = array(&state["positions"]["path_node_ids"])?;
let mouth = path.first().ok_or("empty final model path")?;
let source = path.last().ok_or("empty final model path")?;
let (mouth, source) = (id(mouth)?, id(source)?);
let mut events = array(&state["events"])?.clone();
for e in &mut events {
let node_id = id(&e["node_id"])?;
let object = e.as_object_mut().ok_or("invalid final point event")?;
object.insert("object_type".into(), json!("node"));
object.insert("osm_id".into(), json!(node_id));
for key in [
"osm_id",
"match_method",
"boundary_object_type",
"boundary_osm_id",
"side_distance_km",
"side_route_index",
] {
object.entry(key).or_insert(Value::Null);
}
for key in ["matched_node_ids", "matched_km_range"] {
object.entry(key).or_insert_with(|| json!([]));
}
}
let waterbody = receiver(state["source_waterbody"].clone());
let context = &state["terminal_context"];
let mut formation = json!({"source_branches":[],"candidates":[],"rejected_reason":null});
if waterbody.is_null() && context.is_null() {
let order = data.order.as_ref().ok_or("missing native dataset order")?;
formation = execute(
"--source-formation",
json!({"schema_version":20,"source_node_id":source,"river_name":state["river_name"],"wikidata_id":state["river_id"],"casefold":c.casefold,
"ways":order.ways.iter().map(|id|json!({"id":id,"tags":data.ways[id].tags})).collect::<Vec<_>>(),
"relations":order.relations.iter().map(|id|json!({"id":id,"tags":data.relations[id].tags})).collect::<Vec<_>>(),
"branches":branches.iter().map(|b|fields(b,&["way_id","kind","label","junction_node_id","rejoin_node_id","transfer_role","way_ids","relation_id","waterway_type","side"])).collect::<Vec<_>>()}),
)?;
if !array(&formation["source_branches"])?.is_empty() {
prune(&mut branches, formation["consumed_way_ids"].clone(), None)?;
events
.iter_mut()
.find(|e| e["node_id"] == source)
.ok_or("missing final source event")?["kind"] = json!("formation");
}
}
let has_formation = !array(&formation["source_branches"])?.is_empty();
let mut donor = if !context.is_null() && waterbody.is_null() {
state["terminal_source_donor"].clone()
} else {
Value::Null
};
if waterbody.is_null() && !has_formation && context.is_null() {
let donor_branches = branches
.iter()
.map(|b| {
let mut packet = fields(
b,
&[
"kind",
"relation_id",
"label",
"junction_node_id",
"rejoin_node_id",
"way_ids",
"path_node_ids",
],
);
packet["connections"] = json!(array(&b["connections"])?
.iter()
.map(|p| fields(p, &["node_id", "role"]))
.collect::<Vec<_>>());
Ok(packet)
})
.collect::<Result<Vec<_>, String>>()?;
let selection = execute(
"--transfer-donor",
json!({"schema_version":23,"source_node_id":source,"mouth_node_id":mouth,"river_name":state["river_name"],
"mouth_receiver":if state["mouth_receiver"].is_null(){Value::Null}else{fields(&state["mouth_receiver"],&["object_type","osm_id","name"])},
"branches":donor_branches}),
)?;
if let Some(index) = selection["donor_index"].as_u64() {
let index = usize::try_from(index).map_err(|e| e.to_string())?;
let b = branches.get(index).ok_or("unknown terminal donor index")?;
donor=execute("--model-finalize",json!({"schema_version":35,"mode":"donor","branch":fields(b,&["relation_id","label","waterway_type","wikidata_id","side"])}))?["receiver"].clone();
prune(&mut branches, json!([]), Some(index))?;
}
}
if waterbody.is_null() && !has_formation && donor.is_null() {
donor = state["source_continuation_candidate"].clone();
}
let empty = crate::raw::Tags::new();
let mut description=execute("--source-description",json!({"schema_version":21,"source_node_id":source,
"node_tags":data.node_tags.get(&source).unwrap_or(&empty),"source_waterbody":if waterbody.is_null(){Value::Null}else{fields(&waterbody,&["object_type","osm_id","name","kind","wikidata_id"])},"has_source_branches":has_formation}))?["source"].clone();
events.extend(array(&state["projected_events"])?.iter().cloned());
let mut identities = serde_json::Map::new();
for row in array(&c.way_river_ids)? {
identities.insert(id(&row["way_id"])?.to_string(), row["river_id"].clone());
}
let mut mouth_receiver = state["mouth_receiver"].clone();
let compact_receiver = |v: &Value| {
if v.is_null() {
Value::Null
} else {
fields(
v,
&[
"object_type",
"osm_id",
"name",
"wikidata_id",
"river_id",
"connection_kind",
],
)
}
};
let plan = execute(
"--model-finalize",
json!({"schema_version":35,"mode":"finalize","donor":compact_receiver(&donor),"mouth":compact_receiver(&mouth_receiver),
"has_waterbody":!waterbody.is_null(),"has_formation":has_formation,"identities":identities,
"events":events.iter().map(|e|fields(e,&["km","object_type","osm_id"])).collect::<Vec<_>>(),
"branches":branches.iter().map(|b|fields(b,&["way_id","way_ids","relation_id","river_id","wikidata_id","junction_km"])).collect::<Vec<_>>()}),
)?;
if !plan["mouth_update"].is_null() {
mouth_receiver["river_id"] = plan["mouth_update"]["river_id"].clone();
}
for update in array(&plan["branch_updates"])? {
let index = update["index"]
.as_u64()
.and_then(|i| usize::try_from(i).ok())
.ok_or("invalid branch update index")?;
branches
.get_mut(index)
.ok_or("unknown branch update index")?["river_id"] = update["river_id"].clone();
}
if !plan["source_override"].is_null() {
description = plan["source_override"].clone();
}
let mut terminal = context.clone();
if let Some(object) = terminal.as_object_mut() {
for key in ["way_ids", "all_parent_way_ids", "route"] {
object.remove(key);
}
}
let mut metadata = json!({"main_way_count":array(&state["graph"]["main_way_ids"])?.len(),"terminal_parent_connection":terminal,
"terminal_connection_diagnostics":state["terminal_diagnostics"],"underground_main_sections":state["underground_main_sections"],
"node_count":array(&state["graph"]["node_order"])?.len(),"edge_count":array(&state["graph"]["edges"])?.len(),
"suppressed_mouth_way_ids":state["suppressed_mouth_way_ids"],"unresolved_side_stream_components":state["unresolved_side_stream_components"],
"source_waterbody_candidates":array(&state["source_waterbody_candidates"])?.iter().map(|v|fields(v,&["object_type","osm_id","name","kind"])).collect::<Vec<_>>(),
"source_formation_candidates":formation["candidates"],"source_formation_rejected_reason":formation["rejected_reason"]});
if !array(&state["incomplete_side_stream_paths"])?.is_empty() {
metadata["incomplete_side_stream_paths"] = state["incomplete_side_stream_paths"].clone();
}
let distances = array(&state["positions"]["distances_m"])?;
let identity = state["river_id"]
.as_str()
.ok_or("missing final river identity")?;
let mut model = json!({"wikidata_id":identity,"name":state["river_name"],"mouth_node_id":mouth,"source_node_id":source,
"main_length_km":number(distances.last().ok_or("empty final distances")?)?/1000.,"main_path":path,
"events":ordered(&events,&plan["event_order"] )?,"branches":ordered(&branches,&plan["branch_order"] )?,
"mouth_receiver":mouth_receiver,"source_waterbody":waterbody,"source_donor":donor,"source_kind":plan["source_kind"],
"source_branches":formation["source_branches"],"passages":state["passages"],"metadata":metadata,"source":description});
if identity.starts_with(['R', 'W']) {
model["river_id"] = json!(identity);
model["wikidata_id"] = Value::Null;
}
state["model"] = model;
Ok(state)
}
17 changes: 17 additions & 0 deletions rust/catalogue-geometry/src/worker_protocol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,12 @@ enum Operation {
casefold: HashMap<char, String>,
whitespace: String,
},
DatasetModelFinalize {
key: String,
model_key: String,
configuration: crate::model_complete::Configuration,
save_as: String,
},
DatasetModelBranches {
key: String,
model_key: String,
Expand Down Expand Up @@ -456,6 +462,17 @@ pub(crate) fn serve(limit: usize) -> Result<(), String> {
});
result.and_then(|value| store.result(value, Some(save_as), false))
}
Operation::DatasetModelFinalize {
key,
model_key,
configuration,
save_as,
} => {
let result = store.with_model(&key, &model_key, |data, state| {
crate::model_complete::build(data, state, configuration)
});
result.and_then(|value| store.result(value, Some(save_as), false))
}
Operation::DatasetModelBranches {
key,
model_key,
Expand Down
Loading
Loading