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

Power Systems Economics PUC - RIO 2019.2 #19

Closed
andrewrosemberg opened this issue Oct 11, 2019 · 48 comments
Closed

Power Systems Economics PUC - RIO 2019.2 #19

andrewrosemberg opened this issue Oct 11, 2019 · 48 comments

Comments

@andrewrosemberg
Copy link
Owner

This issue is for questions about studies using the Package

@Veronicafeijao
Copy link

Which version of Julia should I use?

@gcmgabrielmartinez
Copy link

gcmgabrielmartinez commented Oct 12, 2019

So I am trying to install the SDDP package in JuliaPro, but turns out that the installation does not conclude due to a packages called MathOptFormat and HTTP. Apparently, I succeded in installing the SDDP in Julia by the way, but it seems that I have to install for juliaPro as well, because when I call "using SDDP", it can not find it. Also, as I checked the packages files, I found SDDP packages both in julia and JuliaPro (1.0 and 1.2), so I believe that SDDP in JuliaPro may be corrupted at some point. Can you figure it out if it is possible to compile Julia from JuliaPro?
image

@gcmgabrielmartinez
Copy link

gcmgabrielmartinez commented Oct 12, 2019

Also, I have another issue, this time with HydroPowerModels in Julia itself. It seems the file called Cairo was not able to be downloaded as installing proccess was running. Now, when I call using HydroPowerModels I have the warnning below:
image

@Veronicafeijao
Copy link

When I use ATOM, I also have problem with MathOptFormat. Now, I'm not using ATOM and the problem is with package HTTP (to install SDDP.jl) @andrewrosemberg , what's the problem?

@gcmgabrielmartinez
Copy link

gcmgabrielmartinez commented Oct 12, 2019

@Veronicafeijao which IDE are you using instead of ATOM?

@Veronicafeijao
Copy link

I went in ATOM>Julia>Open REPL. There I put: (julia> ] add https://github.com/odow/SDDP.jl/#master )

@gcmgabrielmartinez
Copy link

gcmgabrielmartinez commented Oct 12, 2019

Well, I took a chance on your suggestion, now have problem with both MathOptFormat and HTTP. I checked my first print and actually I already have had the same issue

@andrewrosemberg
Copy link
Owner Author

Which version of Julia should I use?

I have been using Julia 1.0 up to 1.05 to test the code, so those versions are preferred, but I believe it should work with later versions of Julia.

@andrewrosemberg
Copy link
Owner Author

@Veronicafeijao and @GabrielCalvo2812, sometimes there are issues installing SDDP. A solution provided in one of the package's issue (odow/SDDP.jl#182 (comment)) is to first add MathOptFormat.jl:

] add https://github.com/odow/MathOptFormat.jl

] add https://github.com/odow/SDDP.jl

@andrewrosemberg
Copy link
Owner Author

Also, I have another issue, this time with HydroPowerModels in Julia itself. It seems the file called Cairo was not able to be downloaded as installing proccess was running. Now, when I call using HydroPowerModels I have the warnning below:

@GabrielCalvo2812, I believe once you have SDDP properly installed, HydroPowerModels will successfully build and then using it will not produce these errors. If it persists, let me know.

@Veronicafeijao
Copy link

Veronicafeijao commented Oct 13, 2019 via email

@odow
Copy link
Collaborator

odow commented Oct 13, 2019

I'm trying to get SDDP.jl registered (JuliaRegistries/General#4247), so once it is, this should resolve the version issues.

I believe that the issue is that JuliaPro includes a version of HTTP.jl that is missing a required bug-fix for MathOptFormat (we need 0.8.2+). So I would try

] add HTTP

Then run ] st and check that HTTP is at least version 0.8.2. Then run

] add MathOptFormat
] add https://github.com/odow/SDDP.jl

Once that's done, you can add HydroPowerModels.

If you get the libcairo error, try ] add Cairo or ] build Cairo.

@djiegow
Copy link

djiegow commented Oct 13, 2019

Which version of Julia should I use?

I have been using Julia 1.0 up to 1.05 to test the code, so those versions are preferred, but I believe it should work with later versions of Julia.

@andrewrosemberg, I was using Julia 1.2. I added the MathOptFormat, SDDP and HydroPowerModels and I had this problem below:

Screen Shot 2019-10-13 at 13 49 12

I also failed in building "Fontconfig".

Screen Shot 2019-10-13 at 14 04 10

After this, I tried Julia 1.0.5. And I had another problem:

Screen Shot 2019-10-13 at 14 05 04

Am I forgetting anything?

Thanks!

@andrewrosemberg
Copy link
Owner Author

@djiegow, could you send me the output of your project status :
] st

@gcmgabrielmartinez
Copy link

gcmgabrielmartinez commented Oct 13, 2019

@odow I tried your suggestion, I used the command add HTTP and it updated some files:

image

but then using ] st it did not show which version was on the files:

image

Actually I looked for in the files explorer for the HTTP package in juliaPro1.2 and wasn't there ( don't mind about HydroPowerModels, it is corrupted anyway):

image

@andrewrosemberg
Copy link
Owner Author

@GabrielCalvo2812 I would start a new project from scratch to test adding the necessary packages

@gcmgabrielmartinez
Copy link

@andrewrosemberg what you mean with a new project? I am just installing the packages

@djiegow
Copy link

djiegow commented Oct 14, 2019

@djiegow, could you send me the output of your project status :
] st

Sure!

Screen Shot 2019-10-14 at 11 41 55

@andrewrosemberg
Copy link
Owner Author

teste_hydropowermodels.zip

Hi Guys,

This is a small project with a basic script to test the package. I would advise using this as a start.
The above folder contains a test script, a case folder, and a Julia environment (Project.toml and Manifest.toml).

The lines

using Pkg
Pkg.activate(".")
Pkg.instantiate()

will activate the environment and download all the necessary packages at their proper version (SDDP, HydroPowerModels, GLPK).

Please let me know if this doesn't run as intended.

@andrewrosemberg
Copy link
Owner Author

I also just fixed the plotting error

ERROR: Cannot convert Tuple{Array{Float64,2},Array{Float64,2}} to series data for plotting

(caused by an unexpected bug at the new version of Plots.jl).

@ncihangir
Copy link

Hello, I am using JuliaPro 1.2.0. Just tried to run the test script, but still getting the same error. Please see below. Thank you!

image
image

image

@andrewrosemberg
Copy link
Owner Author

@ncihangir could you send the output from the activate+instantiate call?

@ncihangir
Copy link

Hello Andrew, please see below. It gives "resolving package versions" for quite a long time and seems like not able to complete:
image

@andrewrosemberg
Copy link
Owner Author

@ncihangir the output from the activate function shows you are not running this section on the folder of test_hydropowermodels.

You have to run those commands in the same folder of the Project.toml and Manifest.tml.

@thamires-bap
Copy link

Hey, @andrewrosemberg ! I tried to run the test, but when I tried it I got this message:
Erro 1

And then I tried adding the package:
Erro 2

but it didn't work as well...

Could you help me please?

I think I might be doing something wrong. Do I have to do something specific to install HydroPowerModels?

Thanks a lot!

@odow
Copy link
Collaborator

odow commented Oct 15, 2019

@thamires-bap it looks like you're not running the command from the right folder.

To update Andrew's comment:

  1. Download https://github.com/andrewrosemberg/HydroPowerModels.jl/files/3725797/teste_hydropowermodels.zip and unzip it somewhere nice (like ~/Documents/HydroPowerModels/).
  2. Open Julia (or Atom) (or Juno)
  3. Run cd("~/Documents/HydroPowerModels/") (or wherever you saved it.) The path should be such that "~/Documents/HydroPowerModels/Manifest.toml" points to the one you extracted from the zip file
  4. Run using Pkg; Pkg.activate("."); Pkg.instantiate()

@JJhern
Copy link

JJhern commented Oct 15, 2019

@andrewrosemberg I am getting this error: #19 (comment)

How did you fix it ?

@thamires-bap
Copy link

Hey, @odow ! I did just as you said, but the result was this:
Captura de Tela 2019-10-15 às 07 19 48

@mflb
Copy link

mflb commented Oct 15, 2019

Hey, @andrewrosemberg ! I tried to run the test script, but I am getting some errors.
Please see below.

Capturar1

Capturar2

Capturar3

Could you help me, please?
Thank you!

@ncihangir
Copy link

Hello, I also get similar error as Thamires when running Pkg.instantiate( ).
image

@andrewrosemberg
Copy link
Owner Author

@thamires-bap and @ncihangir searching about your problem in google I found this: https://discourse.julialang.org/t/pkg-instantiate-fails/11709/7

Maybe try the fix at the end of this issue. It seems like Windows is having a protocol problem unrelated to the package.

@andrewrosemberg
Copy link
Owner Author

@mflb, your issue is from TimeZones.jl. It doesn't recognize 'America/Sao_Paulo' as a valid time zone. A quick fix as proposed here is to change the timezone of your system.

@Veronicafeijao
Copy link

@mflb , I had a similar problem, but with other different files. I resolved by opening the entire test_hydropowermodels folder with the atom in File> Open folder. Then File> open file> (teste.jl). When I ran, these errors no appeared.
Try it

@andrewrosemberg
Copy link
Owner Author

@andrewrosemberg I am getting this error: #19 (comment)

How did you fix it ?

@JJhern Just update our package and it will be solved. I have downgraded Plots.jl to version "0.26.0", since the new version "0.27.0" had an issue.

@Veronicafeijao
Copy link

@mflb, Andrew helped you in the first problem(America/Sao Paulo), and I was talking about the next problems.

@lopeesfelipe
Copy link

I guess the Plots.jl issue was not solved with it's downgrade.. I already updated the package and it is using the version "0.26.3" of Plots.jl. I also tried to downgrade to version "0.26.0", but the issue persists.

image

@hernanijj
Copy link

@andrewrosemberg I am getting this error: #19 (comment)
How did you fix it ?

@JJhern Just update our package and it will be solved. I have downgraded Plots.jl to version "0.26.0", since the new version "0.27.0" had an issue.

it is still not working @andrewrosemberg

@andrewrosemberg
Copy link
Owner Author

@lopeesfelipe @hernanijj the examples are being executed with plots 0.26.0 in the docs. Please verify you are not using old precompilations of HydroPowerModels.

@lopeesfelipe
Copy link

You're right, but when I update the HydroPowerModels package (with the command ] add https://github.com/andrewrosemberg/HydroPowerModels.jl.git) it's used Plots.jl in 0.26.3 version.

image

image

@andrewrosemberg
Copy link
Owner Author

You're right, but when I update the HydroPowerModels package (with the command ] add https://github.com/andrewrosemberg/HydroPowerModels.jl.git) it's used Plots.jl in 0.26.3 version.

@lopeesfelipe I don't believe this is a problem, but, all the same, instantiate should be installing 0.26.0.

Repository owner deleted a comment from ncihangir Oct 16, 2019
@andrewrosemberg
Copy link
Owner Author

@lopeesfelipe what might happen is that, if you start adding or updating packages after the "instantiate" command, Plots can update to v0.26.3 (where indeed the bug already exists). If you don't feel like instantiating again the original environment, do the following:

] add Plots#v0.26.0
] pin Plots

@andrewrosemberg
Copy link
Owner Author

andrewrosemberg commented Oct 18, 2019

Hi Guys,

Some have asked me about LMPs (Nodal price or PLDs in Portuguese). Following the PowerModels output, they are called 'lam_kcl_r' and are inside the bus solution dictionary (PS.: they are acctualy the negative of the LMPs). So, to access the different scenarious, do the following:

# circuit MVA
baseMVA = results[:data][1]["powersystem"]["baseMVA"]
# LMPs
nbus = length(results[:data][1]["powersystem"]["bus"])
idxbus = collect(1:nbus)
scen_lmp = convert(Array{Array{Float64,2},1},[[-results[:simulations][i][j][:powersystem]["solution"]["bus"]["$bus"]["lam_kcl_r"] for i=1:nsim, j=1:nstages]' for bus =1:nbus])/baseMVA

I devide by baseMVA to find the LMPS in ($/MW).

@andrewrosemberg
Copy link
Owner Author

andrewrosemberg commented Oct 18, 2019

In order to set different demands for each stage manually, one may use the 'set_active_demand!' function:

HydroPowerModels.set_active_demand!(data,demand)

where demand should be an Array{Float64,2}. Lines represent stage and columns bus.
PS.: The matrix 'demand' should have columns for all busses, even if no load is set to some of the busses. Also, this only works if you have at max 1 load per bus.

@andrewrosemberg
Copy link
Owner Author

andrewrosemberg commented Oct 18, 2019

For those trying to plot the future cost function, there isn't a function for this yet (SDDP.jl's issue).

I have implemented a simple function to help until a better solution appears:

using Plots

function plot_cuts(model::SDDP.PolicyGraph{T};node_idx::Int=1) where {T}
   node_name_parser = SDDP._node_name_parser
   cuts = Dict{String, Any}[]
   node= model.nodes[1];
   states = vcat([[values(stat.state)...] for stat in model[1].bellman_function.global_theta.cut_oracle.states]...)
   
   ncuts = length(node.bellman_function.global_theta.cut_oracle.cuts)
   plt = plot() 
   for i = 1:ncuts
       cut = node.bellman_function.global_theta.cut_oracle.cuts[i]
       cut_coef_aux = [values(copy(cut.coefficients))...][:,:]
       vals = cut.intercept .- states*cut_coef_aux

       plot!(plt,states,vals)
   end
   
   return plot(plt, legend=false)

end

PS.: This might be wrong, critical view advised.

To use it:

plot_cuts(hydromodel.policygraph)

@felipefmds
Copy link

Hi @andrewrosemberg . How can I do to get reservoir volume for each simulation (from 1 to 100) and scenario (1 to 12) ?
Thank you.

@andrewrosemberg
Copy link
Owner Author

andrewrosemberg commented Oct 29, 2019

Hi Guys,

If you are trying to get the sampled inflows:

scen_inflows = convert(Array{Array{Float64,2},1},[[results[:data][1]["hydro"]["Hydrogenerators"][res]["inflow"][HydroPowerModels.cidx(j,results[:data][1]["hydro"]["size_inflow"][1]),results[:simulations][i][j][:noise_term]] for i=1:nsim, j=1:nstages]' for res = 1:results[:data][1]["hydro"]["nHyd"]])

If you are trying to get the reservoir volume (@felipefmds):

scen_voume = convert(Array{Array{Float64,2},1},[[results[:simulations][i][j][:reservoirs][:reservoir][res].out for i=1:nsim, j=1:nstages]' for res = 1:results[:data][1]["hydro"]["nHyd"]])

@andrewrosemberg
Copy link
Owner Author

FAQ: Dual and primal variables are changing if more SDDP iterations are executed even though it already has statistically converged. Is this expected?

Answer: Yes, a more conservative notion of convergence would require both primal variable stalling and dual variable stalling. For case 3, this happens around the 1000th iteration.

@odow
Copy link
Collaborator

odow commented Oct 30, 2019

FAQ: Dual and primal variables are changing if more SDDP iterations are executed even though it already has statistically converged. Is this expected?

Answer: Yes, a more conservative notion of convergence would require both primal variable stalling and dual variable stalling. For case 3, this happens around the 1000th iteration.

I'm so glad this came up. For those interested, see odow/SDDP.jl#178. I recommend plotting the solution every X iterations until you "see" it stabilize.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests