Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bugfix for polynomial root-finding #1322

Merged
merged 6 commits into from
Mar 1, 2024

Conversation

DavidLegg
Copy link
Contributor

@DavidLegg DavidLegg commented Feb 6, 2024

  • Tickets addressed: N/A
  • Review: By commit
  • Merge strategy: Merge (no squash)

Description

Fixes a few bugs related to rootfinding and expiry-propagation for Polynomial resources. The most important of these fixes are:

  • Taking expiry into account for dynamicsChange condition. This was an unusual case exposed by the solver: A solution could expire early due to inputs that expire, but the updated inputs return the same result. In this case, the solution data remains the same, but the solution expiry is extended. This needs to count as the dynamics "changing", since downstream consumers may be interested in the expiry, not just the data.
  • Stability and performance improvements for Polynomial root-finding.
    • For stability, addresses an edge case where binary search for the exact root could overflow, and conditions the problem for the Laguerre solver by normalizing the polynomial's constant term to 1. This lets the solver converge in a few extra edge cases without affecting "regular" cases much.
    • For performance, adds a special case for linear polynomials, where we directly solve for the root instead of using the Laguerre solver. This tends to be faster and possibly more stable, and a large proportion of real-world cases tend to be linear.
  • Passing expiry through the solver and clampedIntegrate functions. These components used to erase expiry information, as a patch over the bug in the dynamicsChange condition described above (though I didn't know at the time that was why erasing expiry information helped.) Now, by more carefully and selectively erasing expiry information outside the solver, we can preserve expiry information from inputs to the solver and clampedIntegrate through to the output. This in turn lets downstream components like approximations make better decisions. In particular, we have a use case for the SRL model with an approximation of a quadratic clamped integral. If we don't pass expiry information through, then the approximation "overshoots" the expiry, is interrupted by the next quadratic segment, and produces a discontinuity in the output. By passing the expiry through to the approximation, the approximation can align the approximation segment's endpoint with the expiry, and hence avoid this discontinuity.

Before:
image

After
image

Verification

The changes in polynomial root-finding come with additional unit tests to detect some of these edge cases. Additionally, Brad has tested these changes with the SRL model, with positive results.

Documentation

N/A

Future work

N/A

@DavidLegg DavidLegg requested a review from a team as a code owner February 6, 2024 18:27
@DavidLegg DavidLegg changed the title Bugfix polynomial rootfinding convergence Bugfix for polynomial root-finding Feb 6, 2024
Copy link
Contributor

@bradNASA bradNASA left a comment

Choose a reason for hiding this comment

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

I've tested this. SRL is having to use contrib jars from this branch until merged; the model is broken without it. The performance improvement for SRL seems dramatic, maybe twice as fast.

@mattdailis mattdailis force-pushed the bugfix--polynomial-rootfinding-convergence branch from 1944f51 to fe23aab Compare February 28, 2024 19:30
David Legg added 6 commits February 29, 2024 20:14
There's an edge case that was missed by dynamicsChange conditions: when a cell is set to a dynamics with the same data, but a later expiry.
This was discovered while debugging clamped integrals whose integrands changed from one limited-out value to another.
The solver would emit the same effective rate for the integral (0), but with an expiry that changed from zero time to some positive time.
By only reacting to the first change, the zero expiry time was propagated forward, but the corrected non-zero time wasn't.
When solving for an interval over which to take an approximation, we take the expiry of the dynamics
to be approximated into account. In the case when no solution is found, we should still take expiry into account.

This is especially important when that expiry is much shorter than the typical approximation interval.
In this case, we can often choose the full expiry as the approximation interval without reaching our maximum error tolerance,
resulting in a NoBracketingException from the solver. In this case, we should choose the expiry, not the maximum approximation interval,
to be consistent with the time range we searched.
Improve performance of polynomial root-finding by solving linear polynomials directly,
instead of handing off to the Laguerre solver.
For nonlinear polynomials, improve the stability of root-finding for polynomials with very large or very small coefficients
by first conditioning the problem, normalizing the constant coefficient to 1.
Removes the use of eraseExpiry in LinearBoundaryConsistencySolver.
This was a patch put in place to support feedback loops involving the solver,
but it erases too much information. Leaving the expiry in place and erasing it
only when actually building a feedback loop lets downstream components like approximations
take that expiry into account.

Also reconfigures the use of eraseExpiry in clampedIntegrate to pass expiry information through.
@mattdailis mattdailis force-pushed the bugfix--polynomial-rootfinding-convergence branch from fe23aab to fac6582 Compare March 1, 2024 01:14
@mattdailis mattdailis merged commit e8bfb35 into develop Mar 1, 2024
6 checks passed
@mattdailis mattdailis deleted the bugfix--polynomial-rootfinding-convergence branch March 1, 2024 01:50
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.

3 participants