-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun_all_examples.py
More file actions
263 lines (222 loc) · 7.52 KB
/
run_all_examples.py
File metadata and controls
263 lines (222 loc) · 7.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
"""
Run All Artifacta Examples
===========================
This script runs all example files in sequence and reports the results.
Useful for:
- Validating that all examples work correctly
- Regression testing after code changes
- Quick smoke test before releases
Usage:
python examples/run_all_examples.py # Run all examples
python examples/run_all_examples.py --category core # Run only core examples
python examples/run_all_examples.py --fast # Skip long-running examples
Categories:
- core: Basic Artifacta concepts and primitives
- ml_frameworks: Machine learning framework integrations
- domain_specific: Domain-specific use cases
- all: All examples (default)
"""
import argparse
import subprocess
import sys
import time
from pathlib import Path
# Define all examples with metadata
EXAMPLES = [
# Core examples
{
"path": "core/01_basic_tracking.py",
"name": "Basic Tracking",
"category": "core",
"duration": "fast",
"description": "Minimal hello world example",
},
{
"path": "core/02_all_primitives.py",
"name": "All Primitives Demo",
"category": "core",
"duration": "fast",
"description": "Showcase all 7 data primitives",
},
# ML Framework examples
{
"path": "ml_frameworks/sklearn_classification.py",
"name": "Sklearn Classification",
"category": "ml_frameworks",
"duration": "medium",
"description": "Sklearn with ROC/PR curves",
},
{
"path": "ml_frameworks/xgboost_regression.py",
"name": "XGBoost Regression",
"category": "ml_frameworks",
"duration": "medium",
"description": "XGBoost with feature importance",
},
{
"path": "ml_frameworks/pytorch_mnist.py",
"name": "PyTorch MNIST",
"category": "ml_frameworks",
"duration": "slow",
"description": "PyTorch Lightning with autolog",
},
{
"path": "ml_frameworks/tensorflow_regression.py",
"name": "TensorFlow Regression",
"category": "ml_frameworks",
"duration": "slow",
"description": "TensorFlow/Keras with autolog",
},
# Domain-specific examples
{
"path": "domain_specific/ab_testing_experiment.py",
"name": "A/B Testing",
"category": "domain_specific",
"duration": "fast",
"description": "Domain-agnostic A/B test tracking",
},
{
"path": "domain_specific/protein_expression.py",
"name": "Protein Expression",
"category": "domain_specific",
"duration": "fast",
"description": "Wet lab experiment optimization",
},
]
def run_example(example_path: Path) -> dict:
"""Run a single example and return results.
Args:
example_path: Path to the example file
Returns:
dict with keys: success (bool), duration (float), output (str), error (str)
"""
start_time = time.time()
try:
result = subprocess.run(
[sys.executable, str(example_path)],
capture_output=True,
text=True,
timeout=300, # 5 minute timeout
)
duration = time.time() - start_time
success = result.returncode == 0
return {
"success": success,
"duration": duration,
"output": result.stdout,
"error": result.stderr if not success else None,
}
except subprocess.TimeoutExpired:
duration = time.time() - start_time
return {
"success": False,
"duration": duration,
"output": "",
"error": "Example timed out after 5 minutes",
}
except Exception as e:
duration = time.time() - start_time
return {
"success": False,
"duration": duration,
"output": "",
"error": str(e),
}
def print_header():
"""Print script header."""
print("=" * 80)
print("Artifacta - Run All Examples")
print("=" * 80)
print()
def print_example_header(idx: int, total: int, example: dict):
"""Print example execution header."""
print(f"\n[{idx}/{total}] {example['name']}")
print(f" File: {example['path']}")
print(f" Description: {example['description']}")
print(" Running... ", end="", flush=True)
def print_result(result: dict):
"""Print example result."""
if result["success"]:
print(f"PASSED ({result['duration']:.1f}s)")
else:
print(f"FAILED ({result['duration']:.1f}s)")
if result["error"]:
print("\n Error:")
for line in result["error"].split("\n")[:10]: # Show first 10 lines
print(f" {line}")
def print_summary(results: list[dict], examples: list[dict]):
"""Print final summary table."""
passed = sum(1 for r in results if r["success"])
failed = sum(1 for r in results if not r["success"])
total_duration = sum(r["duration"] for r in results)
print("\n" + "=" * 80)
print("Summary")
print("=" * 80)
print(f"\nTotal: {len(results)} examples")
print(f"Passed: {passed}")
print(f"Failed: {failed}")
print(f"⏱ Total time: {total_duration:.1f}s")
if failed > 0:
print("\nFailed examples:")
for example, result in zip(examples, results):
if not result["success"]:
print(f" {example['name']} ({example['path']})")
print("\n" + "=" * 80)
def main():
"""Main function."""
parser = argparse.ArgumentParser(description="Run all Artifacta examples")
parser.add_argument(
"--category",
choices=["core", "ml_frameworks", "domain_specific", "all"],
default="all",
help="Category of examples to run",
)
parser.add_argument(
"--fast",
action="store_true",
help="Skip slow examples (only run fast/medium duration)",
)
args = parser.parse_args()
# Filter examples based on arguments
examples_to_run = EXAMPLES
if args.category != "all":
examples_to_run = [e for e in examples_to_run if e["category"] == args.category]
if args.fast:
examples_to_run = [e for e in examples_to_run if e["duration"] != "slow"]
if not examples_to_run:
print("No examples match the specified filters.")
return 1
# Print header
print_header()
print(f"Running {len(examples_to_run)} examples")
if args.category != "all":
print(f"Category: {args.category}")
if args.fast:
print("Mode: Fast (skipping slow examples)")
print()
# Get base directory
examples_dir = Path(__file__).parent
# Run each example
results = []
for idx, example in enumerate(examples_to_run, 1):
example_path = examples_dir / example["path"]
if not example_path.exists():
print(f"\n[{idx}/{len(examples_to_run)}] {example['name']}")
print(f" SKIPPED - File not found: {example_path}")
results.append({
"success": False,
"duration": 0,
"output": "",
"error": f"File not found: {example_path}",
})
continue
print_example_header(idx, len(examples_to_run), example)
result = run_example(example_path)
results.append(result)
print_result(result)
# Print summary
print_summary(results, examples_to_run)
# Exit with error code if any examples failed
return 1 if any(not r["success"] for r in results) else 0
if __name__ == "__main__":
sys.exit(main())