Target function script runner
smac.runner.target_function_script_runner
#
TargetFunctionScriptRunner
#
TargetFunctionScriptRunner(
target_function: str,
scenario: Scenario,
required_arguments: list[str] = None,
)
Bases: AbstractSerialRunner
Class to execute target functions from scripts. Uses Popen to execute the script in a
subprocess.
The following example shows how the script is called:
target_function --instance=test --instance_features=test --seed=0 --hyperparameter1=5323
The script must return an echo in the following form (white-spaces are removed):
cost=0.5; runtime=0.01; status=SUCCESS; additional_info=test (single-objective)
cost=0.5, 0.4; runtime=0.01; status=SUCCESS; additional_info=test (multi-objective)
The status must be a string and must be one of the StatusType values. However, runtime,
status and additional_info are optional.
Note
Everytime an instance is passed, also an instance feature in form of a comma-separated list (no spaces) of floats is passed. If no instance feature for the instance is given, an empty list is passed.
| PARAMETER | DESCRIPTION |
|---|---|
target_function
|
The target function.
TYPE:
|
scenario
|
TYPE:
|
required_arguments
|
A list of required arguments, which are passed to the target function. |
Source code in smac/runner/target_function_script_runner.py
__call__
#
Calls the algorithm, which is processed in the run method.
Source code in smac/runner/target_function_script_runner.py
run
#
run(
config: Configuration,
instance: Optional[str] = None,
budget: Optional[float] = None,
seed: Optional[int] = None,
additional_info: Optional[dict[str, Any]] = None,
) -> tuple[
StatusType,
Union[float, list[float]],
float,
float,
dict[str, Any],
]
Calls the target function.
| PARAMETER | DESCRIPTION |
|---|---|
config
|
Configuration to be passed to the target function.
TYPE:
|
instance
|
The Problem instance.
TYPE:
|
budget
|
A positive, real-valued number representing an arbitrary limit to the target function handled by the target function internally.
TYPE:
|
seed
|
TYPE:
|
additional_info
|
All further additional trial information.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
status
|
Status of the trial.
TYPE:
|
cost
|
Resulting cost(s) of the trial. |
runtime
|
The time the target function took to run.
TYPE:
|
cpu_time
|
The time the target function took on the hardware to run.
TYPE:
|
val_additional_info
|
All further additional trial information.
TYPE:
|
Source code in smac/runner/target_function_script_runner.py
80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 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 170 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 | |
run_wrapper
#
run_wrapper(
trial_info: TrialInfo,
**dask_data_to_scatter: dict[str, Any]
) -> tuple[TrialInfo, TrialValue]
Wrapper around run() to execute and check the execution of a given config. This function encapsulates common handling/processing, so that run() implementation is simplified.
| PARAMETER | DESCRIPTION |
|---|---|
trial_info
|
Object that contains enough information to execute a configuration run in isolation.
TYPE:
|
dask_data_to_scatter
|
When a user scatters data from their local process to the distributed network, this data is distributed in a round-robin fashion grouping by number of cores. Roughly speaking, we can keep this data in memory and then we do not have to (de-)serialize the data every time we would like to execute a target function with a big dataset. For example, when your target function has a big dataset shared across all the target function, this argument is very useful. |
| RETURNS | DESCRIPTION |
|---|---|
info
|
An object containing the configuration launched.
TYPE:
|
value
|
Contains information about the status/performance of config.
TYPE:
|
Source code in smac/runner/abstract_runner.py
submit_trial
#
submit_trial(trial_info: TrialInfo) -> None
This function submits a trial_info object in a serial fashion. As there is a single
worker for this task, this interface can be considered a wrapper over the run method.
Both result/exceptions can be completely determined in this step so both lists are properly filled.
| PARAMETER | DESCRIPTION |
|---|---|
trial_info
|
An object containing the configuration launched.
TYPE:
|
Source code in smac/runner/abstract_serial_runner.py
wait
#
The SMBO/intensifier might need to wait for trials to finish before making a decision. For serial runners, no wait is needed as the result is immediately available.