Skip to content

fix: a repeated sample keeps the distributed state; capstan bounds overflow to inf as Python - #50

Merged
SMI-Lab-Inha merged 3 commits into
devfrom
fix/roundoff-cycles-and-capstan
Nov 20, 2026
Merged

SMI-Lab-Inha merged 3 commits into
devfrom
fix/roundoff-cycles-and-capstan

Conversation

@SMI-Lab-Inha

@SMI-Lab-Inha SMI-Lab-Inha commented Nov 20, 2026 •

Copy link
Copy Markdown
Owner

Summary

This PR fixes two kernel defects. Each made the compiled and the reference path give different answers on a valid input:

Defect Input Before Now
Round-off cycles of the distributed model at a constant curvature compute_fatigue(cable, kx=0.01, ky=0, tension_N=2e5, friction_model="distributed"), 33 kV template compiled: inner armour damage 1.4e-58, critical angle 135° (arbitrary); reference: 0. Both: outer armour 1e-69 (compiled 6.2e-69, reference 3.9e-70) 0 on both paths and both layers
Capstan bound overflow when the compiled kernels run as Python (without numba) compute_fatigue(..., friction_model="progressive", mu=1e6) with CABLEXSEC_DISABLE_NUMBA=1; fast_slip forced without numba OverflowError: math range error from math.expm1, then FloatingPointError in the reference progressive history the stuck answer, equal on both paths to mu = 3e4 (from where the progressive model is fully stuck on the probe history)

1. A repeated sample keeps the distributed state

The friction stress of the distributed helix model at a constant curvature of 0.01 1/m and 200 kN behaved differently on the two kernels:

  • Compiled kernel: it drifted by 2e-6 Pa per sample on the inner armour. The kernel starts each increment's Newton iteration from the increment of the last substep. On a sample that repeats the last one, the exact increment is zero, but a start elsewhere converges only to the Newton tolerance (1e-12 h times the force scale). The rainflow counter counted that drift as cycles.
  • Both kernels: on the outer armour they also moved the segment forces by one ulp on the first repeated sample, because the solve recomputes them.

Changes:

  • Under the Coulomb bound (no friction law), a sample whose curvature and pressure equal the last sample's keeps the state in both kernels. There is no solve and no substep, and its outputs equal the last sample's bit for bit.
  • Under a friction law, a repeated sample is still solved, because a node can heal while it sticks. The compiled kernel now starts it from a zero increment, as the reference does.

Only histories with exactly repeated samples change: the repeated samples themselves, and the later samples at round-off (Newton tolerance).

2. Capstan bounds overflow to inf as Python too

Compiled, math.expm1 of an argument beyond log(DBL_MAX) returns inf, and the wires stick. Run as Python (the kernels without numba, and the kernel-coverage pass), it raises OverflowError.

  • New helper. friction_law._expm1_or_inf returns inf past log(DBL_MAX) = 709.782712893384 and math.expm1 below it. Its overflow point matches numba's and CPython's: expm1(709.782712893384) is finite on both, and the next double gives inf compiled and an error in Python.
  • Kernels. The rising bounds of fast_slip and the progressive caps use the helper. Compiled results are therefore unchanged at every argument.
  • Reference progressive history. It also refused the resulting non-finite caps. A sub-element cap past the range (inf, or inf - inf between two such cumulative bounds) is now held at 1e300 Pa, like the reference Papailiou bound (fix: adversarial inputs of the public API are refused early or answered on both kernel paths #41). The history sticks where the compiled kernel sticks.

I first tried capping the exponent at _EXP_LIMIT = 600, as friction_law already does. That is wrong for the progressive model: its sub-element caps are differences of cumulative bounds, so capped elements get zero cap. At mu = 1e4 the damage fell from the stuck limit 9.25e-7 to 8.4e-9. It is not used.

Damage of the progressive model against mu on the probe history (outer armour):

mu compiled, before and after reference, after
1e3 9.252062354718316e-07 9.252062354718314e-07
1e4 9.252062354718293e-07 9.252062354718254e-07
1e6 9.252062354718293e-07 9.252062354718254e-07 (was OverflowError)

Reviewed, not changed

  • friction_law already caps its exponents at 600. That is right there, because its bounds are not differenced.
  • fast_rainflow evaluates 10 ** (log C - m log10 S). This overflows only for subnormal stress ranges, which no history reaches.

Tests

  • test_fast_kernel_fall_backs now expects the fixed point to fail on sample 4 instead of 3, because sample 0 repeats the stress-free start.

  • tests/test_distributed_fast.py (fail without the fix):

    • test_a_repeated_sample_keeps_the_state[signed, uniform]: ramp, hold, reversal and second hold. In both kernels the held samples equal the last sample bit for bit (wire forces, segment field, energies, slip fraction), take no substep, and agree between the kernels.
    • test_a_repeated_sample_under_a_friction_law_is_solved_from_zero: with healing, the fast kernel still matches the reference.
  • tests/test_robustness_inputs.py:

    • test_constant_curvature_gives_no_distributed_damage[reference, fast]: zero damage on both layers. Fails without the fix.
    • test_very_large_mu_sticks_in_the_progressive_model: mu = 1e6 equals mu = 3e4. Fails without numba before the fix.
    • test_expm1_guard_is_the_compiled_expm1_at_every_argument.
    • test_very_large_mu_sticks_on_both_kernel_paths now forces the fast_slip kernel in every environment, including without numba.

No tolerance or band changed.

Gates

On f8438f5. The next commit changes only the CHANGELOG wording. 439624b changes only test_fast_kernel_fall_backs, an interpreted-kernel test that counts fixed-point calls: its first sample repeats the stress-free start and now needs no solve, so the failing call moves from sample 3 to sample 4.

  • full suite with NUMBA_NUM_THREADS=1: 4879 passed, 4 skipped
  • full suite with CABLEXSEC_DISABLE_NUMBA=1: 4761 passed, 2 failed, 120 skipped. The two failures were test_fast_kernel_fall_backs[0.127, 0.0], fixed in 439624b; tests/test_distributed_fast.py then passes in full, 29 tests without numba and 26 with (3 skipped).
  • python -m mypy: no issues in 120 source files; ruff check and ruff format --check on src tests examples validation release doc: clean
  • taxonomy from --collect-only per marker: unchanged at 1248 / 77 / 59 (the new tests carry no marker)

…erflow to inf as Python

A constant curvature cycled in the distributed helix model. The compiled
kernel started a sample that repeats the last one from the increment of
the last substep and converged to a drift of the Newton tolerance (2e-6 Pa
per sample on the 33 kV template's inner armour at 0.01 1/m and 200 kN),
which compute_fatigue counted as 1e-58 damage where the reference kernel
gave 0. Both kernels also moved the segment forces by one ulp on such a
sample (1e-69 damage on the outer armour). Under the Coulomb bound a
repeated sample now keeps the state in both kernels, with no substep;
under a friction law it is still solved (a node can heal while it sticks),
the compiled kernel starting it from a zero increment as the reference
does.

Run as Python (without numba), the compiled direction-tied and
progressive kernels raised OverflowError from math.expm1 where compiled
they return inf. friction_law._expm1_or_inf gives inf past log(DBL_MAX) on
both, bit for bit equal to math.expm1 below it. Without numba this made
compute_fatigue(..., friction_model="progressive", mu=1e6) fail. The
reference progressive history holds such a sub-element cap at 1e300 Pa, as
the reference Papailiou bound does, so it sticks where the compiled kernel
does. Compiled results are unchanged.

Signed-off-by: Jae Hoon Seo <jaehoon.seo@inha.ac.kr>
Signed-off-by: Jae Hoon Seo <jaehoon.seo@inha.ac.kr>
@SMI-Lab-Inha

Copy link
Copy Markdown
Owner Author

@codex review

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 20, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-20T07:01:00.978053Z 439624b Manual request
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@read-the-docs-community

read-the-docs-community Bot commented Nov 20, 2026 •

Copy link
Copy Markdown

Documentation build overview

📚 CableXSec | 🛠️ Build #36034451 | 📁 Comparing 439624b against latest (240bf9c)

  🔍 Preview build  

24 files changed · ± 24 modified

± Modified

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Breezy!

Reviewed commit: fded8f11c2

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

The interpreted fall-back test counts fixed-point calls. Its first sample
repeats the stress-free start (zero curvature), which now keeps the state
without a solve, so the failing call falls on sample 4 instead of 3.

Signed-off-by: Jae Hoon Seo <jaehoon.seo@inha.ac.kr>
@SMI-Lab-Inha

Copy link
Copy Markdown
Owner Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Chef's kiss.

Reviewed commit: 439624bfd2

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@SMI-Lab-Inha
SMI-Lab-Inha merged commit 49050a7 into dev Nov 20, 2026
14 checks passed
@SMI-Lab-Inha
SMI-Lab-Inha deleted the fix/roundoff-cycles-and-capstan branch November 20, 2026 08:38
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