fluxopt.schema
¶
JSON Schema and dict/JSON round-trip for the element layer.
The user-facing elements are pydantic.dataclasses, so pydantic can emit a
JSON Schema for each type and round-trip instances to plain dicts. This is the
machine-readable contract behind a future config front-end, GUI, or
LLM-assisted authoring surface.
Structural round-trip (:func:to_dict / :func:from_dict) preserves ids,
scalars, nested elements, and :class:~fluxopt.types.ProfileRef references.
Inline array-valued Variate fields (raw time-series) do not serialize —
use a ProfileRef instead, so profiles live in data files rather than in the
config (see docs/design/config-and-pydantic-direction.md). Such fields also
appear as permissive {} in the JSON Schema.
Functions:
| Name | Description |
|---|---|
element_schema |
Return the JSON Schema for one element type. |
all_element_schemas |
Return JSON Schemas for every element type, keyed by class name. |
to_dict |
Serialize an element to a JSON-safe dict. |
from_dict |
Reconstruct an element from a dict produced by :func: |
Attributes:
| Name | Type | Description |
|---|---|---|
ELEMENT_TYPES |
tuple[type, ...]
|
Every user-facing element type, in declaration order. |
ELEMENT_TYPES
module-attribute
¶
ELEMENT_TYPES: tuple[type, ...] = (
Carrier,
Effect,
Flow,
Sizing,
Investment,
Status,
Storage,
Port,
Converter,
)
Every user-facing element type, in declaration order.
element_schema
¶
element_schema(element_type: type) -> dict[str, Any]
all_element_schemas
¶
Return JSON Schemas for every element type, keyed by class name.
to_dict
¶
Serialize an element to a JSON-safe dict.
Nested elements and ProfileRef references are
included; inline array-valued Variate fields are not serializable —
reference them with a ProfileRef instead.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
object
|
Any element instance (e.g. |
required |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the element holds inline array values, listing each offending field. |