lanl-ansi / PowerModels.jl

A Julia/JuMP Package for Power Network Optimization
https://lanl-ansi.github.io/PowerModels.jl/stable/
Other
388 stars 145 forks source link

"IOError: stream is closed or unusable" when using parse_file() in Pluto.jl #830

Open samtalki opened 2 years ago

samtalki commented 2 years ago

Hello all,

I have encountered a new bug on my machine over the past few months when attempting to use parse_file() within a Pluto.jl notebook.. This is one of those tricky issues where it's not clear which package is causing the bug, so I apologize in advance for the confusion. I looked into the source of both packages to try to seek out the root cause, but unfortunately I couldn't figure it out on my own. Please let me know if you agree that I should also open an issue with Pluto.

Info on my machine:

Step 1: setup environment to reproduce:

For convenience, you could skip this step and clone my repository I made to demonstrate this issue (available here).

Alternatively, make a fresh Julia environment >=1.7 and load your favorite test case into the root directory. Run these commands in the REPL:

pkg> generate PlutoPowerModelsTest
shell> cd PlutoPowerModelsTest
pkg> activate .
pkg> add Pluto
julia> import Pluto
julia> Pluto.run()

Step 2: run parse_file() in a Pluto.jl notebook

Within the Pluto landing page, create a new notebook. Drop your case14.m or other file into the same directory as the notebook and then run the following commands within the notebook to reproduce the error.

using PowerModels
case14 = parse_file("case14.m")

You should receive the following error: image

ccoffrin commented 2 years ago

@samtalki, thanks for reporting this issue. Given that parse_file is a very well tested feature of PowerModels and that I have never encountered the error that you are seeing here, I think this has to be an issue with Pluto and I would recommend posting to their GitHub repo or raising this question on Julia Discourse for discussion. Maybe other Pluto users are familiar with this?

If you can build a MWE that produces this error without using Pluto, then please post that here and I can explore how to fix it.

ccoffrin commented 2 years ago

I am going to close this as it is not reproducible in this repo.

MartaVanin commented 1 year ago

hi, sorry for commenting on this very old issue, hope you don't mind. we bumped into this problem today and I just wanted to add for future reference that probably something broke between pluto 0.18.0 and 0.19.0 (which was released before you opened this issue, so I reckon this was what you were using). If you downgrade pluto to 0.18.0 the parse_file function works, so that's a quick workaround.

ccoffrin commented 1 year ago

Thanks @MartaVanin. Can you document a MWE so that this issue can be reproduced?

MartaVanin commented 1 year ago

yes, using Julia 1.8, if I run the following in a Pluto 0.18.0 notebook it works, while it fails on the latest Pluto (v0.19.24)

begin
    using PowerModels # automatically install latest, see https://github.com/fonsp/Pluto.jl/wiki/%F0%9F%8E%81-Package-management
    test_file = joinpath(dirname(dirname(pathof(PowerModels))), "test/data/matpower/case5.m")
    f = parse_matpower(test_file)
end

I can open an issue on Pluto and @ you there if you like

ccoffrin commented 1 year ago

Report from @ChrisRackauckas on how to reproduce,

import PowerModels
file_name = "../../benchmarks/OptimizationFrameworks/opf_data/pglib_opf_case5_pjm.m"
data = PowerModels.parse_file(file_name)

works, but

import PowerModels
file_name = "../../benchmarks/OptimizationFrameworks/opf_data/pglib_opf_case5_pjm.m"
data = PowerModels.parse_file(file_name)

fails

The issue is related to Memento's stream being closed prematurely.

ccoffrin commented 1 year ago

Related issue, https://github.com/JunoLab/Weave.jl/issues/442

886 does not appear to fix the issue.