Version: dev

validate_equation_dimensions

Stable function · Units

Tier: stable · Kind: function · Topic: Units

JuliaTypeScriptPythonRustGo
validate_equation_dimensionsnot exportednot exportedvalidate_equation_dimensionsValidateEquationDimensions

Julia

validate_equation_dimensions(eq::Equation, var_units::AbstractDict)

Validate that an equation is dimensionally consistent.

Checks that both sides are internally consistent and that the left-hand side and right-hand side have the same dimensions. Returns false only for a PROVABLE inconsistency; an equation whose dimensions cannot be determined is skipped (counted consistent), because a validator must not fail what it cannot prove.

Source

TypeScript

TypeScript does not export this function.

Python

Python does not export this function.

Rust

pub fn validate_equation_dimensions(eq: &Equation, env: &HashMap<String, Unit>) -> Result<(), UnitError>

Validate that an equation’s LHS and RHS have matching dimensions.

Returns Ok(()) when both sides propagate to dimensionally-equal units, and a UnitError with a descriptive message otherwise. Propagation errors from either side are surfaced verbatim.

This is the single-outcome view. Validation uses check_equation_dimensions , which reports EVERY finding and separates provable mismatches from undeterminable dimensions.

A time derivative D(x)/Dt whose t declares no units has an undeterminable left-hand side (esm-spec §4.8.4), so the full comparison is skipped and the weaker rule applies: if no time unit can reconcile the two sides, the result is UnitError::DimensionMismatch; if one can, it is UnitError::UnknownUnit (“skipped”), not Ok(()).

Source · Rust docs

Example (validate_equation_dimensions)

let doc = load_path(fixture("decay.esm"))?;
let model = &doc.models.as_ref().unwrap()["Decay"];
let (env, failures) = build_unit_env(&model.variables);
assert!(failures.is_empty());

// half_life = log(2) / lambda: seconds on both sides.
validate_equation_dimensions(&model.equations[1], &env)?;
// half_life is in s but lambda is in 1/s.
let wrong = parse_equation("half_life = lambda")?;
let err = validate_equation_dimensions(&wrong, &env).unwrap_err();
println!("{err}");
assert!(err.to_string().contains("mismatch"));

From docs/api/examples/rust/units.rs

Go

func ValidateEquationDimensions(eq *Equation, env map[string]Unit, path string) *UnitWarning

ValidateEquationDimensions checks that the LHS and RHS of an equation have the same dimension. It returns a non-nil UnitWarning iff a concrete inconsistency was detected. Missing annotations are treated as “unknown” and do NOT produce a warning (matching the Python/Julia best-effort semantics).

The reported Path is the EQUATION pointer (/models/<M>/equations/<i>) for every finding, including one discovered inside the LHS or RHS. That is the pointer tests/invalid/expected_errors.json pins and the one TypeScript emits; the previous /lhs and /rhs suffixes pointed at no schema node and did not match the corpus.

Source · Go docs