-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
Model file export #4305
base: main
Are you sure you want to change the base?
Model file export #4305
Conversation
this is interesting. I cannot use it as is. We cannot use iostream. The complex path is to implement gzip reading/writing in the File interface, which is a pain. |
Thanks @lperron . My first attempt was to not use iostream. I had to duplicate |
So, the best way to integrate it to add a field in the File class (ortools/base/file.h) that indicates if the file is a gzip one. For instance, the MPS reader uses the FileLine class, which is turns call File::Read() raw API. On the MPS writer, I would make sure that we flush the output string to file regularly, and that this flush is done by the File API, which internally would use the gzip API. Am I clear ? |
Yes, thanks again! I'll try my best to work on those parts. |
Please sync with main. You will have a conflict. The only missing is gzip support in File (and hooking to linear_solver C# if you want it). |
247818b
to
5b325e2
Compare
@lperron Thank you so much. I resolved the conflicts and called your function from linear_solver. Made it optional to export to gzip with a bool parameter. |
I'll resolve the conflicts |
Thank you @Mizux for including this in the next release candidate list. Thank you @lperron for including file write operations for other language wrappers. File write is already huge for us, being able to compress will be a real nice to have too. I updated my branch and it only has gzip file compression now. |
easier to comply with naming conventions of C# and Java
ortools/base/gzipfile.cc
Outdated
return { | ||
absl::StatusCode::kInternal, | ||
absl::StrCat( | ||
"Error while writing chunk to compressed file:", |
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.
"Error while closing the file" or "Unable to close the file"
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.
Thanks 👍 . I chose "Unable to close the file" to match with the error message thrown when opening a file.
Write models to .mps files
We can export linear solver models and get a string as a result. However, when working with very large models, the process (.NET in my case) fails when the export method is called, due to string type's size limitation. In our use case, we don't actually need the exported model in memory, we write the string to a file. A method that directly writes to a file helps us overcome the limitation.
The file write method has been added by @lperron, which simplifies this PR.