Skip to content

Reject delta_N < 1 in accumulators - #5358

Merged
jngrad merged 2 commits into
espressomd:pythonfrom
RudolfWeeber:fix/bug-24-accumulator-deltaN-validate
Aug 4, 2026
Merged

Reject delta_N < 1 in accumulators#5358
jngrad merged 2 commits into
espressomd:pythonfrom
RudolfWeeber:fix/bug-24-accumulator-deltaN-validate

Conversation

@RudolfWeeber

Copy link
Copy Markdown
Contributor

The Python accumulator API documented delta_N as a positive integer sample
spacing, but no layer validated it. delta_N <= 0 reached the core unchecked:

  • Correlator(delta_N=0): m_dt = time_step * 0 = 0, so the m_tau_max <= m_dt
    guard (e.g. 2.0 <= 0.0) is false; initialize_operations() then computes
    ceil(1 + log2(inf)) and static_cast(inf) for the hierarchy depth (UB),
    producing a bad multi_array resize. Observed as MemoryError
    (std::bad_array_new_length) at construction. This UB does not throw, so the
    existing parallel_try_catch around construction did not catch it.
  • MeanVarianceCalculator/TimeSeries/ContactTimes(delta_N=0) constructed fine,
    then auto_update_accumulators.add(acc) + integrator.run() set frequency=0,
    making next_update() return 0 -> integrate(0) never advances -> infinite
    loop (release) / assert abort (debug).
  • The runtime setter acc.delta_N = 0 was equally unguarded.

Fix (PREVENT invalid input, matching the existing tau_lin/tau_max validation
convention): add a single chokepoint guard in the core
Accumulators::AccumulatorBase ctor (all four accumulators chain to it) that
throws std::runtime_error("delta_N must be >= 1") before initialize() runs,
killing both the Correlator UB and the auto-update hang. Wrap the previously
unwrapped MeanVarianceCalculator and TimeSeries SI ctors in
parallel_try_catch so the throw is MPI-coordinated (Correlator/ContactTimes
already do this). Guard the SI delta_N setter the same way so acc.delta_N = 0
is rejected and leaves the previous value intact.

Extend test_correlator_exceptions and add test_delta_N_validation in
accumulator_correlator.py to cover delta_N in (0, -1) at construction and via
the runtime setter for Correlator, MeanVarianceCalculator and TimeSeries.

Co-Authored-By: Claude Opus 4.8 noreply@anthropic.com

🤖 Generated with Claude Code

…#24)

The Python accumulator API documented delta_N as a positive integer sample
spacing, but no layer validated it. delta_N <= 0 reached the core unchecked:

- Correlator(delta_N=0): m_dt = time_step * 0 = 0, so the m_tau_max <= m_dt
  guard (e.g. 2.0 <= 0.0) is false; initialize_operations() then computes
  ceil(1 + log2(inf)) and static_cast<int>(inf) for the hierarchy depth (UB),
  producing a bad multi_array resize. Observed as MemoryError
  (std::bad_array_new_length) at construction. This UB does not throw, so the
  existing parallel_try_catch around construction did not catch it.
- MeanVarianceCalculator/TimeSeries/ContactTimes(delta_N=0) constructed fine,
  then auto_update_accumulators.add(acc) + integrator.run() set frequency=0,
  making next_update() return 0 -> integrate(0) never advances -> infinite
  loop (release) / assert abort (debug).
- The runtime setter acc.delta_N = 0 was equally unguarded.

Fix (PREVENT invalid input, matching the existing tau_lin/tau_max validation
convention): add a single chokepoint guard in the core
Accumulators::AccumulatorBase ctor (all four accumulators chain to it) that
throws std::runtime_error("delta_N must be >= 1") before initialize() runs,
killing both the Correlator UB and the auto-update hang. Wrap the previously
unwrapped MeanVarianceCalculator and TimeSeries SI ctors in
parallel_try_catch so the throw is MPI-coordinated (Correlator/ContactTimes
already do this). Guard the SI delta_N setter the same way so acc.delta_N = 0
is rejected and leaves the previous value intact.

Extend test_correlator_exceptions and add test_delta_N_validation in
accumulator_correlator.py to cover delta_N in (0, -1) at construction and via
the runtime setter for Correlator, MeanVarianceCalculator and TimeSeries.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@RudolfWeeber RudolfWeeber added this to the ESPResSo 5.0.2 milestone Jul 23, 2026
@jngrad jngrad changed the title accumulators: reject delta_N < 1 in core ctor and SI setter (bug-sweep #24) Reject delta_N < 1 in accumulators Aug 4, 2026
@jngrad jngrad added the BugFix label Aug 4, 2026
@jngrad
jngrad marked this pull request as ready for review August 4, 2026 16:51
@jngrad
jngrad merged commit bc2f57b into espressomd:python Aug 4, 2026
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants