Abstract intensifier
smac.intensifier.abstract_intensifier
#
AbstractIntensifier
#
AbstractIntensifier(
scenario: Scenario,
n_seeds: int | None = None,
max_config_calls: int | None = None,
max_incumbents: int = 10,
seed: int | None = None,
)
Abstract implementation of an intensifier supporting multi-fidelity, multi-objective, and multi-threading. The abstract intensifier keeps track of the incumbent, which is updated everytime the runhistory changes.
Parameters#
n_seeds : int | None, defaults to None How many seeds to use for each instance. It is used in the abstract intensifier to determine validation trials. max_config_calls : int, defaults to None Maximum number of configuration evaluations. Basically, how many instance-seed keys should be max evaluated for a configuration. It is used in the abstract intensifier to determine validation trials. max_incumbents : int, defaults to 10 How many incumbents to keep track of in the case of multi-objective. seed : int, defaults to None Internal seed used for random events like shuffle seeds.
Source code in smac/intensifier/abstract_intensifier.py
config_generator
property
#
config_generator: Iterator[Configuration]
Based on the configuration selector, an iterator is returned that generates configurations.
config_selector
property
writable
#
config_selector: ConfigSelector
The configuration selector for the intensifier.
trajectory
property
#
trajectory: list[TrajectoryItem]
Returns the trajectory (changes of incumbents) of the optimization run.
uses_budgets
abstractmethod
property
#
uses_budgets: bool
If the intensifier needs to make use of budgets.
uses_instances
abstractmethod
property
#
uses_instances: bool
If the intensifier needs to make use of instances.
uses_seeds
abstractmethod
property
#
uses_seeds: bool
If the intensifier needs to make use of seeds.
__iter__
abstractmethod
#
Main loop of the intensifier. This method always returns a TrialInfo object, although the intensifier algorithm may need to wait for the result of the trial. Please refer to a specific intensifier to get more information.
Source code in smac/intensifier/abstract_intensifier.py
__post_init__
#
Fills self._tf_seeds
and self._tf_instances
. Moreover, the incumbents are updated.
Source code in smac/intensifier/abstract_intensifier.py
get_callback
#
get_callback() -> Callback
The intensifier makes use of a callback to efficiently update the incumbent based on the runhistory (every time new information is available). Moreover, incorporating the callback here allows developers more options in the future.
Source code in smac/intensifier/abstract_intensifier.py
get_incumbent
#
Returns the current incumbent in a single-objective setting.
Source code in smac/intensifier/abstract_intensifier.py
get_incumbent_instance_seed_budget_key_differences
#
get_incumbent_instance_seed_budget_key_differences(
compare: bool = False,
) -> list[InstanceSeedBudgetKey]
There are situations in which incumbents are evaluated on more trials than others. This method returns the instances that are not part of the lowest intersection of instances for all incumbents.
Source code in smac/intensifier/abstract_intensifier.py
get_incumbent_instance_seed_budget_keys
#
get_incumbent_instance_seed_budget_keys(
compare: bool = False,
) -> list[InstanceSeedBudgetKey]
Find the lowest intersection of instance-seed-budget keys for all incumbents.
Source code in smac/intensifier/abstract_intensifier.py
get_incumbents
#
Returns the incumbents (points on the pareto front) of the runhistory as copy. In case of a single-objective optimization, only one incumbent (if is) is returned.
Returns#
configs : list[Configuration]
The configs of the Pareto front.
sort_by : str, defaults to None
Sort the trials by cost
(lowest cost first) or num_trials
(config with lowest number of trials
first).
Source code in smac/intensifier/abstract_intensifier.py
get_instance_seed_budget_keys
#
get_instance_seed_budget_keys(
config: Configuration, compare: bool = False
) -> list[InstanceSeedBudgetKey]
Returns the instance-seed-budget keys for a given configuration. This method is used for updating the incumbents and might differ for different intensifiers. For example, if incumbents should only be compared on the highest observed budgets.
Source code in smac/intensifier/abstract_intensifier.py
get_instance_seed_keys_of_interest
#
get_instance_seed_keys_of_interest(
*, validate: bool = False, seed: int | None = None
) -> list[InstanceSeedKey]
Returns a list of instance-seed keys. Considers seeds and instances from the
runhistory (self._tf_seeds
and self._tf_instances
). If no seeds or instances were found, new
seeds and instances are generated based on the global intensifier seed.
Warning#
The passed seed is only used for validation. For training, the global intensifier seed is used.
Parameters#
validate : bool, defaults to False Whether to get validation trials or training trials. The only difference lies in different seeds. seed : int | None, defaults to None The seed used for the validation trials.
Returns#
instance_seed_keys : list[InstanceSeedKey] Instance-seed keys of interest.
Source code in smac/intensifier/abstract_intensifier.py
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 |
|
get_rejected_configs
#
get_rejected_configs() -> list[Configuration]
Returns rejected configurations when racing against the incumbent failed.
Source code in smac/intensifier/abstract_intensifier.py
get_state
#
The current state of the intensifier. Used to restore the state of the intensifier when continuing a run.
get_trials_of_interest
#
get_trials_of_interest(
config: Configuration,
*,
validate: bool = False,
seed: int | None = None
) -> list[TrialInfo]
Returns the trials of interest for a given configuration.
Expands the keys from get_instance_seed_keys_of_interest
with the config.
Source code in smac/intensifier/abstract_intensifier.py
load
#
Loads the latest state of the intensifier including the incumbents and trajectory.
Source code in smac/intensifier/abstract_intensifier.py
reset
#
Reset the internal variables of the intensifier.
Source code in smac/intensifier/abstract_intensifier.py
save
#
Saves the current state of the intensifier. In addition to the state (retrieved by get_state
), this
method also saves the incumbents and trajectory.
Source code in smac/intensifier/abstract_intensifier.py
set_state
#
Sets the state of the intensifier. Used to restore the state of the intensifier when continuing a run.
update_incumbents
#
Updates the incumbents. This method is called everytime a trial is added to the runhistory. Since only the affected config and the current incumbents are used, this method is very efficient. Furthermore, a configuration is only considered incumbent if it has a better performance on all incumbent instances.
Crucially, if there is no incumbent (at the start) then, the first configuration assumes incumbent status. For the next configuration, we need to check if the configuration is better on all instances that have been evaluated for the incumbent. If this is the case, then we can replace the incumbent. Otherwise, a) we need to requeue the config to obtain the missing instance-seed-budget combination or b) mark this configuration as inferior ("rejected") to not consider it again. The comparison behaviour is controlled by self.get_instance_seed_budget_keys() and self.get_incumbent_instance_seed_budget_keys().
Notably, this method is written to support both multi-fidelity and multi-objective optimization. While the get_instance_seed_budget_keys() method and self.get_incumbent_instance_seed_budget_keys() are used for the multi-fidelity behaviour, calculate_pareto_front() is used as a hard coded way to support multi-objective optimization, including the single objective as special case. calculate_pareto_front() is called on the set of all (in case of MO) incumbents amended with the challenger configuration, provided it has a sufficient overlap in seed-instance-budget combinations.
Lastly, if we have a self._max_incumbents and the pareto front provides more than this specified amount, we cut the incumbents using crowding distance.
Source code in smac/intensifier/abstract_intensifier.py
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 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 |
|