Skip to content

fix parse_file and _rename_network_components! to support matlab files#27

Open
niwq15 wants to merge 3 commits intolanl-ansi:mainfrom
niwq15:fix_parse_file_for_distribution_network_matlab_files
Open

fix parse_file and _rename_network_components! to support matlab files#27
niwq15 wants to merge 3 commits intolanl-ansi:mainfrom
niwq15:fix_parse_file_for_distribution_network_matlab_files

Conversation

@niwq15
Copy link

@niwq15 niwq15 commented Oct 16, 2025

Pull Request (PR) for Distribution Network Data with MATPOWER Files

When using PowerModelsITD to parse MATLAB (.m) distribution network files, there were issues preventing direct conversion. Specifically:

  1. parse_file did not handle the format of certain components correctly. For example. data["name"] in MATPOWER files is often in the format of SubString{String} rather than String.

  2. _rename_network_components! did not handle the format of certain components correctly. For example, for load/shunt components, source_id can be a Vector{Any}, which caused the error:

    *(::String, ::Vector{Any})
    

These made it impossible to load MATLAB-based distribution networks directly.


Changes

  1. Updated _rename_network_components! to safely handle source_id, bus, and related fields when they are Vector{Any}, numbers, or strings.
  2. Ensured MATLAB distribution files can now be parsed without triggering type errors.
  3. Preserved all existing behavior for JSON/DSS files.

Testing

  • Verified that multiple .m distribution files can now be loaded via parse_files(pm_file, pmd_files, boundary_file) without errors.
  • Existing unit tests pass.

Notes

  • This fix is backward-compatible with existing JSON and DSS distribution network inputs.
  • No functional interface changes.

@juanjospina
Copy link
Contributor

Hi @niwq15. Thanks for the PR. A few points to keep in mind. PowerModelsITD relies heavily on PowerModelsDistribution.jl (PMD) for handling distribution system data. PMD officially supports OpenDSS ".dss" files, and MATPOWER files have been mostly used at the beginning for debugging, considering that MATPOWER is useful for balanced transmission system, and not really that useful for unbalanced distribution systems. See how PMD 'artificially' creates multiconductor the distribution system via the function make_multiconductor!(data, real(3)); this is not a very realistic way of defining a distribution system.

However if this new addition does not break the codebase, we could consider adding it for general support.

A few suggested changes for facilitating the merging of the PR are:

  1. Pull out the function _safe_prefix! outside the _rename_network_components! function.
  2. Add unit tests for all the features proposed.

These changes will help expedite the merging process. Thanks.

@niwq15
Copy link
Author

niwq15 commented Oct 20, 2025

Hi @juanjospina Thank you for the feedback!

I have pushed the requested changes addressing the formatting and naming issues. For the unit tests, I updated

  • one matlab version of the existing distribution network, test/data/distribution/case3_balanced_withoutgen.m,
  • and one test file, test/test_matlab.jl.

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