Benchmark¶
benchmark
¶
Benchmark runner and result serialization for Q2MM.
Run a single (backend, optimizer, molecule) combination and produce a
:class:BenchmarkResult that can be saved to / loaded from JSON.
BenchmarkResult
dataclass
¶
BenchmarkResult(metadata: dict = dict(), qm_reference: dict = dict(), default_ff: dict | None = None, seminario: dict | None = None, optimized: dict | None = None, pes_distortion: dict | None = None)
Serializable result from a single benchmark run.
Attributes:
| Name | Type | Description |
|---|---|---|
metadata |
dict
|
Backend, optimizer, molecule, timestamp, source, and level_of_theory metadata. |
qm_reference |
dict
|
QM reference data including frequencies_cm1 and level_of_theory. |
default_ff |
dict | None
|
Default force field results including frequencies_cm1, rmsd, and mae (if evaluated). |
seminario |
dict | None
|
Seminario estimation results including frequencies_cm1, rmsd, mae, and elapsed_s. |
optimized |
dict | None
|
Optimization results including frequencies_cm1, rmsd, mae, elapsed_s, n_eval, converged, initial_score, final_score, message, param_names, param_initial, and param_final. |
pes_distortion |
dict | None
|
PES distortion results including modes (list), median_error_pct, max_error_pct, and elapsed_s. |
to_json
¶
Save result to a JSON file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str | Path
|
Destination file path. Parent directories are created if they do not exist. |
required |
Source code in q2mm/diagnostics/benchmark.py
from_json
classmethod
¶
from_json(path: str | Path) -> BenchmarkResult
Load a result from a JSON file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str | Path
|
Path to the JSON file. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
BenchmarkResult |
BenchmarkResult
|
Deserialized benchmark result. |
Source code in q2mm/diagnostics/benchmark.py
from_upstream
classmethod
¶
from_upstream(frequencies_cm1: list[float], *, molecule: str = 'unknown', label: str = 'upstream', level_of_theory: str = 'unknown') -> BenchmarkResult
Create a result from externally-computed frequencies.
Use this to import results from the upstream/legacy q2mm code or any other source for comparison.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
frequencies_cm1
|
list[float]
|
Vibrational frequencies in cm⁻¹. |
required |
molecule
|
str
|
Human-readable molecule name. |
'unknown'
|
label
|
str
|
Source label (e.g., |
'upstream'
|
level_of_theory
|
str
|
QM level of theory string. |
'unknown'
|
Returns:
| Name | Type | Description |
|---|---|---|
BenchmarkResult |
BenchmarkResult
|
Result populated with the given frequencies and metadata suitable for leaderboard comparison. |
Source code in q2mm/diagnostics/benchmark.py
frequency_rmsd
¶
Compute RMSD between two frequency arrays (truncates to shorter).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
a
|
array - like
|
First array of frequencies. |
required |
b
|
array - like
|
Second array of frequencies. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
float |
float
|
Root-mean-square deviation between the two arrays. |
Source code in q2mm/diagnostics/benchmark.py
frequency_mae
¶
Compute mean absolute error between two frequency arrays.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
a
|
array - like
|
First array of frequencies. |
required |
b
|
array - like
|
Second array of frequencies. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
float |
float
|
Mean absolute error between the two arrays. |
Source code in q2mm/diagnostics/benchmark.py
real_frequencies
¶
Extract and sort real (non-imaginary, non-translational) frequencies.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
freqs
|
array - like
|
Input frequencies. |
required |
threshold
|
float
|
Minimum frequency in cm⁻¹ to include. Modes below this are treated as translational/rotational. |
50.0
|
Returns:
| Type | Description |
|---|---|
ndarray
|
np.ndarray: Sorted array of frequencies above the threshold. |
Source code in q2mm/diagnostics/benchmark.py
run_benchmark
¶
run_benchmark(engine, molecule, qm_freqs: ndarray, qm_hessian: ndarray | None = None, normal_modes: dict | None = None, *, optimizer_method: str = 'L-BFGS-B', optimizer_kwargs: dict[str, Any] | None = None, maxiter: int = 10000, backend_name: str = 'unknown', molecule_name: str = 'unknown', level_of_theory: str = 'unknown') -> BenchmarkResult
Run a complete benchmark for one (backend, optimizer) combination.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
engine
|
MMEngine
|
The MM backend engine to use. |
required |
molecule
|
Q2MMMolecule
|
The molecule (at QM equilibrium geometry). |
required |
qm_freqs
|
ndarray
|
QM reference frequencies (all real modes, cm⁻¹). |
required |
qm_hessian
|
ndarray | None
|
QM Hessian matrix for Seminario
estimation. If |
None
|
normal_modes
|
dict | None
|
Pre-computed normal modes from
|
None
|
optimizer_method
|
str
|
Scipy optimizer method (e.g.,
|
'L-BFGS-B'
|
optimizer_kwargs
|
dict[str, Any] | None
|
Extra keyword arguments
for |
None
|
maxiter
|
int
|
Maximum optimizer iterations. |
10000
|
backend_name
|
str
|
Human-readable backend name for result metadata. |
'unknown'
|
molecule_name
|
str
|
Human-readable molecule name. |
'unknown'
|
level_of_theory
|
str
|
QM level of theory string. |
'unknown'
|
Returns:
| Name | Type | Description |
|---|---|---|
BenchmarkResult |
BenchmarkResult
|
Complete result with all metrics. |
Source code in q2mm/diagnostics/benchmark.py
206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 | |