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

Add write_to_file and read_from_file #2114

Merged
merged 8 commits into from
Dec 9, 2019
Merged

Add write_to_file and read_from_file #2114

merged 8 commits into from
Dec 9, 2019

Conversation

odow
Copy link
Member

@odow odow commented Dec 3, 2019

Closes #1075
Closes #1982

cc @dourouc05

@mlubin
Copy link
Member

mlubin commented Dec 3, 2019

My only concern is that we're not following the standard Julia API by allowing reading and writing from an IO object. It's inevitable that we'll get requests for this. Does MOF support writing to streams?

@dourouc05
Copy link
Contributor

dourouc05 commented Dec 4, 2019

Looks good to me (even though the failures on Windows are quite strange). Maybe refactor a bit the test suite to avoid having three times the exact same model? (Sorry for the delay, I still have the tab for my PR opened, but had too little time to work on it, unfortunately :(.)

I think this API is already quite good as it is. For streams, I suspect write and read overloads should be provided, but these cannot support the convenient inference from file name. This calls for a slightly different interface, like read/write(io::IO, m::Model, compression, format).

Another though: wouldn't the order format-compression for the arguments be easier to grasp? The file names almost invariably have first the file format, then the compression format (like .lp.gz).

Considering documentation, copying parts of MOF here really makes sense from a user point of view. However, if a format is added to MOF, it will require a manual modification of JuMP's doc: isn't there any other solution, like including parts of MOF docs from JuMP?

@codecov
Copy link

codecov bot commented Dec 4, 2019

Codecov Report

Merging #2114 into master will increase coverage by 0.07%.
The diff coverage is 92.85%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #2114      +/-   ##
==========================================
+ Coverage   91.01%   91.08%   +0.07%     
==========================================
  Files          40       41       +1     
  Lines        4350     4376      +26     
==========================================
+ Hits         3959     3986      +27     
+ Misses        391      390       -1
Impacted Files Coverage Δ
src/JuMP.jl 80.98% <0%> (ø) ⬆️
src/file_formats.jl 100% <100%> (ø)
src/copy.jl 91.3% <100%> (+0.82%) ⬆️
src/print.jl 86.18% <0%> (+0.36%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update d2f6a29...f7ab9d5. Read the comment docs.

@odow
Copy link
Member Author

odow commented Dec 4, 2019

Does MOF support writing to streams?

I've added the read/write to streams.

isn't there any other solution, like including parts of MOF docs from JuMP?

Longer term, we should probably pull MOF into MOI. Our longer term goal is to unify the JuMP/MOI documentation in a nice way.

@dourouc05
Copy link
Contributor

Longer term, we should probably pull MOF into MOI. Our longer term goal is to unify the JuMP/MOI documentation in a nice way.

Nice to hear!

I've added the read/write to streams.

Why aren't you using the "standard" way of defining IO operations on streams (with read and write methods)? This would also imply to have the IO stream as a first argument, but would be more convenient for people picking up JuMP after Julia.

@odow
Copy link
Member Author

odow commented Dec 4, 2019

Why aren't you using the "standard" way of defining IO operations on streams (with read and write methods)?

Mainly to keep consistency with write_to_file and read_from_file. It's a small change to swap filename to io. I'll defer to @mlubin if he prefers read/write though.

Copy link
Member

@mlubin mlubin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see the point of keeping consistency with write_to_file for the IO version. An IO isn't necessarily a file, so the name is misleading. I prefer using read and write with the argument order that's standard in Julia (https://docs.julialang.org/en/v1/manual/style-guide/#Write-functions-with-argument-ordering-similar-to-Julia-Base-1).

@odow
Copy link
Member Author

odow commented Dec 6, 2019

I'm making changes to MathOptFormat.jl which should simplify JuMP's implementation. See: odow/MathOptFormat.jl#100.

@odow
Copy link
Member Author

odow commented Dec 6, 2019

I've merged and released the changes to MathOptFormat.jl, so now things are now considerably simpler on the JuMP side.

@odow odow merged commit 3ca230f into master Dec 9, 2019
@odow odow deleted the od/mof branch December 9, 2019 14:19
dourouc05 added a commit to dourouc05/Seleroute.jl that referenced this pull request Apr 18, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

Problem writers
4 participants