π Run Module API Referenceο
The run module provides the main interface for executing and analyzing experiments.
Main user interface for running experiments.
This module provides the simple, intelligent interface that users interact with. No complex configuration needed - just run experiments and get insights.
- class rexf.run.ExperimentRunner(storage_path='experiments.db', intelligent=True)[source]ο
Bases:
objectIntelligent experiment runner with zero configuration.
This replaces the complex ExperimentRunner with a much simpler interface focused on user experience rather than architectural purity.
- __init__(storage_path='experiments.db', intelligent=True)[source]ο
Initialize with minimal configuration.
- best(metric=None, top=5)[source]ο
Get the best experiments by a metric.
- Parameters:
- Return type:
- Returns:
List of best experiments
- find(query)[source]ο
Find experiments using query expressions.
Supports queries like: - βaccuracy > 0.9β - βstatus == βcompletedββ - βruntime < 60β - βparam_learning_rate between 0.001 and 0.01β
- Parameters:
query (
str) β Query expression string- Return type:
- Returns:
List of matching experiments
- suggest(experiment_func=None, count=3, strategy='balanced', optimization_target=None)[source]ο
Suggest next experiments to run.
- Parameters:
- Return type:
- Returns:
Dictionary with parameter suggestions and reasoning
- auto_explore(experiment_func, strategy='random', budget=10, parameter_ranges=None, optimization_target=None)[source]ο
Automatically explore parameter space for an experiment.
- Parameters:
experiment_func β Function decorated with @experiment
strategy (
str) β Exploration strategy (βrandomβ, βgridβ, βadaptiveβ)budget (
int) β Number of experiments to runparameter_ranges (
Optional[Dict[str,Any]]) β Dict of parameter name -> range specificationoptimization_target (
Optional[str]) β Metric to optimize for
- Return type:
- Returns:
List of experiment run IDs
- metric_trends(metric_name, experiment_name=None)[source]ο
Get trends for a specific metric over time.
- rexf.run.single(experiment_func, **params)[source]ο
Run a single experiment. See ExperimentRunner.single().
- Return type:
- rexf.run.best(metric=None, top=5)[source]ο
Get best experiments. See ExperimentRunner.best().
- Return type:
- rexf.run.recent(hours=24)[source]ο
Get recent experiments. See ExperimentRunner.recent().
- Return type:
- rexf.run.find(query)[source]ο
Find experiments by query. See ExperimentRunner.find().
- Return type:
- rexf.run.compare(experiments=None)[source]ο
Compare experiments. See ExperimentRunner.compare().
- Return type:
- rexf.run.insights(experiment_name=None)[source]ο
Get experiment insights. See ExperimentRunner.insights().
- rexf.run.suggest(experiment_func=None, count=3, strategy='balanced', optimization_target=None)[source]ο
Get experiment suggestions. See ExperimentRunner.suggest().
- rexf.run.parameter_space(experiment_name=None)[source]ο
Get parameter space analysis. See ExperimentRunner.parameter_space().
- rexf.run.metric_trends(metric_name, experiment_name=None)[source]ο
Get metric trends. See ExperimentRunner.metric_trends().
- rexf.run.auto_explore(experiment_func, strategy='random', budget=10, parameter_ranges=None, optimization_target=None)[source]ο
Auto-explore parameter space. See ExperimentRunner.auto_explore().
- rexf.run.dashboard(host='localhost', port=8080, open_browser=True)[source]ο
Launch web dashboard. See ExperimentRunner.dashboard().
- Return type:
Quick Referenceο
from rexf import run
# Execute experiments
run_id = run.single(my_experiment, param1=value1)
run_ids = run.auto_explore(my_experiment, strategy="random", budget=10)
# Retrieve results
experiments = run.all()
recent = run.recent(hours=6)
best = run.best(metric="accuracy", top=5)
found = run.find("accuracy > 0.9")
# Analysis and insights
insights = run.insights()
suggestions = run.suggest(my_experiment, count=5)
run.compare(best[:3])
# Interactive tools
run.dashboard()
Execution Functionsο
single()ο
Execute a single experiment with specified parameters.
- rexf.run.single(experiment_func, **params)[source]ο
Run a single experiment. See ExperimentRunner.single().
- Return type:
# Basic usage
run_id = run.single(my_experiment)
# With parameters
run_id = run.single(my_experiment, learning_rate=0.01, epochs=100)
# With keyword arguments
run_id = run.single(
my_experiment,
**{"learning_rate": 0.01, "batch_size": 32}
)
auto_explore()ο
Automatically explore parameter space using different strategies.
- rexf.run.auto_explore(experiment_func, strategy='random', budget=10, parameter_ranges=None, optimization_target=None)[source]ο
Auto-explore parameter space. See ExperimentRunner.auto_explore().
# Random exploration
run_ids = run.auto_explore(
my_experiment,
strategy="random",
budget=20,
optimization_target="accuracy"
)
# Grid search
run_ids = run.auto_explore(
my_experiment,
strategy="grid",
budget=15,
parameter_ranges={
"learning_rate": [0.001, 0.01, 0.1],
"batch_size": [32, 64, 128]
}
)
# Adaptive/Bayesian optimization
run_ids = run.auto_explore(
my_experiment,
strategy="adaptive",
budget=25,
optimization_target="accuracy"
)
Retrieval Functionsο
all()ο
Get all experiments from the database.
experiments = run.all()
print(f"Total experiments: {len(experiments)}")
recent()ο
Get experiments from recent time period.
- rexf.run.recent(hours=24)[source]ο
Get recent experiments. See ExperimentRunner.recent().
- Return type:
# Last 24 hours (default)
recent_experiments = run.recent()
# Last 6 hours
last_6h = run.recent(hours=6)
# Last 2 days
last_2d = run.recent(hours=48)
best()ο
Get top-performing experiments by a specific metric.
- rexf.run.best(metric=None, top=5)[source]ο
Get best experiments. See ExperimentRunner.best().
- Return type:
# Top 5 by accuracy (descending)
top_accuracy = run.best(metric="accuracy", top=5)
# Fastest experiments (ascending order)
fastest = run.best(metric="training_time", top=3, ascending=True)
# Best from specific experiment
best_ml = run.best(
metric="f1_score",
top=10,
experiment_name="ml_experiment"
)
find()ο
Query experiments using expression strings.
- rexf.run.find(query)[source]ο
Find experiments by query. See ExperimentRunner.find().
- Return type:
# Simple comparisons
high_acc = run.find("accuracy > 0.9")
fast_runs = run.find("training_time < 60")
recent_good = run.find("accuracy > 0.8 and start_time > '2024-01-01'")
# Parameter queries (use param_ prefix)
low_lr = run.find("param_learning_rate < 0.01")
large_batches = run.find("param_batch_size >= 64")
# Range queries
moderate_acc = run.find("accuracy between 0.7 and 0.9")
# Status queries
completed = run.find("status == 'completed'")
failed = run.find("status == 'failed'")
Query Operatorsο
Supported operators in find() expressions:
Comparison:
>,>=,<,<=,==,!=Range:
between(e.g.,"value between 0.1 and 0.9")Logical:
and(orsupport coming soon)
Query Examples:
# Numeric comparisons
run.find("accuracy > 0.95")
run.find("loss <= 0.1")
run.find("epochs != 100")
# String comparisons
run.find("status == 'completed'")
run.find("param_optimizer == 'adam'")
# Range queries
run.find("accuracy between 0.8 and 0.95")
run.find("param_learning_rate between 0.001 and 0.1")
# Combined conditions
run.find("accuracy > 0.9 and training_time < 300")
run.find("param_batch_size >= 32 and status == 'completed'")
by_name()ο
Get experiments by experiment function name.
# Get all runs of specific experiment
ml_experiments = run.by_name("ml_hyperparameter_search")
# Get recent runs of specific experiment
recent_ml = run.by_name("ml_experiment", limit=10)
get_by_id()ο
Get a specific experiment by its run ID.
# Get specific experiment
experiment = run.get_by_id("abc123def456")
if experiment:
print(f"Status: {experiment.status}")
print(f"Metrics: {experiment.metrics}")
print(f"Parameters: {experiment.parameters}")
Analysis Functionsο
insights()ο
Generate intelligent insights from experiment data.
- rexf.run.insights(experiment_name=None)[source]ο
Get experiment insights. See ExperimentRunner.insights().
# Overall insights
insights = run.insights()
# Insights for specific experiment
ml_insights = run.insights(experiment_name="ml_experiment")
# Access insight categories
summary = insights["summary"]
param_insights = insights["parameter_insights"]
performance = insights["performance_insights"]
correlations = insights["correlation_insights"]
anomalies = insights["anomaly_insights"]
recommendations = insights["recommendations"]
Example insight structure:
{
"summary": {
"total_experiments": 150,
"success_rate": 0.92,
"avg_accuracy": 0.847,
"total_duration": 3600.5
},
"parameter_insights": {
"learning_rate": {
"impact_score": 0.85,
"optimal_range": [0.001, 0.01],
"correlation": 0.72
}
},
"performance_insights": {
"fastest_duration": 45.2,
"slowest_duration": 320.1,
"avg_duration": 120.5
},
"recommendations": [
{
"title": "Optimize learning rate",
"description": "Try learning rates between 0.005 and 0.015",
"priority": "high"
}
]
}
suggest()ο
Get intelligent suggestions for next experiments.
- rexf.run.suggest(experiment_func=None, count=3, strategy='balanced', optimization_target=None)[source]ο
Get experiment suggestions. See ExperimentRunner.suggest().
# Basic suggestions
suggestions = run.suggest(my_experiment, count=5)
# Exploitation strategy (focus on best regions)
exploit_suggestions = run.suggest(
my_experiment,
count=3,
strategy="exploit",
optimization_target="accuracy"
)
# Exploration strategy (try new regions)
explore_suggestions = run.suggest(
my_experiment,
count=5,
strategy="explore"
)
# Balanced strategy (mix of both)
balanced_suggestions = run.suggest(
my_experiment,
count=4,
strategy="balanced",
optimization_target="f1_score"
)
# Use suggestions
for suggestion in suggestions["suggestions"]:
print(f"Try: {suggestion['parameters']}")
print(f"Reason: {suggestion['reasoning']}")
print(f"Expected improvement: {suggestion['expected_improvement']}")
compare()ο
Compare multiple experiments side-by-side.
- rexf.run.compare(experiments=None)[source]ο
Compare experiments. See ExperimentRunner.compare().
- Return type:
# Compare best experiments
best_experiments = run.best(metric="accuracy", top=3)
run.compare(best_experiments)
# Compare specific experiments by ID
run.compare(["run_id_1", "run_id_2", "run_id_3"])
# Compare from query results
high_accuracy = run.find("accuracy > 0.9")
run.compare(high_accuracy[:5])
The comparison displays:
Parameter differences between experiments
Metric comparisons with statistical analysis
Performance analysis
Recommendations based on differences
Interactive Functionsο
dashboard()ο
Launch the interactive web dashboard.
- rexf.run.dashboard(host='localhost', port=8080, open_browser=True)[source]ο
Launch web dashboard. See ExperimentRunner.dashboard().
- Return type:
# Launch with defaults (localhost:8080)
run.dashboard()
# Custom host and port
run.dashboard(host="0.0.0.0", port=9000)
# Don't open browser automatically
run.dashboard(open_browser=False)
query_help()ο
Get help with query syntax and suggestions.
# Get query suggestions
suggestions = run.query_help()
print("Suggested queries:")
for suggestion in suggestions:
print(f" {suggestion}")
# Example output:
# accuracy > 0.9
# param_learning_rate < 0.01
# training_time between 60 and 300
Utility Functionsο
summary()ο
Get a quick summary of all experiments.
summary = run.summary()
print(f"Total experiments: {summary['total']}")
print(f"Successful: {summary['successful']}")
print(f"Failed: {summary['failed']}")
print(f"Average duration: {summary['avg_duration']:.2f}s")
stats()ο
Get detailed statistics about experiments.
stats = run.stats()
# Experiment counts by name
by_name = stats["by_experiment_name"]
# Success/failure rates
success_rate = stats["success_rate"]
# Performance statistics
performance = stats["performance_stats"]
Advanced Usageο
Working with ExperimentRunnerο
For advanced use cases, you can work directly with the ExperimentRunner:
from rexf.run import ExperimentRunner
# Create custom runner with specific storage path
runner = ExperimentRunner(storage_path="custom_experiments.db")
# Use custom runner
run_id = runner.single(my_experiment, param1=value1)
# Get insights from custom runner
insights = runner.insights()
# Clean up
runner.close()
Batch Operationsο
For efficient batch processing:
# Process multiple parameter sets efficiently
param_sets = [
{"learning_rate": 0.01, "batch_size": 32},
{"learning_rate": 0.005, "batch_size": 64},
{"learning_rate": 0.001, "batch_size": 128},
]
run_ids = []
for params in param_sets:
run_id = run.single(my_experiment, **params)
run_ids.append(run_id)
# Analyze batch results
batch_experiments = [run.get_by_id(rid) for rid in run_ids]
run.compare(batch_experiments)
Error Handlingο
The run module gracefully handles various error conditions:
# Experiment function that might fail
@experiment
def risky_experiment(fail_probability=0.1):
import random
if random.random() < fail_probability:
raise ValueError("Simulated failure")
return {"success": True}
# Failed experiments still return run_ids
run_id = run.single(risky_experiment, fail_probability=0.5)
# Check if experiment failed
experiment = run.get_by_id(run_id)
if experiment.status == "failed":
error_msg = experiment.metadata.get("error", "Unknown error")
print(f"Experiment failed: {error_msg}")
# Query failed experiments
failed_experiments = run.find("status == 'failed'")
print(f"Found {len(failed_experiments)} failed experiments")
Performance Tipsο
Use batch operations for multiple experiments
Limit query results with
run.find()for large datasetsClose runners when using custom ExperimentRunner instances
Use specific queries instead of retrieving all experiments
# Good: Specific query
recent_good = run.find("accuracy > 0.9 and start_time > '2024-01-01'")
# Less efficient: Get all then filter
all_experiments = run.all()
recent_good = [exp for exp in all_experiments
if exp.metrics.get("accuracy", 0) > 0.9]