loader
YAML / JSON problem loader.
Reads a structured problem definition from a YAML or JSON file (or a plain
Python dict) and returns the keyword arguments needed to construct a
openscvx.problem.Problem.
YAML Schema & Editor Autocomplete
The accepted YAML structure is defined by ProblemSpec (a pydantic
model). You can generate a JSON Schema for editor autocomplete and
validation with:
openscvx schema # prints to stdout
openscvx schema -o schema.json # writes to file
Then enable it in your editor:
- VS Code (with the
redhat.vscode-yamlextension) -- add a modeline as the first line of your YAML file: Or configure globally insettings.json: - JetBrains -- Languages & Frameworks > Schemas and DTDs > JSON Schema Mappings, point at the generated file and associate a file pattern.
This gives you field-name autocomplete, hover docs, and red squiggles on typos or wrong types -- all derived from the pydantic models, so the schema always matches the version of openscvx you have installed.
ProblemSpec
¶
Bases: BaseModel
Validates the entire YAML/JSON problem structure.
Source code in openscvx/loader.py
load_dict(data: dict) -> dict
¶
Convert a parsed dict into Problem constructor keyword arguments.
This is the core routine called by :func:load_yaml and
:func:load_json. It can also be called directly with an
already-parsed Python dict.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
dict
|
Problem definition dictionary (see module docstring for schema). |
required |
Returns:
| Name | Type | Description |
|---|---|---|
dict
|
Dict with keys |
|
dict
|
|
|
dict
|
|
|
dict
|
|
|
via |
dict
|
meth: |
dict
|
after construction). |
Source code in openscvx/loader.py
115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 | |
load_json(path: Union[str, Path]) -> dict
¶
Load a JSON problem definition and return Problem constructor kwargs.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
Union[str, Path]
|
Path to the JSON file. |
required |
Returns:
| Type | Description |
|---|---|
dict
|
Dict of keyword arguments suitable for |
Source code in openscvx/loader.py
load_yaml(path: Union[str, Path]) -> dict
¶
Load a YAML problem definition and return Problem constructor kwargs.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
Union[str, Path]
|
Path to the YAML file. |
required |
Returns:
| Type | Description |
|---|---|
dict
|
Dict of keyword arguments suitable for |