Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 24 additions & 7 deletions lib/python/picongpu/pypicongpu/grid.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import enum
from typing import Annotated

from pydantic import BaseModel, Field, PlainSerializer, model_validator
from pydantic import AfterValidator, BaseModel, Field, PlainSerializer, model_validator
from typing_extensions import Self

from .rendering import RenderedObject
Expand Down Expand Up @@ -59,6 +59,21 @@ def serialise_grid_dist(value):
)


def all_gt(iterable, m):
if all(correct := [x > m for x in iterable]):
return iterable
else:
message = f"{iterable=} contains values <= {m=} while all should be greater than m. Valid are the following: {correct=}."
raise ValueError(message)


def grid_dist_validate(grid_dist):
if grid_dist is None:
return None
if all_gt(sum(grid_dist, []), 0):
return grid_dist


class Grid3D(BaseModel, RenderedObject):
"""
PIConGPU 3 dimensional (cartesian) grid
Expand All @@ -68,10 +83,10 @@ class Grid3D(BaseModel, RenderedObject):
The bounding box is implicitly given as TODO.
"""

cell_size: Vec3_float = Field(alias="cell_size_si")
cell_size: Annotated[Vec3_float, AfterValidator(lambda x: all_gt(x, 0))] = Field(alias="cell_size_si")
"""Width of individual cell in each direction"""

cell_cnt: Vec3_int
cell_cnt: Annotated[Vec3_int, AfterValidator(lambda x: all_gt(x, 0))]
"""total number of cells in each direction"""

boundary_condition: Annotated[
Expand All @@ -80,10 +95,14 @@ class Grid3D(BaseModel, RenderedObject):
]
"""behavior towards particles crossing each boundary"""

gpu_cnt: Vec3_int = Field((1, 1, 1), alias="n_gpus")
gpu_cnt: Annotated[Vec3_int, AfterValidator(lambda x: all_gt(x, 0))] = Field((1, 1, 1), alias="n_gpus")
"""number of GPUs in x y and z direction as 3-integer tuple"""

grid_dist: Annotated[tuple[list[int], list[int], list[int]] | None, PlainSerializer(serialise_grid_dist)] = None
grid_dist: Annotated[
tuple[list[int], list[int], list[int]] | None,
PlainSerializer(serialise_grid_dist),
AfterValidator(grid_dist_validate),
] = None
"""distribution of grid cells to GPUs for each axis"""

super_cell_size: Vec3_int
Expand All @@ -92,8 +111,6 @@ class Grid3D(BaseModel, RenderedObject):
@model_validator(mode="after")
def check(self) -> Self:
"""serialized representation provided for RenderedObject"""
assert all(x > 0 for x in self.cell_cnt), "cell_cnt must be greater than 0"
assert all(x > 0 for x in self.gpu_cnt), "all n_gpus entries must be greater than 0"
if self.grid_dist is not None:
assert sum(self.grid_dist[0]) == self.cell_cnt[0], "sum of grid_dists in x must be equal to number_of_cells"
assert sum(self.grid_dist[1]) == self.cell_cnt[1], "sum of grid_dists in y must be equal to number_of_cells"
Expand Down
7 changes: 6 additions & 1 deletion lib/python/picongpu/pypicongpu/rendering/renderedobject.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,12 @@ def _get_schema_from_class(class_type: type) -> typing.Any:
try:
schema = RenderedObject._registry.contents(uri)
except referencing.exceptions.NoSuchResource:
raise referencing.exceptions.NoSuchResource("schema not found for FQN {}: URI {}".format(fqn, uri))
try:
schema = class_type.model_json_schema(mode="serialization", by_alias=False) | {"$id": uri}
except Exception as second_error:
raise referencing.exceptions.NoSuchResource(
"schema not found for FQN {}: URI {}".format(fqn, uri)
) from second_error

# validate schema
validator = jsonschema.Draft202012Validator(schema=schema)
Expand Down
173 changes: 0 additions & 173 deletions share/picongpu/pypicongpu/schema/grid.Grid3D.json

This file was deleted.

4 changes: 1 addition & 3 deletions share/picongpu/pypicongpu/schema/output/auto.Auto.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@
"png_axis"
],
"properties": {
"period": {
"$ref": "https://registry.hzdr.de/crp/picongpu/schema/picongpu.pypicongpu.output.timestepspec.TimeStepSpec"
},
"period": {},
"png_axis": {
"description": "axis pairs (i.e. planes) for which to generate png output",
"type": "array",
Expand Down
8 changes: 1 addition & 7 deletions share/picongpu/pypicongpu/schema/output/binning.Binning.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,7 @@
},
"description": "Species to bin"
},
"period": {
"type": [
"object"
],
"$ref": "https://registry.hzdr.de/crp/picongpu/schema/picongpu.pypicongpu.output.timestepspec.TimeStepSpec",
"description": "Create binning output on specified steps"
},
"period": {},
"openPMD": {
"type": [
"string",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,7 @@
}
],
"properties": {
"period": {
"type": [
"object",
"null"
],
"$ref": "https://registry.hzdr.de/crp/picongpu/schema/picongpu.pypicongpu.output.timestepspec.TimeStepSpec",
"description": "Create checkpoints in specified steps"
},
"period": {},
"timePeriod": {
"type": [
"integer",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,7 @@
"species": {
"$ref": "https://registry.hzdr.de/crp/picongpu/schema/picongpu.pypicongpu.species.species.Species"
},
"period": {
"$ref": "https://registry.hzdr.de/crp/picongpu/schema/picongpu.pypicongpu.output.timestepspec.TimeStepSpec"
},
"period": {},
"bin_count": {
"type": "integer",
"minimum": 1,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@
"species": {
"$ref": "https://registry.hzdr.de/crp/picongpu/schema/picongpu.pypicongpu.species.species.Species"
},
"period": {
"$ref": "https://registry.hzdr.de/crp/picongpu/schema/picongpu.pypicongpu.output.timestepspec.TimeStepSpec"
}
"period": {}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,7 @@
"species": {
"$ref": "https://registry.hzdr.de/crp/picongpu/schema/picongpu.pypicongpu.species.species.Species"
},
"period": {
"$ref": "https://registry.hzdr.de/crp/picongpu/schema/picongpu.pypicongpu.output.timestepspec.TimeStepSpec"
},
"period": {},
"spatial_coordinate": {
"type": "string",
"enum": [
Expand Down
4 changes: 1 addition & 3 deletions share/picongpu/pypicongpu/schema/output/png.Png.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,7 @@
"preChannel3"
],
"properties": {
"period": {
"$ref": "https://registry.hzdr.de/crp/picongpu/schema/picongpu.pypicongpu.output.timestepspec.TimeStepSpec"
},
"period": {},
"axis": {
"type": "string",
"description": "2D plane for PNG output (e.g., 'yx')."
Expand Down
26 changes: 0 additions & 26 deletions share/picongpu/pypicongpu/schema/output/timestepspec.json

This file was deleted.

4 changes: 1 addition & 3 deletions share/picongpu/pypicongpu/schema/simulation.Simulation.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,7 @@
}
]
},
"grid": {
"$ref": "https://registry.hzdr.de/crp/picongpu/schema/picongpu.pypicongpu.grid.Grid3D"
},
"grid": {},
"laser": {
"anyOf": [
{
Expand Down
Loading