from bofire.benchmarks.svm import SVMfrom bofire.data_models.strategies.api import SoboStrategyfrom bofire.data_models.kernels.api import SphericalLinearKernelfrom bofire.data_models.surrogates.api import SingleTaskGPSurrogate, BotorchSurrogatesimport bofire.strategies.api as strategies
/opt/hostedtoolcache/Python/3.12.14/x64/lib/python3.12/site-packages/torch/jit/_script.py:1491: FutureWarning: `torch.jit.script` is deprecated. Please switch to `torch.compile` or `torch.export`.
warnings.warn(
# problem setup for spherical linear kernelsbenchmark = SVM()candidates = benchmark._domain.inputs.sample(benchmark.dim+1, seed=benchmark.seed)experiments = candidates.copy()result = benchmark._f(experiments)# Add empty columns 'y' and 'valid_y' to experiments DataFrameexperiments["y"], experiments["valid_y"] = result["y"], result["valid_y"]sobo_strategy_data_model = SoboStrategy( domain=benchmark._domain, seed=benchmark.seed, surrogate_specs=BotorchSurrogates( surrogates=[ SingleTaskGPSurrogate( inputs=benchmark._domain.inputs, outputs=benchmark._domain.outputs, kernel=SphericalLinearKernel(), ) ] ),)strategy = strategies.map(sobo_strategy_data_model)
Downloading SVM data...
Download complete.
Running the optimization loop
strategy.tell(experiments, replace=True)num_steps =3# set the number of steps here (the original paper uses 1000 steps)for step_number inrange(num_steps):print(f"Step {step_number+1}/{num_steps}") new_candidates = strategy.ask(candidate_count=1) new_experiments = new_candidates.copy() result = benchmark._f(new_candidates) new_experiments["y"], new_experiments["valid_y"] = result["y"], result["valid_y"]print(f"New experiment:\n{new_experiments}") strategy.tell(experiments=new_experiments)# save all the experimentsall_experiments = strategy.experiments
/opt/hostedtoolcache/Python/3.12.14/x64/lib/python3.12/site-packages/bofire/utils/torch_tools.py:51: UserWarning: The given NumPy array is not writable, and PyTorch does not support non-writable tensors. This means writing to this tensor will result in undefined behavior. You may want to copy the array to protect its data or make it writable before converting it to a tensor. This type of warning will be suppressed for the rest of this program. (Triggered internally at /__w/pytorch/pytorch/torch/csrc/utils/tensor_numpy.cpp:213.)
return torch.from_numpy(np.ascontiguousarray(df.to_numpy())).to(**tkwargs)
Step 1/3
/opt/hostedtoolcache/Python/3.12.14/x64/lib/python3.12/site-packages/linear_operator/utils/cholesky.py:41: NumericalWarning: A not p.d., added jitter of 1.0e-08 to the diagonal
warnings.warn(
/opt/hostedtoolcache/Python/3.12.14/x64/lib/python3.12/site-packages/botorch/optim/optimize.py:844: RuntimeWarning: Optimization failed in `gen_candidates_scipy` with the following warning(s):
[NumericalWarning('A not p.d., added jitter of 1.0e-08 to the diagonal'), OptimizationWarning('Optimization failed within `scipy.optimize.minimize` with status 2 and message ABNORMAL: .'), NumericalWarning('A not p.d., added jitter of 1.0e-08 to the diagonal')]
Trying again with a new set of initial conditions.
return _optimize_acqf_batch(opt_inputs=opt_inputs)
/opt/hostedtoolcache/Python/3.12.14/x64/lib/python3.12/site-packages/linear_operator/utils/cholesky.py:41: NumericalWarning: A not p.d., added jitter of 1.0e-08 to the diagonal
warnings.warn(
/opt/hostedtoolcache/Python/3.12.14/x64/lib/python3.12/site-packages/linear_operator/utils/cholesky.py:41: NumericalWarning: A not p.d., added jitter of 1.0e-08 to the diagonal
warnings.warn(
---title: Spherical linear kernels for high dimensional BOjupyter: python3---[Spherical Linear Kernel](https://arxiv.org/pdf/2512.00170) is useful for optimizing high-dimensional problems.```{python}from bofire.benchmarks.svm import SVMfrom bofire.data_models.strategies.api import SoboStrategyfrom bofire.data_models.kernels.api import SphericalLinearKernelfrom bofire.data_models.surrogates.api import SingleTaskGPSurrogate, BotorchSurrogatesimport bofire.strategies.api as strategies```We use the [SVM](https://github.com/LeoIV/BenchSuite/blob/master/benchsuite/svm.py) benchmark.```{python}# problem setup for spherical linear kernelsbenchmark = SVM()candidates = benchmark._domain.inputs.sample(benchmark.dim+1, seed=benchmark.seed)experiments = candidates.copy()result = benchmark._f(experiments)# Add empty columns 'y' and 'valid_y' to experiments DataFrameexperiments["y"], experiments["valid_y"] = result["y"], result["valid_y"]sobo_strategy_data_model = SoboStrategy( domain=benchmark._domain, seed=benchmark.seed, surrogate_specs=BotorchSurrogates( surrogates=[ SingleTaskGPSurrogate( inputs=benchmark._domain.inputs, outputs=benchmark._domain.outputs, kernel=SphericalLinearKernel(), ) ] ),)strategy = strategies.map(sobo_strategy_data_model)```Running the optimization loop```{python}strategy.tell(experiments, replace=True)num_steps =3# set the number of steps here (the original paper uses 1000 steps)for step_number inrange(num_steps):print(f"Step {step_number+1}/{num_steps}") new_candidates = strategy.ask(candidate_count=1) new_experiments = new_candidates.copy() result = benchmark._f(new_candidates) new_experiments["y"], new_experiments["valid_y"] = result["y"], result["valid_y"]print(f"New experiment:\n{new_experiments}") strategy.tell(experiments=new_experiments)# save all the experimentsall_experiments = strategy.experiments```One can use the results obtained in ```all_experiments``` to get the evolution of the optimum with respect to the iterations.