feat: add scheduler job metadata to output - #1366
Open
davidberenstein1957 wants to merge 2 commits into
Open
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## fix/csv-update-dtype-coercion #1366 +/- ##
=================================================================
+ Coverage 91.42% 91.57% +0.15%
=================================================================
Files 49 50 +1
Lines 5051 5083 +32
=================================================================
+ Hits 4618 4655 +37
+ Misses 433 428 -5 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Read the job identity SLURM already exports into every job step and store it on the emissions record, so an HPC job's rows are joinable against `sacct` instead of users smuggling the job id into `project_name`. Other schedulers map their own variables onto the same fields through `CODECARBON_SCHEDULER` / `CODECARBON_JOB_*`, which also override the auto-detected SLURM values. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Rebased on fix/csv-update-dtype-coercion (#1370), which fixes the CSV dtype coercion properly, so the local workaround in file.py is dropped. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
davidberenstein1957
force-pushed
the
feat/slurm-integration
branch
from
August 12, 2026 17:52
f79e03a to
81bc919
Compare
davidberenstein1957
changed the base branch from
master
to
fix/csv-update-dtype-coercion
August 12, 2026 17:53
davidberenstein1957
marked this pull request as ready for review
August 12, 2026 19:14
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What this adds
CodeCarbon now reads the batch scheduler job identity out of the environment and stores it on every emissions record. Under SLURM this happens automatically — there is nothing to enable, no new flag, and no code change in a user's batch script. An existing
.slurmscript starts producing tagged rows as soon as it upgrades.The point is joinability: with
job_id,job_accountandnode_nameon the row,emissions.csvlines up directly againstsacct -j <id>, which is what turns a pile of per-run rows into a cluster report. It also retires theCODECARBON_PROJECT_NAME=$SLURM_JOB_IDworkaround, which worked but overloaded a field that means something else.User-facing surface
Seven new CSV columns, all defaulting to
""so nothing changes off a cluster:scheduler,job_id,job_name,job_user,job_account,job_partition,node_namePopulated from
SLURM_JOB_ID,SLURM_JOB_NAME,SLURM_JOB_USER,SLURM_JOB_ACCOUNT,SLURM_JOB_PARTITIONandSLURMD_NODENAME.Any field can also be set or overridden with an environment variable named after it —
CODECARBON_SCHEDULER,CODECARBON_JOB_ID,CODECARBON_NODE_NAMEand so on. That is the whole story for PBS, LSF and OAR: a site maps its scheduler's variables onto ours in three lines of shell, and we ship a documented contract rather than a backend per scheduler.No new dependencies — this is
os.environand a dataclass.How it fits
EmissionsTracker._prepare_emissions_data()is already where run context is assembled onto the record alongside cloud and geography metadata, so this is one more context source in the place that collects context. The API output path lists its fields explicitly inApiClient.add_emission, and Prometheus labels are an explicit allowlist, so neither contract changes — the new columns land in the CSV only.Verified
tests/test_schedulers.py: fake SLURM environment produces populated metadata; an empty environment stays inert; a partial environment fills only what is present; theCODECARBON_*contract works standalone and takes precedence over SLURM; and an end-to-end check that the fields reachEmissionsDataand its CSV columns. Allmonkeypatch-style env fixtures — no cluster required.tests/test_viz_data.pyexcluded, it needsdashwhich is not in the dev environment).black --checkandruff checkclean on the touched files, modulo the repo-widetyping.Dictwarnings that predate this branch.Upgrade note: existing
emissions.csvfiles are rotated onceFileOutput.has_valid_headerscompares sorted header lists, so seven new columns mean that on the first run after upgrading, an existingemissions.csvis backed up next to itself and a new file is started with the new header. Nothing is lost, but a pipeline reading a fixed path will find only the new rows in it. Documented indocs/reference/output.md.tests/test_data/emissions_valid_headers.csvgains the new columns, as it must whenever the CSV schema grows.Based on #1370
The schema change surfaces a bug in
FileOutput.out's"update"mode: it cast each value through the stored column's dtype, and an all-empty text column is read back by pandas asfloat64, sofloat("")raised and the write failed. #1370 fixes that at the root by dropping the coercion entirely, so this branch is stacked onfix/csv-update-dtype-coercionand carries no workaround of its own. Rebase onto master once #1370 merges.Multi-rank double counting is now a runtime warning
SLURM_NTASKS_PER_NODE > 1withtracking_mode="machine"means every rank measures the whole node and the job's total is multiplied by the rank count. A docs warning does not catch people, sowarn_on_multi_rank_double_counting()logs it at tracker init.Deliberately left out
codecarbon slurmwrapper command.codecarbon monitor -- <cmd>already wraps an arbitrary command, and with metadata detected automatically it needs nothing SLURM-specific. A dedicated command should wait for a job the generic one cannot do.LOCAL_RANK == 0in distributed training — worth solving once, generically, when there is a caller. For now the multi-node double-counting hazard is documented as a warning indocs/how-to/slurm.md.Docs updated:
docs/reference/output.mdgains the field table entries, anddocs/how-to/slurm.mdgains a "Job metadata in the output" section covering the variable mapping, thesacctjoin, the other-scheduler contract and the multi-node caveat.Closes #1355
🤖 Generated with Claude Code