Skip to content

Commit

Permalink
C. Benjamins: Upgrade to ConfigSpace 1.x (#1124)
Browse files Browse the repository at this point in the history
  • Loading branch information
Github Actions committed Jul 17, 2024
1 parent 86b2965 commit d3f2d0a
Show file tree
Hide file tree
Showing 658 changed files with 10,466 additions and 3,340 deletions.
Binary file modified development/.doctrees/api/smac.utils.doctree
Binary file not shown.
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 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 modified development/.doctrees/sg_execution_times.doctree
Binary file not shown.
5 changes: 5 additions & 0 deletions development/10_experimental.html
Original file line number Diff line number Diff line change
Expand Up @@ -913,6 +913,11 @@
smac.utils.multi_objective
</a>
</li>
<li class="toctree-l3">
<a class="reference internal" href="api/smac.utils.numpyencoder.html">
smac.utils.numpyencoder
</a>
</li>
<li class="toctree-l3">
<a class="reference internal" href="api/smac.utils.pareto_front.html">
smac.utils.pareto_front
Expand Down
5 changes: 5 additions & 0 deletions development/1_installation.html
Original file line number Diff line number Diff line change
Expand Up @@ -915,6 +915,11 @@
smac.utils.multi_objective
</a>
</li>
<li class="toctree-l3">
<a class="reference internal" href="api/smac.utils.numpyencoder.html">
smac.utils.numpyencoder
</a>
</li>
<li class="toctree-l3">
<a class="reference internal" href="api/smac.utils.pareto_front.html">
smac.utils.pareto_front
Expand Down
5 changes: 5 additions & 0 deletions development/2_package_overview.html
Original file line number Diff line number Diff line change
Expand Up @@ -915,6 +915,11 @@
smac.utils.multi_objective
</a>
</li>
<li class="toctree-l3">
<a class="reference internal" href="api/smac.utils.numpyencoder.html">
smac.utils.numpyencoder
</a>
</li>
<li class="toctree-l3">
<a class="reference internal" href="api/smac.utils.pareto_front.html">
smac.utils.pareto_front
Expand Down
5 changes: 5 additions & 0 deletions development/3_getting_started.html
Original file line number Diff line number Diff line change
Expand Up @@ -915,6 +915,11 @@
smac.utils.multi_objective
</a>
</li>
<li class="toctree-l3">
<a class="reference internal" href="api/smac.utils.numpyencoder.html">
smac.utils.numpyencoder
</a>
</li>
<li class="toctree-l3">
<a class="reference internal" href="api/smac.utils.pareto_front.html">
smac.utils.pareto_front
Expand Down
5 changes: 5 additions & 0 deletions development/4_minimal_example.html
Original file line number Diff line number Diff line change
Expand Up @@ -915,6 +915,11 @@
smac.utils.multi_objective
</a>
</li>
<li class="toctree-l3">
<a class="reference internal" href="api/smac.utils.numpyencoder.html">
smac.utils.numpyencoder
</a>
</li>
<li class="toctree-l3">
<a class="reference internal" href="api/smac.utils.pareto_front.html">
smac.utils.pareto_front
Expand Down
5 changes: 5 additions & 0 deletions development/5_api.html
Original file line number Diff line number Diff line change
Expand Up @@ -916,6 +916,11 @@
smac.utils.multi_objective
</a>
</li>
<li class="toctree-l3">
<a class="reference internal" href="api/smac.utils.numpyencoder.html">
smac.utils.numpyencoder
</a>
</li>
<li class="toctree-l3">
<a class="reference internal" href="api/smac.utils.pareto_front.html">
smac.utils.pareto_front
Expand Down
5 changes: 5 additions & 0 deletions development/6_references.html
Original file line number Diff line number Diff line change
Expand Up @@ -915,6 +915,11 @@
smac.utils.multi_objective
</a>
</li>
<li class="toctree-l3">
<a class="reference internal" href="api/smac.utils.numpyencoder.html">
smac.utils.numpyencoder
</a>
</li>
<li class="toctree-l3">
<a class="reference internal" href="api/smac.utils.pareto_front.html">
smac.utils.pareto_front
Expand Down
5 changes: 5 additions & 0 deletions development/7_glossary.html
Original file line number Diff line number Diff line change
Expand Up @@ -915,6 +915,11 @@
smac.utils.multi_objective
</a>
</li>
<li class="toctree-l3">
<a class="reference internal" href="api/smac.utils.numpyencoder.html">
smac.utils.numpyencoder
</a>
</li>
<li class="toctree-l3">
<a class="reference internal" href="api/smac.utils.pareto_front.html">
smac.utils.pareto_front
Expand Down
5 changes: 5 additions & 0 deletions development/8_faq.html
Original file line number Diff line number Diff line change
Expand Up @@ -915,6 +915,11 @@
smac.utils.multi_objective
</a>
</li>
<li class="toctree-l3">
<a class="reference internal" href="api/smac.utils.numpyencoder.html">
smac.utils.numpyencoder
</a>
</li>
<li class="toctree-l3">
<a class="reference internal" href="api/smac.utils.pareto_front.html">
smac.utils.pareto_front
Expand Down
5 changes: 5 additions & 0 deletions development/9_license.html
Original file line number Diff line number Diff line change
Expand Up @@ -914,6 +914,11 @@
smac.utils.multi_objective
</a>
</li>
<li class="toctree-l3">
<a class="reference internal" href="api/smac.utils.numpyencoder.html">
smac.utils.numpyencoder
</a>
</li>
<li class="toctree-l3">
<a class="reference internal" href="api/smac.utils.pareto_front.html">
smac.utils.pareto_front
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,14 @@ def configspace(self) -> ConfigurationSpace:
learning_rate = Categorical("learning_rate", ["constant", "invscaling", "adaptive"], default="constant")
learning_rate_init = Float("learning_rate_init", (0.0001, 1.0), default=0.001, log=True)

cs.add_hyperparameters([n_layer, n_neurons, activation, solver, batch_size, learning_rate, learning_rate_init])
cs.add([n_layer, n_neurons, activation, solver, batch_size, learning_rate, learning_rate_init])

use_lr = EqualsCondition(child=learning_rate, parent=solver, value="sgd")
use_lr_init = InCondition(child=learning_rate_init, parent=solver, values=["sgd", "adam"])
use_batch_size = InCondition(child=batch_size, parent=solver, values=["sgd", "adam"])

# We can also add multiple conditions on hyperparameters at once:
cs.add_conditions([use_lr, use_batch_size, use_lr_init])
cs.add([use_lr, use_batch_size, use_lr_init])

return cs

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class QuadraticFunction:
def configspace(self) -> ConfigurationSpace:
cs = ConfigurationSpace(seed=0)
x = Float("x", (-5, 5), default=-5)
cs.add_hyperparameters([x])
cs.add([x])

return cs

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def configspace(self) -> ConfigurationSpace:
cs = ConfigurationSpace(seed=0)
x0 = Float("x0", (-5, 10), default=-3)
x1 = Float("x1", (-5, 10), default=-4)
cs.add_hyperparameters([x0, x1])
cs.add([x0, x1])

return cs

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
},
"outputs": [],
"source": [
"from __future__ import annotations\n\nfrom ConfigSpace import Configuration, ConfigurationSpace, Float\n\nfrom smac import Callback\nfrom smac import HyperparameterOptimizationFacade as HPOFacade\nfrom smac import Scenario\nfrom smac.main.smbo import SMBO\nfrom smac.runhistory import TrialInfo, TrialValue\n\n__copyright__ = \"Copyright 2021, AutoML.org Freiburg-Hannover\"\n__license__ = \"3-clause BSD\"\n\n\nclass StopCallback(Callback):\n def __init__(self, stop_after: int):\n self._stop_after = stop_after\n\n def on_tell_end(self, smbo: SMBO, info: TrialInfo, value: TrialValue) -> bool | None:\n \"\"\"Called after the stats are updated and the trial is added to the runhistory. Optionally, returns false\n to gracefully stop the optimization.\n \"\"\"\n if smbo.runhistory.finished == self._stop_after:\n return False\n\n return None\n\n\nclass QuadraticFunction:\n @property\n def configspace(self) -> ConfigurationSpace:\n cs = ConfigurationSpace(seed=0)\n x = Float(\"x\", (-5, 5), default=-5)\n cs.add_hyperparameters([x])\n\n return cs\n\n def train(self, config: Configuration, seed: int = 0) -> float:\n \"\"\"Returns the y value of a quadratic function with a minimum at x=0.\"\"\"\n x = config[\"x\"]\n return x * x\n\n\nif __name__ == \"__main__\":\n model = QuadraticFunction()\n\n # Scenario object specifying the optimization \"environment\"\n scenario = Scenario(model.configspace, deterministic=True, n_trials=50)\n stop_after = 10\n\n # Now we use SMAC to find the best hyperparameters\n smac = HPOFacade(\n scenario,\n model.train, # We pass the target function here\n callbacks=[StopCallback(stop_after=stop_after)],\n overwrite=True, # Overrides any previous results that are found that are inconsistent with the meta-data\n )\n\n incumbent = smac.optimize()\n assert smac.runhistory.finished == stop_after\n\n # Now, we want to continue the optimization\n # Make sure, we don't overwrite the last run\n smac2 = HPOFacade(\n scenario,\n model.train,\n overwrite=False,\n )\n\n # Check whether we get the same incumbent\n assert smac.intensifier.get_incumbent() == smac2.intensifier.get_incumbent()\n assert smac2.runhistory.finished == stop_after\n\n # And now we finish the optimization\n incumbent2 = smac2.optimize()\n\n default_cost = smac.validate(model.configspace.get_default_configuration())\n print(f\"Default cost: {default_cost}\")\n\n incumbent_cost = smac.validate(incumbent)\n print(f\"Incumbent cost of first run: {incumbent_cost}\")\n\n incumbent_cost = smac2.validate(incumbent2)\n print(f\"Incumbent cost of continued run: {incumbent_cost}\")"
"from __future__ import annotations\n\nfrom ConfigSpace import Configuration, ConfigurationSpace, Float\n\nfrom smac import Callback\nfrom smac import HyperparameterOptimizationFacade as HPOFacade\nfrom smac import Scenario\nfrom smac.main.smbo import SMBO\nfrom smac.runhistory import TrialInfo, TrialValue\n\n__copyright__ = \"Copyright 2021, AutoML.org Freiburg-Hannover\"\n__license__ = \"3-clause BSD\"\n\n\nclass StopCallback(Callback):\n def __init__(self, stop_after: int):\n self._stop_after = stop_after\n\n def on_tell_end(self, smbo: SMBO, info: TrialInfo, value: TrialValue) -> bool | None:\n \"\"\"Called after the stats are updated and the trial is added to the runhistory. Optionally, returns false\n to gracefully stop the optimization.\n \"\"\"\n if smbo.runhistory.finished == self._stop_after:\n return False\n\n return None\n\n\nclass QuadraticFunction:\n @property\n def configspace(self) -> ConfigurationSpace:\n cs = ConfigurationSpace(seed=0)\n x = Float(\"x\", (-5, 5), default=-5)\n cs.add([x])\n\n return cs\n\n def train(self, config: Configuration, seed: int = 0) -> float:\n \"\"\"Returns the y value of a quadratic function with a minimum at x=0.\"\"\"\n x = config[\"x\"]\n return x * x\n\n\nif __name__ == \"__main__\":\n model = QuadraticFunction()\n\n # Scenario object specifying the optimization \"environment\"\n scenario = Scenario(model.configspace, deterministic=True, n_trials=50)\n stop_after = 10\n\n # Now we use SMAC to find the best hyperparameters\n smac = HPOFacade(\n scenario,\n model.train, # We pass the target function here\n callbacks=[StopCallback(stop_after=stop_after)],\n overwrite=True, # Overrides any previous results that are found that are inconsistent with the meta-data\n )\n\n incumbent = smac.optimize()\n assert smac.runhistory.finished == stop_after\n\n # Now, we want to continue the optimization\n # Make sure, we don't overwrite the last run\n smac2 = HPOFacade(\n scenario,\n model.train,\n overwrite=False,\n )\n\n # Check whether we get the same incumbent\n assert smac.intensifier.get_incumbent() == smac2.intensifier.get_incumbent()\n assert smac2.runhistory.finished == stop_after\n\n # And now we finish the optimization\n incumbent2 = smac2.optimize()\n\n default_cost = smac.validate(model.configspace.get_default_configuration())\n print(f\"Default cost: {default_cost}\")\n\n incumbent_cost = smac.validate(incumbent)\n print(f\"Incumbent cost of first run: {incumbent_cost}\")\n\n incumbent_cost = smac2.validate(incumbent2)\n print(f\"Incumbent cost of continued run: {incumbent_cost}\")"
]
}
],
Expand Down
Loading

0 comments on commit d3f2d0a

Please sign in to comment.