NASA-AMMOS / aerie

A software framework for modeling spacecraft.
https://nasa-ammos.github.io/aerie-docs/
MIT License
68 stars 19 forks source link

Add efficient resource reduction #1532

Closed DavidLegg closed 3 weeks ago

DavidLegg commented 1 month ago

Description

Adds reduce methods to a number of Resource monads, which do a "flat" resource reduction. That is, they use ThinResourceMonad.reduce to produce a single resource node, which collects all dependencies and reduces the dynamics, rather than the original Resources.reduce method, which creates a number of intermediate resources linear in the number of operands.

When doing large roll-ups, like a power model, those intermediate nodes each contribute a small performance overhead which can eventually add up. Providing a standard way to do reduction efficiently, and using that to do common operations like taking a sum or maximum, should help.

Verification

Some methods which use the new reduce operations, like PolynomialResources.min and max, already have unit tests. Those tests continue to pass unaltered.

Documentation

No documentation was invalidated - existing functions should have no logical changes, but they may be more efficient. These reduce operators are mentioned in the streamline users' guide already. I wrote them once before and thought they were part of the main library, but I must have written them on another branch that has since been abandoned.

Future work

N/A