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

feat: implement haskey for _CoreComponentOptContainerDict #49

Merged
merged 1 commit into from
Jan 8, 2025

Conversation

daschw
Copy link
Collaborator

@daschw daschw commented Jan 8, 2025

Consider

julia> using IESopt, JuMP

julia> m = Model(); @variable m x[1:10]
10-element Vector{VariableRef}:
 x[1]
 x[2]
 x[3]
 x[4]
 x[5]
 x[6]
 x[7]
 x[8]
 x[9]
 x[10]

julia> ccocd = IESopt._CoreComponentOptContainerDict(Dict(:x => x))
IESopt._CoreComponentOptContainerDict{Vector{VariableRef}}(Dict{Symbol, Vector{VariableRef}}(:x => [x[1], x[2], x[3], x[4], x[5], x[6], x[7], x[8], x[9], x[10]]))

julia> haskey(ccocd, :x)
ERROR: MethodError: no method matching haskey(::IESopt._CoreComponentOptContainerDict{Vector{VariableRef}}, ::Symbol)
The function `haskey` exists, but no method is defined for this combination of argument types.

Closest candidates are:
  haskey(::Base.TermInfo, ::Symbol)
   @ Base terminfo.jl:221
  haskey(::LibGit2.CachedCredentials, ::Any)
   @ LibGit2 C:\Users\SchwabenederD\.julia\juliaup\julia-1.11.2+0.x64.w64.mingw32\share\julia\stdlib\v1.11\LibGit2\src\types.jl:1315
  haskey(::Pkg.Types.Manifest, ::Any)
   @ Pkg C:\Users\SchwabenederD\.julia\juliaup\julia-1.11.2+0.x64.w64.mingw32\share\julia\stdlib\v1.11\Pkg\src\Types.jl:314
  ...

Stacktrace:
 [1] top-level scope
   @ REPL[17]:1

julia>

Though this can be achieved currently with

julia> :x in keys(ccocd)
true

I think having an implementation for haskey does not hurt.

@sstroemer sstroemer merged commit 91d38b2 into ait-energy:main Jan 8, 2025
2 checks passed
@daschw daschw deleted the ccocd branch January 8, 2025 16:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants