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

Change argument order of NonlinearOperator #3468

Merged
merged 3 commits into from
Sep 1, 2023
Merged

Change argument order of NonlinearOperator #3468

merged 3 commits into from
Sep 1, 2023

Conversation

blegat
Copy link
Member

@blegat blegat commented Aug 31, 2023

This also changes the order between the two because when one of the two has a default value depending on the other one it's usually the second positional argument.
It also allows to write NonlinearOperator(func::Function, head::Symbol = Symbol(func)) in the docstring which wouldn't be possible if the order was reversed.
This change only matters when NonlinearOperator is called directly and not through @operator.
It seems to me that when NonlinearOperator is called directly, you would want the symbol to be the function name 99% of the time so having this default value makes sense. It's also the default in the @operator macro so it's consistent.

@blegat blegat marked this pull request as ready for review August 31, 2023 09:36
@odow
Copy link
Member

odow commented Aug 31, 2023

I'm not in favor of this.

Adding lots of shortcuts for the sake of saving a few characters typing is not worth the trade-off. Constructing new operators with the constructor will be used very rarely.

Also, we shouldn't be advising people to use the NonlinearOperator constructor. Users should interact with it via @operator and add_nonlinear_operator.

If needed at all, surely this just requires the method:

NonlinearOperator(f::Function) = NonlinearOperator(Symbol(f), f)

@odow
Copy link
Member

odow commented Aug 31, 2023

I also think that, as a rule, we should be considering only breaking changes right now. Quality of life changes that can be added as feature additions can wait until this is out in the wild and we see how people are using it.

@blegat
Copy link
Member Author

blegat commented Aug 31, 2023

It's breaking if we reorder the fields.

Constructing new operators with the constructor will be used very rarely.
Also, we shouldn't be advising people to use the NonlinearOperator constructor. Users should interact with it via @operator and add_nonlinear_operator.

I think that's where we disagree. If you're not planning to set the MOI.UserDefinedFunction attribute then the add_nonlinear_operator function is a bit combersome since you need to give the model and the arity which prevents you to define an operator that could be used with any model and the arity doesn't matter here.

@odow
Copy link
Member

odow commented Aug 31, 2023

It's breaking if we reorder the fields.

Why do we need to do that?

I think that's where we disagree.

Who is going to be using NonlinearOperator? The only use-case I can see would be inside DCP.jl, and that can just type out the symbol. It doesn't need to save space.

@odow
Copy link
Member

odow commented Aug 31, 2023

I guess swapping the order is in the style guide, which says that functions should go as the first argument.

@odow odow changed the title Default head of NonlinearOperator to function symbol Change argument order of NonlinearOperator Aug 31, 2023
@codecov
Copy link

codecov bot commented Sep 1, 2023

Codecov Report

Patch coverage: 100.00% and no project coverage change.

Comparison is base (a573de2) 98.09% compared to head (e483105) 98.09%.
Report is 3 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #3468   +/-   ##
=======================================
  Coverage   98.09%   98.09%           
=======================================
  Files          37       37           
  Lines        5501     5501           
=======================================
  Hits         5396     5396           
  Misses        105      105           
Files Changed Coverage Δ
src/macros.jl 97.97% <ø> (ø)
src/nlp_expr.jl 99.24% <100.00%> (ø)

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Member

@odow odow left a comment

Choose a reason for hiding this comment

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

I'm okay with this. But I don't think we need an optional argument.

@blegat blegat merged commit 2a3fc52 into master Sep 1, 2023
@blegat blegat deleted the bl/default_head branch September 1, 2023 06:51
@blegat
Copy link
Member Author

blegat commented Sep 1, 2023

Who is going to be using NonlinearOperator? The only use-case I can see would be inside DCP.jl, and that can just type out the symbol. It doesn't need to save space.

It's not about saving the space, it's about removing the possibility to make a typo where you miss a character in the symbol for instance. Again, any non-AD usage would require that because we hardcode the list of operators to be exactly AD. Since we have MOI.ListOfSupportedNonlinearOperator in MOI, it means we expect solver to be able support more (e.g., Alpine, DCP, constraint programming, ...). These solvers would want to define op_foo for some foo function and would want it to look like foo because how the expressions was constructed doesn't matter. Also, if it's build front MOI, op_foo isn't even a thing so there is no reason to name it something else than foo.

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