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

[Bug]: type Thermal has no attribute cum_min_retired_cap_mw #766

Closed
NLaws opened this issue Sep 4, 2024 · 8 comments
Closed

[Bug]: type Thermal has no attribute cum_min_retired_cap_mw #766

NLaws opened this issue Sep 4, 2024 · 8 comments
Labels
bug Something isn't working
Milestone

Comments

@NLaws
Copy link
Contributor

NLaws commented Sep 4, 2024

Bug description

it looks like there is a missing attribute in the generated code for thermal resources? I see

# Endogenous retirement
for attr in (:min_retired_cap_inverter_mw,
    :min_retired_cap_solar_mw,
    :min_retired_cap_wind_mw,
    :min_retired_cap_elec_mw,
    :min_retired_cap_discharge_dc_mw,
    :min_retired_cap_charge_dc_mw,
    :min_retired_cap_discharge_ac_mw,
    :min_retired_cap_charge_ac_mw)
    @eval @interface $attr default_zero
    cum_attr = Symbol("cum_" * String(attr))
    @eval @interface $cum_attr default_zero
end

in resources.jl, but adding :min_retired_cap_mw to the list of attr does not fix the error.

Here is the traceback:

Endogenous Retirement (Discharge) Module
ERROR: LoadError: type Thermal has no attribute cum_min_retired_cap_mw
Stacktrace:
  [1] getproperty(r::GenX.Thermal{Symbol, Any}, sym::Symbol)
    @ GenX ~/.julia/packages/GenX/6iHtB/src/model/resources/resources.jl:55
  [2] cum_min_retired_cap_mw(r::GenX.Thermal{Symbol, Any})
    @ GenX ~/.julia/packages/GenX/6iHtB/src/model/resources/resources.jl:685
  [3] macro expansion
    @ ~/.julia/packages/GenX/6iHtB/src/multi_stage/endogenous_retirement.jl:226 [inlined]
  [4] macro expansion
    @ ~/.julia/packages/MutableArithmetics/OfRUD/src/rewrite.jl:346 [inlined]
  [5] macro expansion
    @ ~/.julia/packages/JuMP/PKxEW/src/macros.jl:257 [inlined]
  [6] macro expansion
    @ ~/.julia/packages/JuMP/PKxEW/src/macros/@expression.jl:86 [inlined]
  [7] (::GenX.var"#1756#1770"{Vector{Int64}, Vector{GenX.AbstractResource}, JuMP.Model})(y::Int64)
    @ GenX ~/.julia/packages/JuMP/PKxEW/src/Containers/macro.jl:545
  [8] #87
    @ ~/.julia/packages/JuMP/PKxEW/src/Containers/container.jl:124 [inlined]
  [9] iterate
    @ ./generator.jl:47 [inlined]
 [10] collect(itr::Base.Generator{JuMP.Containers.VectorizedProductIterator{…}, JuMP.Containers.var"#87#89"{…}})
    @ Base ./array.jl:834
 [11] map(f::Function, A::JuMP.Containers.VectorizedProductIterator{Tuple{Vector{Int64}}})
    @ Base ./abstractarray.jl:3313
 [12] container(f::Function, indices::JuMP.Containers.VectorizedProductIterator{…}, ::Type{…}, names::Vector{…})
    @ JuMP.Containers ~/.julia/packages/JuMP/PKxEW/src/Containers/container.jl:123
 [13] container(f::Function, indices::JuMP.Containers.VectorizedProductIterator{…}, ::Type{…}, names::Vector{…})
    @ JuMP.Containers ~/.julia/packages/JuMP/PKxEW/src/Containers/container.jl:75
 [14] macro expansion
    @ ~/.julia/packages/JuMP/PKxEW/src/macros.jl:393 [inlined]
 [15] endogenous_retirement_discharge!(EP::JuMP.Model, inputs::Dict{…}, num_stages::Int64, cur_stage::Int64, stage_lens::Vector{…})
    @ GenX ~/.julia/packages/GenX/6iHtB/src/multi_stage/endogenous_retirement.jl:224
 [16] endogenous_retirement!(EP::JuMP.Model, inputs::Dict{Any, Any}, setup::Dict{Any, Any})
    @ GenX ~/.julia/packages/GenX/6iHtB/src/multi_stage/endogenous_retirement.jl:78
 [17] generate_model(setup::Dict{Any, Any}, inputs::Dict{Any, Any}, OPTIMIZER::MathOptInterface.OptimizerWithAttributes)
    @ GenX ~/.julia/packages/GenX/6iHtB/src/model/generate_model.jl:215
 [18] top-level scope
...

Environment and Version

Julia 1.10.4, GenX v0.4.1

Relevant error messages

No response

Additional context

No response

@NLaws NLaws added the bug Something isn't working label Sep 4, 2024
@sambuddhac
Copy link
Collaborator

Hey @NLaws , great to hear from you and very glad that you're using GenX. Thanks for submitting the issue. I'll get back to you ASAP after running through some tests.

@lbonaldo
Copy link
Collaborator

lbonaldo commented Sep 5, 2024

Hi @NLaws,

Thank you for opening this issue. The cum_min_retired_cap_mw attribute/function is defined for all resources a few lines above the code you attached (see here).

Could you please provide more details on the case you are running? For instance, is it a multistage optimization? If so, have you included a Resource_multistage_data.csv file that lists the resources with minimum capacity retirement? You can find an example here.

The cum_min_retired_cap_mw attribute for each resource is calculated from the min_retired_cap_mw values listed in the Resource_multistage_data.csv during the loading of inputs for a multistage optimization.

Thank you!

@NLaws
Copy link
Contributor Author

NLaws commented Sep 5, 2024

The cum_min_retired_cap_mw attribute/function is defined for all resources a few lines above the code you attached (see here).

I believe that

cum_min_retired_cap_mw(r::AbstractResource) = r.cum_min_retired_cap_mw

only defines the cum_min_retired_cap_mw method, and not the Thermal.cum_min_retired_cap_mw, which is where the code fails (see traceback above).

Yes I have a 3 stage problem (myopic = 1) and Resource_multistage_data.csv hat have min_retired_cap_mw values.
Screenshot 2024-09-05 at 2 22 13 PM

However, even if there are missing min_retired_cap_mw values shouldn't the cum_min_retired_cap_mw default to zero? (It looks like that was the intention with default_zero)

@lbonaldo
Copy link
Collaborator

lbonaldo commented Sep 5, 2024

I believe that

cum_min_retired_cap_mw(r::AbstractResource) = r.cum_min_retired_cap_mw

only defines the cum_min_retired_cap_mw method, and not the Thermal.cum_min_retired_cap_mw, which is where the code fails (see traceback above).

Yes, you are correct. This is where the cum_min_retired_cap_mw attribute is calculated and added to each resource based on the min_retired_cap_mw value.

On the other hand, the functions min_retired_cap_inverter_mw, min_retired_cap_solar_mw etc refer to the attributes related to the module that handles the co-location of renewable and storage resources.

@NLaws
Copy link
Contributor Author

NLaws commented Sep 10, 2024

hrm still not sure what the issue is. does it help to know that the inputs that I'm working with did work with v0.3 of GenX? I have converted to v0.4 format to my best knowledge but I probably missed something. Is there any guidance documentation on how to update input files for the transition to v0.4 from v0.3?

@lbonaldo
Copy link
Collaborator

We’ve written this guide and also developed a script to help with the translation. I'm not sure if you’ve seen it in the release notes. If you’d like, feel free to reach out, and I can take a look at your inputs and do some debugging.

@sambuddhac
Copy link
Collaborator

HI @NLaws , could you please send me and Luca( @lbonaldo ) your availability and a preferred email? We would like to set up a virtual meeting and dig deeper into your issue and hopefully be of better help at addressing it? Thanks !!!

@NLaws
Copy link
Contributor Author

NLaws commented Oct 16, 2024

I finally had a chance to try out the conversion script that @lbonaldo linked to on Sep. 11: it worked!

@NLaws NLaws closed this as completed Oct 16, 2024
@GenXProject GenXProject added this to the v0.4.2 milestone Jan 16, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants