Simcraft Docs

Validate a model#

This guide checks an OSDL document against the schemas and the component libraries it uses. Validation is mechanical JSON Schema checking; no engine is required.

Two phases#

Model validation always has two phases:

  1. The document is validated against the model schema. This checks structure, but treats every component's params object as opaque.
  2. Each component's params is validated against the parameter schema published in its type's library definition, with the core schema registered so shared value forms resolve.

A document can pass phase one and fail phase two. Phase two is what catches a misspelled parameter or a distribution where a scalar is required.

Diagnostic severity#

The Simcraft engine checks model structure after both schema phases. Each structural diagnostic has a severity of error or warning.

  • An error means the engine cannot build the model, or the model would misbehave at run time. Errors block a run.
  • A warning means the model is incomplete, but the engine can build it. The affected component has a defined behavior for the missing connection, such as holding entities or staying inert. Warnings do not block a run.

Match diagnostics by code in tests and tools. The message text describes the finding and can change between releases.

Run the repository validator#

The OSDL repository ships a validator that performs both phases over the specification's own schemas, libraries, and examples. From a checkout of github.com/simcrafthq/osdl, with Node.js 22:

sh
bash validate.sh

The command compiles all six schemas, checks each library document, and validates every example in both phases. When the Lean toolchain is available it also builds the reference machine and checks the conformance catalogue; set OSDL_REQUIRE_LEAN=1 to fail when Lean is missing, which is what continuous integration does.

Validate your own documents#

Any JSON Schema draft 2020-12 validator works for phase one. Point it at the published model schema and your document:

sh
npx ajv-cli validate --spec=draft2020 -s schemas/osdl.schema.json -d my-model.osdl.json

For phase two, validate each component's params against the matching params schema in the library definition, registering osdl.schema.json so $ref references to core value forms resolve.

Identifiers match ^[A-Za-z_][A-Za-z0-9_-]*$. Phase one checks this pattern.

Engine checks#

The schemas do not check the rules below. The Simcraft engine reports each broken rule as an error, even in a schema-valid document:

  • Component ids are unique within their scope (core.duplicate-component-id).
  • A {"param": "name"} reference names a declared model parameter (core.unknown-parameter).
  • A connection joins two ports of the same kind (core.port-kind-mismatch).
  • A port takes one connection unless its library definition sets multiple: true (core.port-connection-limit).
  • A port whose library definition declares connectsTo joins only the ports it lists (core.port-connection-target). In the sd library, sd.stock and sd.flow list each other, so a connection from one stock to another stock is an error.

The engine applies the port rules at a connection end only when that end names a port its component type declares in that direction: an output for from, an input for to. When the other end names an undeclared port on a component of the same library, the engine leaves the connection to that library's validator.

No core.* check reports an undeclared port or a port used against its direction. The des, abm, sd, and data libraries report each connection end on their own components that names no port in the end's direction. The code is <namespace>.unsupported-connection. For a des.queue named waiting, the connection arrivals.out -> waiting.entry gets des.unsupported-connection with this message:

text
des.queue waiting has no input port entry

A reversed connection gets one error for each end. For a des.server named teller, the connection teller.in -> waiting.out gets des.server teller has no output port in and des.queue waiting has no input port out. The sd.auxiliary and data.series types declare no ports, so every connection end on them is an error.

Check port ids against the library pages. Each page also shows a port's connectsTo list in its description.

Read more#