Call Target Function From Script

This simple example shows how to call a script with the following content:

#!/bin/bash

# Set arguments first
for argument in "$@"
do
    key=$(echo $argument | cut -f1 -d=)
    value=$(echo $argument | cut -f2 -d=)

    if [[ $key == *"--"* ]]; then
        v="${key/--/}"
        declare $v="${value}"
    fi
done

# We simply set the cost to our parameter
cost=$x0

# Return everything
echo "cost=$cost"
[INFO][abstract_initial_design.py:81] Reducing the number of initial configurations from 10 to 3 (max_ratio == 0.1).
[INFO][abstract_initial_design.py:133] Using 3 initial design and 0 additional configurations.
[INFO][intensifier.py:275] No incumbent provided in the first run. Sampling a new challenger...
[INFO][intensifier.py:446] First run and no incumbent provided. Challenger is assumed to be the incumbent.
[INFO][intensifier.py:566] Updated estimated cost of incumbent on 1 trials: 267.0
[INFO][abstract_intensifier.py:340] Challenger (116.0) is better than incumbent (267.0) on 1 trials.
[INFO][abstract_intensifier.py:364] Changes in incumbent:
[INFO][abstract_intensifier.py:367] --- x0: 267 -> 116
[INFO][abstract_intensifier.py:340] Challenger (115.0) is better than incumbent (116.0) on 1 trials.
[INFO][abstract_intensifier.py:364] Changes in incumbent:
[INFO][abstract_intensifier.py:367] --- x0: 116 -> 115
[INFO][abstract_intensifier.py:340] Challenger (10.0) is better than incumbent (115.0) on 1 trials.
[INFO][abstract_intensifier.py:364] Changes in incumbent:
[INFO][abstract_intensifier.py:367] --- x0: 115 -> 10
[INFO][base_smbo.py:260] Configuration budget is exhausted.
[INFO][abstract_facade.py:325] Final Incumbent: {'x0': 10}
[INFO][abstract_facade.py:326] Estimated cost: 10.0
Default cost: 500.0
Incumbent cost: 10.0

from ConfigSpace import ConfigurationSpace

from smac import BlackBoxFacade, Scenario

__copyright__ = "Copyright 2021, AutoML.org Freiburg-Hannover"
__license__ = "3-clause BSD"


if __name__ == "__main__":
    cs = ConfigurationSpace({"x0": (0, 1000)}, seed=0)

    # Scenario object specifying the optimization "environment"
    scenario = Scenario(cs, deterministic=True, n_trials=30)

    # Now we use SMAC to find the best hyperparameters
    smac = BlackBoxFacade(
        scenario,
        "./script.sh",  # We pass the filename of our script here
        overwrite=True,  # Overrides any previous results that are found that are inconsistent with the meta-data
    )
    incumbent = smac.optimize()

    # Get cost of default configuration
    default_cost = smac.validate(cs.get_default_configuration())
    print(f"Default cost: {default_cost}")

    # Let's calculate the cost of the incumbent
    incumbent_cost = smac.validate(incumbent)
    print(f"Incumbent cost: {incumbent_cost}")

Total running time of the script: ( 0 minutes 1.030 seconds)