Skip to content

Fix a scoping issue in _get_irreducible_buses_due_to_dlrs#113

Open
odow wants to merge 1 commit into
mainfrom
od/fix-nameof
Open

Fix a scoping issue in _get_irreducible_buses_due_to_dlrs#113
odow wants to merge 1 commit into
mainfrom
od/fix-nameof

Conversation

@odow
Copy link
Copy Markdown
Collaborator

@odow odow commented May 8, 2026

This threw me for a loop. I'm using

import Dates
import HiGHS
import PowerOperationsModels as POM
import PowerSystems as PSY
sys = PSY.System(joinpath(@__DIR__, "performance", "CATS_Sienna.json"))
PSY.transform_single_time_series!(sys, Dates.Hour(1), Dates.Hour(1))
template = POM.OperationsProblemTemplate(
    POM.NetworkModel(
        POM.PTDFPowerModel;
        use_slacks = true,
        duals = [POM.CopperPlateBalanceConstraint],
    ),
);
POM.set_device_model!(template, PSY.ThermalStandard, POM.ThermalBasicUnitCommitment)
POM.set_device_model!(template, PSY.RenewableDispatch, POM.RenewableFullDispatch)
POM.set_device_model!(template, PSY.HydroDispatch, POM.HydroDispatchRunOfRiver)
POM.set_device_model!(template, PSY.PowerLoad, POM.StaticPowerLoad)
POM.set_device_model!(template, PSY.Line, POM.StaticBranch)
POM.set_device_model!(template, PSY.Transformer2W, POM.StaticBranch)
model = POM.DecisionModel(
    template,
    sys;
    name = "CATS_UC2",
    optimizer = HiGHS.Optimizer,
);
POM.build!(model; output_dir = mktempdir(; cleanup = true))

as a script. And I had it working. Then restarted Julia and had a cryptic error message about a missing symbol "PowerSystems.Line".

The issue is that in the guts of set_device_model! we call nameof(D) to set the key:

https://github.com/Sienna-Platform/InfrastructureOptimizationModels.jl/blob/9ccee6240f9b07ee16bf5a23b144e2a9e4fc4459/src/core/device_model.jl#L112-L116

but in POM we use Symbol(D). These differ depending on whether D is in the current scope:

julia> import PowerSystems as PSY

julia> nameof(PSY.Line)
:Line

julia> Symbol(PSY.Line)
Symbol("PowerSystems.Line")

julia> using PowerSystems

julia> Symbol(PSY.Line)
:Line

julia> Symbol(PSY.Line)
:Line

I must have had using PowerSystems in the first REPL and not the second.

@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 8, 2026

Performance Results

Version Precompile Time
Main 2.82504863
This Branch 2.801345689
Version Build Time
Main-Build Time Precompile 97.367770511
Main-Build Time Postcompile 14.674480712
This Branch-Build Time Precompile 96.421118763
This Branch-Build Time Postcompile 14.640758201
Version Solve Time
Main-Solve Time Precompile 391.356066522
Main-Solve Time Postcompile 359.336073663
This Branch-Solve Time Precompile 165.101334033
This Branch-Solve Time Postcompile 133.026968389

@luke-kiernan
Copy link
Copy Markdown
Collaborator

luke-kiernan commented May 12, 2026

This comes up in other spots too. (IS's test_printing.jl used to compare with ==, but then it started erroring due to InfrastructureSystems.Foo vs Foo, so I changed it to occursin.) It'd be great to have a comprehensive approach for this.

@odow
Copy link
Copy Markdown
Collaborator Author

odow commented May 12, 2026

It'd be great to have a comprehensive approach for this.

The "correct" approach is to use the actual data types as keys, rather than converting them to some sort of Symbol.

The issue is that it's really hard to detect and fix these scoping issues because they depend on package imports, and the tests just bring everything into scope with using.

@odow odow force-pushed the od/fix-nameof branch from d3204f2 to f88db25 Compare May 20, 2026 00:04
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