mlco2 / mlco2/codecarbon

codecarbon monitor prints a "Saved to" path that ignores output_dir

Open Beginner friendly
#1,322 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
1.9k
Forks
323
Avg merge
1d 12h
Merged PRs (30d)
12

Description

The post-run report printed by codecarbon monitor -- <cmd> resolves the emissions file path from the file name only, so whenever output_dir is not the current working directory the CLI tells the user to look in the wrong place.

Reproduction

cd /home/user
CODECARBON_OUTPUT_DIR=/var/log/codecarbon codecarbon monitor -- ./train.sh

Prints:

   Saved to: /home/user/emissions.csv

while the CSV was actually written to /var/log/codecarbon/emissions.csv. Same happens with output_dir set in .codecarbon.config.

Root cause

codecarbon/cli/monitor.py:119-125 uses tracker._conf["output_file"] and calls os.path.abspath() on it. But output_file is only the basename (default "emissions.csv", codecarbon/emissions_tracker.py:567); the directory lives in a separate key output_dir (emissions_tracker.py:566). The two are joined only inside FileOutput (codecarbon/output_methods/file.py:49). os.path.abspath therefore resolves the bare name against the CWD, which is correct only for the default output_dir=".".

FileOutput does log the correct absolute path at construction (output_methods/file.py:50-52), but the CLI defaults to log_level="error" (cli/main.py, forwarded at cli/monitor.py:54), so that INFO line is suppressed and the wrong path is the only thing the user sees.

Expected vs actual

  • Expected: the report shows the path the CSV was actually written to (and shows nothing when CSV output is disabled).
  • Actual: <cwd>/emissions.csv, unconditionally, even when no file output handler exists.

Display-only defect; measurement and file writing are unaffected.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in codecarbon/cli/monitor.py:119-125 and trace the output_file and output_dir configuration into codecarbon/output_methods/file.py:49-52. Reproduce the monitor command with CODECARBON_OUTPUT_DIR set, then verify the report shows the actual CSV path and omits the path when CSV output is disabled.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
cli
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Quiet
Clarity
Clearly specified
Newbie friendliness
78/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.