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

Replace deprecated SCIP cons_quadratic.h #3027

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

jediahkatz
Copy link

The function SCIPcreateConsBasicQuadratic() along with the entire cons_quadratic.h file are deprecated -- instead, we should use SCIPcreateConsBasicQuadraticNonlinear() which takes the same arguments. Right now, attempting to use quadratic constraints or objectives results in all variables taking a zero value.

For reference see the SCIP docs:
SCIPcreateConsBasicQuadratic: https://www.scipopt.org/doc/html/group__CONSHDLRS.php#gad3707e7f7166bea83b7713cf2e52b0db
SCIPcreateConsBasicQuadraticNonlinear: https://www.scipopt.org/doc/html/group__CONSHDLRS.php#gabef6770f404754e7503f68a7da9ad6da

The function `SCIPcreateConsBasicQuadratic()` along with the entire `cons_quadratic.h` file are deprecated -- instead, we should use `SCIPcreateConsBasicQuadraticNonlinear()` which takes the same arguments.

For reference see the SCIP docs:
SCIPcreateConsBasicQuadratic: https://www.scipopt.org/doc/html/group__CONSHDLRS.php#gad3707e7f7166bea83b7713cf2e52b0db
SCIPcreateConsBasicQuadraticNonlinear: https://www.scipopt.org/doc/html/group__CONSHDLRS.php#gabef6770f404754e7503f68a7da9ad6da
@Mizux Mizux requested review from Mizux and lperron December 20, 2021 09:17
@Mizux Mizux self-assigned this Dec 20, 2021
@Mizux Mizux added Bug Solver: SCIP SCIP Solver related issue labels Dec 20, 2021
@Mizux Mizux added this to the v9.3 milestone Dec 20, 2021
@Mizux
Copy link
Collaborator

Mizux commented Dec 21, 2021

This break the bazel build, trace:

ERROR: /home/runner/work/or-tools/or-tools/ortools/linear_solver/BUILD.bazel:50:11: Compiling ortools/linear_solver/scip_proto_solver.cc failed: (Exit 1): gcc failed: error executing command /usr/bin/gcc -U_FORTIFY_SOURCE -fstack-protector -Wall -Wunused-but-set-parameter -Wno-free-nonheap-object -fno-omit-frame-pointer '-std=c++0x' -MD -MF ... (remaining 55 argument(s) skipped)

Use --sandbox_debug to see verbose messages from the sandbox
In file included from ortools/linear_solver/scip_proto_solver.cc:36:
ortools/linear_solver/scip_proto_solver.cc: In function 'absl::lts_20211102::Status operations_research::{anonymous}::AddQuadraticConstraint(const operations_research::MPGeneralConstraintProto&, const std::vector<SCIP_Var*>&, SCIP*, SCIP_CONS**, std::vector<SCIP_Var*>*, std::vector<double>*, std::vector<SCIP_Var*>*, std::vector<SCIP_Var*>*, std::vector<double>*)':
ortools/linear_solver/scip_proto_solver.cc:243:7: error: 'SCIPcreateConsBasicQuadraticNonlinear' was not declared in this scope; did you mean 'SCIPcreateConsBasicQuadratic2'?
  243 |       SCIPcreateConsBasicQuadraticNonlinear(scip,
      |       ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
./ortools/base/status_macros.h:33:40: note: in definition of macro 'RETURN_IF_ERROR'
   33 |     if (const ::absl::Status status = (expr); status.ok()) { \
      |                                        ^~~~
./ortools/linear_solver/scip_helper_macros.h:39:49: note: in expansion of macro 'SCIP_TO_STATUS'
   39 | #define RETURN_IF_SCIP_ERROR(x) RETURN_IF_ERROR(SCIP_TO_STATUS(x));
      |                                                 ^~~~~~~~~~~~~~
ortools/linear_solver/scip_proto_solver.cc:242:3: note: in expansion of macro 'RETURN_IF_SCIP_ERROR'
  242 |   RETURN_IF_SCIP_ERROR(
      |   ^~~~~~~~~~~~~~~~~~~~
ortools/linear_solver/scip_proto_solver.cc: In function 'absl::lts_20211102::Status operations_research::{anonymous}::AddQuadraticObjective(const operations_research::MPQuadraticObjective&, SCIP*, std::vector<SCIP_Var*>*, std::vector<SCIP_Cons*>*)':
ortools/linear_solver/scip_proto_solver.cc:492:24: error: 'SCIPcreateConsBasicQuadraticNonlinear' was not declared in this scope; did you mean 'SCIPcreateConsBasicQuadratic2'?
  492 |   RETURN_IF_SCIP_ERROR(SCIPcreateConsBasicQuadraticNonlinear(
      |                        ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
./ortools/base/status_macros.h:33:40: note: in definition of macro 'RETURN_IF_ERROR'
   33 |     if (const ::absl::Status status = (expr); status.ok()) { \
      |                                        ^~~~
./ortools/linear_solver/scip_helper_macros.h:39:49: note: in expansion of macro 'SCIP_TO_STATUS'
   39 | #define RETURN_IF_SCIP_ERROR(x) RETURN_IF_ERROR(SCIP_TO_STATUS(x));
      |                                                 ^~~~~~~~~~~~~~
ortools/linear_solver/scip_proto_solver.cc:492:3: note: in expansion of macro 'RETURN_IF_SCIP_ERROR'
  492 |   RETURN_IF_SCIP_ERROR(SCIPcreateConsBasicQuadraticNonlinear(
      |   ^~~~~~~~~~~~~~~~~~~~
INFO: Elapsed time: 896.160s, Critical Path: 38.07s

Maybe need to bump the version first:

or-tools/WORKSPACE

Lines 84 to 90 in 2cb85b4

new_git_repository(
name = "scip",
build_file = "//bazel:scip.BUILD",
patches = ["//bazel:scip.patch"],
commit = "6acb7222e1b871041445bee75fc05bd1bcaed089", # master from Jul 19, 2021
remote = "https://github.com/scipopt/scip.git",
)

@jediahkatz
Copy link
Author

Hmm, strange because nonlinear.h exists in commit 6acb7222e1b871041445bee75fc05bd1bcaed089 of the SCIP repo. Unfortunately though, I realized that the issue is less simple than I originally thought. The all-zero values problem was caused by me using Solve() instead of SolveWithProto(), but when I use SolveWithProto() then I get an error with the following trace:

Traceback (most recent call last):
  File "ortools_samples/quadratic.py", line 88, in <module>
    print(pywraplp.Solver.SolveWithProto(linear_solver_pb2.MPModelRequest(model=input_proto.model), solution))
  File "/home/jediahkatz/.cache/pypoetry/virtualenvs/pythonsat-yDcEWZll-py3.8/lib/python3.8/site-packages/ortools/linear_solver/pywraplp.py", line 358, in SolveWithProto
    return _pywraplp.Solver_SolveWithProto(model_request, response)
TypeError: in method 'Solver_SolveWithProto', argument 1 of type 'operations_research::MPModelRequest const &'

It seems to be a Python/SWIG issue -- the C++ function expects operations_research::MPModelRequest const &, and I think the Python MPModelRequest object is not properly passed as const. For now I have given up on using the quadratics with ortools but maybe at some point I will take another look (but feel free to close the PR if you don't care about such a niche bug).

@lperron
Copy link
Collaborator

lperron commented Jan 2, 2022 via email

@lperron
Copy link
Collaborator

lperron commented Jan 2, 2022 via email

@jediahkatz
Copy link
Author

Ah, thanks so much. I'm not super familiar with how SWIG works but I'll check out your commit for curiosity's sake. Bonne année!

@Mizux Mizux modified the milestones: v9.3, v10.0 Feb 17, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Solver: SCIP SCIP Solver related issue
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants