math_spec.merge
Several files into one model, before any of them is validated.
A component library is a fixed set of templates agreeing on a port and flow convention, and wiring a specific system is rows in a connectivity table rather than generated YAML. What that needs of the language is one function: take the templates and hand back one model, so the whole thing is validated, resolved and lowered exactly once, as a file is.
A fragment is not a :class:~math_spec.model.Spec. It is read as YAML and
merged unvalidated, so a template may name what a sibling declares — a shared
bus, the flow every component writes into — without being a model on its
own. Nothing here resolves a name or checks a dim: the merged mapping goes
through :func:~math_spec.validation.to_spec like any other, against one flat
namespace, and every rule the language has applies to it there and nowhere
else.
Two kinds of declaration, and the split is what merging means:
dimensionsandlookupsare the coordinate space, which templates share on purpose. Declared twice and agreeing, they are one declaration; declared twice and disagreeing, the disagreement is the error.- Everything else is the math, which a template owns. Declared twice it is a collision, whichever fragment wrote it second, because two templates claiming one name is the composition being wrong rather than the file.
Names are not rewritten here. Qualified names are their own question
(#29), and until they land a library keeps its templates apart by naming
them apart — which the collision error above is what enforces.
IRREGULAR = {'piecewise': 'piecewise curve', 'sos': 'special-ordered set'}
module-attribute
#
OWNED_SECTIONS = ('parameters', 'variables', 'constraints', 'expressions', 'macros', 'piecewise', 'sos')
module-attribute
#
SHARED_SECTIONS = ('dimensions', 'lookups')
module-attribute
#
merge(fragments, description=None)
#
Compose fragments into one unvalidated model mapping.
| PARAMETER | DESCRIPTION |
|---|---|
fragments
|
What each fragment is called, to the fragment — the same
|
description
|
What the composed model is. A fragment's own
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
dict[str, Any]
|
One mapping, ready for :func: |
dict[str, Any]
|
in it has been resolved, name-checked or lowered: merging decides what |
dict[str, Any]
|
the declarations are, and the language decides whether they say |
dict[str, Any]
|
anything. |
| RAISES | DESCRIPTION |
|---|---|
LanguageError
|
Two fragments declare one owned name; two fragments
disagree about a shared declaration; two fragments pin different
language versions; or the objectives disagree about |