Skip to content

Fix crash in make_fake_toas when add_correlated_noise=True with no correlated-noise component - #2043

Open
Rome-1 wants to merge 1 commit into
nanograv:masterfrom
Rome-1:fix/make-fake-toas-no-correlated-noise
Open

Rome-1 wants to merge 1 commit into
nanograv:masterfrom
Rome-1:fix/make-fake-toas-no-correlated-noise

Conversation

@Rome-1

@Rome-1 Rome-1 commented Sep 19, 2026

Copy link
Copy Markdown

pint.simulation.make_fake_toas(..., add_correlated_noise=True) crashes with a TypeError/AttributeError (object of type 'NoneType' has no len() / 'NoneType' object has no attribute 'shape') when the timing model has no correlated-noise component, instead of either no-opping or raising a clear error.

The cause is that TimingModel.noise_model_designmatrix and TimingModel.noise_model_basis_weight both return None when the model has no correlated-noise component (no PLRedNoise, PLDMNoise, EcorrNoise, etc.), and make_fake_toas dereferences those return values without a guard.

The fix adds a guard around the None case in make_fake_toas: if either matrix is None, it logs a warning and skips the correlated-noise term instead of crashing. This mirrors how TimingModel.full_designmatrix/full_wideband_designmatrix already treat a None noise design matrix elsewhere in the same module, and follows the existing log.warning-and-fall-back convention already used twice in simulation.py for other unexpected-but-non-fatal inputs.

Reproducer (crashes before this fix, runs cleanly after):

from pint.models import get_model
import pint.simulation, pint, pathlib
ex = pathlib.Path(pint.__file__).parent / "data" / "examples"
m = get_model(str(ex / "J0740+6620.FCP+21.wb.DMX3.0.par"))
pint.simulation.make_fake_toas_fromtim(
    str(ex / "J0740+6620.FCP+21.wb.tim"), model=m,
    add_noise=True, add_correlated_noise=True)

Added a regression test, test_simulate_corrnoise_no_noise_components in tests/test_fake_toas.py, that calls make_fake_toas_uniform(..., add_correlated_noise=True) on a model with no correlated-noise component; it fails on master and passes with this change.

…ut correlated noise

make_fake_toas(..., add_correlated_noise=True) crashed with a
TypeError/AttributeError when the timing model had no correlated-noise
component (no PLRedNoise, PLDMNoise, EcorrNoise, etc.), because
noise_model_designmatrix/noise_model_basis_weight return None in that
case and the None was dereferenced without a guard. Now it logs a
warning and skips the correlated-noise term, matching how
full_designmatrix already treats a None noise design matrix elsewhere
in this module.

Added a regression test in tests/test_fake_toas.py that exercises
add_correlated_noise=True against a model with no correlated-noise
component.
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