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

Constant Folding #51

Open
lukem12345 opened this issue Jun 24, 2024 · 6 comments
Open

Constant Folding #51

lukem12345 opened this issue Jun 24, 2024 · 6 comments
Assignees
Labels
enhancement New feature or request

Comments

@lukem12345
Copy link
Member

lukem12345 commented Jun 24, 2024

Currently, we perform type inference on Decapodes to infer the degree and primality of differential forms.

However, we could also infer that computations derived solely from constants are also constants. I.e. Constant Folding is a special case of type inference on Variables.

So, we should leverage and augment existing type inference machinery to perform constant folding. The compilation of these down to simulation code is in the realm of Decapodes. The scope of a closing PR for DiagrammaticEquations is to just change uninferred nodes (and optionally Form-typed nodes) to constants when possible.

As with most PRs, this feature would be written differently if we stored whether a form is constant or not separately from the type of differential form it may be.

@lukem12345 lukem12345 added the enhancement New feature or request label Jun 24, 2024
@lukem12345 lukem12345 self-assigned this Jun 24, 2024
@lukem12345
Copy link
Member Author

Constants can also be deduced from properties of the algebraic theory, such as two exterior derivatives leading to a Constant 0-valued form. Or, Variable A is 2 times Variable B, Variable C is -1/2 times Variable C, and Variable D is A+B.

Such cases are outside the domain of this issue. They are lower priority, since equations given in the literature usually are presented in fully reduced form. Although maybe someone can find a compelling example. Or maybe such a case can arise from a composition.

@GeorgeR227
Copy link
Contributor

The problems with constant folding here is that constant values are never given to us by the user, only to solve. We merely hold on to their variable names. So if we infer types to be constants, then we'd be asking the user for more given values then they expected to have to give or asking for different ones entirely.

For the case of two exterior derivatives, we can just add a 0-matrix and an identity matrix to the default dec backend.

@lukem12345
Copy link
Member Author

lukem12345 commented Jun 25, 2024

Although that is one way to use this feature, we can still only need the top-level constants. We just add a pre-processing phase that computes downstream constants once beforehand instead of every time inside f. Closures

@GeorgeR227
Copy link
Contributor

I that seems fine but I don't really see any performance gains for doing this. I think most users are going to be using constants for numbers and maybe a few for vectors but those are really light computationally speaking. And in most cases there won't be more than a handful of constants total.

If we can come up with a reasonable example where there is noticeable benefit then we can go ahead and do this.

@lukem12345
Copy link
Member Author

Useful for FEED.

@GeorgeR227
Copy link
Contributor

GeorgeR227 commented Jun 25, 2024

I'm not familiar with what values are labeled Constant in the FEED model. But I would say in any case to benchmark FEED as is now and with manually applied constant folding to see if we get nice gains.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants