Skip to content

FEAT: accept array-valued parameters - #583

Open
grayson-helmholz wants to merge 8 commits into
ENH/jit-estimatorsfrom
FEAT/array-parameters
Open

FEAT: accept array-valued parameters#583
grayson-helmholz wants to merge 8 commits into
ENH/jit-estimatorsfrom
FEAT/array-parameters

Conversation

@grayson-helmholz

@grayson-helmholz grayson-helmholz commented Aug 7, 2026

Copy link
Copy Markdown
Contributor

Closes #571

✨ New features

Estimators now accept array-valued parameters. A parameter value of shape (p,) represents p parameter points, and the estimator returns an array of p estimator values — one per point — computed in a single, backend-parallelized call. Scalar parameter values behave exactly as before and still yield a scalar.

The main use case is propagating fit uncertainties: a set of bootstrapped or sampled parameter points can be evaluated in one vectorized call rather than in a Python loop, and on the JAX backend that call is JIT-compiled like any other estimator evaluation.

New public type alias ParameterType in tensorwaves.interface, which is ParameterValue | Array. It is now used wherever a parameter value is accepted: ParametrizedFunction.__call__, Estimator.__call__, and the estimator implementations. ParameterValue keeps its meaning and now documents itself as the scalar parameter type.

Array parameters are given a trailing axis on entry, so that they broadcast against the event axis of a DataSample, and the estimator reductions consequently reduce over the event axis (axis=-1) rather than over the whole array. Estimator.__call__ is annotated as returning float | FloatArray to reflect the new array case.

New public type aliases Array and FloatArray in tensorwaves.interface. Array is np.ndarray[Any, np.dtype[ScalarT]], generic in its scalar type through the new ScalarT type variable, which defaults to Any so that a bare Array stays dtype-agnostic. FloatArray is Array[np.floating], for arrays that have to be real-valued. DataSample is now dict[str, Array].

⚙️ Enhancements

Estimator.__call__ and both estimator implementations are now @overload-ed, so that a mapping of scalar parameter values is typed as returning float, a mapping of arrays as returning FloatArray, and a mixed mapping as float | FloatArray. Callers no longer have to narrow the return type themselves.

Function signatures that necessarily take a real-valued function are narrowed from Array to FloatArray: ChiSquared, UnbinnedNLL, and IntensityDistributionGenerator. This matches what their docstrings already state, namely that they work on an intensity $f_\mathbf{p}: X^m \rightarrow \mathbb{R}$. Signatures that are genuinely dtype-agnostic keep a bare Array, because a lambdified expression may well be complex-valued: ParametrizedBackendFunction, PositionalArgumentFunction, create_cached_function, and SympyDataTransformer.

🔨 Maintenance

All remaining np.ndarray annotations are replaced with the Array alias, so that the array type is defined in one place and can be narrowed per site. Sphinx is taught to resolve the new aliases (Array, FloatArray, ScalarT) through api_target_substitutions and autodoc_type_aliases.

typing-extensions >=4.4.0 becomes a runtime dependency on Python <3.13, because ScalarT needs PEP 696 type-variable defaults.

The callback logs in ScipyMinimizer now reuse the estimator value that was just computed, instead of re-evaluating the estimator for the log and casting the cached value with float(). The cast on the value that is handed back to SciPy itself stays, since SciPy needs a scalar.

Squash commit messages

* ENH: implement `Array` and `FloatArray` type aliases
* ENH: narrow intensity function types to `FloatArray`
* ENH: use `@overload` for estimator calls
* MAINT: remove redundant estimator value casts

@redeboer redeboer linked an issue Aug 7, 2026 that may be closed by this pull request
@redeboer
redeboer force-pushed the FEAT/array-parameters branch from 9903461 to 83fb16a Compare August 31, 2026 14:44
@redeboer
redeboer force-pushed the FEAT/array-parameters branch from 83fb16a to c5371a1 Compare September 1, 2026 08:59

@redeboer redeboer left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Performance Alert ⚠️

Possible performance regression was detected for benchmark 'TensorWaves benchmark results'.
Benchmark result of this commit is worse than the previous benchmark result exceeding threshold 2.

Benchmark suite Current: 1a4a844 Previous: f5c1db9 Ratio
benchmarks/ampform.py::TestJPsiToGammaPiPi::test_fit[10000-jax] 0.5013097544496096 iter/sec (stddev: 0) 1.439081184425215 iter/sec (stddev: 0) 2.87

This comment was automatically generated by workflow using github-action-benchmark.

@redeboer redeboer added the ✨ Feature New feature added to the package label Sep 1, 2026
@redeboer redeboer changed the title FEAT: accept array-valued parameters in estimators FEAT: accept array-valued parameters Sep 1, 2026
Parameter values passed to ChiSquared and UnbinnedNLL may now be
one-dimensional arrays of shape (p,), which are broadcast against the
event axis so that the estimator returns one value per parameter point,
all in a single backend-parallelized call. This makes it cheap to e.g.
propagate fit uncertainties over bootstrapped parameter samples, as done
in ComPWA/polarimetry. Behavior for scalar parameter values is unchanged.

Closes #571
@redeboer
redeboer force-pushed the FEAT/array-parameters branch from c5371a1 to 4f87c81 Compare September 1, 2026 09:30
@redeboer
redeboer force-pushed the FEAT/array-parameters branch from 7c4412a to 1dca885 Compare September 1, 2026 10:10
@redeboer redeboer added 🔨 Maintenance Maintenance and upkeep improvements ⚙️ Enhancement Improvements and optimizations of existing features labels Sep 1, 2026
@redeboer redeboer modified the milestones: 0.4.18, 0.5.0 Sep 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

⚙️ Enhancement Improvements and optimizations of existing features ✨ Feature New feature added to the package 🔨 Maintenance Maintenance and upkeep improvements

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Array-valued parameters for batched estimator evaluation

2 participants