Skip to content

Commit fa1ed28

Browse files
committed
Fixed most issues with Gemini
1 parent 6ae103a commit fa1ed28

12 files changed

Lines changed: 82 additions & 34 deletions

File tree

‎examples/run-automl.py‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
llm1 = Gemini_LLM(api_key_gemini, "gemini-2.0-flash")
1515
#llm2 = OpenAI_LLM(api_key,"gpt-4.1-nano-2025-04-14", temperature=1.0)
16-
budget = 10
16+
budget = 3
1717

1818
mutation_prompts = [
1919
"Refine the strategy of the selected solution to improve it.", # small mutation
@@ -23,11 +23,11 @@
2323

2424
for llm in [llm1]:
2525
LLaMEA_method = LLaMEA(llm, budget=budget, name="LLaMEA", mutation_prompts=mutation_prompts, n_parents=1, n_offspring=1, elitism=True)
26-
ReEvo_method = ReEvo(llm, budget=budget, name="ReEvo", output_path="results/automl-breast-cancer", pop_size=2, init_pop_size=4)
27-
EoH_method = EoH(llm, budget=budget, name="EoH", output_path="results/automl-breast-cancer")
26+
#ReEvo_method = ReEvo(llm, budget=budget, name="ReEvo", output_path="results/automl-breast-cancer", pop_size=2, init_pop_size=4)
27+
#EoH_method = EoH(llm, budget=budget, name="EoH", output_path="results/automl-breast-cancer")
2828
methods = [LLaMEA_method] #EoH_method, ReEvo_method,
2929
logger = ExperimentLogger("results/automl-breast-cancer-new")
3030
problems = [AutoML()]
31-
experiment = Experiment(methods=methods, problems=problems, runs=1, show_stdout=False, exp_logger=logger, budget=budget, n_jobs=3) #normal run
31+
experiment = Experiment(methods=methods, problems=problems, runs=1, show_stdout=True, exp_logger=logger, budget=budget, n_jobs=3) #normal run
3232

3333
experiment() #run the experiment

‎examples/run-mabbob.py‎

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from iohblade.experiment import MA_BBOB_Experiment
2-
from iohblade.llm import Gemini_LLM, Ollama_LLM
2+
from iohblade.llm import Gemini_LLM, Ollama_LLM, Dummy_LLM
33
from iohblade.methods import LLaMEA, RandomSearch
44
from iohblade.loggers import ExperimentLogger
55
import numpy as np
@@ -10,7 +10,7 @@
1010
ai_model = "gemini-2.0-flash"
1111
llm1 = Gemini_LLM(api_key, ai_model)
1212
llm2 = Ollama_LLM("codestral")
13-
budget = 100
13+
budget = 10
1414

1515

1616
mutation_prompts1 = [
@@ -34,15 +34,15 @@
3434

3535
for llm in [llm1]:#, llm2]:
3636
#RS = RandomSearch(llm, budget=budget) #LLaMEA(llm)
37-
LLaMEA_method1 = LLaMEA(llm, budget=budget, name="LLaMEA-1", mutation_prompts=mutation_prompts1, n_parents=4, n_offspring=12, elitism=False)
38-
LLaMEA_method2 = LLaMEA(llm, budget=budget, name="LLaMEA-2", mutation_prompts=mutation_prompts2, n_parents=4, n_offspring=12, elitism=False)
39-
LLaMEA_method3 = LLaMEA(llm, budget=budget, name="LLaMEA-3", mutation_prompts=mutation_prompts3, n_parents=4, n_offspring=12, elitism=False)
40-
LLaMEA_method4 = LLaMEA(llm, budget=budget, name="LLaMEA-4", mutation_prompts=mutation_prompts4, n_parents=4, n_offspring=12, elitism=False)
41-
LLaMEA_method5 = LLaMEA(llm, budget=budget, name="LLaMEA-5", mutation_prompts=mutation_prompts5, n_parents=4, n_offspring=12, elitism=False)
37+
LLaMEA_method1 = LLaMEA(llm, budget=budget, name="LLaMEA-1", mutation_prompts=mutation_prompts1, n_parents=1, n_offspring=1, elitism=False)
38+
# LLaMEA_method2 = LLaMEA(llm, budget=budget, name="LLaMEA-2", mutation_prompts=mutation_prompts2, n_parents=4, n_offspring=12, elitism=False)
39+
# LLaMEA_method3 = LLaMEA(llm, budget=budget, name="LLaMEA-3", mutation_prompts=mutation_prompts3, n_parents=4, n_offspring=12, elitism=False)
40+
# LLaMEA_method4 = LLaMEA(llm, budget=budget, name="LLaMEA-4", mutation_prompts=mutation_prompts4, n_parents=4, n_offspring=12, elitism=False)
41+
# LLaMEA_method5 = LLaMEA(llm, budget=budget, name="LLaMEA-5", mutation_prompts=mutation_prompts5, n_parents=4, n_offspring=12, elitism=False)
4242

4343
methods = [LLaMEA_method1] #, LLaMEA_method4, LLaMEA_method5]#, LLaMEA_method4, LLaMEA_method5]
44-
logger = ExperimentLogger("results/MA-BBOB")
45-
experiment = MA_BBOB_Experiment(methods=methods, runs=2, seeds=[4,7], dims=[5], budget_factor=2000, budget=100, eval_timeout=60, show_stdout=True, exp_logger=logger) #normal run
44+
logger = ExperimentLogger("results/MA-BBOB-test")
45+
experiment = MA_BBOB_Experiment(methods=methods, runs=2, seeds=[4,7], dims=[5], budget_factor=200, budget=10, eval_timeout=60, show_stdout=True, exp_logger=logger) #normal run
4646
experiment() #run the experiment
4747

4848

‎iohblade/llm.py‎

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -420,6 +420,7 @@ def __init__(
420420
}
421421

422422
self.client = genai.Client(api_key=api_key)
423+
self.api_key = api_key
423424
self.generation_config = generation_config
424425

425426
def _query(
@@ -470,6 +471,27 @@ def _query(
470471

471472
time.sleep(wait)
472473

474+
# ---------- pickling / deepcopy helpers ----------
475+
def __getstate__(self):
476+
state = self.__dict__.copy()
477+
state.pop("client", None)
478+
return state
479+
480+
def __setstate__(self, state):
481+
self.__dict__.update(state)
482+
self.client = genai.Client(api_key=self.api_key)
483+
484+
def __deepcopy__(self, memo):
485+
cls = self.__class__
486+
new = cls.__new__(cls)
487+
memo[id(self)] = new
488+
for k, v in self.__dict__.items():
489+
if k == "client":
490+
continue
491+
setattr(new, k, copy.deepcopy(v, memo))
492+
new.client = genai.Client(api_key=new.api_key)
493+
return new
494+
473495

474496
class Ollama_LLM(LLM):
475497
def __init__(self, model="llama3.2", **kwargs):

‎iohblade/problem.py‎

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,9 @@
1515

1616
# Standard packages installed in every evaluation environment
1717
BASE_DEPENDENCIES = [
18-
"numpy>=1.26.3,<2",
18+
"numpy>=2",
1919
"cloudpickle>=3.1.0,<4",
2020
"joblib>=1.4.2,<2",
21-
# "pandas==2.0.3",
22-
# "polars==1.31.0",
23-
# "scikit-learn==1.3.0",
2421
]
2522

2623
import copy
@@ -72,15 +69,14 @@ def evaluate_in_subprocess(problem, conn, solution):
7269
[str(python_bin), str(script_path)],
7370
check=True,
7471
env=env,
75-
capture_output=False,
72+
capture_output=True,
7673
text=True,
7774
)
7875
with open(result_pickle, "rb") as f:
7976
result = cloudpickle.load(f)
8077
conn.send(result)
8178
except subprocess.CalledProcessError as e:
8279
# Process returned non-zero exit code
83-
print(e.stderr)
8480
conn.send(e.stderr)
8581

8682
except Exception as e:
@@ -159,7 +155,6 @@ def __call__(self, solution: Solution, logger=None):
159155
Returns:
160156
Solution: The evaluated solution with updated fitness and scores.
161157
"""
162-
print("in __call__")
163158
if logger != None:
164159
print("LOGGER is NOT NONE (UNEXPECTED)")
165160
self.logger = logger
@@ -218,7 +213,6 @@ def __call__(self, solution: Solution, logger=None):
218213
process.join()
219214
except Exception:
220215
pass
221-
print("sol", solution.name)
222216
if self.logger is not None:
223217
self.logger.log_individual(solution)
224218
return solution

‎iohblade/problems/automl.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ def __init__(
3434
imports=None,
3535
):
3636
if dependencies is None:
37-
dependencies = ["pandas==2.0.3", "polars==1.31.0", "scikit-learn==1.3.0"]
37+
dependencies = ["pandas==2.2.3", "polars==1.31.0", "scikit-learn==1.3.0"]
3838
if imports is None:
3939
imports = "import pandas as pd\nimport polars\nimport sklearn\n"
4040

‎iohblade/problems/bbob_sboxcost.py‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,8 @@ def __init__(
7171
"""
7272
if dependencies is None:
7373
dependencies = [
74-
"pandas==2.0.3",
75-
"ioh==0.3.18",
74+
"pandas==2.2.3",
75+
"ioh==0.3.19",
7676
"configspace==1.2.1",
7777
"smac==2.3.1",
7878
]

‎iohblade/problems/kerneltuner.py‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,8 @@ def __init__(
7878
dependencies = [
7979
"kernel-tuner @ git+https://github.com/XAI-liacs/kernel_tuner.git@hyperparametertuning_custom_strategies",
8080
"autotuning-methodology @ git+https://github.com/AutoTuningAssociation/autotuning_methodology.git@6a9a50a5a49bc104469b3b753fd43a5324241702",
81-
"pandas==2.0.3",
82-
"ioh==0.3.18",
81+
"pandas==2.2.3",
82+
"ioh==0.3.19",
8383
"configspace==1.2.1",
8484
"smac==2.3.1",
8585
]

‎iohblade/problems/mabbob.py‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,8 @@ def __init__(
5050
"""
5151
if dependencies is None:
5252
dependencies = [
53-
"pandas==2.0.3",
54-
"ioh==0.3.18",
53+
"pandas==2.2.3",
54+
"ioh==0.3.19",
5555
"configspace==1.2.1",
5656
"smac==2.3.1",
5757
]

‎iohblade/problems/photonics.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ def __init__(
4545
seeds (int): Number of random runs.
4646
"""
4747
if dependencies is None:
48-
dependencies = ["ioh==0.3.18", "pandas==2.0.3"]
48+
dependencies = ["ioh==0.3.19", "pandas==2.2.3"]
4949
if imports is None:
5050
imports = "import numpy as np\nimport ioh\n"
5151

‎iohblade/solution.py‎

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,38 @@ def to_dict(self):
164164
"task_prompt": self.task_prompt,
165165
}
166166

167+
def from_dict(self, data):
168+
"""
169+
Updates the Solution instance from a dictionary.
170+
Args:
171+
data (dict): A dictionary representation of the individual.
172+
Returns:
173+
None
174+
"""
175+
configspace = data.get("configspace", None)
176+
177+
if isinstance(configspace, dict): # Deserialize if necessary
178+
try:
179+
configspace = ConfigSpace() # Replace with actual class
180+
configspace.from_serialized_dict(data["configspace"])
181+
except Exception as e:
182+
print(f"Warning: Failed to deserialize configspace - {e}")
183+
configspace = None
184+
185+
# Update instance attributes
186+
self.id = data.get("id")
187+
self.fitness = data.get("fitness")
188+
self.name = data.get("name")
189+
self.description = data.get("description")
190+
self.code = data.get("code")
191+
self.configspace = configspace
192+
self.generation = data.get("generation")
193+
self.feedback = data.get("feedback")
194+
self.error = data.get("error")
195+
self.parent_ids = data.get("parent_ids", [])
196+
self.operator = data.get("operator")
197+
self.metadata = data.get("metadata", {})
198+
167199
def to_json(self):
168200
"""
169201
Converts the individual to a JSON string.

0 commit comments

Comments
 (0)