Preserve size=1 vector parameters and add a prior_draw_mode contract - #455
Merged
Conversation
Merging `dev` to `master`
PTA.map_params collapsed a size=1 vector Parameter to a bare scalar
(conflating size=None and size=1), which breaks matrix ops like C @ x on a
one-dimensional whitened block. Also add Parameter.prior_draw_mode
("component" default, "joint" opt-in via UserParameter) so a correlated
vector parameter can declare that prior-draw proposals must replace it as a
whole block rather than one component at a time.
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## dev #455 +/- ##
==========================================
+ Coverage 72.71% 72.85% +0.14%
==========================================
Files 13 13
Lines 3478 3489 +11
==========================================
+ Hits 2529 2542 +13
+ Misses 949 947 -2
Continue to review full report in Codecov by Harness.
🚀 New features to boost your workflow:
|
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
PTA.map_paramsto preserve asize=1parameter as a length-1 arrayinstead of collapsing it to a bare scalar (
n = p.size if p.size else 1conflated
size=Noneandsize=1). A one-dimensional vector parametermapped to a scalar breaks downstream linear algebra (e.g.
C @ xon a1x1 whitening matrix).
Parameter.prior_draw_mode(default"component", class-levelattribute so every existing
Parametersubclass inherits it unchanged)and
UserParameter(..., prior_draw_mode="component"|"joint"), so acorrelated vector parameter can declare that prior-draw proposals must
replace it as a whole block rather than one component at a time.
param_names(onSignal,SignalCollection,and
PTA) now checksp.size is not Noneinstead of the previous truthyif p.size:check, for the samesize=Nonevssize=1distinctionmap_paramsneeded. (param_namesalready produced the correct indexedname for
size=1today; this just makes the two checks consistent.)Why
Part of implementing
nltiming'sfeature_nltiming_sampling_api.md: afull-whitening nonlinear-timing block is a correlated joint vector Enterprise
parameter, and when only one timing parameter is sampled that block has
size=1. Without themap_paramsfix it silently collapsed to a scalar;without
prior_draw_mode, a generic prior-draw proposal (e.g.enterprise_extensions.JumpProposal.draw_from_prior) has no way to know itmust replace such a block atomically rather than one entry at a time, which
is mathematically invalid for a non-diagonal (correlated) prior.
prior_draw_modeis deliberately generic — no NLT-specific attribute or nameinspection — so it's reusable by any future correlated vector parameter, not
just this one.
Test plan
pytest tests/test_parameter.py tests/test_vector_parameter.py— includesnew
TestPriorDrawModeandTestMapParamsVectorShapecoverage (25 tests,all pass).
black --check/flake8clean on the changed files.test_likelihood.py,test_selections.py,test_set_parameter.py,test_utils.py, etc.) — allpass.
Depends on / paired with
Companion PRs on
enterprise_extensions(honorprior_draw_modeinJumpProposal) andnltiming(Enterprise-native timing parameters that usethis contract).