Usage: Python Library
Beyond the CLI, AIDE ML can be used as a Python library, allowing you to integrate its optimization capabilities directly into your Python scripts and workflows. The core of the library is the aide.Experiment
class.
The Experiment
Class
This class encapsulates a single AIDE ML run. You initialize it with your task details and then call the run()
method to start the agent.
Basic Example
Here is a simple example of how to use aide.Experiment
in a Python script, based on the example from the README.md
.
import aide
import logging
def main():
# Set up logging to see the agent's progress
logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(name)s - %(levelname)s - %(message)s')
aide_logger = logging.getLogger("aide")
aide_logger.setLevel(logging.INFO)
print("Starting experiment...")
# 1. Initialize the Experiment
exp = aide.Experiment(
data_dir="aide/example_tasks/bitcoin_price",
goal="Build a time series forecasting model for bitcoin close price.",
eval="RMSLE" # Root Mean Squared Log Error
)
# 2. Run the agent for a specified number of steps
best_solution = exp.run(steps=5)
# 3. Access the results
print("\n--- Experiment Finished ---")
print(f"Best solution validation metric: {best_solution.valid_metric:.4f}")
print("Best solution code:")
print(best_solution.code)
print("-------------------------")
if __name__ == '__main__':
main()
Breakdown
import aide
: Imports the necessary library.aide.Experiment(...)
: This creates and configures a new experiment.data_dir
: Path to the dataset directory.goal
: The high-level task description for the agent.eval
: The evaluation metric to optimize.
exp.run(steps=5)
: This is the main call that starts the agentic tree search process. The agent will run for the number of iterations specified by thesteps
argument.- Return Value: The
run()
method returns aSolution
object, which is a dataclass containing the best solution found during the search.best_solution.code
: A string containing the Python code of the best solution.best_solution.valid_metric
: The validation metric value achieved by the best solution.
Using AIDE ML as a library is ideal for automated workflows, programmatic experiments, or integrating its code generation capabilities into a larger application.