Skip to content

Commit d9da066

Browse files
committed
docs: document experiment management
1 parent 053d90c commit d9da066

File tree

4 files changed

+62
-8
lines changed

4 files changed

+62
-8
lines changed

README.md

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,10 @@ $ export OPENAI_API_KEY=sk-...
2323
$ export HF_ACCESS_TOKEN=hf_
2424
```
2525

26-
Launch the evolution controller
26+
Launch the evolution controller (create a fresh experiment)
2727

28-
```python
29-
python scripts/run_example.py
28+
```bash
29+
python scripts/run_example.py --experiment my_exp
3030
```
3131

3232
Monitor the evolution process in real‑time using the optional Streamlit dashboard:
@@ -37,6 +37,16 @@ $ streamlit run scripts/dashboard.py
3737

3838
The dashboard uses Streamlit to visualize the evolution process and back‑test results.
3939

40+
### Managing experiments
41+
42+
Use the `--experiment` option to keep runs separate:
43+
44+
```bash
45+
python scripts/run_example.py --experiment my_exp
46+
```
47+
48+
This creates a new SQLite file `my_exp.db` under `~/.alphaevolve/`. The dashboard lists all experiments, allowing you to switch between them or delete one via the **Delete experiment** sidebar button.
49+
4050
---
4151

4252
## ⚙️ Installation
@@ -87,7 +97,7 @@ export LOCAL_MODEL_PATH=~/.cache/phi-2 # or set LOCAL_MODEL_NAME
8797
Run the evolution loop with the local model:
8898

8999
```bash
90-
python scripts/run_example.py
100+
python scripts/run_example.py --experiment my_exp
91101
```
92102

93103
---

alphaevolve/engine.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
from alphaevolve.evolution.controller import Controller
1111
from alphaevolve.store.sqlite import ProgramStore
12+
from alphaevolve.config import settings
1213
from examples import config as example_settings
1314

1415
__all__ = ["AlphaEvolve", "Strategy"]
@@ -31,9 +32,18 @@ def __init__(
3132
initial_program_paths: list[str],
3233
*,
3334
store: ProgramStore | None = None,
35+
experiment_name: str | None = None,
3436
) -> None:
3537
self.initial_program_paths = [Path(p) for p in initial_program_paths]
36-
self.store = store or ProgramStore()
38+
if store is not None:
39+
self.store = store
40+
else:
41+
if experiment_name:
42+
base = Path(settings.sqlite_db).expanduser()
43+
db_path = base.parent / f"{experiment_name}.db"
44+
self.store = ProgramStore(db_path=db_path)
45+
else:
46+
self.store = ProgramStore()
3747
metrics = (
3848
example_settings.BRANCH_METRICS if example_settings.MULTI_BRANCH_MUTATION else [None]
3949
)

scripts/dashboard.py

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,16 @@
1111
* Inspect source code in expandable section
1212
"""
1313
from __future__ import annotations
14+
import os
1415
import textwrap
1516
import streamlit as st
1617
import pandas as pd
1718
import matplotlib.pyplot as plt
1819

20+
from pathlib import Path
21+
1922
from alphaevolve.store.sqlite import ProgramStore
23+
from alphaevolve.config import settings
2024
from examples import config as example_config
2125
from alphaevolve.evaluator.backtest import (
2226
_load_module_from_code, # type: ignore (private helper is okay for internal app)
@@ -25,7 +29,21 @@
2529
)
2630

2731
st.set_page_config(page_title="Alpha‑Evolve Dashboard", layout="wide")
28-
store = ProgramStore()
32+
33+
db_dir = Path(settings.sqlite_db).expanduser().parent
34+
db_files = sorted(db_dir.glob("*.db"))
35+
experiments = [f.stem for f in db_files]
36+
if not experiments:
37+
st.warning("No experiments found – run the controller first.")
38+
st.stop()
39+
40+
selected_exp = st.sidebar.selectbox("Experiment", experiments)
41+
db_path = db_dir / f"{selected_exp}.db"
42+
if st.sidebar.button("Delete experiment"):
43+
os.remove(db_path)
44+
st.experimental_rerun()
45+
46+
store = ProgramStore(db_path)
2947

3048
# ------------------------------------------------------------------
3149
# Hall of Fame table

scripts/run_example.py

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,30 @@
1+
import argparse
12
import asyncio
23

34
from alphaevolve import AlphaEvolve
45

6+
parser = argparse.ArgumentParser(description="Run AlphaEvolve demo")
7+
parser.add_argument(
8+
"--experiment",
9+
type=str,
10+
default=None,
11+
help="Experiment name (creates or resumes a SQLite DB)",
12+
)
13+
parser.add_argument(
14+
"--iterations", type=int, default=10, help="Number of evolution iterations"
15+
)
16+
args = parser.parse_args()
17+
518
# Initialize the system
6-
evolve = AlphaEvolve(initial_program_paths=["examples/sma_momentum.py"])
19+
evolve = AlphaEvolve(
20+
initial_program_paths=["examples/sma_momentum.py"],
21+
experiment_name=args.experiment,
22+
)
723

824

925
# Run the evolution
1026
async def main() -> None:
11-
best_strategy = await evolve.run(iterations=10)
27+
best_strategy = await evolve.run(iterations=args.iterations)
1228
print("Best strategy metrics:")
1329
for name, value in best_strategy.metrics.items():
1430
print(f" {name}: {value:.4f}")

0 commit comments

Comments
 (0)