Skip to content

Add opt-in interval CSV measurement export#1270

Open
sankalpsthakur wants to merge 3 commits into
mlco2:masterfrom
sankalpsthakur:fix/467-interval-csv-export
Open

Add opt-in interval CSV measurement export#1270
sankalpsthakur wants to merge 3 commits into
mlco2:masterfrom
sankalpsthakur:fix/467-interval-csv-export

Conversation

@sankalpsthakur

@sankalpsthakur sankalpsthakur commented Jul 22, 2026

Copy link
Copy Markdown

Summary

Fixes #467 by writing CSV measurement rows on the same live cadence as API/Prometheus (api_call_interval * measure_power_secs).

  • Opt-in csv_run_name (filename, or "auto" / ""emissions_<run_id>.csv). Default emissions.csv stays final-only unless csv_run_name targets the same file.
  • FileOutput.live_out behind enable_live_out — reuses the existing measurement loop instead of ad-hoc flush threads.

Why this matters

Long-running jobs previously had no structured way to inspect intermediate power/emissions without enabling API or Prometheus export. Interval CSV gives operators a file-based audit trail (notebooks, log pipelines, offline analysis) with predictable row cadence and without changing the default single-row emissions.csv contract.

Related (not in scope here): #559 asks whether power columns belong in CSV — this PR follows the existing measurement schema; #448 covers periodic export for other output modes beyond CSV.

Usage

from codecarbon import EmissionsTracker

tracker = EmissionsTracker(
    project_name="Test",
    tracking_mode="machine",
    csv_run_name="emissions_test54.csv",
)
tracker.start()
# ... workload ...
tracker.stop()

Test plan

  • tests/output_methods/test_file.py live_out coverage
  • tests/test_emissions_tracker.py named / auto / empty / same-as-output_file / default final-only / without CSV method
  • Docs: docs/reference/output.md interval CSV note

Write measurement rows on the API/Prometheus live cadence when
csv_run_name is set, avoiding ad-hoc flush threads (mlco2#467).
@sankalpsthakur
sankalpsthakur force-pushed the fix/467-interval-csv-export branch from 1c57416 to ba687ca Compare July 22, 2026 11:59
@sankalpsthakur

sankalpsthakur commented Jul 22, 2026

Copy link
Copy Markdown
Author

@benoit-cty @mlco2/core-maintainers — implements the #467 approach: opt-in csv_run_name writes measurement rows on the API/Prometheus live cadence. Default emissions.csv stays final-only.

CI is waiting on first-time contributor approval — could a maintainer run the workflows?

Cover empty-string auto naming and default final-only CSV behavior,
and fix spacing so pre-commit style checks stay clean.
@sankalpsthakur
sankalpsthakur force-pushed the fix/467-interval-csv-export branch 3 times, most recently from 2e37bba to f3d04e0 Compare July 22, 2026 14:12
Cover the opt-in live CSV path in output docs and add a regression test
for interval export without OutputMethod.CSV.
@sankalpsthakur
sankalpsthakur force-pushed the fix/467-interval-csv-export branch from f3d04e0 to 8658551 Compare July 22, 2026 14:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Capture measurements in CSV based on time intervals

1 participant