Skip to content

Use _SubexpressionStorage inside _FunctionStorage #2747

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

Closed
wants to merge 12 commits into from

Conversation

blegat
Copy link
Member

@blegat blegat commented May 6, 2025

No description provided.

@odow
Copy link
Member

odow commented May 7, 2025

In addition to getting these tests passing, we also need to run solver-tests.yml.

@odow
Copy link
Member

odow commented May 8, 2025

This is only marginally a net win for lines of code. I'd err towards not merging this as-is. I'm all for cleaning up the ReverseAD implementation, but I'm also quite wary of making changes. The last release showed how easy it is to make a tiny mistake that isn't caught by the current tests.

@@ -297,12 +296,7 @@ Reverse-mode evaluation of an expression tree given in `f`.
* This function assumes `f.partials_storage` is already updated.
* This function assumes that `f.reverse_storage` has been initialized with 0.0.
"""
function _reverse_eval(
# !!! warning
Copy link
Member Author

Choose a reason for hiding this comment

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

The fact that we get rid of these warnings is a good sign

@blegat
Copy link
Member Author

blegat commented May 8, 2025

I'm not planning much deeper refactoring but I think this one helps a lot in readability and simplifies the logic.
It's not really about the number of lines, it's more about the overall readability.

@odow
Copy link
Member

odow commented May 9, 2025

@blegat
Copy link
Member Author

blegat commented May 9, 2025

@odow
Copy link
Member

odow commented May 9, 2025

Breaking a solver, even if it was using private API, is a reason to close this PR. I really don't think we need to make changes to ReverseAD unless necessary.

@blegat
Copy link
Member Author

blegat commented May 10, 2025

We can overload Base.getproperty to make it non-breaking. Once we have #2750, we can add in the comment of getproperty that it's just for backward compat and then in a later release we can warn and then in a later release we can delete.
But I don't think it's the first time we changed something internally and broke a package. If a package is using MOI's internal, it should pin MOI's version.
I still feel that we need this. I know refactoring something that works is adding risks so it should better be worth it but I think the benefits outweighs the risk here. Adding a little bit of encapsulation will simplify the source code.
It's also adding coverages to _SubexpressionStorage. At the moment, since JuMP does not use _SubexpressionStorage, it is not covered so much. At least with this PR, both the expressions of constraint, the objective and subexpressions end-up in the same code-path down the line which is good.
The only difference between subexpressions and objective/constraints was that subexpression cannot share the partials_storage_ϵ. I don't think that it is enough to justify duplicating all the fields in the two structs. We can just create a shared vector in MOI.initialize.

@odow
Copy link
Member

odow commented May 10, 2025

I don't want to complicate things by overloading getproperty. And it still means that we'd break EAGO for some versions of of MOI and EAGO.

Perhaps we need to talk in person to understand the motivation for all this work on ReverseAD.

I'd strongly prefer that we just left it alone.

If you're interested in writing a new AD engine, prototype it in a separate package. We can swap AD backends now, so we don't need to make changes to ReverseAD.

@blegat
Copy link
Member Author

blegat commented May 10, 2025

The motivation is that I'd like to add support for vector AD in ReverseAD. I actually think that most of the design of ReverseAD will fit quite well for the vector version as well so I wanted to see if it could just be added on top. As it will need to slightly complicate it, I wanted to do small refactoring to simplify it before, and that was also helped me understand it better. But you're right, I'll start it as a separate package.

@blegat
Copy link
Member Author

blegat commented May 10, 2025

We can close as it was moved to blegat/ArrayAD.jl#3

@blegat blegat closed this May 10, 2025
@odow odow deleted the bl/subexpr_merge branch May 10, 2025 23:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants