Schema
The typed study contract. See Study Schema for the rules and the published JSON Schema.
mdo_framework.schema
This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
Finite = Annotated[float, Field(strict=True, allow_inf_nan=False)]
module-attribute
Finite float: rejects NaN, infinities, bool and str (int is widened).
Name = Annotated[str, StringConstraints(pattern=NAME_PATTERN, max_length=MAX_NAME_LENGTH), AfterValidator(_reject_python_keyword)]
module-attribute
Identifier usable as a keyword argument: pattern, length and keyword checked.
Scalar = StrictBool | StrictInt | Annotated[StrictFloat, Field(allow_inf_nan=False)] | StrictStr
module-attribute
Exact-typed scalar: bool, int, finite float or str.
ChoiceVar
Bases: _Strict
Categorical design variable taking one of several homogeneous values.
Attributes:
| Name | Type | Description |
|---|---|---|
kind |
Literal['choice']
|
Discriminator, always |
name |
Name
|
Variable name. |
choices |
list[Scalar]
|
At least two unique values sharing one Python type. |
ordered |
StrictBool | None
|
|
initial |
Scalar | None
|
Optional starting value, one of |
units |
str | None
|
Optional free-form unit label. |
Source code in src/mdo_framework/schema.py
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 | |
value_type
property
Type name of the choices, as expected by the parameter codec.
ConstraintSpec
Bases: _Strict
Inequality constraint on a produced variable.
Attributes:
| Name | Type | Description |
|---|---|---|
name |
Name
|
Name of the produced variable to constrain. |
bound |
Finite
|
Constraint bound. |
op |
Literal['<=', '>=']
|
|
tolerance |
Annotated[Finite, Field(ge=0)]
|
Violation of the bound, in the units of the variable, that still counts as satisfied. |
scale |
Annotated[Finite, Field(gt=0)] | None
|
Typical magnitude of the variable, used to compare violations of
different constraints. |
Source code in src/mdo_framework/schema.py
315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 | |
Finding
Bases: _Strict
Single validation issue.
Attributes:
| Name | Type | Description |
|---|---|---|
code |
str
|
Stable machine-readable code. |
message |
str
|
Human-readable description. |
names |
tuple[str, ...]
|
Variable, tool or field names involved. |
Source code in src/mdo_framework/schema.py
335 336 337 338 339 340 341 342 343 344 345 346 | |
FixedParam
Bases: _Strict
Constant input passed unchanged to the tools that declare it.
Attributes:
| Name | Type | Description |
|---|---|---|
kind |
Literal['fixed']
|
Discriminator, always |
name |
Name
|
Variable name. |
value |
Scalar
|
The constant value. |
units |
str | None
|
Optional free-form unit label. |
Source code in src/mdo_framework/schema.py
173 174 175 176 177 178 179 180 181 182 183 184 185 186 | |
ObjectiveSpec
Bases: _Strict
Optimization objective.
Attributes:
| Name | Type | Description |
|---|---|---|
name |
Name
|
Name of the produced variable to optimize. |
minimize |
bool
|
|
threshold |
Finite | None
|
Optional reference point for multi-objective runs. |
Source code in src/mdo_framework/schema.py
301 302 303 304 305 306 307 308 309 310 311 312 | |
RangeVar
Bases: _Strict
Continuous or integer design variable bounded by [lower, upper].
Attributes:
| Name | Type | Description |
|---|---|---|
kind |
Literal['range']
|
Discriminator, always |
name |
Name
|
Variable name. |
lower |
Finite
|
Inclusive lower bound. |
upper |
Finite
|
Inclusive upper bound, strictly above |
value_type |
Literal['float', 'int']
|
|
scaling |
Literal['linear', 'log']
|
|
initial |
Finite | None
|
Optional starting point within the bounds. |
units |
str | None
|
Optional free-form unit label. |
Source code in src/mdo_framework/schema.py
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 | |
StateVar
Bases: _Strict
Variable produced by a tool (an output or a coupling variable).
Attributes:
| Name | Type | Description |
|---|---|---|
kind |
Literal['state']
|
Discriminator, always |
name |
Name
|
Variable name. |
initial_guess |
Finite | Annotated[list[Finite], Field(min_length=1)] | None
|
Optional scalar or non-empty list used to seed couplings. |
units |
str | None
|
Optional free-form unit label. |
Source code in src/mdo_framework/schema.py
189 190 191 192 193 194 195 196 197 198 199 200 201 202 | |
StudySchema
Bases: _Strict
Typed, shared description of a study: variables and tools.
Variable order is significant: design variables keep their declaration order.
Attributes:
| Name | Type | Description |
|---|---|---|
schema_version |
Literal['1']
|
Schema format version. |
variables |
list[Variable]
|
Declared variables. |
tools |
list[ToolSpec]
|
Declared tools. |
Source code in src/mdo_framework/schema.py
387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 | |
content_hash()
Hash the schema content, sensitive to variable and tool order.
Returns:
| Type | Description |
|---|---|
str
|
SHA-256 hex digest of the canonical JSON form. |
Source code in src/mdo_framework/schema.py
534 535 536 537 538 539 540 541 542 543 | |
producers()
Map every produced variable name to the tool that produces it.
Returns:
| Type | Description |
|---|---|
dict[str, str]
|
Dictionary of variable name to producing tool name. |
Source code in src/mdo_framework/schema.py
526 527 528 529 530 531 532 | |
tool(name)
Return the tool called name.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Tool name. |
required |
Returns:
| Type | Description |
|---|---|
ToolSpec
|
The matching tool. |
Raises:
| Type | Description |
|---|---|
KeyError
|
If no tool has this name. |
Source code in src/mdo_framework/schema.py
509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 | |
variable(name)
Return the variable called name.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Variable name. |
required |
Returns:
| Type | Description |
|---|---|
Variable
|
The matching variable. |
Raises:
| Type | Description |
|---|---|
KeyError
|
If no variable has this name. |
Source code in src/mdo_framework/schema.py
492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 | |
StudyValidationError
Bases: ValueError
Raised when a study fails validation.
Attributes:
| Name | Type | Description |
|---|---|---|
report |
The full validation report. |
Source code in src/mdo_framework/schema.py
368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 | |
__init__(report)
Build the error from a report.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
report
|
ValidationReport
|
Report whose errors are listed in the message. |
required |
Source code in src/mdo_framework/schema.py
375 376 377 378 379 380 381 382 383 384 | |
ToolNode
Bases: _Strict
Tool (discipline) as stored on a graph node, without its edges.
Attributes:
| Name | Type | Description |
|---|---|---|
name |
Name
|
Tool name. |
fidelity |
Name
|
Fidelity level label. |
deterministic |
StrictBool
|
Whether the tool returns the same outputs for the same inputs. A non-deterministic tool is never cached, so every evaluation calls it again. |
thread_safe |
StrictBool
|
Whether the tool may run concurrently in several threads. Required of every tool in a coupled group to evaluate it in parallel. |
arg_map |
dict[Name, Name]
|
Graph input name to Python argument name, for inputs whose argument has a different name. Two graph inputs cannot feed the same argument. |
Source code in src/mdo_framework/schema.py
235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 | |
ToolSpec
Bases: ToolNode
Tool (discipline) with its input and output variable names.
Attributes:
| Name | Type | Description |
|---|---|---|
name |
Name
|
Tool name. |
fidelity |
Name
|
Fidelity level label. |
deterministic |
StrictBool
|
Whether the tool is cacheable. |
thread_safe |
StrictBool
|
Whether the tool may run concurrently in threads. |
arg_map |
dict[Name, Name]
|
Graph input name to Python argument name. |
inputs |
list[Name]
|
Unique names of the variables the tool reads. |
outputs |
list[Name]
|
Unique names of the variables the tool produces. |
Source code in src/mdo_framework/schema.py
269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 | |
ValidationReport
Bases: _Strict
Outcome of validating a study.
Attributes:
| Name | Type | Description |
|---|---|---|
errors |
tuple[Finding, ...]
|
Findings that make the study unusable. |
warnings |
tuple[Finding, ...]
|
Findings that do not block the study. |
valid |
bool
|
Computed flag, |
Source code in src/mdo_framework/schema.py
349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 | |
valid
property
Whether the report contains no error.
argument_collisions(inputs, arg_map)
Find the Python arguments that several graph inputs would be passed as.
The argument of an input is its arg_map value, or its own name when it
is not mapped.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
inputs
|
Sequence[str]
|
Graph input names of a tool. |
required |
arg_map
|
Mapping[str, str]
|
Graph input name to Python argument name. |
required |
Returns:
| Type | Description |
|---|---|
dict[str, list[str]]
|
The colliding inputs, in order, per argument name. Empty when every |
dict[str, list[str]]
|
input has its own argument. |
Source code in src/mdo_framework/schema.py
211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 | |
report_from_validation_error(exc)
Convert a failed StudySchema validation into a report.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
exc
|
ValidationError
|
Error raised by |
required |
Returns:
| Type | Description |
|---|---|
ValidationReport
|
Report with one finding per structural violation, and a |
ValidationReport
|
|
Source code in src/mdo_framework/schema.py
546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 | |