-
Notifications
You must be signed in to change notification settings - Fork 517
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
Appsi fbbt KeyError when Var bounded by Param #2574
Comments
Note: as part of resolving this issue, we should revisit the use of APPSI FBBT in GDPopt (as disabled in #2575) |
I just ran into this issue on current |
And the same thing affects constraint bounds: from pyomo.environ import *
m = ConcreteModel()
m.x = Var()
m.clb = Param(initialize=0)
m.c = Constraint(expr=(m.clb, m.x, None))
SolverFactory("appsi_ipopt").solve(m) Result:
@michaelbynum it seems like the constraint and variable bounds need to go through |
@bknueven - request: can you see if the same issue occurs using |
Good question --
|
The reason this is not accounted for is because I never use non-mutable parameters, so I never think about these edge cases. I don't think we can run the bounds through generate_standard_repn because that will also remove the mutable parameters (note that mutable parameters in variable bounds work). This might be fixed just by removing these two if statements: pyomo/pyomo/contrib/appsi/base.py Line 1101 in 3a43b40
pyomo/pyomo/contrib/appsi/base.py Line 1304 in 3a43b40
|
Thanks Michael. That does seem to work, unsurprisingly. What about the following patch? It keeps the non-mutable parameters out of the diff --git a/pyomo/contrib/appsi/cmodel/src/expression.cpp b/pyomo/contrib/appsi/cmodel/src/expression.cpp
index 234ef47e8..8079de42b 100644
--- a/pyomo/contrib/appsi/cmodel/src/expression.cpp
+++ b/pyomo/contrib/appsi/cmodel/src/expression.cpp
@@ -1548,7 +1548,10 @@ appsi_operator_from_pyomo_expr(py::handle expr, py::handle var_map,
break;
}
case param: {
- res = param_map[expr_types.id(expr)].cast<std::shared_ptr<Node>>();
+ if (expr.attr("parent_component")().attr("mutable").cast<bool>())
+ res = param_map[expr_types.id(expr)].cast<std::shared_ptr<Node>>();
+ else
+ res = std::make_shared<Constant>(expr.attr("value").cast<double>());
break;
}
case product: { |
Looks great to me! |
FYI, @bknueven , the bug you reported in |
Summary
There's a KeyError when using appsi fbbt on a model where there are Params in the Var bounds
Steps to reproduce the issue
Error Message
Note that replacing
m.p
withvalue(m.p)
works as expected.Information on your system
Pyomo version: main
Python version: 3.8
Operating system: linux
How Pyomo was installed (PyPI, conda, source): source
Solver (if applicable):
The text was updated successfully, but these errors were encountered: