Adding a custom problemΒΆ
This tutorial demonstrates how to extend BLADE with your own optimization problem and evaluate it using LLaMEA.
[ ]:
# Optional setup (required on COLAB)
!pip install swig
!pip install iohblade
[1]:
from iohblade.problem import Problem
from iohblade.experiment import Experiment
from iohblade.llm import Ollama_LLM
from iohblade.methods import LLaMEA
from iohblade.loggers import ExperimentLogger
import numpy as np
[2]:
class CustomSphere(Problem):
def __init__(self, dims=5, budget_factor=1000, name='Sphere'):
super().__init__(name=name, training_instances=[(1,1)])
def evaluate(self, x):
return {'fitness': float(np.sum(np.array(x)**2))}
def test(self, x):
pass
def to_dict(self):
return {"name":"Sphere"}
Tip: Make sure OLlama is running and the model is downloaded before executing the next cell. When using COLAB, you might need to set up port forwarding to connect to your local Ollama instance or use Gemini/OpenAI instead.
[ ]:
llm = Ollama_LLM('qwen2.5-coder:14b') # Make sure Ollama is running and the model is downloaded.
method = LLaMEA(llm, budget=30)
problems = [CustomSphere()]
logger = ExperimentLogger('custom_problem')
experiment = Experiment(methods=[method], problems=problems, runs=1, exp_logger=logger, show_stdout=True)
Warning: The next step might take several hours to run (depending on the budget and number of runs)
[ ]:
experiment()