evotoolkit.solve()¶
evotoolkit.solve
¶
solve(
interface: BaseMethodInterface,
output_path: str = "./results",
**kwargs,
) -> Any
Factory method to create and run an evolutionary optimization workflow.
This is the main entry point for using evotool with an explicit, unambiguous API. Users must explicitly create task and interface instances before calling solve().
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
interface
|
BaseMethodInterface
|
Interface instance (e.g.,
|
required |
output_path
|
str
|
Path to save results. |
'./results'
|
**kwargs
|
Any
|
Additional parameters passed to algorithm config
(e.g., |
{}
|
Returns:
| Name | Type | Description |
|---|---|---|
Any |
Any
|
Best solution found during the evolutionary optimization run. |
Example
Create task instance explicitly¶
task = FuncApproxTask(x_data, y_noisy, y_true)
Create interface instance explicitly¶
interface = EoHPythonInterface(task)
Call solve with explicit interface¶
result = evotool.solve( interface=interface, output_path='./results', running_llm=llm_api, max_generations=5, max_sample_nums=10 )
Source code in src/evotoolkit/__init__.py
示例¶
import evotoolkit
from evotoolkit.task.python_task.scientific_regression import ScientificRegressionTask
from evotoolkit.task.python_task import EvoEngineerPythonInterface
from evotoolkit.tools import HttpsApi
# 创建任务
task = ScientificRegressionTask(dataset_name="bactgrow")
# 创建接口
interface = EvoEngineerPythonInterface(task)
# 配置 LLM
llm_api = HttpsApi(
api_url="https://api.openai.com/v1/chat/completions",
key="your-api-key",
model="gpt-4o"
)
# 求解
result = evotoolkit.solve(
interface=interface,
output_path='./results',
running_llm=llm_api,
max_generations=5,
max_sample_nums=10,
pop_size=5
)
print(f"最佳得分: {result.evaluation_res.score}")