import sys
import os
import torch
import numpy as np
root_dir = os.path.abspath(os.path.join(os.path.dirname(__file__), "../../"))
if root_dir not in sys.path:
sys.path.append(root_dir)
from evogo_torch.evogo import EvoGO
from test_functions.simple_functions import Rosenbrock
if __name__ == "__main__":
dim = 5
num_parallel = 2
seed = 42
device = "cuda:0" if torch.cuda.is_available() else "cpu"
device_obj = torch.device(device)
print(f"Running on {device}")
objective_fn = Rosenbrock(
dim=dim,
device=device_obj,
parallels=num_parallel
)
solver = EvoGO(
max_iter=10,
batch_size=1000,
gm_batch_size=1000,
num_parallel=num_parallel,
use_gp=True,
debug=True,
gpu_id=0 if "cuda" in device else -1
)
print(f"Starting to solve {dim}-dimensional Rosenbrock function...")
best_x, best_y = solver.solve(objective_fn, dim=dim, seed=seed, device=device)
print("\n" + "="*30)
print(f"Optimization Complete!")
print(f"Best x (normalized input to solver): {best_x}")
print(f"Best y: {best_y}")
print("="*30)