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

Using integer values in input data Dict leads to an InexactError in compute_ac_pf() #938

Open
LKuhrmann opened this issue Jan 22, 2025 · 3 comments · May be fixed by #939
Open

Using integer values in input data Dict leads to an InexactError in compute_ac_pf() #938

LKuhrmann opened this issue Jan 22, 2025 · 3 comments · May be fixed by #939

Comments

@LKuhrmann
Copy link

When trying to compute the ac power flow for my model, it didn't work as I had integer zeroes (0) instead of float zeroes (0.0) in my input dictionary.
Attached is the stacktrace and two very similar cases, where one works and one doesn't. The only difference is the 0/0.0.

Stacktrace:

ERROR: InexactError: Int64(-0.07035222288586446)
Stacktrace:
  [1] Int64
    @ .\float.jl:994 [inlined]
  [2] convert
    @ .\number.jl:7 [inlined]
  [3] setindex!(h::Dict{String, Int64}, v0::Float64, key::String)
    @ Base .\dict.jl:355
  [4] _assign_qg!(sol_gens::Dict{String, Any}, bus_gens::Vector{Any}, qg_remaining::Float64)
    @ PowerModels C:\Users\kuhrmann\.julia\packages\PowerModels\6U4MZ\src\prob\pf.jl:506
  [5] compute_ac_pf(pf_data::PowerFlowData; kwargs::@Kwargs{})
    @ PowerModels C:\Users\kuhrmann\.julia\packages\PowerModels\6U4MZ\src\prob\pf.jl:348
  [6] compute_ac_pf
    @ C:\Users\kuhrmann\.julia\packages\PowerModels\6U4MZ\src\prob\pf.jl:293 [inlined]
  [7] #compute_ac_pf#1003
    @ C:\Users\kuhrmann\.julia\packages\PowerModels\6U4MZ\src\prob\pf.jl:282 [inlined]
  [8] compute_ac_pf
    @ C:\Users\kuhrmann\.julia\packages\PowerModels\6U4MZ\src\prob\pf.jl:276 [inlined]
  [9] solve_ac_PF(solver_type::String, network_data::Dict{String, Any})

See attached models as examples:

broken_model.json
working_model.json

The only code used was parse_file() and compute_ac_pf().

The only difference is that pg in the working models is 0.0, while in the broken model it is 0.
I think think that this should maybe be caught somewhere in correct_network_data!().
Also doesn't happen if the model is in mixed units (i assume the 0 gets divided by the unit base, leading to a 0.0).

Thanks for your efforts! Love the project!

@ccoffrin
Copy link
Member

I have not had a chance to check your data in detail, but it looks like the data types in the not working json file are not conforming to the data model assumptions. There are some fields which need to integers (e.g., bus ids) and others which can be integers or floats (e.g., a power demand value). The error seems to indicate that one of the integer fields has been given a float value of -0.070... resolve those issues and these functions should work.

@odow
Copy link
Collaborator

odow commented Jan 23, 2025

Yeah the issue is

"3": {
            "gen_bus": 3,
            "pg": 0,
        }

The pg field needs to be a Float64.

But we could potentially fix this in PowerModels.

The issue is that:

gen_assignment[i] = Dict(
"pg" => gen["pg"],
"qg" => gen["qg"]
)

needs to be

               gen_assignment[i] = Dict{String,Float64}(  # Or Dict{String,Any}
                    "pg" => gen["pg"],
                    "qg" => gen["qg"]
                )

There are many cases where we could do better to ensure the proper type conversion.

@LKuhrmann
Copy link
Author

@ccoffrin
Sorry should have clarified:
Was able to avoid this issue by changing my code that generates the data dict I feed into PowerModels!

Just thought that this is perhaps something that should either be explicitly rejected as an input not fulfilling the data type assumptions or that should be automatically converted from int to float! (Esp considering that an int type for pg works when feeding data in actual units instead of per unit)

@odow odow linked a pull request Jan 24, 2025 that will close this issue
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 a pull request may close this issue.

3 participants