Schema Validation¶
The Pydantic v2 models that define the simulation.toml v1.0 contract, and
validate_simulation_toml(), the entry point that returns a strictly typed
SimulationSchema.
This subpackage is authoritative: readers.config.load_config() is a thin
translator that delegates all shape validation here and then maps the result
onto the internal SimulationConfig / GridInfo / Normalization /
SpeciesInfo. It deliberately has no pypic-internal imports — only stdlib and
pydantic — so it can be lifted into a standalone distribution.
The prose specification is Schema; the annotated reference
template is pypic.simulation.toml at the repository root. A generated JSON
Schema ships in the wheel for consumers that are not running Python:
uv run pypic schema export -o simulation.schema.v2.0.json
uv run pypic schema validate path/to/simulation.toml
uv run pypic schema diff path/to/proposed.json
schema
¶
Pydantic v2 validator for the pypic simulation.toml v2.0 schema.
Designed to be decoupled from pypic itself — the only imports are stdlib and pydantic, so this subpackage can be lifted into a standalone distribution without modification.
Entry point: validate_simulation_toml, which accepts a path,
a TOML text blob, or a pre-parsed dict and returns a fully typed
SimulationSchema root model.
Examples:
>>> from pypic.schema import validate_simulation_toml
>>> doc = '''
... [schema]
... version = "2.0"
... [model]
... name = "demo"
... type = "PIC"
... [run]
... name = "r0"
... [time]
... scheme = "fixed"
... dt = 0.1
... t_start = 0.0
... t_end = 1.0
... n_steps = 10
... [grid]
... dimensions = [4, 4, 4]
... spacing = [1.0, 1.0, 1.0]
... lower = [0.0, 0.0, 0.0]
... upper = [4.0, 4.0, 4.0]
... [units]
... anchor = "si"
... [coordinates]
... geometry = "cartesian"
... frame = "sim"
... [[species]]
... name = "electrons"
... charge = -1.0
... mass = 1.0
... '''
>>> s = validate_simulation_toml(doc)
>>> s.model.type
'PIC'
Allocation
¶
Bases: _StrictBase
One entry in [[run.resources.allocations]] (heterogeneous HW).
Source code in src/pypic/schema/_models.py
194 195 196 197 198 199 200 | |
Author
¶
Bases: _StrictBase
Person entry in [model].authors or [run].authors.
Source code in src/pypic/schema/_models.py
172 173 174 175 176 177 178 | |
Body
¶
Bases: _StrictBase
One entry in [[bodies]] — registry of physical objects.
Source code in src/pypic/schema/_models.py
985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 | |
BoundaryConditions
¶
Bases: BoundaryConditionsBase
[boundary_conditions] — per-face tag arrays.
The default form: one tag per face per axis applied uniformly to
every field. field_overrides lets PIC PML simulations and
solar-wind-driven runs declare different BCs for E (PML), B (PML),
and particles (reflecting / absorbing / thermal-bath) at the same
face. Each entry is a BoundaryConditionsBase matching the
same axis count as the default.
Source code in src/pypic/schema/_models.py
610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 | |
BoundaryConditionsBase
¶
Bases: _StrictBase
Reusable per-face BC vector + optional driver foreign keys.
lower / upper carry one tag per axis ("periodic",
"reflecting", "open", "driven", ...). The vocabulary is
free-form: validators don't constrain the strings, so different code
families coexist without an upstream enum cut.
drivers_lower / drivers_upper link individual faces to a
declared [[drivers]].name entry. Each is sparse: a dict keyed by
axis index as a string ("0", "1", "2"), valued with the
driver name. Faces without a driver simply don't appear. The root
validator enforces foreign-key resolution against [[drivers]]
and the axis-index range against grid.dimensions.
Source code in src/pypic/schema/_models.py
562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 | |
BoxRegion
¶
Bases: _StrictBase
[output.streams.<n>.region] — axis-aligned box selection.
Coordinates in code units (matches [grid].lower / [grid].upper
convention). upper must be strictly greater than lower per
axis; the per-axis count must align with [grid].dimensions —
enforced at the root level.
Source code in src/pypic/schema/_models.py
1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 | |
Collision
¶
Bases: _ExtensibleBase
One entry in [[collisions]] — inter-species collision model.
Collisional PIC codes (Smilei, EPOCH, OSIRIS-collisional, PIConGPU) declare per-pair Coulomb collisions, BGK relaxation, or Monte-Carlo scattering. The schema captures the declaration of each pair; numerical parameters live on the entry.
species_pair lists the two species names participating; the
root validator enforces that both names exist in [[species]].
Self-collisions (same species twice) are permitted.
Extra keys are accepted (_ExtensibleBase) so code-specific
knobs — cross-section table paths, BGK relaxation-rate models,
Monte-Carlo scattering-table identifiers — can land here without
forcing every collisional reader through the top-level x-
namespace. Portable additions (when a vocabulary stabilises across
codes) become typed fields in a future version.
Source code in src/pypic/schema/_models.py
1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 | |
Coordinates
¶
Bases: _StrictBase
[coordinates] — geometry + reference frame.
physical_extent is metadata at the schema level: the validator
only checks shape and positivity. Post-translation, the reader-side
helper pypic.readers.config.apply_physical_extent consumes it to
auto-compute transform scale factors and a shrink-factor diagnostic
(see docs/schema.md § Coordinates).
modes is required when geometry = "thetaMode" (FBPIC azimuthal-
mode decomposition over an (r, z) grid) and forbidden otherwise.
Source code in src/pypic/schema/_models.py
870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 | |
CoordinatesModes
¶
Bases: _StrictBase
[coordinates.modes] — azimuthal-mode decomposition for FBPIC RZ.
Required when geometry = "thetaMode". n_modes counts the
azimuthal modes stored on disk (typically 1–3, with mode 0 cylindrically
symmetric). mode_indices is an optional explicit list of mode
numbers — when omitted, modes are assumed to run 0, 1, ..., n_modes-1.
Source code in src/pypic/schema/_models.py
848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 | |
CoordinateTransform
¶
Bases: _StrictBase
One entry under [coordinates.transforms.<frame>].
rotation, when present, must be a 3×3 signed permutation
matrix: exactly one ±1 per row and per column with every other
entry zero. That covers all axis-relabeling / handedness flips
pypic's frame transforms support today (GSE↔GSM-style rotations
with continuous angles are time-dependent and route through
parameter instead — see coordinates.transforms). Catching
a malformed matrix here is cheaper than letting it slip into
pypic.coordinates._frames and surface as a runtime error at
apply time.
Source code in src/pypic/schema/_models.py
795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 | |
Driver
¶
Bases: _ExtensibleBase
One entry in [[drivers]].
Drivers have a core set of v2.0 fields plus driver-type-specific keys — extra keys allowed so individual driver types (magnetogram, solar_wind_timeseries, pickup_ion_source, ...) don't need a model per type in v2.0.
An entry describes the external input from this run's
perspective. For two-way coupling (direction = "two_way"),
the asymmetry is in information flow, not in physics: the peer
run, if pypic-aware, owns its own simulation.toml with its
own [[drivers]] entry pointing back. [drivers.model] is
where the peer's identity (name, type, url, description) lives;
pure data drivers (CSV, HDF5 timeseries) can omit the sub-table
and use source alone.
Source code in src/pypic/schema/_models.py
1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 | |
DriverModel
¶
Bases: _ExtensibleBase
[drivers.model] — identity of a coupled external system.
Used when a driver entry refers to a named model rather than (or
in addition to) a flat data file. The type vocabulary is open:
"MHD" and "PIC" cover pypic-aware peers, but
"ionosphere_potential_solver" (RIM, Weimer), "magnetic_field_
extrapolation" (PFSS, NLFFF), "fluid_atmosphere" (GITM, TIE-
GCM), "fusion_transport" (ASTRA, JETTO), and any other category
are equally valid.
url is a single opaque pointer. It may be the peer's
simulation.toml cross-link (when pypic-aware), a homepage URL,
a DOI, or any other machine- or human-readable metadata reference.
The schema does not resolve or sniff the format — that is a consumer
concern, in the same spirit as restart.from and the top-level
[model].url. A non-standard metadata file is better than no
link at all.
_ExtensibleBase lets coupling-specific keys (version,
doi, git_sha, model-specific knobs) ride along without
bloating the typed surface.
Source code in src/pypic/schema/_models.py
1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 | |
Ensemble
¶
Bases: _StrictBase
[run.ensemble] — ensemble-member identity for stochastic runs.
Required for cosmological PIC, turbulence realizations, and any other
setup where multiple runs share initial conditions modulo a random
seed. member_id is 1-indexed and bounded by total; the
validator enforces 1 <= member_id <= total.
Source code in src/pypic/schema/_models.py
220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 | |
Grid
¶
Bases: _StrictBase
[grid] — computational grid in code units.
ghost_cells records the number of ghost cells per axis used by the
code's halo exchange. Optional metadata for downstream edge-derivative
analysis; readers strip ghosts before populating FieldDataset.
stretched describes per-axis non-uniform cell widths. Sparse —
only axes with non-uniform spacing appear in
[grid.stretched.axis_widths]; the remaining axes inherit
spacing. The validator enforces that any listed axis widths sum
to upper[i] - lower[i] and that the list length equals
dimensions[i].
stagger consolidates the three field-placement-inside-cell
tiers (convention, fields, position) under a single
sub-table — see GridStagger.
Source code in src/pypic/schema/_models.py
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 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 | |
GridAMR
¶
Bases: _StrictBase
[grid.amr] — dynamic adaptive refinement parameters.
amr_kind discriminates block/patch (BoxLib / AMReX / Chombo / FLASH)
from octree codes (RAMSES, MPI-AMRVAC); octree leaves are single cells
so block_size does not apply. level_subcycling records whether
different AMR levels advance at different effective timesteps (Athena++
and AMReX-based codes); a per-level dt_factor array would be a
future v2.1 add if needed.
Source code in src/pypic/schema/_models.py
369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 | |
GridRefinementBox
¶
Bases: _StrictBase
One entry in [[grid.refinement]] (static nested refinement box).
Source code in src/pypic/schema/_models.py
389 390 391 392 393 | |
GridStretched
¶
Bases: _StrictBase
[grid.stretched] — non-uniform per-axis cell widths.
Sparse, keyed by axis index as a string ("0" / "1" / "2").
Only stretched axes appear; uniform axes inherit Grid.spacing.
Per-axis cell widths must sum to upper[i] - lower[i] and the
list length must equal dimensions[i]; both invariants are
enforced by Grid._check_axis_consistency.
Adopted to describe ARMS spherical-r stretches, PLUTO log-radial grids, Athena++ stretched grids, and FLASH per-block-non-uniform layouts losslessly. Kept additive so uniform documents validate unchanged. Metric-aware operators are out of scope for v2.0.x — consumers that need them should guard explicitly.
Source code in src/pypic/schema/_models.py
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 | |
HybridSolver
¶
Bases: _ExtensibleBase
[physics.hybrid.solver]. Extra keys accepted.
Source code in src/pypic/schema/_models.py
955 956 957 958 959 960 961 962 963 | |
InitialConditions
¶
Bases: _ExtensibleBase
[initial_conditions] — flat table, setup-specific keys vary.
Source code in src/pypic/schema/_models.py
1002 1003 1004 1005 | |
MHDSolver
¶
Bases: _ExtensibleBase
[physics.mhd.solver]. Extra keys accepted.
Source code in src/pypic/schema/_models.py
935 936 937 938 939 940 941 942 943 | |
Model
¶
Bases: _StrictBase
[model] — identity of the code that produced the data.
Source code in src/pypic/schema/_models.py
181 182 183 184 185 186 187 188 189 190 191 | |
Output
¶
Bases: _StrictBase
[output] — umbrella for all write-side configuration.
Source code in src/pypic/schema/_models.py
1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 | |
OutputCheckpoints
¶
Bases: _OutputBase
[output.checkpoints] — lossless full-state dumps.
Source code in src/pypic/schema/_models.py
1276 1277 1278 1279 1280 | |
OutputDiagnostics
¶
Bases: _OutputBase
[output.diagnostics] — on-the-fly derived quantities.
Source code in src/pypic/schema/_models.py
1312 1313 1314 1315 | |
OutputFields
¶
Bases: _OutputBase
[output.fields] — field output cadence + quantities.
Source code in src/pypic/schema/_models.py
1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 | |
OutputParticles
¶
Bases: _OutputBase
[output.particles] — particle output cadence + selection.
Source code in src/pypic/schema/_models.py
1297 1298 1299 1300 1301 1302 1303 | |
OutputProbes
¶
Bases: _OutputBase
[output.probes] — probe time-series cadence.
Source code in src/pypic/schema/_models.py
1306 1307 1308 1309 | |
OutputStream
¶
Bases: _OutputBase
One entry in [[output.streams]] — multi-cadence / ROI output.
The repeatable form alongside the existing singleton [output.fields].
Use this for runs that write moments at 10x the cadence of full
distributions, or ROI slabs at 10x the cadence of the global volume,
or that simply need named output groups for downstream pipelines.
name is required and must be unique across streams. region
optionally restricts the write to a sub-volume or plane;
precision_overrides re-uses the [output.fields] semantics
(per-field-name dtype overrides; names must appear in quantities).
Source code in src/pypic/schema/_models.py
1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 | |
PhaseSpace
¶
Bases: _StrictBase
[phase_space] — kinetic phase-space dimensions for >3D codes.
Gyrokinetic codes (GENE, GS2, GX, Gkeyll-GK) run on 5-D grids
(3 spatial + 2 velocity); continuum-Vlasov codes use 6-D phase
space (3 spatial + 3 velocity). This block describes the
augmented phase-space dimensionality without lifting the
Grid.dimensions cap on the spatial side.
Required when the simulation operates on a phase-space grid larger
than [grid].dimensions. Optional otherwise. The root validator
enforces consistency: [phase_space].dimensions[:n_spatial]
must match [grid].dimensions when both are present.
storage is the sparse-block sub-table for continuum-Vlasov
codes. Gyrokinetic runs omit it.
Source code in src/pypic/schema/_models.py
1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 | |
PhaseSpaceStorage
¶
Bases: _StrictBase
[phase_space.storage] — sparse-block velocity-grid storage.
Continuum-Vlasov codes (Vlasiator, Gkeyll-Vlasov-Maxwell) subdivide
the velocity sub-grid into blocks for adaptive memory use, dropping
blocks whose distribution-function density falls below a threshold.
block_size records the per-velocity-axis block factor;
sparsity_threshold records the density floor.
Optional sub-table on PhaseSpace. Gyrokinetic codes
(GENE, GS2, GX, Gkeyll-GK) emit dense 5-D grids and omit this
block entirely. The validator checks that block_size length
matches the velocity sub-axes of the parent dimensions —
enforced on the parent PhaseSpace once the spatial
dimension count is known at the root level.
Source code in src/pypic/schema/_models.py
1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 | |
Physics
¶
Bases: _ExtensibleBase
[physics] — flags whose semantics are identical across models.
Extra top-level keys under [physics] are accepted to leave room
for v2.1+ additions ([physics.vlasov] in particular).
Source code in src/pypic/schema/_models.py
972 973 974 975 976 977 978 979 980 981 982 | |
PhysicsHybrid
¶
Bases: _ExtensibleBase
[physics.hybrid] — hybrid physics-model knobs. Extra keys accepted.
Source code in src/pypic/schema/_models.py
966 967 968 969 | |
PhysicsMHD
¶
Bases: _ExtensibleBase
[physics.mhd] — MHD physics-model knobs. Extra keys accepted.
Source code in src/pypic/schema/_models.py
946 947 948 949 950 951 952 | |
PhysicsPIC
¶
Bases: _ExtensibleBase
[physics.pic] — PIC physics-model knobs. Extra keys accepted.
Source code in src/pypic/schema/_models.py
928 929 930 931 932 | |
PICSolver
¶
Bases: _ExtensibleBase
[physics.pic.solver]. Extra keys accepted — vocabulary evolves.
current_smoothing / charge_smoothing count the binomial /
compensator filter passes per step (standard in WarpX, Smilei,
PIConGPU, OSIRIS — already exposed on HybridSolver).
charge_correction, current_deposition adopt the openPMD
ED-PIC vocabulary; see ChargeCorrection,
CurrentDeposition.
Source code in src/pypic/schema/_models.py
906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 | |
PlaneRegion
¶
Bases: _StrictBase
[output.streams.<n>.region] — single-axis plane slice.
axis selects a coordinate axis (0/1/2).
value is the plane position in code units; the reader is
responsible for resolving it to the nearest grid index.
Source code in src/pypic/schema/_models.py
1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 | |
Probe
¶
Bases: _StrictBase
One entry in [[probes]] — fixed or trajectory sampler.
fields controls which dataset fields the probe samples. Two modes:
fields = None(omitted) — sample every storage-primitive field present in the dataset at probe time. Storage primitives are what readers expose viaavailable_fields()— moments and EM fields actually on disk, never derived quantities like|B|orbeta. Users who want derived quantities listed must request them explicitly. The narrow default keeps probe time-series cheap on big runs.fields = [...]— sample exactly this list. Names that don't resolve at sample time should fail loudly rather than be silently dropped; resolution againstavailable_fields()happens in the probe sampler, not here.
Source code in src/pypic/schema/_models.py
1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 | |
resolve_fields(available)
¶
Return the concrete field list this probe samples.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
available
|
Iterable[str]
|
Storage-primitive field names present in the dataset, as
returned by |
required |
Returns:
| Type | Description |
|---|---|
list[str]
|
|
Source code in src/pypic/schema/_models.py
1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 | |
Restart
¶
Bases: _StrictBase
[restart] — continuation pointer from a prior run.
from is the path (or paths) to the restart artifact:
- a single file (
./chk_000030.h5), - a directory of per-rank checkpoints (
./restart_30000/), - a glob pattern, or
- an explicit list of per-rank files for runs whose names don't follow the source code's convention (relocated reruns, mixed naming schemes).
Whether the path resolves to one file or many is determined at read time by the filesystem and the code, not by the schema.
restore enables partial restart — restarting only the listed
state categories rather than all of them (e.g., fields-only
continuation that re-initializes particles from a fresh
distribution). mode distinguishes a full state reload
("hot") from a setup-restart that re-applies initial
conditions on top of the saved geometry ("cold"). Both
optional; a missing restore means the full state is restored.
Source code in src/pypic/schema/_models.py
1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 | |
Run
¶
Bases: _StrictBase
[run] — identity + provenance of THIS run.
id is the stable, globally unique identifier for the run, and is
the key every derived product carries back to its source. name
is a human label and carries no uniqueness contract; doi is
scarce by design, since archives do not mint one per run. No format
is enforced — CCMC run IDs, ULIDs and per-lab conventions all differ,
and the schema's job here is to record an identifier, not to police
its shape.
references is results metadata: what was published from this
run. Distinct from doi (this run's data) and [model].doi
(the code).
idealized is deliberately tri-state. True means the run does
not correspond to a real time period — artificial drivers, artificial
internal settings, or a 2D reduction of a 3D system — so harvesting
real-event characteristics from it would produce wrong metadata.
False asserts the conditions are real. None (the default)
means unstated, which is what every deck written before this key
existed actually means; a plain bool default would make all of
them silently claim to be real events.
epoch anchors code time t = 0 to a UTC instant, so a run of a
real event can say which event. It lives here rather than on
[time] because [time] does not survive to the typed
in-memory config — only dt reaches a FieldDataset — whereas
[run] round-trips end to end. It is also identity: "which real
period is this" is a search-and-discovery question, not an
integrator setting.
Source code in src/pypic/schema/_models.py
267 268 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 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 | |
RunReference
¶
Bases: _StrictBase
[[run.references]] — one result published from this run.
Results metadata is what makes an archived run findable by the
science it produced rather than only by its settings. Each entry
needs at least one of doi / url / citation — an entry
naming only a kind identifies nothing.
Source code in src/pypic/schema/_models.py
242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 | |
RunResources
¶
Bases: _StrictBase
[run.resources] — runtime accounting (all keys optional).
Source code in src/pypic/schema/_models.py
203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 | |
SchemaMeta
¶
Bases: _StrictBase
[schema] — schema version + creation date.
Source code in src/pypic/schema/_models.py
1589 1590 1591 1592 1593 | |
SimulationSchema
¶
Bases: _ExtensibleBase
Root model for a pypic simulation.toml v2.0 document.
Required top-level sections per v2.0: [schema], [model], [run], [time], [grid], [units], [coordinates], and at least one [[species]] entry.
Optional sections may be omitted entirely.
Extension policy at root: unknown keys must start with x- or
x_. Known optional sections that are present are strictly
validated.
[schema].version is the single discriminator for both the
TOML config and the on-disk vocabulary it describes; v2.x is
additive-only per schema.md §1 Versioning.
Source code in src/pypic/schema/_models.py
1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 | |
Species
¶
Bases: _StrictBase
One entry in [[species]].
Provide either (charge, mass) OR charge_to_mass, not both.
Validated after the fact.
Species are indexed in declaration order — _s0 binds to the
first [[species]] entry, _s1 to the second, etc. Reordering
entries is a breaking change to any downstream field-name reference
that uses the _sN suffix.
Source code in src/pypic/schema/_models.py
1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 | |
Time
¶
Bases: _StrictBase
[time] — temporal integration controls.
Scheme-specific keys are deliberately not modelled as a discriminated union — the vocabulary is still settling and the cost of a wrong shape here is low. v2.0 enforces only the cross-field invariants that are unambiguous:
- fixed/subcycled require
dt > 0(the integration step); - subcycled requires
field_substeps(dt_fieldis recommended but advisory, not enforced); - adaptive omits
dt(or accepts any non-negative value as a hint); the runtime derives the first step fromcfl/dt_min/dt_maxand owns CFL bookkeeping thereafter.
A future v2.1 may formalise these as a discriminated union once codes converge on a common spelling.
Source code in src/pypic/schema/_models.py
321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 | |
UnitsExplicit
¶
Bases: _UnitsBase
[units] with anchor = "explicit" — the length unit is given.
Covers MHD, PLUTO/Athena++-class codes, gyrokinetics, and any hand-built reference set. Three relations close the eight primitives:
The third ties the field, velocity and density scales together, so
a deck supplies reference_length plus any two of:
- a velocity —
reference_velocityorreference_time - a density —
reference_number_densityorreference_mass_density - a field —
reference_b_fieldorreference_e_field
and the third follows. Supplying all three is legal: the relations
then describe rather than derive, which is what gyrokinetic decks
need, where \(v \neq l/t\) by \(\rho_*\) and \(B^2 \neq \mu_0 n m v^2\) by
\(2/\beta\) on purpose. Normalization.rationalization_ratio reports
the result.
Duplicate spellings of one primitive are rejected; redundant
distinct primitives are accepted. Both density keys together is
an error, because which unit a number carries would be ambiguous.
reference_b_field with reference_velocity is fine — those are
two different quantities, and a tolerance gate could not tell a
deliberate \(2/\beta\) from a typo anyway.
reference_mass defaults to the proton mass whichever density
spelling is used. Keying the default off the spelling would make
two decks describing one plasma disagree by \(m_p/m_e\) in silence,
which is the trap this form exists to remove.
Source code in src/pypic/schema/_models.py
681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 | |
UnitsFromSpecies
¶
Bases: _UnitsBase
[units] with anchor = "from_species" — length from microphysics.
The form for codes that resolve a kinetic scale: PIC, hybrid, and
anything else whose grid is measured in skin depths. The length
unit is derived, \(l_{ref} = c/\omega_{ref}\), from the reference
species' plasma frequency — which is what distinguishes this form
from UnitsExplicit, where length is given.
The velocity unit defaults to c, the PIC convention. Hybrid codes
normalize to the Alfvén speed instead and set reference_velocity
to it, which makes \(B_{ref}\) the field at which \(v_A\) equals that
speed and lands the time unit on the inverse ion cyclotron
frequency, via \(d_i \Omega_{ci} = v_A\).
Source code in src/pypic/schema/_models.py
654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 | |
UnitsSI
¶
Bases: _UnitsBase
[units] with anchor = "si" — SI data with no code-unit anchor.
All eight references are 1.0, so conversion is a no-op. That makes
electromagnetic quantities unsafe: pypic.derived computes in
SI-rationalized units where \(\mu_0 = 1\), and SI data has
\(\mu_0 = 1.2566\times10^{-6}\), so anything carrying a vacuum
constant is wrong by a power of it.
A deck that wants its SI arrays computed on correctly declares a
real anchor and sets data_in_si instead.
Source code in src/pypic/schema/_models.py
761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 | |
schema_structured_diff(a, b)
¶
Return a structured {added, removed, changed} diff.
Semantics
added: sorted list of paths present in b but not a.removed: sorted list of paths present in a but not b.changed: dict mapping path →{"before": ..., "after": ...}for leaf-value mismatches or list-length differences. Lists of equal length recurse element-wise (each index gets its own path); lists of differing lengths record the entire lists at the parent path without per-element add/remove decomposition.
Paths use RFC 6901 JSON Pointer syntax (/$defs/Run,
/properties/time/properties/dt) with ~ → ~0 and
/ → ~1 escapes for object keys.
Examples:
>>> schema_structured_diff({"a": 1}, {"a": 1})
{'added': [], 'removed': [], 'changed': {}}
>>> schema_structured_diff({"a": 1, "b": 2}, {"a": 1, "c": 3})
{'added': ['/c'], 'removed': ['/b'], 'changed': {}}
Source code in src/pypic/schema/_diff.py
70 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 | |
schema_text_diff(a, b, *, fromfile='a', tofile='b', n_context=3)
¶
Return a unified text diff of two JSON Schema documents.
Returns the empty string when the documents are byte-equivalent after pretty-printing with sorted keys.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
a
|
Mapping[str, Any]
|
JSON Schema documents (or any JSON-serializable mappings) to
compare. Order is significant: lines prefixed |
required |
b
|
Mapping[str, Any]
|
JSON Schema documents (or any JSON-serializable mappings) to
compare. Order is significant: lines prefixed |
required |
fromfile
|
str
|
Labels for the unified-diff header lines. |
'a'
|
tofile
|
str
|
Labels for the unified-diff header lines. |
'a'
|
n_context
|
int
|
Number of context lines around each hunk ( |
3
|
Source code in src/pypic/schema/_diff.py
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 | |
build_schema(*, include_x_extensions=False, inline_single_use_defs=False, schema_version=SCHEMA_VERSION)
¶
Return the post-processed JSON Schema 2020-12 document.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
include_x_extensions
|
bool
|
When True, annotate non-strict object schemas with
|
False
|
inline_single_use_defs
|
bool
|
When True, |
False
|
schema_version
|
str
|
Override the version stamped in |
SCHEMA_VERSION
|
Source code in src/pypic/schema/_export.py
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 | |
dump_schema(schema, *, pretty=True)
¶
Serialize schema as JSON with stable key ordering.
Both pretty and compact output end with a trailing newline
so the file plays nicely with POSIX text-file conventions and
git diff, and so callers don't have to special-case the sink.
Source code in src/pypic/schema/_export.py
81 82 83 84 85 86 87 88 89 90 | |
get_schema_path(version=SCHEMA_VERSION)
¶
Locate the bundled JSON Schema file inside the installed package.
Returns the path to simulation.schema.v{version}.json shipped in
the pypic wheel. Works for normal pip install; zipped installs
would require importlib.resources.as_file — pypic isn't packaged
that way in practice (requires-python >=3.13 wheels).
Source code in src/pypic/schema/_export.py
93 94 95 96 97 98 99 100 101 102 103 104 | |
validate_simulation_toml(source)
¶
Validate a pypic v2.0 simulation.toml document.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
source
|
str | bytes | PathLike[str] | dict[str, Any]
|
Either a filesystem path to a .toml file, a str/bytes blob of
TOML text, or a pre-parsed dict (the output of |
required |
Returns:
| Type | Description |
|---|---|
SimulationSchema
|
The validated, fully-typed root model. All cross-section invariants have already been checked. |
Raises:
| Type | Description |
|---|---|
ValidationError
|
When any field fails validation. The error object carries
precise dotted paths (e.g. |
FileNotFoundError
|
When |
TOMLDecodeError
|
When |
Examples:
>>> doc = '''
... [schema]
... version = "2.0"
... [model]
... name = "demo"
... type = "PIC"
... [run]
... name = "r0"
... [time]
... scheme = "fixed"
... dt = 0.1
... t_start = 0.0
... t_end = 1.0
... n_steps = 10
... [grid]
... dimensions = [4, 4, 4]
... spacing = [1.0, 1.0, 1.0]
... lower = [0.0, 0.0, 0.0]
... upper = [4.0, 4.0, 4.0]
... [units]
... anchor = "si"
... [coordinates]
... geometry = "cartesian"
... frame = "sim"
... [[species]]
... name = "electrons"
... charge = -1.0
... mass = 1.0
... '''
>>> s = validate_simulation_toml(doc)
>>> s.model.name
'demo'
Source code in src/pypic/schema/_loader.py
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 | |