simet.parser.restraint¶
simet.parser.restraint ¶
RestraintParser ¶
Factory wrapper that builds restraint objects from config dicts.
Converts a user/config value (e.g., from YAML/JSON) into a
:class:RestraintType and delegates construction to
:meth:RestraintType.get_restraint.
parse_restraint
staticmethod
¶
parse_restraint(restraint_data)
Parse config and return a concrete restraint instance.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
restraint_data
|
dict
|
Mapping that must include the key |
required |
Returns:
| Name | Type | Description |
|---|---|---|
Restraint |
Restraint
|
An instance of the requested restraint class. |
Raises:
| Type | Description |
|---|---|
KeyError
|
If |
ValueError
|
If the |
Source code in simet/parser/restraint.py
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 | |
RestraintType ¶
Bases: StrEnum
Enum of supported restraint identifiers (string-valued).
get_restraint
staticmethod
¶
get_restraint(restraint_type, restraint_data)
Construct a restraint instance for the given enum value.
Expects restraint_data to provide upper_bound and/or lower_bound
as appropriate for the metric. For Precision/Recall, list-like bounds
are coerced to tuples.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
restraint_type
|
RestraintType
|
Enum indicating which restraint to build. |
required |
restraint_data
|
dict
|
Source config (typically parsed from YAML/JSON). |
required |
Returns:
| Name | Type | Description |
|---|---|---|
Restraint |
Restraint
|
A concrete restraint instance:
- |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the |
Notes
upper_bound/lower_boundmay be absent orNone. Accessing them directly (e.g.,restraint_data["upper_bound"]) will raiseKeyError; adapt if you plan to make them optional.- Ensure the order/length of Precision/Recall bounds match that restraint’s output semantics.
Source code in simet/parser/restraint.py
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 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 | |