CpSolverResponse exceeding protobuf limits

243 views
Skip to first unread message

arnaban...@gmail.com

unread,
May 10, 2023, 2:57:44 PM5/10/23
to or-tools-discuss
I am receiving the following error message:

[libprotobuf ERROR /project/build_cp38-cp38/_deps/protobuf-src/src/google/protobuf/message_lite.cc:449] operations_research.sat.CpSolverResponse exceeded maximum protobuf size of 2GB: 21519507841

What possible options do I have to avoid this issue?

Laurent Perron

unread,
May 10, 2023, 3:18:38 PM5/10/23
to or-tools-discuss
I am surprised you have a response that is bigger than the input proto?

Are you using anything special ?

--
You received this message because you are subscribed to the Google Groups "or-tools-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to or-tools-discu...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/or-tools-discuss/cdbbe0bb-9ba2-4a15-976f-1086fcb090f8n%40googlegroups.com.
Message has been deleted

arnaban...@gmail.com

unread,
May 10, 2023, 3:30:52 PM5/10/23
to or-tools-discuss
I am using ortools v9.5.2237, The status came out as "UNKNOWN" and the text output of "model.Validate" was over 15GB (my HDD was full so I don't know the actual size)

As for special constraints there are lots of "AddBoolOr" and "AddBoolAnd" with "OnlyEnforceIf". Actually 95%+ constraints are these only.

There are many boolean variables which I do not add in the objective function, but are added in the constraints. Also many are hardfixed as true or false. It is done this way so that it is easier to code the constraints, otherwise I have to calculate the RHS of the constraints by myself.

arnaban...@gmail.com

unread,
May 10, 2023, 3:39:54 PM5/10/23
to or-tools-discuss
I don't know if it is relevant but I'm using Azure VM.

Laurent Perron

unread,
May 10, 2023, 4:07:03 PM5/10/23
to or-tools-discuss
Still strange, the validate model returns the string of the first error. 

How do you generate an error message that is 15GB?

Note that the error happens when crossing the c++/Python barrier.

arnaban...@gmail.com

unread,
May 10, 2023, 4:29:33 PM5/10/23
to or-tools-discuss
I could not open the text file as it was huge, but on running `tail` command on it, "domain" was printed numerous times with numbers accompanied by it. The entire thing was on 1 line I believe, that's why my system froze.
I just put "print(model.Validate())" if feasible/optimal solution was not found. Since I am explicitly asking it to print, it might not have been an error, maybe it printed the model itself.

But still that should not matter as far as CpSolverResponse's size is concerned, right?

Assuming that it actually outputs an error, if the error happens when crossing c++/python barrier can it be due to wrong memory address reference due to SWIG or Azure VM?

I will try to prepare a sample model proto, if the problem is not Azure VM specific.

Laurent Perron

unread,
May 10, 2023, 4:35:04 PM5/10/23
to or-tools-discuss
Both model and response are protobufs.
They have to be serialized to cross languages, and the limit is 2gb.

The best thing to do is to debug your code to not create the error. 

Dichotomy on the code seems to be the only option. 


arnaban...@gmail.com

unread,
May 10, 2023, 5:43:54 PM5/10/23
to or-tools-discuss
So you are suggesting that if I code it in C++ instead of Python I don't have to worry about protobuf size limits?

I know that it runs fine for smaller inputs.

I ran it on the main branch as of today (9.6.xxxx), made the model size 10% smaller, removed the "print(model.Validate())" and it provided the following output:

Check failed: StringToProtobuf(serialized_model, model_proto)
*** Check failure stack trace: ***
Aborted (core dumped)


Earlier when I had a very large model it was resulting in direct segmentation fault without all these shenanigans.

Laurent Perron

unread,
May 11, 2023, 5:22:43 AM5/11/23
to or-tools...@googlegroups.com
So, when coding in non C++, the model has to be serialized, and the limit is 2GB.
Same thing with the response. There are no limits on the C++.

What is surprising to me is that the input model does not hit the limit, but the response do.
There are 2 parameters that can make the response proto grow a lot:
  - log_to_response
  - fill_additional_solutions_in_response

From what I understand, the response proto overflows with a validation message. 
This means that the text message of the error of 1 constraint or 1 variable overflows 2GB, while the binary representation of the whole model does not.
Impressive :-)
Laurent Perron | Operations Research | lpe...@google.com | (33) 1 42 68 53 00



Mark

unread,
Oct 19, 2023, 1:39:20 PM10/19/23
to or-tools-discuss
I'm trying to understand the size limits a bit better.

The c++ documentation states:
"""
The interface to the C++ CP-SAT solver is implemented through the CpModelBuilder class described in ortools/sat/cp_model.h. This class is just a helper to fill in the cp_model protobuf.

Calling Solve() method will return a CpSolverResponse protobuf that contains the solve status, the values for each variable in the model if solve was successful, and some metrics.
"""

Am I correct in saying the following things?:
- The size limit on protobufs is 2 GB, regardless of what programming language is used.
- Even c++ uses protobufs (as per the documentation above).
- Therefore, even c++ has a limit on maximum model size of 2 GB.
- The reason the python code failed but equivalent c++ code would not fail is to do with the size of the response proto, which because extremely large when calling Validate?

I'm trying to get a more complete understanding of what caused the python to fail, and why equivalent c++ would not fail.  
Right now it seems like the proto would still exceed 2GB if validate was called in c++.

Laurent Perron

unread,
Oct 19, 2023, 1:41:04 PM10/19/23
to or-tools-discuss
No. The size limit applies when you serialize the proto (to file, or across languages).

Reply all
Reply to author
Forward
0 new messages