Skip to content

fix: draw_randomly_via_pdf normalises sample weights - #1751

Merged
Jammy2211 merged 1 commit into
mainfrom
feature/magnification-errors-source-science
Oct 31, 2026
Merged

Jammy2211 merged 1 commit into
mainfrom
feature/magnification-errors-source-science

Conversation

@Jammy2211

Copy link
Copy Markdown
Collaborator

Summary

SamplesPDF.draw_randomly_via_pdf passed the raw sample weights to np.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 raise ValueError: 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 the autolens_workspace source_science scripts (PyAutoLabs/autolens_workspace#610).

The weights are now normalised before the draw, as samples_drawn_randomly_via_pdf already does. The test-mode weights themselves are unchanged (they are locked by test__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_pdf now accepts sample weights that do not sum exactly to 1 (normalising them), instead of raising.
See full details below.

Test Plan

  • New test__draw_randomly_via_pdf__weights_not_summing_to_one — fails without the change, passes with it
  • python -m pytest test_autofit — 4171 passed, 2 skipped, 1 xfailed
  • autolens_workspace imaging / imaging MGE / interferometer source_science.py smoke runs (PYAUTO_TEST_MODE=2, PYAUTO_SMALL_DATASETS=1) pass with this branch; all three failed on main
Full 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

  • None.

Generated by the PyAutoLabs agent workflow.

🤖 Generated with Claude Code

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>
@Jammy2211 Jammy2211 added the pending-release PR queued for the next release build label Oct 31, 2026
@Jammy2211
Jammy2211 merged commit e9d3c6a into main Oct 31, 2026
5 checks passed
@Jammy2211
Jammy2211 deleted the feature/magnification-errors-source-science branch October 31, 2026 14:59
@pyautolabs-bot pyautolabs-bot Bot removed the pending-release PR queued for the next release build label Nov 1, 2026
@Jammy2211

Copy link
Copy Markdown
Collaborator Author

Workspace PR: PyAutoLabs/autolens_workspace#613

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.

1 participant