fix: from_dict dropped dict entries with falsy values (0.0 parameters vanish on load)#1384
Merged
Merged
Conversation
The type=="dict" branch filtered entries with `if value`, silently dropping any entry whose deserialized value is falsy — including parameters exactly 0.0. Exposed by PYAUTO_TEST_MODE_SAMPLES (#1381) bypass output: lens centres/ell_comps have zero prior medians, so bypass-written summaries loaded with 8 of 15 parameters missing and al.agg reconstruction crashed with KeyError. Only None is skipped now. Regression test: zero-valued Sample kwargs round-trip. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
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.
Summary
from_dict's dict branch (autofit/mapper/model_object.py) filtered entries withif value, silently dropping any dictionary entry whose deserialized value is falsy — including parameters whose value is exactly0.0. Exposed by thePYAUTO_TEST_MODE_SAMPLESbypass (#1381), which writes exact prior-median sample values: lens-model centres and ell_comps have zero medians, so a bypass-writtensamples_summary.jsonloaded back with 8 of 15 parameters missing andTracerAgg/FitImagingAggreconstruction crashed withKeyErroron the missing paths. Any stored dict with a legitimately-zero value (sample kwargs, info dicts) was affected — this predates #1381, which merely made it deterministic.API Changes
None — bug fix only:
from_dicton a serialized dict now keeps entries whose value is0.0/False/""and drops onlyNone(the original intent of the filter).See full details below.
Test Plan
pytest test_autofit/— 1494 passed, 1 skippedtest_autofit/serialise/test_samples.py::test_sample_zero_valued_kwargs_round_tripPYAUTO_TEST_MODE=2bypass fit of a lens model (zero-median centre priors) round-trips its summary and reconstructs tracers/fits throughal.agg(aggregator-lens-profiling harness, autolens_workspace_test PR)Full API Changes (for automation & release notes)
Changed Behaviour
ModelObject.from_dict(type == "dict"branch) — entries with falsy non-None values (0.0,False,"") are no longer silently dropped on deserialization; onlyNonevalues are skipped.Generated by the PyAutoLabs agent workflow.