Runhistory
smac.runhistory.runhistory
#
RunHistory
#
RunHistory(
multi_objective_algorithm: AbstractMultiObjectiveAlgorithm
| None = None,
overwrite_existing_trials: bool = False,
)
Bases: Mapping[TrialKey, TrialValue]
Container for the target function run information.
Most importantly, the runhistory contains an efficient mapping from each evaluated configuration to the empirical cost observed on either the full instance set or a subset. The cost is the average over all observed costs for one configuration:
- If using budgets for a single instance, only the cost on the highest observed budget is returned.
- If using instances as the budget, the average cost over all evaluated instances is returned.
- Theoretically, the runhistory object can handle instances and budgets at the same time. This is neither used nor tested.
Note#
Guaranteed to be picklable.
Parameters#
multi_objective_algorithm : AbstractMultiObjectiveAlgorithm | None, defaults to None The multi-objective algorithm is required to scalarize the costs in case of multi-objective. overwrite_existing_trials : bool, defaults to false Overwrites a trial (combination of configuration, instance, budget and seed) if it already exists.
Source code in smac/runhistory/runhistory.py
multi_objective_algorithm
property
writable
#
multi_objective_algorithm: AbstractMultiObjectiveAlgorithm | None
The multi-objective algorithm required to scaralize the costs in case of multi-objective.
objective_bounds
property
#
Returns the lower and upper bound of each objective.
__contains__
#
__eq__
#
__getitem__
#
__getitem__(k: TrialKey) -> TrialValue
__iter__
#
add
#
add(
config: Configuration,
cost: int | float | list[int | float],
time: float = 0.0,
cpu_time: float = 0.0,
status: StatusType = SUCCESS,
instance: str | None = None,
seed: int | None = None,
budget: float | None = None,
starttime: float = 0.0,
endtime: float = 0.0,
additional_info: dict[str, Any] = None,
force_update: bool = False,
) -> None
Adds a new trial to the RunHistory.
Parameters#
config : Configuration cost : int | float | list[int | float] Cost of the evaluated trial. Might be a list in case of multi-objective. time : float How much time was needed to evaluate the trial. cpu_time : float How much time was needed on the hardware to evaluate the trial. status : StatusType, defaults to StatusType.SUCCESS The status of the trial. instance : str | None, defaults to none seed : int | None, defaults to none budget : float | None, defaults to none starttime : float, defaults to 0.0 endtime : float, defaults to 0.0 additional_info : dict[str, Any], defaults to {} force_update : bool, defaults to false Overwrites a previous trial if the trial already exists.
Source code in smac/runhistory/runhistory.py
171 172 173 174 175 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 203 204 205 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 |
|
add_running_trial
#
add_running_trial(trial: TrialInfo) -> None
Adds a running trial to the runhistory.
Parameters#
trial : TrialInfo
The TrialInfo
object of the running trial.
Source code in smac/runhistory/runhistory.py
add_trial
#
add_trial(info: TrialInfo, value: TrialValue) -> None
Adds a trial to the runhistory.
Parameters#
trial : TrialInfo
The TrialInfo
object of the running trial.
Source code in smac/runhistory/runhistory.py
average_cost
#
average_cost(
config: Configuration,
instance_seed_budget_keys: list[InstanceSeedBudgetKey]
| None = None,
normalize: bool = False,
) -> float | list[float]
Return the average cost of a configuration. This is the mean of costs of all instance- seed pairs.
Parameters#
config : Configuration Configuration to calculate objective for. instance_seed_budget_keys : list, optional (default=None) List of tuples of instance-seeds-budget keys. If None, the runhistory is queried for all trials of the given configuration. normalize : bool, optional (default=False) Normalizes the costs wrt. objective bounds in the multi-objective setting. Only a float is returned if normalize is True. Warning: The value can change over time because the objective bounds are changing. Also, the objective weights are incorporated.
Returns#
Cost: float | list[float] Average cost. In case of multiple objectives, the mean of each objective is returned.
Source code in smac/runhistory/runhistory.py
empty
#
empty() -> bool
Check whether the RunHistory is empty.
Returns#
emptiness: bool True if trials have been added to the RunHistory.
get_configs
#
Return all configurations in this RunHistory object.
Parameters#
sort_by : str | None, defaults to None
Sort the configs by cost
(lowest cost first) or num_trials
(config with lowest number of trials
first).
Returns#
configurations : list All configurations in the runhistory.
Source code in smac/runhistory/runhistory.py
get_configs_per_budget
#
get_configs_per_budget(
budget_subset: list[float | int | None] | None = None,
) -> list[Configuration]
Return all configs in this runhistory that have been run on one of these budgets.
Parameters#
budget_subset: list[float | int | None] | None, defaults to None
Returns#
configurations : list
List of configurations that have been run on the budgets in budget_subset
.
Source code in smac/runhistory/runhistory.py
get_cost
#
get_cost(config: Configuration) -> float
Returns empirical cost for a configuration. See the class docstring for how the costs are computed. The costs are not re-computed, but are read from cache.
Parameters#
config: Configuration
Returns#
cost: float Computed cost for configuration
Source code in smac/runhistory/runhistory.py
get_instance_seed_budget_keys
#
get_instance_seed_budget_keys(
config: Configuration,
highest_observed_budget_only: bool = True,
) -> list[InstanceSeedBudgetKey]
Uses get_trials
to return a list of instance-seed-budget keys.
Warning#
Does not return running instances.
Parameters#
config : Configuration highest_observed_budget_only : bool, defaults to True Select only the highest observed budget run for this configuration.
Returns#
list[InstanceSeedBudgetKey]
Source code in smac/runhistory/runhistory.py
get_min_cost
#
get_min_cost(config: Configuration) -> float
Returns the lowest empirical cost for a configuration across all trials.
See the class docstring for how the costs are computed. The costs are not re-computed but are read from cache.
Parameters#
config : Configuration
Returns#
min_cost: float Computed cost for configuration
Source code in smac/runhistory/runhistory.py
get_running_configs
#
get_running_configs() -> list[Configuration]
Returns all configurations which have at least one running trial.
Returns#
list[Configuration] List of configurations, all of which have at least one running trial.
Source code in smac/runhistory/runhistory.py
get_running_trials
#
Returns all running trials for the passed configuration.
Parameters#
config : Configuration | None, defaults to None Return only running trials from the passed configuration. If None, all configs are considered.
Returns#
trials : list[TrialInfo] List of trials, all of which are still running.
Source code in smac/runhistory/runhistory.py
get_trials
#
Returns all trials for a configuration.
Warning#
Does not return running trials. Please use get_running_trials
to receive running trials.
Parameters#
config : Configuration highest_observed_budget_only : bool Select only the highest observed budget run for this configuration. Meaning on multiple executions of the same instance-seed pair for a a given configuration, only the highest observed budget is returned.
Returns#
trials : list[InstanceSeedBudgetKey] List of trials for the passed configuration.
Source code in smac/runhistory/runhistory.py
incremental_update_cost
#
Incrementally updates the performance of a configuration by using a moving average.
Parameters#
config: Configuration configuration to update cost based on all trials in runhistory cost: float cost of new run of config
Source code in smac/runhistory/runhistory.py
load
#
Loads the runhistory from disk.
Warning#
Overwrites the current runhistory.
Parameters#
filename : str | Path configspace : ConfigSpace
Source code in smac/runhistory/runhistory.py
min_cost
#
min_cost(
config: Configuration,
instance_seed_budget_keys: list[InstanceSeedBudgetKey]
| None = None,
normalize: bool = False,
) -> float | list[float]
Return the minimum cost of a configuration. This is the minimum cost of all instance-seed pairs.
Warning#
In the case of multi-fidelity, the minimum cost per objectives is returned.
Parameters#
config : Configuration Configuration to calculate objective for. instance_seed_budget_keys : list, optional (default=None) List of tuples of instance-seeds-budget keys. If None, the runhistory is queried for all trials of the given configuration. normalize : bool, optional (default=False) Normalizes the costs wrt objective bounds in the multi-objective setting. Only a float is returned if normalize is True. Warning: The value can change over time because the objective bounds are changing. Also, the objective weights are incorporated.
Returns#
min_cost: float | list[float] Minimum cost of the config. In case of multi-objective, the minimum cost per objective is returned.
Source code in smac/runhistory/runhistory.py
reset
#
Resets this runhistory to its default state.
Source code in smac/runhistory/runhistory.py
save
#
Saves RunHistory to disk.
Parameters#
filename : str | Path, defaults to "runhistory.json"
Source code in smac/runhistory/runhistory.py
sum_cost
#
sum_cost(
config: Configuration,
instance_seed_budget_keys: list[InstanceSeedBudgetKey]
| None = None,
normalize: bool = False,
) -> float | list[float]
Return the sum of costs of a configuration. This is the sum of costs of all instance-seed pairs.
Parameters#
config : Configuration Configuration to calculate objective for. instance_seed_budget_keys : list, optional (default=None) List of tuples of instance-seeds-budget keys. If None, the runhistory is queried for all trials of the given configuration. normalize : bool, optional (default=False) Normalizes the costs wrt objective bounds in the multi-objective setting. Only a float is returned if normalize is True. Warning: The value can change over time because the objective bounds are changing. Also, the objective weights are incorporated.
Returns#
sum_cost: float | list[float] Sum of costs of config. In case of multiple objectives, the costs are summed up for each objective individually.
Source code in smac/runhistory/runhistory.py
update
#
update(runhistory: RunHistory) -> None
Updates the current RunHistory by adding new trials from another RunHistory.
Parameters#
runhistory : RunHistory RunHistory with additional data to be added to self
Source code in smac/runhistory/runhistory.py
update_cost
#
Stores the performance of a configuration across the instances in self._cost_per_config
and also updates self._num_trials_per_config
.
Parameters#
config: Configuration configuration to update cost based on all trials in runhistory
Source code in smac/runhistory/runhistory.py
update_costs
#
Computes the cost of all configurations from scratch and overwrites self._cost_per_config
and self._num_trials_per_config
accordingly.
Parameters#
instances: list[str] | None, defaults to none List of instances; if given, cost is only computed wrt to this instance set.
Source code in smac/runhistory/runhistory.py
update_from_json
#
update_from_json(
filename: str, configspace: ConfigurationSpace
) -> None
Updates the current RunHistory by adding new trials from a json file.
Parameters#
filename : str File name to load from. configspace : ConfigurationSpace