Parameters¶
Parameter system utilities.
Params
dataclass
¶
Params(*, preset: str | None = None)
Bases: CLI
Base class for script-style single models with parameters.
Declare parameters as class attributes in the same form as dataclass fields with any of:
- Standard type annotations (
int,float,bool, etc.) - Default value (unannotated attributes infer types from default values)
- Field factory functions provided for creating fields with constraints
dataclasses.fieldsame as any other dataclass
When run directly as a script, CLI arguments are parsed automatically at
class definition time, and resolved parameter values are accessible as
class attributes. A handler is registered to retrieve the rendered model
using show when the script completes, if not
manually called.
A presets class attribute may declare a selection of
Preset objects.
Note
Subclasses are created as dataclasses automatically.
Do not decorate subclasses with @dataclass.
Example
class P(Params):
width = Float(40.0, min=10, max=100)
thickness = Float(3.0, min=1, max=10)
presets = (Preset("small", width=15.0, thickness=2.0),)
result = Box(P.width, P.width, P.thickness)
with_preset
classmethod
¶
with_preset(preset: str, **overrides: Any) -> Self
Create a new instance with values from a preset applied.
Parameters:
-
preset(str) –Name of the preset to apply.
-
**overrides(Any, default:{}) –Additional field values to apply after the preset.
Source code in bdbox/parameters/parameters.py
107 108 109 110 111 112 113 114 115 | |