Skip to content

fix: log all figures in CustomMLFlowLogger.log_image()#499

Open
Raj-Taware wants to merge 3 commits intomllam:mainfrom
Raj-Taware:fix/log-image-multi-fig
Open

fix: log all figures in CustomMLFlowLogger.log_image()#499
Raj-Taware wants to merge 3 commits intomllam:mainfrom
Raj-Taware:fix/log-image-multi-fig

Conversation

@Raj-Taware
Copy link
Copy Markdown

Describe your changes

log_image() in neural_lam/custom_loggers.py hardcoded images[0], silently dropping all figures after the first when a list of multiple figures was passed.

  • Iterate over all figures in the images list
  • Use a unique key per image ({key}_0, {key}_1, …) when more than one figure is present; preserve the original key for single-figure calls (backwards compatible)
  • Move the NoCredentialsError handler inside the loop so every iteration is covered

No new dependencies.

Issue Link

Closes #495

Type of change

  • 🐛 Bug fix (non-breaking change that fixes an issue)
  • ✨ New feature (non-breaking change that adds functionality)
  • 💥 Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • 📖 Documentation (Addition or improvements to documentation)

Checklist before requesting a review

  • My branch is up-to-date with the target branch - if not update your fork with the changes from the target branch (use pull with --rebase option if possible).
  • I have performed a self-review of my code
  • For any new/modified functions/classes I have added docstrings that clearly describe its purpose, expected inputs and returned values
  • I have placed in-line comments to clarify the intent of any hard-to-understand passages of my code
  • I have updated the README to cover introduced code changes
  • I have added tests that prove my fix is effective or that my feature works
  • I have given the PR a name that clearly describes the change, written in imperative form (context).
  • I have requested a reviewer and an assignee (assignee is responsible for merging). This applies only if you have write access to the repo, otherwise feel free to tag a maintainer to add a reviewer and assignee.

Checklist for reviewers

Each PR comes with its own improvements and flaws. The reviewer should check the following:

  • the code is readable
  • the code is well tested
  • the code is documented (including return types and parameters)
  • the code is easy to maintain

Author checklist after completed review

  • I have added a line to the CHANGELOG describing this change, in a section
    reflecting type of change (add section where missing):
    • added: when you have added new functionality
    • changed: when default behaviour of the code has been changed
    • fixes: when your contribution fixes a bug
    • maintenance: when your contribution is relates to repo maintenance, e.g. CI/CD or documentation

Checklist for assignee

  • PR is up to date with the base branch
  • the tests pass
  • (if the PR is not just maintenance/bugfix) the PR is assigned to the next milestone. If it is not, propose it for a future milestone.
  • author has added an entry to the changelog (and designated the change as added, changed, fixed or maintenance)
  • Once the PR is ready to be merged, squash commits and merge the PR.

Raj_taware added 2 commits March 23, 2026 13:17
Previously only images[0] was saved and logged; all subsequent figures
were silently dropped. Iterate over the full list, using a unique key
per image (key_0, key_1, ...) when more than one figure is present, and
wrap each iteration in the NoCredentialsError handler.

Closes mllam#495

LiveReview Pre-Commit Check: skipped (iter:1, coverage:0%)
Covers single-image key preservation, multi-image indexed keys,
step-based key prefixing, and NoCredentialsError exits on any iteration.

LiveReview Pre-Commit Check: skipped (iter:1, coverage:0%)
@princekumarlahon
Copy link
Copy Markdown

Hi! I had opened an issue suggesting support for logging multiple images and saw this PR implementing it. Great work I’d be happy to help with testing, edge cases, or any improvements if needed

@Raj-Taware
Copy link
Copy Markdown
Author

Hi! I had opened an issue suggesting support for logging multiple images and saw this PR implementing it. Great work I’d be happy to help with testing, edge cases, or any improvements if needed

Hey @princekumarlahon thanks !
Happy to have another set of eyes on this PR ! if you spot any edge cases I have missed,feel free to comment or push a suggestion :)

@princekumarlahon
Copy link
Copy Markdown

Nice improvement overall, this definitely makes the function more flexible

I had a few small observations while going through the code:

  1. It looks like "images[0].savefig(...)" before the loop might be unnecessary since all images are already being handled inside the loop.
  2. Right nowb it seems like only the last image gets logged after the loop, so multiple images might not be logged as intended.
  3. The exception block also looks like it has some duplicated or unreachable code that could probably be simplified.
  4. Also, the filename used in "mlflow.log_image" doesn’t seem to match the indexed filenames created inside the loop.

Maybe moving the logging part inside the loop would make things cleaner and ensure each image is handled consistently.

Happy to take another look or help test if needed

@Raj-Taware
Copy link
Copy Markdown
Author

Nice improvement overall, this definitely makes the function more flexible

I had a few small observations while going through the code:

  1. It looks like "images[0].savefig(...)" before the loop might be unnecessary since all images are already being handled inside the loop.
  2. Right nowb it seems like only the last image gets logged after the loop, so multiple images might not be logged as intended.
  3. The exception block also looks like it has some duplicated or unreachable code that could probably be simplified.
  4. Also, the filename used in "mlflow.log_image" doesn’t seem to match the indexed filenames created inside the loop.

Maybe moving the logging part inside the loop would make things cleaner and ensure each image is handled consistently.

Happy to take another look or help test if needed

Hey ! Thank you for your input ! It seems like you maybe reading the old original code, the bugs you are talking about are exactly what this PR fixes.

@princekumarlahon
Copy link
Copy Markdown

Ahh got it, thanks for pointing that out I must have been looking at the earlier version of the code. The changes make sense now I’ll go through the updated implementation more carefully and see if I can spot any edge cases or improvements.

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.

Support logging multiple images in log_image method

2 participants