-
-
Notifications
You must be signed in to change notification settings - Fork 393
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
Register NLparameters and pretty print them #2516
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One issue is that this is actually a breaking change because this will now error (where previously it worked):
@variable(model, x)
@NLparameter(model, x == 1)
The code to look up a name isn't great (this only works for single parameters) but it is an improvement. It also only prints in subexpressions, not pure parameters
Lines 752 to 758 in 442aee8
function function_string(::Type{<:PrintMode}, p::NonlinearExpression) | |
return "Reference to nonlinear expression #$(p.index)" | |
end | |
function function_string(::Type{<:PrintMode}, p::NonlinearParameter) | |
return "Reference to nonlinear parameter #$(p.index)" | |
end |
Tests are failing here:
Lines 250 to 255 in 442aee8
"(subexpression[1] - parameter[1]) - 0.0 $le 0", | |
) | |
io_test( | |
IJuliaMode, | |
constr, | |
"(subexpression_{1} - parameter_{1}) - 0.0 \\leq 0", |
If you have code that would benefit from registering parameters, you can just go
model[:p] = @NLparameter(model, p == 1)
I'm really just interested in the pretty printing at the moment. So maybe the way to change this PR is to only merge the pretty printing side, which would be non breaking, and then I can do the registration step manually on my end? Having said that, it might make sense to bring in the breaking change of not allowing variables and parameters to have the same name in some new major version? That does seem like a sensible default? But obviously no rush on that. For now I'll change this PR to only do the pretty printing, and I'll also try to make that a bit more robust. |
Codecov Report
@@ Coverage Diff @@
## master #2516 +/- ##
==========================================
- Coverage 92.42% 88.05% -4.37%
==========================================
Files 43 42 -1
Lines 4688 3802 -886
==========================================
- Hits 4333 3348 -985
- Misses 355 454 +99
Continue to review full report at Codecov.
|
Alright, so this PR now has the registration of parameters removed, and all it does is use the name of a parameter in printing, if that parameter was manually registered with the model. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, we could definitely do better than this, but I think it will take a much bigger NLP redesign.
Fixes #2509.
I have to admit I'm not sure this makes sense or whether the implementation is a good idea. But it does start to print the parameter name in the
show
output rather than writingparameter_1
etc :) But in any case, someone with a better understanding of the code base needs to weigh in and say whether this could potentially work or not.