experimaestro 1.11.1__py3-none-any.whl → 2.0.0b4__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of experimaestro might be problematic. Click here for more details.

Files changed (133) hide show
  1. experimaestro/__init__.py +10 -11
  2. experimaestro/annotations.py +167 -206
  3. experimaestro/cli/__init__.py +140 -16
  4. experimaestro/cli/filter.py +42 -74
  5. experimaestro/cli/jobs.py +157 -106
  6. experimaestro/cli/progress.py +269 -0
  7. experimaestro/cli/refactor.py +249 -0
  8. experimaestro/click.py +0 -1
  9. experimaestro/commandline.py +19 -3
  10. experimaestro/connectors/__init__.py +22 -3
  11. experimaestro/connectors/local.py +12 -0
  12. experimaestro/core/arguments.py +192 -37
  13. experimaestro/core/identifier.py +127 -12
  14. experimaestro/core/objects/__init__.py +6 -0
  15. experimaestro/core/objects/config.py +702 -285
  16. experimaestro/core/objects/config_walk.py +24 -6
  17. experimaestro/core/serialization.py +91 -34
  18. experimaestro/core/serializers.py +1 -8
  19. experimaestro/core/subparameters.py +164 -0
  20. experimaestro/core/types.py +198 -83
  21. experimaestro/exceptions.py +26 -0
  22. experimaestro/experiments/cli.py +107 -25
  23. experimaestro/generators.py +50 -9
  24. experimaestro/huggingface.py +3 -1
  25. experimaestro/launcherfinder/parser.py +29 -0
  26. experimaestro/launcherfinder/registry.py +3 -3
  27. experimaestro/launchers/__init__.py +26 -1
  28. experimaestro/launchers/direct.py +12 -0
  29. experimaestro/launchers/slurm/base.py +154 -2
  30. experimaestro/mkdocs/base.py +6 -8
  31. experimaestro/mkdocs/metaloader.py +0 -1
  32. experimaestro/mypy.py +452 -7
  33. experimaestro/notifications.py +75 -16
  34. experimaestro/progress.py +404 -0
  35. experimaestro/rpyc.py +0 -1
  36. experimaestro/run.py +19 -6
  37. experimaestro/scheduler/__init__.py +18 -1
  38. experimaestro/scheduler/base.py +504 -959
  39. experimaestro/scheduler/dependencies.py +43 -28
  40. experimaestro/scheduler/dynamic_outputs.py +259 -130
  41. experimaestro/scheduler/experiment.py +582 -0
  42. experimaestro/scheduler/interfaces.py +474 -0
  43. experimaestro/scheduler/jobs.py +485 -0
  44. experimaestro/scheduler/services.py +186 -12
  45. experimaestro/scheduler/signal_handler.py +32 -0
  46. experimaestro/scheduler/state.py +1 -1
  47. experimaestro/scheduler/state_db.py +388 -0
  48. experimaestro/scheduler/state_provider.py +2345 -0
  49. experimaestro/scheduler/state_sync.py +834 -0
  50. experimaestro/scheduler/workspace.py +52 -10
  51. experimaestro/scriptbuilder.py +7 -0
  52. experimaestro/server/__init__.py +153 -32
  53. experimaestro/server/data/index.css +0 -125
  54. experimaestro/server/data/index.css.map +1 -1
  55. experimaestro/server/data/index.js +194 -58
  56. experimaestro/server/data/index.js.map +1 -1
  57. experimaestro/settings.py +47 -6
  58. experimaestro/sphinx/__init__.py +3 -3
  59. experimaestro/taskglobals.py +20 -0
  60. experimaestro/tests/conftest.py +80 -0
  61. experimaestro/tests/core/test_generics.py +2 -2
  62. experimaestro/tests/identifier_stability.json +45 -0
  63. experimaestro/tests/launchers/bin/sacct +6 -2
  64. experimaestro/tests/launchers/bin/sbatch +4 -2
  65. experimaestro/tests/launchers/common.py +2 -2
  66. experimaestro/tests/launchers/test_slurm.py +80 -0
  67. experimaestro/tests/restart.py +1 -1
  68. experimaestro/tests/tasks/all.py +7 -0
  69. experimaestro/tests/tasks/test_dynamic.py +231 -0
  70. experimaestro/tests/test_checkers.py +2 -2
  71. experimaestro/tests/test_cli_jobs.py +615 -0
  72. experimaestro/tests/test_dependencies.py +11 -17
  73. experimaestro/tests/test_deprecated.py +630 -0
  74. experimaestro/tests/test_environment.py +200 -0
  75. experimaestro/tests/test_experiment.py +3 -3
  76. experimaestro/tests/test_file_progress.py +425 -0
  77. experimaestro/tests/test_file_progress_integration.py +477 -0
  78. experimaestro/tests/test_forward.py +3 -3
  79. experimaestro/tests/test_generators.py +93 -0
  80. experimaestro/tests/test_identifier.py +520 -169
  81. experimaestro/tests/test_identifier_stability.py +458 -0
  82. experimaestro/tests/test_instance.py +16 -21
  83. experimaestro/tests/test_multitoken.py +442 -0
  84. experimaestro/tests/test_mypy.py +433 -0
  85. experimaestro/tests/test_objects.py +314 -30
  86. experimaestro/tests/test_outputs.py +8 -8
  87. experimaestro/tests/test_param.py +22 -26
  88. experimaestro/tests/test_partial_paths.py +231 -0
  89. experimaestro/tests/test_progress.py +2 -50
  90. experimaestro/tests/test_resumable_task.py +480 -0
  91. experimaestro/tests/test_serializers.py +141 -60
  92. experimaestro/tests/test_state_db.py +434 -0
  93. experimaestro/tests/test_subparameters.py +160 -0
  94. experimaestro/tests/test_tags.py +151 -15
  95. experimaestro/tests/test_tasks.py +137 -160
  96. experimaestro/tests/test_token_locking.py +252 -0
  97. experimaestro/tests/test_tokens.py +25 -19
  98. experimaestro/tests/test_types.py +133 -11
  99. experimaestro/tests/test_validation.py +19 -19
  100. experimaestro/tests/test_workspace_triggers.py +158 -0
  101. experimaestro/tests/token_reschedule.py +5 -3
  102. experimaestro/tests/utils.py +2 -2
  103. experimaestro/tokens.py +154 -57
  104. experimaestro/tools/diff.py +8 -1
  105. experimaestro/tui/__init__.py +8 -0
  106. experimaestro/tui/app.py +2303 -0
  107. experimaestro/tui/app.tcss +353 -0
  108. experimaestro/tui/log_viewer.py +228 -0
  109. experimaestro/typingutils.py +11 -2
  110. experimaestro/utils/__init__.py +23 -0
  111. experimaestro/utils/environment.py +148 -0
  112. experimaestro/utils/git.py +129 -0
  113. experimaestro/utils/resources.py +1 -1
  114. experimaestro/version.py +34 -0
  115. {experimaestro-1.11.1.dist-info → experimaestro-2.0.0b4.dist-info}/METADATA +70 -39
  116. experimaestro-2.0.0b4.dist-info/RECORD +181 -0
  117. {experimaestro-1.11.1.dist-info → experimaestro-2.0.0b4.dist-info}/WHEEL +1 -1
  118. experimaestro-2.0.0b4.dist-info/entry_points.txt +16 -0
  119. experimaestro/compat.py +0 -6
  120. experimaestro/core/objects.pyi +0 -225
  121. experimaestro/server/data/0c35d18bf06992036b69.woff2 +0 -0
  122. experimaestro/server/data/219aa9140e099e6c72ed.woff2 +0 -0
  123. experimaestro/server/data/3a4004a46a653d4b2166.woff +0 -0
  124. experimaestro/server/data/3baa5b8f3469222b822d.woff +0 -0
  125. experimaestro/server/data/4d73cb90e394b34b7670.woff +0 -0
  126. experimaestro/server/data/4ef4218c522f1eb6b5b1.woff2 +0 -0
  127. experimaestro/server/data/5d681e2edae8c60630db.woff +0 -0
  128. experimaestro/server/data/6f420cf17cc0d7676fad.woff2 +0 -0
  129. experimaestro/server/data/c380809fd3677d7d6903.woff2 +0 -0
  130. experimaestro/server/data/f882956fd323fd322f31.woff +0 -0
  131. experimaestro-1.11.1.dist-info/RECORD +0 -158
  132. experimaestro-1.11.1.dist-info/entry_points.txt +0 -17
  133. {experimaestro-1.11.1.dist-info → experimaestro-2.0.0b4.dist-info/licenses}/LICENSE +0 -0
@@ -0,0 +1,404 @@
1
+ """File-based progress tracking system for experimaestro tasks."""
2
+
3
+ import json
4
+ import threading
5
+ import time
6
+ from dataclasses import dataclass, asdict
7
+ from pathlib import Path
8
+ from typing import Optional, List, Iterator, Dict, Any
9
+ from datetime import datetime, timedelta
10
+ import fcntl
11
+ import os
12
+
13
+ from .utils import logger
14
+
15
+ DEFAULT_MAX_ENTRIES_PER_FILE = 10_000
16
+
17
+
18
+ @dataclass
19
+ class ProgressEntry:
20
+ """A single progress entry in the JSONL file"""
21
+
22
+ timestamp: float
23
+ level: int
24
+ progress: float
25
+ desc: Optional[str] = None
26
+
27
+ def to_dict(self) -> Dict[str, Any]:
28
+ """Convert to dictionary for JSON serialization"""
29
+ return asdict(self)
30
+
31
+ @classmethod
32
+ def from_dict(cls, data: Dict[str, Any]) -> "ProgressEntry":
33
+ """Create from dictionary"""
34
+ return cls(**data)
35
+
36
+
37
+ class StateFile:
38
+ """Represents the state file for progress tracking.
39
+ Checks if the state must be written based on time and progress changes.
40
+ By default, it writes every second or when progress changes significantly (>1%)"""
41
+
42
+ def __init__(self, filename: Path):
43
+ self.filename = filename
44
+ self.state: Dict[int, ProgressEntry] = {}
45
+
46
+ # Write threshold to avoid too frequent writes
47
+ self._time_threshold = timedelta(seconds=1.0)
48
+ self._last_write_time: datetime = datetime.now()
49
+ # Minimum progress change to trigger write
50
+ self._progress_threshold = 0.01
51
+ self._last_write_progress: Optional[Dict[int, float]] = None
52
+
53
+ self.filename.parent.mkdir(parents=True, exist_ok=True)
54
+ self.load()
55
+
56
+ def _allow_write(self) -> bool:
57
+ """Check if the state should be written based on time and progress changes.
58
+ Allows writing if:
59
+ - BOTH: More than 1 second has passed since last write
60
+ - AND: Progress has changed significantly (>1%)
61
+ - OR: All entries are done (progress >= 1.0)"""
62
+ time_check = datetime.now() - self._last_write_time > self._time_threshold
63
+ progress_check = self._last_write_progress is None or any(
64
+ abs(entry.progress - self._last_write_progress.get(entry.level, 0.0))
65
+ > self._progress_threshold
66
+ for entry in self.state.values()
67
+ )
68
+ all_entries_done = all(entry.progress >= 1.0 for entry in self.state.values())
69
+ return all_entries_done or (time_check and progress_check)
70
+
71
+ def write(self, force: bool = False):
72
+ """Write the current state to the file."""
73
+ if self._allow_write() or force:
74
+ with open(self.filename, "w") as f:
75
+ json.dump({k: v.to_dict() for k, v in self.state.items()}, f)
76
+ self._last_write_time = datetime.now()
77
+ self._last_write_progress = {k: v.progress for k, v in self.state.items()}
78
+
79
+ def update(self, entry: ProgressEntry):
80
+ self.state[entry.level] = entry
81
+
82
+ def load(self):
83
+ """Load the state from the file"""
84
+ if self.filename.exists():
85
+ with self.filename.open("r") as f:
86
+ try:
87
+ data = json.load(f)
88
+ self.state = {
89
+ int(k): ProgressEntry.from_dict(v) for k, v in data.items()
90
+ }
91
+ except (json.JSONDecodeError, IOError):
92
+ logger.warning(f"Failed to load state from {self.filename}")
93
+
94
+ def read(self) -> Dict[int, ProgressEntry]:
95
+ """Read the state from the file"""
96
+ self.load()
97
+ return self.state
98
+
99
+ # flush on exit
100
+ def __del__(self):
101
+ """Ensure state is written on exit"""
102
+ try:
103
+ self.write(force=True)
104
+ except Exception as e:
105
+ logger.error(f"Failed to write state on exit: {e}")
106
+
107
+
108
+ class ProgressFileWriter:
109
+ def __init__(
110
+ self, task_path: Path, max_entries_per_file: int = DEFAULT_MAX_ENTRIES_PER_FILE
111
+ ):
112
+ self.task_path = task_path
113
+ self.progress_dir = task_path / ".experimaestro"
114
+ self.max_entries_per_file = max_entries_per_file
115
+ self.current_file_index = 0
116
+ self.current_file_entries = 0
117
+ self.lock = threading.Lock()
118
+
119
+ # Ensure directory exists
120
+ self.progress_dir.mkdir(exist_ok=True)
121
+
122
+ # State is the latest entry per level
123
+ self.state = StateFile(self.progress_dir / "progress_state.json")
124
+
125
+ # Find the latest file index
126
+ self._find_latest_file()
127
+
128
+ def _find_latest_file(self):
129
+ """Find the latest progress file and entry count"""
130
+ progress_files = list(self.progress_dir.glob("progress-*.jsonl"))
131
+ if not progress_files:
132
+ self.current_file_index = 0
133
+ self.current_file_entries = 0
134
+ return
135
+
136
+ # Sort by file index
137
+ max_index = None
138
+ for f in progress_files:
139
+ try:
140
+ index = int(f.stem.split("-")[1])
141
+ if max_index is None or index > max_index:
142
+ max_index = index
143
+ except (ValueError, IndexError):
144
+ continue
145
+
146
+ if max_index is not None:
147
+ self.current_file_index = max_index
148
+ # Count entries in current file
149
+ current_file = self._get_current_file_path()
150
+ if current_file.exists():
151
+ with current_file.open("r") as f:
152
+ self.current_file_entries = sum(1 for _ in f.readlines())
153
+ else:
154
+ self.current_file_entries = 0
155
+ else:
156
+ self.current_file_index = 0
157
+ self.current_file_entries = 0
158
+
159
+ def _get_current_file_path(self) -> Path:
160
+ """Get path to current progress file"""
161
+ return self.progress_dir / f"progress-{self.current_file_index:04d}.jsonl"
162
+
163
+ def _get_latest_symlink_path(self) -> Path:
164
+ """Get path to latest progress symlink"""
165
+ return self.progress_dir / "progress-latest.jsonl"
166
+
167
+ def _rotate_file_if_needed(self):
168
+ """Create new file if current one is full"""
169
+ if self.current_file_entries >= self.max_entries_per_file:
170
+ self.current_file_index += 1
171
+ self.current_file_entries = 0
172
+ logger.debug(f"Rotating to new progress file: {self.current_file_index}")
173
+
174
+ def _update_latest_symlink(self):
175
+ """Update symlink to point to latest file"""
176
+ current_file = self._get_current_file_path()
177
+ latest_symlink = self._get_latest_symlink_path()
178
+
179
+ # Remove existing symlink
180
+ if latest_symlink.exists() or latest_symlink.is_symlink():
181
+ latest_symlink.unlink()
182
+
183
+ # Create new symlink
184
+ latest_symlink.symlink_to(current_file.name)
185
+
186
+ def write_progress(self, level: int, progress: float, desc: Optional[str] = None):
187
+ """Write a progress entry to the file
188
+
189
+ Args:
190
+ level: Progress level (0 is top level)
191
+ progress: Progress value between 0.0 and 1.0
192
+ desc: Optional description
193
+ """
194
+ with self.lock:
195
+ # Eventually rotate internal state if needed
196
+ self._rotate_file_if_needed()
197
+
198
+ entry = ProgressEntry(
199
+ timestamp=time.time(), level=level, progress=progress, desc=desc
200
+ )
201
+ self.state.update(entry)
202
+ self.state.write(force=level == -1) # Force write on EOJ
203
+
204
+ current_file = self._get_current_file_path()
205
+
206
+ # Write with file locking for concurrent access
207
+ with current_file.open("a") as f:
208
+ try:
209
+ fcntl.flock(f.fileno(), fcntl.LOCK_EX)
210
+ f.write(json.dumps(entry.to_dict()) + "\n")
211
+ f.flush() # Flush the file buffer
212
+ os.fsync(f.fileno()) # Ensure data is written to disk
213
+ finally:
214
+ fcntl.flock(f.fileno(), fcntl.LOCK_UN)
215
+
216
+ self.current_file_entries += 1
217
+ self._update_latest_symlink()
218
+
219
+ logger.debug(
220
+ f"Progress written: level={level}, progress={progress}, desc={desc}"
221
+ )
222
+
223
+ def __del__(self):
224
+ """Ensure state is written on exit"""
225
+ try:
226
+ self.state.write(force=True)
227
+ except Exception as e:
228
+ logger.error(f"Failed to write state on exit: {e}")
229
+
230
+
231
+ class ProgressFileReader:
232
+ """Reads progress entries from JSONL files"""
233
+
234
+ def __init__(self, task_path: Path):
235
+ """Initialize progress file reader
236
+
237
+ Args:
238
+ task_path: Path to the task directory
239
+ """
240
+ self.task_path = task_path
241
+ self.progress_dir = task_path / ".experimaestro"
242
+ self.max_entries_per_file: Optional[int] = None
243
+ self.state = StateFile(self.progress_dir / "progress_state.json")
244
+
245
+ def get_progress_files(self) -> List[Path]:
246
+ """Get all progress files sorted by index"""
247
+ if not self.progress_dir.exists():
248
+ return []
249
+
250
+ progress_files = list(self.progress_dir.glob("progress-*.jsonl"))
251
+
252
+ # Filter out symlinks to avoid duplicates
253
+ progress_files = [f for f in progress_files if not f.is_symlink()]
254
+
255
+ # Sort by file index
256
+ # Alternatively, we could simply sort by filename
257
+ def get_index(path: Path) -> int:
258
+ try:
259
+ return int(path.stem.split("-")[1])
260
+ except (ValueError, IndexError):
261
+ return 0
262
+
263
+ return sorted(progress_files, key=get_index)
264
+
265
+ def get_latest_file(self) -> Optional[Path]:
266
+ """Get the latest progress file via symlink"""
267
+ latest_symlink = self.progress_dir / "progress-latest.jsonl"
268
+ if latest_symlink.exists() and latest_symlink.is_symlink():
269
+ return latest_symlink.resolve()
270
+
271
+ # Fallback to finding latest manually
272
+ files = self.get_progress_files()
273
+ return files[-1] if files else None
274
+
275
+ def read_entries(self, file_path: Path) -> Iterator[ProgressEntry]:
276
+ """Read progress entries from a file
277
+
278
+ Args:
279
+ file_path: Path to progress file
280
+
281
+ Yields:
282
+ ProgressEntry objects
283
+ """
284
+ if not file_path.exists():
285
+ return
286
+
287
+ try:
288
+ with file_path.open("r") as f:
289
+ fcntl.flock(f.fileno(), fcntl.LOCK_SH)
290
+ try:
291
+ for line in f:
292
+ line = line.strip()
293
+ if line:
294
+ try:
295
+ data = json.loads(line)
296
+ yield ProgressEntry.from_dict(data)
297
+ except json.JSONDecodeError as e:
298
+ logger.warning(
299
+ f"Invalid JSON in progress file {file_path}: {e}"
300
+ )
301
+ finally:
302
+ fcntl.flock(f.fileno(), fcntl.LOCK_UN)
303
+ except IOError as e:
304
+ logger.warning(f"Could not read progress file {file_path}: {e}")
305
+
306
+ def read_all_entries(self) -> Iterator[ProgressEntry]:
307
+ """Read all progress entries from all files in order
308
+
309
+ Yields:
310
+ ProgressEntry objects in chronological order
311
+ """
312
+ logger.warning("Reading all progress entries, this may be slow for large jobs.")
313
+ for file_path in self.get_progress_files():
314
+ yield from self.read_entries(file_path)
315
+
316
+ def read_latest_entries(self, count: Optional[int] = None) -> List[ProgressEntry]:
317
+ """Read the latest N progress entries"""
318
+ entries = []
319
+
320
+ # Read files in reverse order to get latest entries first
321
+ files = self.get_progress_files()
322
+ # Fetch the max length of files, in lines
323
+ if files and count is None:
324
+ # Fetch the number of entries in the first file
325
+ # This is the most likely to be the longest file
326
+ count = sum(1 for _ in self.read_entries(files[0]))
327
+ if count is None:
328
+ count = DEFAULT_MAX_ENTRIES_PER_FILE
329
+
330
+ for file_path in reversed(files):
331
+ file_entries = list(self.read_entries(file_path))
332
+ entries.extend(reversed(file_entries))
333
+
334
+ if len(entries) >= count:
335
+ break
336
+
337
+ # Return latest entries in chronological order
338
+ return list(reversed(entries[:count]))
339
+
340
+ def get_current_progress(
341
+ self, count: Optional[int] = None
342
+ ) -> Dict[int, ProgressEntry]:
343
+ """Get the current progress for each level"""
344
+ logger.warning(
345
+ "Reading current progress from progress logs, this may be slow for large jobs."
346
+ )
347
+ return {entry.level: entry for entry in self.read_latest_entries(count)}
348
+
349
+ def get_current_state(self) -> Optional[Dict[int, ProgressEntry]]:
350
+ """Fetch the latest progress entry from the state file"""
351
+ current_state = self.state.read()
352
+ return current_state or self.get_current_progress()
353
+
354
+ def is_done(self) -> bool:
355
+ """Check if the task is done by looking for a special 'done' file.
356
+ Fallback to checking for end-of-job (EOJ) entries."""
357
+
358
+ task_name = self.task_path.parent.stem.split(".")[-1]
359
+ job_done_file = self.task_path / f"{task_name}.done"
360
+ if job_done_file.exists() and job_done_file.is_file():
361
+ return True
362
+
363
+ # Check if any progress file has a level -1 entry indicating EOJ
364
+ return any(entry.level == -1 for entry in self.read_all_entries())
365
+
366
+
367
+ class FileBasedProgressReporter:
368
+ """File-based progress reporter that replaces the socket-based Reporter"""
369
+
370
+ def __init__(self, task_path: Path):
371
+ """Initialize file-based progress reporter
372
+
373
+ Args:
374
+ task_path: Path to the task directory
375
+ """
376
+ self.task_path = task_path
377
+ self.writer = ProgressFileWriter(task_path)
378
+ self.current_progress = {} # level -> (progress, desc)
379
+ self.lock = threading.Lock()
380
+
381
+ def set_progress(self, progress: float, level: int = 0, desc: Optional[str] = None):
382
+ """Set progress for a specific level
383
+
384
+ Args:
385
+ progress: Progress value between 0.0 and 1.0
386
+ level: Progress level (0 is top level)
387
+ desc: Optional description
388
+ """
389
+ with self.lock:
390
+ # Check if progress has changed significantly
391
+ current = self.current_progress.get(level, (None, None))
392
+ if (
393
+ current[0] is None
394
+ or abs(progress - current[0]) > 0.01
395
+ or desc != current[1]
396
+ ):
397
+ self.current_progress[level] = (progress, desc)
398
+ self.writer.write_progress(level, progress, desc)
399
+
400
+ def eoj(self):
401
+ """End of job notification"""
402
+ with self.lock:
403
+ # Write a special end-of-job marker
404
+ self.writer.write_progress(-1, 1.0, "EOJ")
experimaestro/rpyc.py CHANGED
@@ -1,5 +1,4 @@
1
1
  import atexit
2
- import shutil
3
2
  import tempfile
4
3
  from pathlib import Path
5
4
  from subprocess import Popen, PIPE, run
experimaestro/run.py CHANGED
@@ -9,6 +9,7 @@ from typing import List
9
9
  import fasteners
10
10
  from experimaestro.notifications import progress, report_eoj
11
11
  from experimaestro.utils.multiprocessing import delayed_shutdown
12
+ from experimaestro.exceptions import GracefulTimeout
12
13
  from .core.types import ObjectType
13
14
  from experimaestro.utils import logger
14
15
  from experimaestro.core.objects import ConfigInformation
@@ -41,9 +42,6 @@ def run(parameters: Path):
41
42
  task = ConfigInformation.fromParameters(params["objects"])
42
43
  task.__taskdir__ = Path.cwd()
43
44
 
44
- # Set the tags
45
- task.__tags__ = params["tags"]
46
-
47
45
  # Notify that the task has started
48
46
  progress(0)
49
47
 
@@ -92,9 +90,20 @@ class TaskRunner:
92
90
  report_eoj()
93
91
  logger.info("Finished cleanup")
94
92
 
95
- def handle_error(self, code, frame_type):
96
- logger.info("Error handler: finished with code %d", code)
97
- self.failedpath.write_text(str(code))
93
+ def handle_error(self, code, frame_type, reason: str = "failed", message: str = ""):
94
+ """Handle task error and write failure information.
95
+
96
+ Args:
97
+ code: Exit code
98
+ frame_type: Signal frame type (unused)
99
+ reason: Failure reason (e.g., "failed", "timeout")
100
+ message: Optional message with details
101
+ """
102
+ logger.info("Error handler: finished with code %d, reason=%s", code, reason)
103
+ failure_info = {"code": code, "reason": reason}
104
+ if message:
105
+ failure_info["message"] = message
106
+ self.failedpath.write_text(json.dumps(failure_info))
98
107
  self.cleanup()
99
108
  logger.info("Exiting")
100
109
  delayed_shutdown(60, exit_code=code)
@@ -147,6 +156,10 @@ class TaskRunner:
147
156
  # Everything went OK
148
157
  logger.info("Task ended successfully")
149
158
  sys.exit(0)
159
+ except GracefulTimeout as e:
160
+ logger.info("Task requested graceful timeout: %s", e.message)
161
+ self.handle_error(1, None, reason="timeout", message=e.message)
162
+
150
163
  except Exception:
151
164
  logger.exception("Got exception while running")
152
165
  self.handle_error(1, None)
@@ -1 +1,18 @@
1
- from .base import *
1
+ from .base import Scheduler, Listener
2
+ from .workspace import Workspace, RunMode
3
+ from .experiment import experiment, FailedExperiment
4
+ from .jobs import Job, JobState, JobFailureStatus, JobDependency, JobContext
5
+
6
+ __all__ = [
7
+ "Scheduler",
8
+ "Listener",
9
+ "Workspace",
10
+ "RunMode",
11
+ "experiment",
12
+ "FailedExperiment",
13
+ "Job",
14
+ "JobState",
15
+ "JobFailureStatus",
16
+ "JobDependency",
17
+ "JobContext",
18
+ ]