diff --git a/webserver.ipynb b/webserver.ipynb deleted file mode 100644 index 7ec9791..0000000 --- a/webserver.ipynb +++ /dev/null @@ -1,159 +0,0 @@ -{ - "cells": [ - { - "cell_type": "code", - "execution_count": 8, - "metadata": {}, - "outputs": [], - "source": [ - "import requests\n", - "from bofire.data_models.domain.api import Domain\n", - "\n", - "from pydantic import BaseModel, Field\n", - "from bofire.data_models.strategies.api import AnyStrategy, RandomStrategy, SoboStrategy\n", - "from typing import Optional\n", - "from bofire.data_models.features.api import ContinuousInput\n", - "\n", - "from bofire.data_models.dataframes.api import Experiments, Candidates\n", - "from bofire.benchmarks.api import Himmelblau, DTLZ2\n", - "import json\n", - "\n", - "\n", - "class CandidateRequest(BaseModel):\n", - " strategy_data: AnyStrategy\n", - " n_candidates: int = Field(\n", - " default=1, gt=0, description=\"Number of candidates to generate\"\n", - " )\n", - " experiments: Optional[Experiments]\n", - " pendings: Optional[Candidates]\n", - "\n", - "bench = Himmelblau()\n", - "bench2 = DTLZ2(dim=6)\n", - "experiments = bench.f(bench.domain.inputs.sample(10), return_complete=True)\n", - "experiments2 = bench2.f(bench2.domain.inputs.sample(10), return_complete=True)\n", - "\n", - "\n", - "cr = CandidateRequest(\n", - " strategy_data=SoboStrategy(domain=bench.domain),\n", - " n_candidates=1,\n", - " experiments=Experiments.from_pandas(experiments2, bench2.domain),\n", - " pendings=None\n", - ")\n", - "\n", - "\n", - "URL = \"http://127.0.0.1:8000/candidates\"\n", - "HEADERS = {'accept': 'application/json', 'Content-Type': 'application/json'}\n", - "\n", - "response = requests.post(url=f\"{URL}/generate\", data=cr.model_dump_json(), headers=HEADERS)\n" - ] - }, - { - "cell_type": "code", - "execution_count": 10, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "b'{\"detail\":[{\"type\":\"value_error\",\"loc\":[\"body\"],\"msg\":\"Value error, no col for input feature `y`\",\"input\":{\"strategy_data\":{\"type\":\"SoboStrategy\",\"domain\":{\"type\":\"Domain\",\"inputs\":{\"type\":\"Inputs\",\"features\":[{\"type\":\"ContinuousInput\",\"key\":\"x_1\",\"unit\":null,\"bounds\":[-6.0,6.0],\"local_relative_bounds\":null,\"stepsize\":null},{\"type\":\"ContinuousInput\",\"key\":\"x_2\",\"unit\":null,\"bounds\":[-6.0,6.0],\"local_relative_bounds\":null,\"stepsize\":null}]},\"outputs\":{\"type\":\"Outputs\",\"features\":[{\"type\":\"ContinuousOutput\",\"key\":\"y\",\"unit\":null,\"objective\":{\"type\":\"MinimizeObjective\",\"w\":1.0,\"bounds\":[0.0,1.0]}}]},\"constraints\":{\"type\":\"Constraints\",\"constraints\":[]}},\"seed\":null,\"num_restarts\":8,\"num_raw_samples\":1024,\"maxiter\":2000,\"batch_limit\":8,\"descriptor_method\":\"EXHAUSTIVE\",\"categorical_method\":\"EXHAUSTIVE\",\"discrete_method\":\"EXHAUSTIVE\",\"surrogate_specs\":{\"surrogates\":[{\"hyperconfig\":{\"type\":\"SingleTaskGPHyperconfig\",\"hyperstrategy\":\"FactorialStrategy\",\"inputs\":{\"type\":\"Inputs\",\"features\":[{\"type\":\"CategoricalInput\",\"key\":\"kernel\",\"categories\":[\"rbf\",\"matern_1.5\",\"matern_2.5\"],\"allowed\":[true,true,true]},{\"type\":\"CategoricalInput\",\"key\":\"prior\",\"categories\":[\"mbo\",\"botorch\"],\"allowed\":[true,true]},{\"type\":\"CategoricalInput\",\"key\":\"ard\",\"categories\":[\"True\",\"False\"],\"allowed\":[true,true]}]},\"n_iterations\":null,\"target_metric\":\"MAE\"},\"aggregations\":null,\"type\":\"SingleTaskGPSurrogate\",\"inputs\":{\"type\":\"Inputs\",\"features\":[{\"type\":\"ContinuousInput\",\"key\":\"x_1\",\"unit\":null,\"bounds\":[-6.0,6.0],\"local_relative_bounds\":null,\"stepsize\":null},{\"type\":\"ContinuousInput\",\"key\":\"x_2\",\"unit\":null,\"bounds\":[-6.0,6.0],\"local_relative_bounds\":null,\"stepsize\":null}]},\"outputs\":{\"type\":\"Outputs\",\"features\":[{\"type\":\"ContinuousOutput\",\"key\":\"y\",\"unit\":null,\"objective\":{\"type\":\"MinimizeObjective\",\"w\":1.0,\"bounds\":[0.0,1.0]}}]},\"input_preprocessing_specs\":{},\"dump\":null,\"scaler\":\"NORMALIZE\",\"output_scaler\":\"STANDARDIZE\",\"kernel\":{\"type\":\"ScaleKernel\",\"base_kernel\":{\"type\":\"MaternKernel\",\"ard\":true,\"nu\":2.5,\"lengthscale_prior\":{\"type\":\"GammaPrior\",\"concentration\":3.0,\"rate\":6.0}},\"outputscale_prior\":{\"type\":\"GammaPrior\",\"concentration\":2.0,\"rate\":0.15}},\"noise_prior\":{\"type\":\"GammaPrior\",\"concentration\":1.1,\"rate\":0.05}}]},\"outlier_detection_specs\":null,\"min_experiments_before_outlier_check\":1,\"frequency_check\":1,\"frequency_hyperopt\":0,\"folds\":5,\"local_search_config\":null,\"acquisition_function\":{\"type\":\"qLogNEI\",\"prune_baseline\":true,\"n_mc_samples\":512}},\"n_candidates\":1,\"experiments\":{\"type\":\"Experiments\",\"rows\":[{\"type\":\"ExperimentRow\",\"inputs\":{\"x_0\":{\"value\":0.3427501192597544},\"x_1\":{\"value\":0.2248806738882979},\"x_2\":{\"value\":0.8003505911844943},\"x_3\":{\"value\":0.5496478127474617},\"x_4\":{\"value\":0.6784806084539219},\"x_5\":{\"value\":0.44598910305378847}},\"outputs\":{\"f_0\":{\"value\":1.0329365461946272,\"valid\":true},\"f_1\":{\"value\":0.6169152426370024,\"valid\":true}}},{\"type\":\"ExperimentRow\",\"inputs\":{\"x_0\":{\"value\":0.7307238068427896},\"x_1\":{\"value\":0.38811093055046497},\"x_2\":{\"value\":0.7491624180475678},\"x_3\":{\"value\":0.025220276398040142},\"x_4\":{\"value\":0.7810733605661323},\"x_5\":{\"value\":0.2635829692280586}},\"outputs\":{\"f_0\":{\"value\":0.5889996653153501,\"valid\":true},\"f_1\":{\"value\":1.3084541064140396,\"valid\":true}}},{\"type\":\"ExperimentRow\",\"inputs\":{\"x_0\":{\"value\":0.23270421549900577},\"x_1\":{\"value\":0.06170310809264712},\"x_2\":{\"value\":0.8643943603828655},\"x_3\":{\"value\":0.348390768255757},\"x_4\":{\"value\":0.5521183287632825},\"x_5\":{\"value\":0.6750931687504705}},\"outputs\":{\"f_0\":{\"value\":1.289993426681666,\"valid\":true},\"f_1\":{\"value\":0.49372000130756777,\"valid\":true}}},{\"type\":\"ExperimentRow\",\"inputs\":{\"x_0\":{\"value\":0.40630255545911453},\"x_1\":{\"value\":0.6268592388753335},\"x_2\":{\"value\":0.4219821142244917},\"x_3\":{\"value\":0.8556460220440621},\"x_4\":{\"value\":0.2890354892457304},\"x_5\":{\"value\":0.37627189687807383}},\"outputs\":{\"f_0\":{\"value\":0.9705998554311998,\"valid\":true},\"f_1\":{\"value\":0.7199701208241278,\"valid\":true}}},{\"type\":\"ExperimentRow\",\"inputs\":{\"x_0\":{\"value\":0.24239145170561927},\"x_1\":{\"value\":0.682231601617558},\"x_2\":{\"value\":0.9612679495346724},\"x_3\":{\"value\":0.8653156008241764},\"x_4\":{\"value\":0.9246465459322838},\"x_5\":{\"value\":0.9487898660512805}},\"outputs\":{\"f_0\":{\"value\":1.6350465358688016,\"valid\":true},\"f_1\":{\"value\":0.6544761786231652,\"valid\":true}}},{\"type\":\"ExperimentRow\",\"inputs\":{\"x_0\":{\"value\":0.14186604785048063},\"x_1\":{\"value\":0.2179031196426503},\"x_2\":{\"value\":0.8937723471178198},\"x_3\":{\"value\":0.8849014989346576},\"x_4\":{\"value\":0.954950376904073},\"x_5\":{\"value\":0.5347004904647011}},\"outputs\":{\"f_0\":{\"value\":1.5516288114067027,\"valid\":true},\"f_1\":{\"value\":0.3516086224967904,\"valid\":true}}},{\"type\":\"ExperimentRow\",\"inputs\":{\"x_0\":{\"value\":0.8748828197055685},\"x_1\":{\"value\":0.8158072755176716},\"x_2\":{\"value\":0.7710387942608429},\"x_3\":{\"value\":0.5982383795561488},\"x_4\":{\"value\":0.7962388882651396},\"x_5\":{\"value\":0.12998475533131415}},\"outputs\":{\"f_0\":{\"value\":0.2748468047904255,\"valid\":true},\"f_1\":{\"value\":1.3804202145427396,\"valid\":true}}},{\"type\":\"ExperimentRow\",\"inputs\":{\"x_0\":{\"value\":0.18827505231464126},\"x_1\":{\"value\":0.08516482602561604},\"x_2\":{\"value\":0.402553106144209},\"x_3\":{\"value\":0.08113633706124646},\"x_4\":{\"value\":0.580836180282068},\"x_5\":{\"value\":0.5779032502138202}},\"outputs\":{\"f_0\":{\"value\":1.3101732891172118,\"valid\":true},\"f_1\":{\"value\":0.399179213219553,\"valid\":true}}},{\"type\":\"ExperimentRow\",\"inputs\":{\"x_0\":{\"value\":0.8042208561351486},\"x_1\":{\"value\":0.3285350488476546},\"x_2\":{\"value\":0.9496838919525497},\"x_3\":{\"value\":0.1650790762586849},\"x_4\":{\"value\":0.6429166455733385},\"x_5\":{\"value\":0.8227018610806988}},\"outputs\":{\"f_0\":{\"value\":0.4444762172347086,\"valid\":true},\"f_1\":{\"value\":1.3994610368185196,\"valid\":true}}},{\"type\":\"ExperimentRow\",\"inputs\":{\"x_0\":{\"value\":0.5971468698779449},\"x_1\":{\"value\":0.9339177625674423},\"x_2\":{\"value\":0.8841040139375298},\"x_3\":{\"value\":0.6848538733478423},\"x_4\":{\"value\":0.7396016091770633},\"x_5\":{\"value\":0.014247780078584071}},\"outputs\":{\"f_0\":{\"value\":0.983716994499296,\"valid\":true},\"f_1\":{\"value\":1.3412877406367683,\"valid\":true}}}]},\"pendings\":null},\"ctx\":{\"error\":{}}}]}'" - ] - }, - "execution_count": 10, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "response.content" - ] - }, - { - "cell_type": "code", - "execution_count": 28, - "metadata": {}, - "outputs": [ - { - "data": { - "text/html": [ - "
\n", - " | x_1 | \n", - "x_2 | \n", - "y_pred | \n", - "y_std | \n", - "y_des | \n", - "
---|---|---|---|---|---|
0 | \n", - "-3.029691 | \n", - "-1.247332 | \n", - "45.611653 | \n", - "250.717458 | \n", - "-45.611653 | \n", - "