Understanding the Code¶
Let's break down what each part does:
1. Task Creation¶
A Task defines what problem you're solving and how to evaluate solutions. ScientificRegressionTask is a built-in task for discovering mathematical equations from real scientific datasets. The datasets are automatically downloaded on first use (lazy loading).
2. Interface Creation¶
An Interface connects your task to a specific evolutionary algorithm. Here we use EvoEngineerPythonInterface for the EvoEngineer algorithm.
3. LLM Configuration¶
llm_api = HttpsApi(
api_url="https://api.openai.com/v1/chat/completions",
key="your-api-key-here",
model="gpt-4o"
)
This sets up the LLM API client that will generate and improve code solutions. Replace your-api-key-here with your actual API key.
4. Solving the Problem¶
result = evotoolkit.solve(
interface=interface,
output_path='./results',
running_llm=llm_api,
max_generations=5,
max_sample_nums=10,
pop_size=5
)
The evotoolkit.solve() function:
- Runs the evolutionary algorithm for 5 generations
- Uses a population size of 5
- Samples up to 10 LLM responses per generation
- Saves results to
./results/
Next: Exploring the Results