Repository navigation
Description
Problem
When a variable is round-tripped through the edit/patch path (pysimlin model.edit() -> simlin_project_apply_patch_json -> the Rust JSON patch UpsertVariable path), the variable's display name is replaced by its canonical identifier.
src/simlin-engine/src/patch.rs runs canonicalize_stock / canonicalize_flow / canonicalize_aux / canonicalize_module on every upserted variable, which does *ident = canonicalize(ident) in place. Because the datamodel stores a single ident field that doubles as the human-facing display name (there is no separate display-name field), this is lossy: the display casing and XMILE \n line breaks are destroyed for the edited variable, while untouched variables keep theirs.
Concrete examples
test/conveyors/minimal_conveyor.xmile: upserting the stock namedStudents(only changing its documentation) leaves the project serialized with the stock renamed tostudents. The siblingAlumni(untouched) keeps its casing.test/conveyors/covid19_severity.stmx: upserting the flow displayed astesting\nassymptomatic(literal backslash-n line break in the XMILE display name) leaves it astesting_assymptomatic.
Repro
import json, simlin
m = simlin.load("test/conveyors/minimal_conveyor.xmile")
with m.edit() as (current, patch):
s = current["Students"]
s.documentation = "x"
patch.upsert_stock(s)
print([s["name"] for s in json.loads(m.project.serialize_json())["models"][0]["stocks"]])
# -> ['Alumni', 'students']The Python side sends "Students" verbatim in the patch JSON; the canonicalization happens in the Rust patch-application path.
Why it matters
- A routine pysimlin edit (e.g. touching documentation) silently rewrites the user's chosen display name -- lowercased, line breaks collapsed to underscores.
- Diagram labels churn: the view still shows the original name while the variable's name has changed underneath, or the label degrades on the next render.
- The lossiness is inconsistent (only edited variables are affected), so repeated edits gradually erode a model's presentation.
Components affected
src/simlin-engine/src/patch.rs(canonicalize_identand callers, applied toUpsertVariable)src/pysimlin(model.edit()surface),src/libsimlin(simlin_project_apply_patch_json)
Possible approaches
- Match variables by canonical ident for lookup/dedup purposes but preserve the incoming (or existing) display-form
identwhen storing the upserted variable. E.g. canonicalize a copy for matching, and if the canonical form equals the canonical form of an existing variable, keep the existing display name unless the patch explicitly renames. - Longer term: separate display name from canonical ident in the datamodel, so canonicalization can never be lossy. Related old report: XMILE export from simlin: variable name to lowercase but not in equations #82 (XMILE export lowercases variable names in the
<variables>block but not in equations), which stems from the same single-field name/ident conflation.
Discovery context
Identified while working on #882 (pysimlin JSON converter dropping Compat fields) on branch conveyor-engine; out of scope for that fix.
Activity