Benchmark configuration for registration
| 113 | |
| 114 | |
| 115 | class BenchmarkConfig(BaseModel): |
| 116 | """Benchmark configuration for registration""" |
| 117 | name: str = Field(description="The name of the benchmark") |
| 118 | description: str = Field(description="The description of the benchmark") |
| 119 | version: str = Field(default="1.0.0", description="Version of the benchmark") |
| 120 | |
| 121 | cls: Optional[Type[Benchmark]] = Field(default=None, description="The class of the benchmark") |
| 122 | instance: Optional[Any] = Field(default=None, description="The instance of the benchmark") |
| 123 | config: Optional[Dict[str, Any]] = Field(default_factory=dict, description="The initialization configuration") |
| 124 | metadata: Optional[Dict[str, Any]] = Field(default_factory=dict, description="The metadata") |
| 125 | code: Optional[str] = Field(default=None, description="Source code") |
| 126 | |
| 127 | def model_dump(self, **kwargs) -> Dict[str, Any]: |
| 128 | """Dump the model to a dictionary.""" |
| 129 | return { |
| 130 | "name": self.name, |
| 131 | "description": self.description, |
| 132 | "version": self.version, |
| 133 | "cls": dynamic_manager.get_class_string(self.cls) if self.cls else None, |
| 134 | "config": self.config, |
| 135 | "instance": None, # Don't serialize instance |
| 136 | "metadata": self.metadata, |
| 137 | "code": self.code, |
| 138 | } |
| 139 | |
| 140 | @classmethod |
| 141 | def model_validate(cls, data: Dict[str, Any]) -> 'BenchmarkConfig': |
| 142 | """Validate the model from a dictionary.""" |
| 143 | name = data.get("name") |
| 144 | description = data.get("description") |
| 145 | version = data.get("version", "1.0.0") |
| 146 | |
| 147 | cls_ = None |
| 148 | code = data.get("code") |
| 149 | if code: |
| 150 | class_name = dynamic_manager.extract_class_name_from_code(code) |
| 151 | if class_name: |
| 152 | try: |
| 153 | cls_ = dynamic_manager.load_class( |
| 154 | code, |
| 155 | class_name=class_name, |
| 156 | base_class=Benchmark, |
| 157 | context="benchmark" |
| 158 | ) |
| 159 | except Exception: |
| 160 | cls_ = None |
| 161 | |
| 162 | config = data.get("config", {}) |
| 163 | instance = data.get("instance", None) |
| 164 | metadata = data.get("metadata", {}) |
| 165 | |
| 166 | return cls( |
| 167 | name=name, |
| 168 | description=description, |
| 169 | version=version, |
| 170 | cls=cls_, |
| 171 | config=config, |
| 172 | instance=instance, |
no outgoing calls
no test coverage detected