Repository navigation
fix: draw_randomly_via_pdf normalises sample weights - #1751
Merged
Merged
Conversation
np.random.choice requires probabilities summing to 1; test-mode bypass samples (weights 1, 0.5, 0.25, 0.125) made every draw raise. Normalise as samples_drawn_randomly_via_pdf already does. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2 of 3 tasks
Collaborator
Author
|
Workspace PR: PyAutoLabs/autolens_workspace#613 |
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
SamplesPDF.draw_randomly_via_pdfpassed the raw sample weights tonp.random.choice, which requires them to sum to 1. The test-mode bypass samples (PYAUTO_TEST_MODE=2, weights[1.0, 0.5, 0.25, 0.125], sum 1.875) therefore made every draw raiseValueError: probabilities do not sum to 1. That blocks the smoke run of any workspace script that draws from a posterior, including the new magnification-error sections in theautolens_workspacesource_science scripts (PyAutoLabs/autolens_workspace#610).The weights are now normalised before the draw, as
samples_drawn_randomly_via_pdfalready does. The test-mode weights themselves are unchanged (they are locked bytest__env_unset__legacy_four_samples_byte_identical).Heart was RED at ship time (release integrate stage; reasons quoted on autolens_workspace#610). The human authorised development under the Heart RED override for this task on 2026-10-31 and chose "Fix PyAutoFit first" for this blocker. Merge requires its own human /prm.
API Changes
None to signatures.
draw_randomly_via_pdfnow accepts sample weights that do not sum exactly to 1 (normalising them), instead of raising.See full details below.
Test Plan
test__draw_randomly_via_pdf__weights_not_summing_to_one— fails without the change, passes with itpython -m pytest test_autofit— 4171 passed, 2 skipped, 1 xfailedsource_science.pysmoke runs (PYAUTO_TEST_MODE=2, PYAUTO_SMALL_DATASETS=1) pass with this branch; all three failed on mainFull API Changes (for automation & release notes)
Changed
SamplesPDF.draw_randomly_via_pdf(as_instance=True, as_dict=False)— sample weights are normalised to sum to 1 before drawing.Migration
Generated by the PyAutoLabs agent workflow.
🤖 Generated with Claude Code