Skip to content

Commit

Permalink
Tim Ruhkopf: [doc] #1038, #987 added warm starting using ask and tell (
Browse files Browse the repository at this point in the history
  • Loading branch information
Github Actions committed Sep 25, 2024
1 parent 699b59c commit b12a47d
Show file tree
Hide file tree
Showing 636 changed files with 11,138 additions and 306 deletions.
Binary file not shown.
Binary file modified development/.doctrees/advanced_usage/index.doctree
Binary file not shown.
Binary file modified development/.doctrees/environment.pickle
Binary file not shown.
Binary file not shown.
Binary file modified development/.doctrees/examples/1_basics/2_svm_cv.doctree
Binary file not shown.
Binary file modified development/.doctrees/examples/1_basics/3_ask_and_tell.doctree
Binary file not shown.
Binary file modified development/.doctrees/examples/1_basics/4_callback.doctree
Binary file not shown.
Binary file modified development/.doctrees/examples/1_basics/5_continue.doctree
Binary file not shown.
Binary file modified development/.doctrees/examples/1_basics/6_priors.doctree
Binary file not shown.
Binary file not shown.
Binary file modified development/.doctrees/examples/1_basics/index.doctree
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file modified development/.doctrees/examples/3_multi_objective/2_parego.doctree
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file modified development/.doctrees/examples/index.doctree
Binary file not shown.
Binary file modified development/.doctrees/sg_execution_times.doctree
Binary file not shown.
10 changes: 10 additions & 0 deletions development/10_experimental.html
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,11 @@
User Priors over the Optimum
</a>
</li>
<li class="toctree-l3">
<a class="reference internal" href="examples/1_basics/8_warmstart.html">
Warmstarting SMAC
</a>
</li>
</ul>
</li>
<li class="toctree-l2 has-children">
Expand Down Expand Up @@ -307,6 +312,11 @@
Ask-and-Tell Interface
</a>
</li>
<li class="toctree-l2">
<a class="reference internal" href="advanced_usage/5.1_warmstarting.html">
Warmstarting SMAC
</a>
</li>
<li class="toctree-l2">
<a class="reference internal" href="advanced_usage/6_commandline.html">
Command-Line Interface
Expand Down
10 changes: 10 additions & 0 deletions development/1_installation.html
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,11 @@
User Priors over the Optimum
</a>
</li>
<li class="toctree-l3">
<a class="reference internal" href="examples/1_basics/8_warmstart.html">
Warmstarting SMAC
</a>
</li>
</ul>
</li>
<li class="toctree-l2 has-children">
Expand Down Expand Up @@ -309,6 +314,11 @@
Ask-and-Tell Interface
</a>
</li>
<li class="toctree-l2">
<a class="reference internal" href="advanced_usage/5.1_warmstarting.html">
Warmstarting SMAC
</a>
</li>
<li class="toctree-l2">
<a class="reference internal" href="advanced_usage/6_commandline.html">
Command-Line Interface
Expand Down
10 changes: 10 additions & 0 deletions development/2_package_overview.html
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,11 @@
User Priors over the Optimum
</a>
</li>
<li class="toctree-l3">
<a class="reference internal" href="examples/1_basics/8_warmstart.html">
Warmstarting SMAC
</a>
</li>
</ul>
</li>
<li class="toctree-l2 has-children">
Expand Down Expand Up @@ -309,6 +314,11 @@
Ask-and-Tell Interface
</a>
</li>
<li class="toctree-l2">
<a class="reference internal" href="advanced_usage/5.1_warmstarting.html">
Warmstarting SMAC
</a>
</li>
<li class="toctree-l2">
<a class="reference internal" href="advanced_usage/6_commandline.html">
Command-Line Interface
Expand Down
10 changes: 10 additions & 0 deletions development/3_getting_started.html
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,11 @@
User Priors over the Optimum
</a>
</li>
<li class="toctree-l3">
<a class="reference internal" href="examples/1_basics/8_warmstart.html">
Warmstarting SMAC
</a>
</li>
</ul>
</li>
<li class="toctree-l2 has-children">
Expand Down Expand Up @@ -309,6 +314,11 @@
Ask-and-Tell Interface
</a>
</li>
<li class="toctree-l2">
<a class="reference internal" href="advanced_usage/5.1_warmstarting.html">
Warmstarting SMAC
</a>
</li>
<li class="toctree-l2">
<a class="reference internal" href="advanced_usage/6_commandline.html">
Command-Line Interface
Expand Down
10 changes: 10 additions & 0 deletions development/4_minimal_example.html
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,11 @@
User Priors over the Optimum
</a>
</li>
<li class="toctree-l3">
<a class="reference internal" href="examples/1_basics/8_warmstart.html">
Warmstarting SMAC
</a>
</li>
</ul>
</li>
<li class="toctree-l2 has-children">
Expand Down Expand Up @@ -309,6 +314,11 @@
Ask-and-Tell Interface
</a>
</li>
<li class="toctree-l2">
<a class="reference internal" href="advanced_usage/5.1_warmstarting.html">
Warmstarting SMAC
</a>
</li>
<li class="toctree-l2">
<a class="reference internal" href="advanced_usage/6_commandline.html">
Command-Line Interface
Expand Down
10 changes: 10 additions & 0 deletions development/5_api.html
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,11 @@
User Priors over the Optimum
</a>
</li>
<li class="toctree-l3">
<a class="reference internal" href="examples/1_basics/8_warmstart.html">
Warmstarting SMAC
</a>
</li>
</ul>
</li>
<li class="toctree-l2 has-children">
Expand Down Expand Up @@ -310,6 +315,11 @@
Ask-and-Tell Interface
</a>
</li>
<li class="toctree-l2">
<a class="reference internal" href="advanced_usage/5.1_warmstarting.html">
Warmstarting SMAC
</a>
</li>
<li class="toctree-l2">
<a class="reference internal" href="advanced_usage/6_commandline.html">
Command-Line Interface
Expand Down
10 changes: 10 additions & 0 deletions development/6_references.html
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,11 @@
User Priors over the Optimum
</a>
</li>
<li class="toctree-l3">
<a class="reference internal" href="examples/1_basics/8_warmstart.html">
Warmstarting SMAC
</a>
</li>
</ul>
</li>
<li class="toctree-l2 has-children">
Expand Down Expand Up @@ -309,6 +314,11 @@
Ask-and-Tell Interface
</a>
</li>
<li class="toctree-l2">
<a class="reference internal" href="advanced_usage/5.1_warmstarting.html">
Warmstarting SMAC
</a>
</li>
<li class="toctree-l2">
<a class="reference internal" href="advanced_usage/6_commandline.html">
Command-Line Interface
Expand Down
10 changes: 10 additions & 0 deletions development/7_glossary.html
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,11 @@
User Priors over the Optimum
</a>
</li>
<li class="toctree-l3">
<a class="reference internal" href="examples/1_basics/8_warmstart.html">
Warmstarting SMAC
</a>
</li>
</ul>
</li>
<li class="toctree-l2 has-children">
Expand Down Expand Up @@ -309,6 +314,11 @@
Ask-and-Tell Interface
</a>
</li>
<li class="toctree-l2">
<a class="reference internal" href="advanced_usage/5.1_warmstarting.html">
Warmstarting SMAC
</a>
</li>
<li class="toctree-l2">
<a class="reference internal" href="advanced_usage/6_commandline.html">
Command-Line Interface
Expand Down
10 changes: 10 additions & 0 deletions development/8_faq.html
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,11 @@
User Priors over the Optimum
</a>
</li>
<li class="toctree-l3">
<a class="reference internal" href="examples/1_basics/8_warmstart.html">
Warmstarting SMAC
</a>
</li>
</ul>
</li>
<li class="toctree-l2 has-children">
Expand Down Expand Up @@ -309,6 +314,11 @@
Ask-and-Tell Interface
</a>
</li>
<li class="toctree-l2">
<a class="reference internal" href="advanced_usage/5.1_warmstarting.html">
Warmstarting SMAC
</a>
</li>
<li class="toctree-l2">
<a class="reference internal" href="advanced_usage/6_commandline.html">
Command-Line Interface
Expand Down
10 changes: 10 additions & 0 deletions development/9_license.html
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,11 @@
User Priors over the Optimum
</a>
</li>
<li class="toctree-l3">
<a class="reference internal" href="examples/1_basics/8_warmstart.html">
Warmstarting SMAC
</a>
</li>
</ul>
</li>
<li class="toctree-l2 has-children">
Expand Down Expand Up @@ -308,6 +313,11 @@
Ask-and-Tell Interface
</a>
</li>
<li class="toctree-l2">
<a class="reference internal" href="advanced_usage/5.1_warmstarting.html">
Warmstarting SMAC
</a>
</li>
<li class="toctree-l2">
<a class="reference internal" href="advanced_usage/6_commandline.html">
Command-Line Interface
Expand Down
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
"""
Warmstarting SMAC
======================================
With the ask and tell interface, we can support warmstarting SMAC. We can communicate rich
information about the previous trials to SMAC using `TrialInfo` and `TrialValue` instances.
For more details on ask and tell consult `advanced_usage/5_ask_and_tell`.
"""
from __future__ import annotations

from smac.scenario import Scenario
from smac.facade import HyperparameterOptimizationFacade
from ConfigSpace import Configuration, ConfigurationSpace, Float
from smac.runhistory.dataclasses import TrialValue, TrialInfo


class Rosenbrock2D:
@property
def configspace(self) -> ConfigurationSpace:
cs = ConfigurationSpace(seed=0)
x0 = Float("x0", (-5, 10), default=-3)
x1 = Float("x1", (-5, 10), default=-4)
cs.add([x0, x1])

return cs

def evaluate(self, config: Configuration, seed: int = 0) -> float:
"""The 2-dimensional Rosenbrock function as a toy model.
The Rosenbrock function is well know in the optimization community and
often serves as a toy problem. It can be defined for arbitrary
dimensions. The minimium is always at x_i = 1 with a function value of
zero. All input parameters are continuous. The search domain for
all x's is the interval [-5, 10].
"""
x1 = config["x0"]
x2 = config["x1"]

cost = 100.0 * (x2 - x1**2.0) ** 2.0 + (1 - x1) ** 2.0
return cost


if __name__ == "__main__":
SEED = 12345
task = Rosenbrock2D()

# Previous evaluations
# X vectors need to be connected to the configuration space
configurations = [
Configuration(task.configspace, {'x0':1, 'x1':2}),
Configuration(task.configspace, {'x0':-1, 'x1':3}),
Configuration(task.configspace, {'x0':5, 'x1':5}),
]
costs = [task.evaluate(c, seed=SEED) for c in configurations]

# Define optimization problem and budget
scenario = Scenario(task.configspace, deterministic=False, n_trials=30)
intensifier = HyperparameterOptimizationFacade.get_intensifier(scenario, max_config_calls=1)
smac = HyperparameterOptimizationFacade(
scenario,
task.evaluate,
intensifier=intensifier,
overwrite=True,

# Modify the initial design to use our custom initial design
initial_design=HyperparameterOptimizationFacade.get_initial_design(
scenario,
n_configs=0, # Do not use the default initial design
additional_configs=configurations # Use the configurations previously evaluated as initial design
# This only passes the configurations but not the cost!
# So in order to actually use the custom, pre-evaluated initial design
# we need to tell those trials, like below.
)
)

# Convert previously evaluated configurations into TrialInfo and TrialValue instances to pass to SMAC
trial_infos = [TrialInfo(config=c, seed=SEED) for c in configurations]
trial_values = [TrialValue(cost=c) for c in costs]

# Warmstart SMAC with the trial information and values
for info, value in zip(trial_infos, trial_values):
smac.tell(info, value)

# Optimize as usual
smac.optimize()
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"\n# Warmstarting SMAC\n\nWith the ask and tell interface, we can support warmstarting SMAC. We can communicate rich\ninformation about the previous trials to SMAC using `TrialInfo` and `TrialValue` instances.\nFor more details on ask and tell consult `advanced_usage/5_ask_and_tell`.\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"from __future__ import annotations\n\nfrom smac.scenario import Scenario\nfrom smac.facade import HyperparameterOptimizationFacade\nfrom ConfigSpace import Configuration, ConfigurationSpace, Float\nfrom smac.runhistory.dataclasses import TrialValue, TrialInfo\n\n\nclass Rosenbrock2D:\n @property\n def configspace(self) -> ConfigurationSpace:\n cs = ConfigurationSpace(seed=0)\n x0 = Float(\"x0\", (-5, 10), default=-3)\n x1 = Float(\"x1\", (-5, 10), default=-4)\n cs.add([x0, x1])\n\n return cs\n\n def evaluate(self, config: Configuration, seed: int = 0) -> float:\n \"\"\"The 2-dimensional Rosenbrock function as a toy model.\n The Rosenbrock function is well know in the optimization community and\n often serves as a toy problem. It can be defined for arbitrary\n dimensions. The minimium is always at x_i = 1 with a function value of\n zero. All input parameters are continuous. The search domain for\n all x's is the interval [-5, 10].\n \"\"\"\n x1 = config[\"x0\"]\n x2 = config[\"x1\"]\n\n cost = 100.0 * (x2 - x1**2.0) ** 2.0 + (1 - x1) ** 2.0\n return cost\n\n\nif __name__ == \"__main__\":\n SEED = 12345\n task = Rosenbrock2D()\n\n # Previous evaluations\n # X vectors need to be connected to the configuration space\n configurations = [\n Configuration(task.configspace, {'x0':1, 'x1':2}),\n Configuration(task.configspace, {'x0':-1, 'x1':3}),\n Configuration(task.configspace, {'x0':5, 'x1':5}),\n ]\n costs = [task.evaluate(c, seed=SEED) for c in configurations]\n\n # Define optimization problem and budget\n scenario = Scenario(task.configspace, deterministic=False, n_trials=30)\n intensifier = HyperparameterOptimizationFacade.get_intensifier(scenario, max_config_calls=1)\n smac = HyperparameterOptimizationFacade(\n scenario,\n task.evaluate,\n intensifier=intensifier,\n overwrite=True,\n\n # Modify the initial design to use our custom initial design\n initial_design=HyperparameterOptimizationFacade.get_initial_design(\n scenario, \n n_configs=0, # Do not use the default initial design\n additional_configs=configurations # Use the configurations previously evaluated as initial design\n # This only passes the configurations but not the cost!\n # So in order to actually use the custom, pre-evaluated initial design\n # we need to tell those trials, like below.\n )\n )\n\n # Convert previously evaluated configurations into TrialInfo and TrialValue instances to pass to SMAC\n trial_infos = [TrialInfo(config=c, seed=SEED) for c in configurations]\n trial_values = [TrialValue(cost=c) for c in costs]\n\n # Warmstart SMAC with the trial information and values\n for info, value in zip(trial_infos, trial_values):\n smac.tell(info, value)\n\n # Optimize as usual\n smac.optimize()"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.15"
}
},
"nbformat": 4,
"nbformat_minor": 0
}
Binary file modified development/_images/sphx_glr_1_mlp_epochs_001.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified development/_images/sphx_glr_1_mlp_epochs_thumb.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified development/_images/sphx_glr_2_parego_001.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified development/_images/sphx_glr_2_parego_thumb.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
10 changes: 10 additions & 0 deletions development/_modules/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,11 @@
User Priors over the Optimum
</a>
</li>
<li class="toctree-l3">
<a class="reference internal" href="../examples/1_basics/8_warmstart.html">
Warmstarting SMAC
</a>
</li>
</ul>
</li>
<li class="toctree-l2 has-children">
Expand Down Expand Up @@ -306,6 +311,11 @@
Ask-and-Tell Interface
</a>
</li>
<li class="toctree-l2">
<a class="reference internal" href="../advanced_usage/5.1_warmstarting.html">
Warmstarting SMAC
</a>
</li>
<li class="toctree-l2">
<a class="reference internal" href="../advanced_usage/6_commandline.html">
Command-Line Interface
Expand Down
Loading

0 comments on commit b12a47d

Please sign in to comment.