Closed BYS543 closed 3 years ago
I am guessing that you are not on the latest version (v0.6.2) that introduced new @stochastic_model
syntax. Try updating. If you explicitly run pkg> add StochasticPrograms@0.6.2
you can check if there are any dependency blocks. The old anonymous syntax still works as well (check docs for v0.6.1)
Tkank you for your help, Martin. I have run pkg> add StochasticPrograms@0.6.2
, and it shows as,
(@JuliaPro_v1.5.4-1) pkg> add StochasticPrograms@0.6.2
Updating registry at `C:\Users\Lenovo\.julia\registries\General`
Updating registry at `C:\Users\Lenovo\.julia\registries\JuliaComputingRegistry`
Resolving package versions...
Installed Observables ───────── v0.4.0
Installed Distances ─────────── v0.10.3
Installed YAML ──────────────── v0.4.7
Installed LibCURL ───────────── v0.6.3
Installed ForwardDiff ───────── v0.10.18
Installed Colors ────────────── v0.12.8
Installed JLLWrappers ───────── v1.3.0
Installed LoweredCodeUtils ──── v2.1.0
Installed Conda ─────────────── v1.5.2
Installed Reexport ──────────── v1.1.0
Installed StochasticPrograms ── v0.6.2
Installed ArrayInterface ────── v3.1.17
Installed ChainRulesCore ────── v0.10.1
Installed TimerOutputs ──────── v0.5.9
Installed SpecialFunctions ──── v1.5.1
Installed ColorTypes ────────── v0.11.0
Installed CategoricalArrays ─── v0.9.7
Installed MozillaCACerts_jll ── v2021.1.19+0
Installed WebIO ─────────────── v0.8.92
Installed OrderedCollections ── v1.4.1
Installed StructTypes ───────── v1.7.2
Installed TimeZones ─────────── v1.5.5
Installed Widgets ───────────── v0.6.3
Installed DocStringExtensions ─ v0.8.4
Installed TOML ──────────────── v1.0.3
Installed Compat ────────────── v3.30.0
Installed LazyArtifacts ─────── v1.3.0
Installed Bzip2_jll ─────────── v1.0.7+0
Installed Tables ────────────── v1.4.3
Installed BenchmarkTools ────── v1.0.0
Installed JuliaInterpreter ──── v0.8.16
Installed TableTraits ───────── v1.0.1
Installed StringEncodings ───── v0.3.4
Installed Downloads ─────────── v1.5.1
Installed Static ────────────── v0.2.5
Installed Parsers ───────────── v1.1.0
Installed MathOptInterface ──── v0.9.22
Installed libsodium_jll ─────── v1.0.19+0
Installed Preferences ───────── v1.2.2
Installed FileIO ────────────── v1.9.1
Installed Distributions ─────── v0.25.2
Installed Tokenize ──────────── v0.5.16
Installed MutableArithmetics ── v0.2.19
Installed StaticArrays ──────── v1.2.2
Updating `C:\Users\Lenovo\.julia\environments\JuliaPro_v1.5.4-1\Project.toml`
[8b8459f2] ↑ StochasticPrograms v0.5.0 ⇒ v0.6.2
Updating `C:\Users\Lenovo\.julia\environments\JuliaPro_v1.5.4-1\Manifest.toml`
[4fba245c] ↑ ArrayInterface v3.1.9 ⇒ v3.1.17
[6e4b80f9] ↑ BenchmarkTools v0.5.0 ⇒ v1.0.0
[6e34b625] ↑ Bzip2_jll v1.0.6+5 ⇒ v1.0.7+0
[324d7699] ↑ CategoricalArrays v0.9.3 ⇒ v0.9.7
[d360d2e6] ↑ ChainRulesCore v0.9.29 ⇒ v0.10.1
[3da002f7] ↑ ColorTypes v0.10.12 ⇒ v0.11.0
[5ae59095] ↑ Colors v0.12.6 ⇒ v0.12.8
[34da2185] ↑ Compat v3.25.0 ⇒ v3.30.0
[8f4d0f93] ↑ Conda v1.5.1 ⇒ v1.5.2
[b4f34e82] ↑ Distances v0.10.2 ⇒ v0.10.3
[31c24e10] ↑ Distributions v0.24.18 ⇒ v0.25.2
[ffbed154] ↑ DocStringExtensions v0.8.3 ⇒ v0.8.4
[f43a241f] ↑ Downloads v1.4.0 ⇒ v1.5.1
[5789e2e9] ↑ FileIO v1.6.4 ⇒ v1.9.1
[f6369f11] ↑ ForwardDiff v0.10.17 ⇒ v0.10.18
[692b3bcd] ↑ JLLWrappers v1.2.0 ⇒ v1.3.0
[aa1ae85d] ↑ JuliaInterpreter v0.8.11 ⇒ v0.8.16
[4af54fe1] + LazyArtifacts v1.3.0
[b27032c2] ↑ LibCURL v0.6.2 ⇒ v0.6.3
[6f1432cf] ↑ LoweredCodeUtils v2.0.0 ⇒ v2.1.0
[b8f27783] ↑ MathOptInterface v0.9.20 ⇒ v0.9.22
[14a3606d] ↑ MozillaCACerts_jll v2020.10.14+0 ⇒ v2021.1.19+0
[d8a4904e] ↑ MutableArithmetics v0.2.14 ⇒ v0.2.19
[510215fc] ↑ Observables v0.3.3 ⇒ v0.4.0
[bac558e1] ↑ OrderedCollections v1.4.0 ⇒ v1.4.1
[69de0a69] ↑ Parsers v1.0.16 ⇒ v1.1.0
[21216c6a] + Preferences v1.2.2
[189a3867] ↑ Reexport v0.2.0 ⇒ v1.1.0
[276daf66] ↑ SpecialFunctions v1.3.0 ⇒ v1.5.1
[aedffcd0] ↑ Static v0.2.4 ⇒ v0.2.5
[90137ffa] ↑ StaticArrays v1.0.1 ⇒ v1.2.2
[8b8459f2] ↑ StochasticPrograms v0.5.0 ⇒ v0.6.2
[69024149] + StringEncodings v0.3.4
[856f2bd8] ↑ StructTypes v1.4.0 ⇒ v1.7.2
[fa267f1f] + TOML v1.0.3
[3783bdb8] ↑ TableTraits v1.0.0 ⇒ v1.0.1
[bd369af6] ↑ Tables v1.4.0 ⇒ v1.4.3
[f269a46b] ↑ TimeZones v1.5.3 ⇒ v1.5.5
[a759f4b9] ↑ TimerOutputs v0.5.8 ⇒ v0.5.9
[0796e94c] ↑ Tokenize v0.5.13 ⇒ v0.5.16
[0f1e0344] ↓ WebIO v0.8.93 ⇒ v0.8.92
[cc8bc4a8] ↑ Widgets v0.6.2 ⇒ v0.6.3
[ddb6d928] ↑ YAML v0.4.6 ⇒ v0.4.7
[a9144af2] ↑ libsodium_jll v1.0.18+1 ⇒ v1.0.19+0
Building Conda ────→ `C:\Users\Lenovo\.julia\packages\Conda\sNGum\deps\build.log`
Building WebIO ────→ `C:\Users\Lenovo\.julia\packages\WebIO\cOHMI\deps\build.log`
Building TimeZones → `C:\Users\Lenovo\.julia\packages\TimeZones\y3gf6\deps\build.log`
When I run the example farmer
,it still tells me
ERROR: LoadError: LoadError: MethodError: no method matching @stochastic_model(::LineNumberNode, ::Module, ::Symbol, ::Expr)
Closest candidates are:
@stochastic_model(::LineNumberNode, ::Module, ::Any) at C:\Users\Lenovo\.julia\packages\StochasticPrograms\54439\src\types\stochasticmodel.jl:73
Stacktrace:
[1] include_string(::Function, ::Module, ::String, ::String) at .\loading.jl:1088
in expression starting at C:\Users\Lenovo\Downloads\StochasticPrograms.jl-master\test\problems\farmer.jl:2
in expression starting at C:\Users\Lenovo\Downloads\StochasticPrograms.jl-master\test\problems\farmer.jl:2
From the error message it still looks like you are on the wrong version. What is the output of pkg> status
? I have never used JuliaPro if it is related to that somehow.
So it is related to my IDE "JuliaPro"? if I run pkg> status
Status `C:\Users\Lenovo\.julia\environments\JuliaPro_v1.5.4-1\Project.toml`
[c52e3926] Atom v0.12.30 ⚲
[a076750e] CPLEX v0.7.6
[a93c6f00] DataFrames v0.22.5
[60bf3e95] GLPK v0.14.8
[2e9cd046] Gurobi v0.9.11
[7073ff75] IJulia v1.23.2
[b6b21f68] Ipopt v0.6.5
[4076af6c] JuMP v0.21.6
[e5e0dc1b] Juno v0.8.4 ⚲
[4722fa14] PkgAuthentication v1.1.0
[e0fc9d43] PkgMirrors v1.3.0
[c36e90e8] PowerModels v0.18.1
[295af30f] Revise v3.1.15
[f4570300] SDDP v0.3.14 `https://github.com/odow/SDDP.jl#master`
[8b8459f2] StochasticPrograms v0.6.2
[44d3d7a6] Weave v0.10.7
[fdbf4ff8] XLSX v0.7.6
Everything looks fine, does it not work if you load StochasticPrograms: using StochasticPrograms
and copy paste the farmer code into that session?
Well, I have used ctrl+d to clear the workspace and load StochaticPrograms again ,the new error occurs:
[ Info: Precompiling StochasticPrograms [8b8459f2-c380-502b-8633-9aed2d6c2b35]
ERROR: LoadError: LoadError: LoadError: LoadError: LoadError: UndefVarError: coefficient not defined
Stacktrace:
[1] getproperty(::Module, ::Symbol) at .\Base.jl:26
[2] top-level scope at C:\Users\Lenovo\.julia\packages\StochasticPrograms\Jl6sf\src\types\decisions\expressions\affine.jl:97
[3] include(::Function, ::Module, ::String) at .\Base.jl:380
[4] include at .\Base.jl:368 [inlined]
[5] include(::String) at C:\Users\Lenovo\.julia\packages\StochasticPrograms\Jl6sf\src\StochasticPrograms.jl:2
[6] top-level scope at C:\Users\Lenovo\.julia\packages\StochasticPrograms\Jl6sf\src\types\decisions\expressions\expressions.jl:1
[7] include(::Function, ::Module, ::String) at .\Base.jl:380
[8] include at .\Base.jl:368 [inlined]
[9] include(::String) at C:\Users\Lenovo\.julia\packages\StochasticPrograms\Jl6sf\src\StochasticPrograms.jl:2
[10] top-level scope at C:\Users\Lenovo\.julia\packages\StochasticPrograms\Jl6sf\src\types\decisions\decisions.jl:313
[11] include(::Function, ::Module, ::String) at .\Base.jl:380
[12] include at .\Base.jl:368 [inlined]
[13] include(::String) at C:\Users\Lenovo\.julia\packages\StochasticPrograms\Jl6sf\src\StochasticPrograms.jl:2
[14] top-level scope at C:\Users\Lenovo\.julia\packages\StochasticPrograms\Jl6sf\src\types\types.jl:8
[15] include(::Function, ::Module, ::String) at .\Base.jl:380
[16] include at .\Base.jl:368 [inlined]
[17] include(::String) at C:\Users\Lenovo\.julia\packages\StochasticPrograms\Jl6sf\src\StochasticPrograms.jl:2
[18] top-level scope at C:\Users\Lenovo\.julia\packages\StochasticPrograms\Jl6sf\src\StochasticPrograms.jl:236
[19] include(::Function, ::Module, ::String) at .\Base.jl:380
[20] include(::Module, ::String) at .\Base.jl:368
[21] top-level scope at none:2
[22] eval at .\boot.jl:347 [inlined]
[23] eval(::Expr) at .\client.jl:467
[24] top-level scope at .\none:3
in expression starting at C:\Users\Lenovo\.julia\packages\StochasticPrograms\Jl6sf\src\types\decisions\expressions\affine.jl:97
in expression starting at C:\Users\Lenovo\.julia\packages\StochasticPrograms\Jl6sf\src\types\decisions\expressions\expressions.jl:1
in expression starting at C:\Users\Lenovo\.julia\packages\StochasticPrograms\Jl6sf\src\types\decisions\decisions.jl:313
in expression starting at C:\Users\Lenovo\.julia\packages\StochasticPrograms\Jl6sf\src\types\types.jl:8
in expression starting at C:\Users\Lenovo\.julia\packages\StochasticPrograms\Jl6sf\src\StochasticPrograms.jl:236
ERROR: LoadError: Failed to precompile StochasticPrograms [8b8459f2-c380-502b-8633-9aed2d6c2b35] to C:\Users\Lenovo\.julia\compiled\v1.5\StochasticPrograms\ohftP_TjFT6.ji.
Stacktrace:
[1] error(::String) at .\error.jl:33
[2] compilecache(::Base.PkgId, ::String) at .\loading.jl:1305
[3] _require(::Base.PkgId) at .\loading.jl:1030
[4] require(::Base.PkgId) at .\loading.jl:928
[5] require(::Module, ::Symbol) at .\loading.jl:923
[6] include_string(::Function, ::Module, ::String, ::String) at .\loading.jl:1088
in expression starting at C:\Users\Lenovo\Downloads\StochasticPrograms.jl-master\test\problems\farmer.jl:1
Ah, I have not been careful enough with compat. You need to update JuMP to at least v0.21.7.
So it seems new error occurs after I update JuMP,
[ Info: Precompiling StochasticPrograms [8b8459f2-c380-502b-8633-9aed2d6c2b35]
ERROR: LoadError: UndefVarError: SPResult not defined
Stacktrace:
[1] top-level scope at C:\Users\Lenovo\Downloads\StochasticPrograms.jl-master\test\problems\farmer.jl:38
[2] include_string(::Function, ::Module, ::String, ::String) at .\loading.jl:1088
in expression starting at C:\Users\Lenovo\Downloads\StochasticPrograms.jl-master\test\problems\farmer.jl:38
This is just from running the testfile verbatim. You do not need SPResult
. You can just skip the final lines and keep the model definition and the scenarios.
Thank you very much, Martin. It can fly without errors.
Perfect, happy to help!
Hi, Martin I have added the StochasticPrograms package,and use "using StochasticPrograms" ,but when I run the example"farmer" it tells me as following error:
Also, it has the warning in the command window:
WARNING: both Distributions and JuMP export "shape"; uses of it in module StochasticPrograms must be qualified
How can I deal with it? Thanks a lot!