Concrete workload configuration for benchmarking. Defines a specific instance of a computational workload with concrete values for all variable axes and specifications for all input data. This represents an executable configuration that can be benchmarked.
| 100 | |
| 101 | |
| 102 | class Workload(BaseModelWithDocstrings): |
| 103 | """Concrete workload configuration for benchmarking. |
| 104 | |
| 105 | Defines a specific instance of a computational workload with concrete |
| 106 | values for all variable axes and specifications for all input data. |
| 107 | This represents an executable configuration that can be benchmarked. |
| 108 | """ |
| 109 | |
| 110 | axes: dict[str, NonNegativeInt] |
| 111 | """Dictionary mapping axis names to their concrete integer values. All values must be |
| 112 | positive.""" |
| 113 | inputs: dict[str, InputSpec] |
| 114 | """Dictionary mapping input names to their data specifications.""" |
| 115 | uuid: NonEmptyString |
| 116 | """Unique identifier for this specific workload configuration.""" |
| 117 | tolerance: ToleranceSpec = Field(default=ToleranceSpec()) |
| 118 | """Tolerance specification for the workload.""" |
| 119 | |
| 120 | @model_validator(mode="after") |
| 121 | def _validate_inputs(self) -> Workload: |
| 122 | custom_inputs = [ |
| 123 | name |
| 124 | for name, input in self.inputs.items() |
| 125 | if isinstance(input, CustomInput) |
| 126 | ] |
| 127 | non_custom_inputs = [ |
| 128 | name |
| 129 | for name, input in self.inputs.items() |
| 130 | if not isinstance(input, CustomInput) |
| 131 | ] |
| 132 | if len(custom_inputs) > 0 and len(non_custom_inputs) > 0: |
| 133 | raise ValueError( |
| 134 | f"A workload cannot have both custom and non-custom inputs. Custom: {custom_inputs}. Non-custom: {non_custom_inputs}" |
| 135 | ) |
| 136 | return self |
| 137 | |
| 138 | def get_scalar_inputs(self) -> dict[str, int]: |
| 139 | return { |
| 140 | name: input.value |
| 141 | for name, input in self.inputs.items() |
| 142 | if isinstance(input, ScalarInput) |
| 143 | } |