stemflow.utils.execution_monitor
Install stemflow[monitoring] for psutil-backed process-memory measurements. The usual entry point is model.monitor_execution(...); ExecutionMonitor can also wrap a standalone workflow.
with model.monitor_execution(
sample_interval=1.0,
log_interval=30.0,
output_path="data/execution_monitor.json",
detailed_memory=False,
max_samples=0,
) as monitor:
model.fit(X_train, y_train, temporal_window_prequery=True)
with monitor.phase("held_out_prediction"):
probability = model.predict_proba(X_test, n_jobs=2)
report = model.execution_monitor_
Set log_interval=None to disable live logging. A new context replaces the previous model report. Save the model after leaving the context to retain the finalized report; the live thread and locks are not serialized with it. JSON output replaces one report file rather than accumulating snapshots. max_samples=0 retains summaries only; a positive value bounds the recent raw samples retained.
Report interpretation
| Field | Meaning |
|---|---|
wall_seconds |
Elapsed time for the monitored context. |
stages |
Inclusive stage timings and sampled stage peaks; nested durations are not additive. |
peak_tree_rss_bytes |
Maximum sampled simultaneous sum of parent and descendant RSS on this node. |
peak_process_count |
Maximum sampled process count in the monitored tree. |
sampling_error, output_error |
Measurement/reporting failures, reported independently of model errors. |
latest_sample, recent_samples |
Latest reading and optionally bounded raw history. |
RSS can count shared pages in multiple processes. With detailed_memory=True, supported USS, Linux PSS and macOS physical-footprint readings remain separate fields. Inaccessible/disappearing workers and incomplete coverage are explicit. Sampling can miss short peaks. These values are not GPU memory, remote-node measurements, Slurm/cgroup accounting, an exact allocator breakdown, or a memory limit.
See the executed monitoring example and measurement guide.
Monitor fitting, prediction and custom stages in the calling process.
Memory includes descendants on this node, including native estimator memory. RSS counts shared pages repeatedly. Optional USS, Linux PSS and macOS physical footprint are recorded separately when supported and accessible. These are not interchangeable or equal to a scheduler's memory charge. This is a sampler, not a memory limiter, allocation profiler or remote/GPU monitor.
Parameters:
-
sample_interval(float, default:1.0) –Seconds between background memory samples (default 1).
-
log_interval(float | None, default:30.0) –Seconds between flushed stdout updates; None disables logs. Stage completions and workflow start/end are also logged when enabled.
-
output_path(str | Path | None, default:None) –Optional compact JSON report. Updated alongside live logs and on exit, replacing one file rather than accumulating snapshots.
-
detailed_memory(bool, default:False) –Collect USS/PSS and physical footprint when available. Default False keeps cheap RSS sampling; detailed reads can be slower.
-
max_samples(int, default:0) –Retain at most this many recent samples; default 0 stores summaries only. Stage records and peaks survive trace truncation.
A context is single-use. Use stages from its calling thread. AdaSTEM models retain a plain report in execution_monitor_, updated after each outer model call and on context exit. The live sampler is never stored on the model.
Source code in stemflow/utils/execution_monitor.py
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 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 | |
phase(name)
Record an inclusive stage, including nested calls and worker memory.
Source code in stemflow/utils/execution_monitor.py
summary()
Return a JSON-compatible snapshot, also available during execution.