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:82] Reducing the number of initial configurations from 8 to 7 (max_ratio == 0.25).
[INFO][abstract_initial_design.py:134] Using 7 initial design configurations and 0 additional configurations.
[INFO][abstract_intensifier.py:306] Using only one seed for deterministic scenario.
[INFO][abstract_intensifier.py:493] Added config 33ba44 as new incumbent because there are no incumbents yet.
[INFO][abstract_intensifier.py:565] Added config 249a5c and rejected config 33ba44 as incumbent because it is not better than the incumbents on 1 instances:
[INFO][configspace.py:175] --- x0: 267 -> 144
[INFO][abstract_intensifier.py:565] Added config 17babd and rejected config 249a5c as incumbent because it is not better than the incumbents on 1 instances:
[INFO][configspace.py:175] --- x0: 144 -> 98
[INFO][abstract_intensifier.py:565] Added config 6bd331 and rejected config 17babd as incumbent because it is not better than the incumbents on 1 instances:
[INFO][configspace.py:175] --- x0: 98 -> 0
[INFO][smbo.py:306] Configuration budget is exhausted:
[INFO][smbo.py:307] --- Remaining wallclock time: inf
[INFO][smbo.py:308] --- Remaining cpu time: inf
[INFO][smbo.py:309] --- Remaining trials: 0
[INFO][abstract_intensifier.py:306] Using only one seed for deterministic scenario.
Default cost: 500.0
Incumbent cost: 0.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 7.076 seconds)