Base Optimizer¶
Wrapper around Xopt for automated parameter optimization.
This class provides a simplified interface to the Xopt optimization library, designed specifically for integration with the GEECS scanner system. It handles the generation of candidate parameter sets and evaluation of objective functions while maintaining separation from control system logic.
The optimizer supports various optimization algorithms and evaluation modes, with built-in integration for experimental data acquisition and logging.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
vocs
|
VOCS
|
Variables, Objectives, and Constraints Specification defining the optimization problem structure. |
required |
evaluate_function
|
callable
|
Function that takes a dictionary of variable values and returns a dictionary of objective and constraint results. |
required |
generator_name
|
str
|
Name of the Xopt generator algorithm to use (e.g., 'random', 'cnsga', 'upper_confidence_bound'). |
required |
xopt_config_overrides
|
dict
|
Dictionary to override default Xopt configuration parameters. |
None
|
evaluator
|
BaseEvaluator
|
Reference to the evaluator object providing the evaluate_function. |
None
|
device_requirements
|
dict
|
Dictionary defining required devices and variables for optimization. |
None
|
scan_data_manager
|
ScanDataManager
|
Manager instance for accessing saved non-scalar data. |
None
|
data_logger
|
DataLogger
|
Logger instance for accessing shot data and bin information. |
None
|
seed_dump_files
|
list of Path
|
Paths to prior Xopt dump YAML files whose evaluated data will be loaded into the optimizer before the scan begins. VOCS must be compatible (same variable and objective names); differing bounds produce warnings only. |
None
|
move_to_best_on_finish
|
bool
|
If True, |
False
|
Attributes:
| Name | Type | Description |
|---|---|---|
vocs |
VOCS
|
The optimization problem specification. |
evaluate_function |
callable
|
The objective function evaluator. |
generator_name |
str
|
Name of the optimization algorithm being used. |
evaluator |
BaseEvaluator or None
|
Reference to the evaluator instance. |
device_requirements |
dict
|
Required devices and variables configuration. |
xopt |
Xopt or None
|
The underlying Xopt optimizer instance. |
scan_data_manager |
ScanDataManager or None
|
Data manager for accessing scan data. |
data_logger |
DataLogger or None
|
Logger for accessing experimental data. |
Methods:
| Name | Description |
|---|---|
initialize |
Run initial random evaluations to seed the optimization. |
generate |
Generate candidate parameter sets for evaluation. |
evaluate |
Evaluate candidate points and store results. |
get_results |
Return the complete optimization results. |
get_best |
Return the best observed parameter set. |
seed_from_dumps |
Load historical data from dump files into the optimizer. |
from_config_file |
Create optimizer instance from YAML configuration file. |
Source code in geecs_scanner/optimization/base_optimizer.py
141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 | |
Attributes¶
xopt_config_overrides
instance-attribute
¶
xopt_config_overrides: dict[str, Any] = dict(xopt_config_overrides or {})
n_seeded
property
¶
n_seeded: int
Number of evaluations loaded from dump files before the scan started.
Functions¶
best_observed_setpoint ¶
best_observed_setpoint() -> Optional[Dict[str, float]]
Return the VOCS-variable values of the best-observed row in X.data.
Returns:
| Type | Description |
|---|---|
dict or None
|
|
Source code in geecs_scanner/optimization/base_optimizer.py
176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 | |
seed_from_dumps ¶
seed_from_dumps(dump_paths: List[Path]) -> int
Load historical data from prior Xopt dump files.
Each file's VOCS is checked for compatibility with this optimizer's
VOCS before any data is loaded. Rows where xopt_error is True or
any objective column is NaN are filtered out.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dump_paths
|
List[Path]
|
Paths to |
required |
Returns:
| Type | Description |
|---|---|
int
|
Total number of rows added to the optimizer (after filtering). |
Source code in geecs_scanner/optimization/base_optimizer.py
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 | |
initialize ¶
initialize(num_initial: int = 1)
Run initial random evaluations to seed the optimization.
Performs random sampling of the parameter space to provide initial data points for the optimization algorithm. This is particularly important for algorithms that require historical data to function effectively (e.g., Bayesian optimization).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
num_initial
|
int
|
Number of random evaluations to perform for initialization. |
1
|
Source code in geecs_scanner/optimization/base_optimizer.py
314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 | |
generate ¶
generate(n: int = 1) -> List[dict]
Generate candidate parameter sets for evaluation.
Uses the configured optimization algorithm to propose new parameter combinations that are likely to improve the objective function based on previously evaluated points.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
n
|
int
|
Number of candidate parameter sets to generate. |
1
|
Returns:
| Type | Description |
|---|---|
list of dict
|
List of parameter dictionaries, each representing a set of control variable values to be evaluated. |
Source code in geecs_scanner/optimization/base_optimizer.py
330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 | |
evaluate ¶
evaluate(inputs: List[dict])
Evaluate candidate parameter sets and store results.
Evaluates the provided parameter sets using the configured evaluation function and stores the results in the optimization history for use by future generation steps.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
inputs
|
list of dict
|
List of parameter dictionaries to evaluate, typically generated
by the |
required |
Source code in geecs_scanner/optimization/base_optimizer.py
351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 | |
get_results ¶
get_results()
Return complete optimization results.
Retrieves the full DataFrame containing all evaluated parameter sets and their corresponding objective and constraint values.
Returns:
| Type | Description |
|---|---|
DataFrame
|
Complete results DataFrame with columns for all variables, objectives, and constraints that have been evaluated. |
Source code in geecs_scanner/optimization/base_optimizer.py
396 397 398 399 400 401 402 403 404 405 406 407 408 409 | |
get_best ¶
get_best()
Return the best observed parameter set.
Identifies and returns the parameter combination that achieved the best objective function value according to the optimization criteria (minimize or maximize).
Returns:
| Type | Description |
|---|---|
DataFrame
|
Single-row DataFrame containing the best parameter set and its corresponding objective and constraint values. |
Source code in geecs_scanner/optimization/base_optimizer.py
411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 | |
from_config_file
classmethod
¶
from_config_file(config_path: str, scan_data_manager: Optional['ScanDataManager'] = None, data_logger: Optional['DataLogger'] = None) -> 'BaseOptimizer'
Create optimizer instance from YAML configuration file.
Loads optimizer configuration, evaluator settings, and VOCS specification from a YAML file and creates a fully configured BaseOptimizer instance. This method provides a convenient way to set up complex optimization problems without manual instantiation.
The evaluator class is dynamically imported based on the module and class name specified in the configuration file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config_path
|
str
|
Path to the YAML configuration file containing optimizer settings. |
required |
scan_data_manager
|
ScanDataManager
|
Instance of ScanDataManager for accessing data during acquisition. |
None
|
data_logger
|
DataLogger
|
Instance of DataLogger for accessing shot data and bin information. |
None
|
Returns:
| Type | Description |
|---|---|
BaseOptimizer
|
Fully configured optimizer instance ready for use. |
Source code in geecs_scanner/optimization/base_optimizer.py
428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 | |