Fix YAML anchor references in params.yaml by implementing NoAnchorDumper#941
Conversation
|
@PythonFZ 👋 This repository doesn't have Copilot instructions. With Copilot instructions, I can understand the repository better, work faster and produce higher quality PRs. I can generate a .github/copilot-instructions.md file for you automatically. Click here to open a pre-filled issue and assign it to me. I'll write the instructions, and then tag you for review. |
Co-authored-by: PythonFZ <46721498+PythonFZ@users.noreply.github.com>
&id001 refs| config.PARAMS_FILE_PATH.write_text(yaml.dump(params_dict, Dumper=_NoAnchorDumper)) | ||
| config.DVC_FILE_PATH.write_text(yaml.dump(dvc_dict, Dumper=_NoAnchorDumper)) |
There was a problem hiding this comment.
I think it would be better to use json.loads(json.dumps(...)) because it adds less code and with a comment refering to yaml/pyyaml#535 this would be much simpler.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #941 +/- ##
==========================================
+ Coverage 88.74% 88.77% +0.03%
==========================================
Files 40 40
Lines 2434 2442 +8
==========================================
+ Hits 2160 2168 +8
Misses 274 274 ☔ View full report in Codecov by Harness. |

This PR fixes an issue where
params.yamlfiles sometimes contained unwanted YAML anchor references like&id001when the same object appeared multiple times in the data structure.Problem
PyYAML automatically generates anchor references when the same object is referenced multiple times to avoid duplication. For example:
While this is valid YAML, it creates confusing and unreadable configuration files that are harder to understand and maintain.
Solution
Implemented a custom
_NoAnchorDumperclass that inherits fromSafeDumperand overrides theignore_aliasesmethod to always returnTrue, preventing automatic anchor generation.Changes
_NoAnchorDumperand updatedparams.yamlanddvc.yamlgeneration_NoAnchorDumperand updated experiment info YAML generationResult
The same data now generates clean, readable YAML:
The fix maintains full semantic equivalence and backward compatibility while producing cleaner, more maintainable configuration files.
Fixes #940.
💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.