feat: better state_handler
This commit is contained in:
@@ -1,19 +1,23 @@
|
||||
from diceplayer.config.dice_config import DiceConfig
|
||||
from diceplayer.config.gaussian_config import GaussianConfig
|
||||
|
||||
from pydantic import BaseModel, Field, model_validator
|
||||
from typing_extensions import Self
|
||||
from pydantic import BaseModel, Field, model_validator, ConfigDict
|
||||
from typing_extensions import Self, Any
|
||||
|
||||
from pathlib import Path
|
||||
|
||||
|
||||
MIN_STEP = 20000
|
||||
STEP_INCREMENT = 1000
|
||||
|
||||
|
||||
class PlayerConfig(BaseModel):
|
||||
"""
|
||||
Data Transfer Object for the player configuration.
|
||||
"""
|
||||
model_config = ConfigDict(
|
||||
frozen=True,
|
||||
)
|
||||
|
||||
opt: bool = Field(..., description="Whether to perform geometry optimization")
|
||||
maxcyc: int = Field(
|
||||
@@ -42,7 +46,9 @@ class PlayerConfig(BaseModel):
|
||||
"simfiles", description="Directory name for the simulation files"
|
||||
)
|
||||
|
||||
@model_validator(mode="after")
|
||||
def validate_altsteps(self) -> Self:
|
||||
self.altsteps = round(max(MIN_STEP, self.altsteps) / 1000) * 1000
|
||||
return self
|
||||
@model_validator(mode="before")
|
||||
@staticmethod
|
||||
def validate_altsteps(fields) -> dict[str, Any]:
|
||||
altsteps = fields.pop("altsteps", MIN_STEP)
|
||||
fields["altsteps"] = round(max(MIN_STEP, altsteps) / STEP_INCREMENT) * STEP_INCREMENT
|
||||
return fields
|
||||
|
||||
Reference in New Issue
Block a user