Skip to content

fix: SimulatorImaging draws Poisson noise only when used and clips round-off negatives - #688

Merged
Jammy2211 merged 1 commit into
mainfrom
feature/simulator-poisson-flag-guard
Nov 10, 2026
Merged

Jammy2211 merged 1 commit into
mainfrom
feature/simulator-poisson-flag-guard

Conversation

@Jammy2211

Copy link
Copy Markdown
Collaborator

Summary

SimulatorImaging.via_image_from always drew Poisson noise and only then checked add_poisson_noise_to_data. With Poisson noise switched off, round-off negatives from PSF convolution (around 1e-17 of the peak) still reached np.random.poisson, which raised ValueError: lam < 0. That killed 4 of 100 Euclid sersic resimulations. Closes #687.

  • The draw now runs only when add_poisson_noise_to_data or include_poisson_noise_in_noise_map is set. This is a Python-level check on the simulator's flags, so JAX tracing is unaffected.
  • poisson_noise_via_data_eps_from clips round-off negatives to zero before drawing, on both the NumPy and JAX paths. On NumPy, an image that is genuinely negative (minimum below -1e-10 times its maximum) raises a clear DatasetException.

API Changes

Behaviour changes only, no signature changes:

  • With both Poisson flags off, the simulator no longer draws Poisson noise and so no longer reseeds or consumes the global np.random state.
  • Round-off negatives are clipped before the Poisson draw instead of raising.
  • A genuinely negative image with Poisson on raises DatasetException (NumPy) instead of NumPy's ValueError. Under JAX it is clipped to zero.
    See full details below.

Test Plan

  • 5 new tests in test_autoarray/dataset/imaging/test_simulator.py and test_autoarray/dataset/test_preprocess.py; 4 of them fail on main.
  • Full test_autoarray: 2408 passed.
  • Independent review (Fable 5.2, adversary mode): CLEAN, witness holds. On main the witness input raises; on this branch it passes through unchanged. Seeded outputs with Poisson on match main under NumPy and JAX (including jax.jit).
  • Smoke: pyauto-heart smoke (all workspaces, worktree source): 154 passed, 0 failed. autocti and autocti_test could not build their environment on the laptop (no GSL headers for arcticpy). Covered instead by the full PyAutoCTI unit suite against this branch's autoarray: 279 passed. CTI simulators subclass SimulatorImaging but override every via_* path and use only the Gaussian-noise helpers.

Heart RED override (development only)

Heart was RED when the task started and is RED at ship. The human authorized the override in-session on 2026-11-10: "Do a, override is fine well fix red separate".

  • Current RED reasons: "PyAutoGalaxy/Tests: failure"; "PyAutoLens/Tests: failure"; "PyAutoHands/workflows/Python Version Matrix: failure"; "PyAutoHeart/workflows/Workspace Smoke: failure"; "Workspace validation: NOT ready — 1399p / 14f / 125s @ cloud#42607741369"; "Worktree drift: 0 orphan / 0 missing / 3 dirty".
  • Branch gates passed: unit tests (above), smoke (above) and independent review CLEAN.
  • This PR does not fix Heart. Merge needs a separate human /prm with every required check green. No release is authorized.
Full API Changes (for automation & release notes)

Changed Behaviour

  • SimulatorImaging.via_image_from: Poisson noise is drawn only when add_poisson_noise_to_data or include_poisson_noise_in_noise_map is true. With both off, the global NumPy RNG is not touched.
  • preprocess.poisson_noise_via_data_eps_from / data_eps_with_poisson_noise_added: negative counts are clipped to 0 before drawing. NumPy path: raises exc.DatasetException when min < -1e-10 * |max|. JAX path: clips only.

Known edge

  • An image whose maximum is ≤ 0 has a threshold of 0, so an all-zero image with a -1e-19 pixel and Poisson on still raises. It raised before too, as a ValueError.

Follow-up after release: remove the pipeline-side workaround in euclid_strong_lens_modeling_pipeline (PR #87).

Generated by the PyAutoLabs agent workflow.

🤖 Generated with Claude Code

…687)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Jammy2211 Jammy2211 added the pending-release PR queued for the next release build label Nov 10, 2026
@Jammy2211
Jammy2211 merged commit 2e494f9 into main Nov 10, 2026
3 checks passed
@Jammy2211
Jammy2211 deleted the feature/simulator-poisson-flag-guard branch November 10, 2026 20:44
@pyautolabs-bot pyautolabs-bot Bot removed the pending-release PR queued for the next release build label Nov 12, 2026
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.

fix: SimulatorImaging draws Poisson noise before checking the flag

1 participant