Skip to content

Conversation

@kornerc
Copy link
Contributor

@kornerc kornerc commented Nov 25, 2025

Fixes issue: #1198

Example:

import numpy as np

from power_grid_model import (
    ComponentType,
    DatasetType,
    LoadGenType,
    PowerGridModel,
    attribute_dtype,
    initialize_array,
)

# node
node = initialize_array(DatasetType.input, ComponentType.node, 3)
node["id"] = np.array([1, 2, 6])
node["u_rated"] = [10.5e3, 10.5e3, 10.5e3]

# line
line = initialize_array(DatasetType.input, ComponentType.line, 3)
line["id"] = [3, 5, 8]
line["from_node"] = [1, 2, 1]
line["to_node"] = [2, 6, 6]
line["from_status"] = [1, 1, 1]
line["to_status"] = [1, 1, 1]
line["r1"] = [0.25, 0.25, 0.25]
line["x1"] = [0.2, 0.2, 0.2]
line["c1"] = [10e-6, 10e-6, 10e-6]
line["tan1"] = [0.0, 0.0, 0.0]
line["i_n"] = [1000, 1000, 1000]

# load
sym_load = initialize_array(DatasetType.input, ComponentType.sym_load, 2)
sym_load["id"] = [4, 7]
sym_load["node"] = [2, 6]
sym_load["status"] = [1, 1]
sym_load["type"] = [LoadGenType.const_power, LoadGenType.const_power]
sym_load["p_specified"] = [20e6, 10e6]
sym_load["q_specified"] = [5e6, 2e6]

# source
source = initialize_array(DatasetType.input, ComponentType.source, 1)
source["id"] = [10]
source["node"] = [1]
source["status"] = [1]
source["u_ref"] = [1.0]

# all
input_data = {
    ComponentType.node: node,
    ComponentType.line: line,
    ComponentType.sym_load: sym_load,
    ComponentType.source: source,
}

source_columns = {
    "id": np.array([10], dtype=attribute_dtype(DatasetType.input, ComponentType.source, "id")),
    "node": np.array([1], dtype=attribute_dtype(DatasetType.input, ComponentType.source, "node")),
    "status": np.array([1], dtype=attribute_dtype(DatasetType.input, ComponentType.source, "status")),
    "u_ref": np.array([1.0], dtype=attribute_dtype(DatasetType.input, ComponentType.source, "u_ref")),
}

input_data = {
    ComponentType.node: node,
    ComponentType.line: line,
    ComponentType.sym_load: sym_load,
    ComponentType.source: source_columns,
}

model = PowerGridModel(input_data)

print(model)

Prints:

PowerGridModel (9 components)
  - node: 3
  - line: 3
  - sym_load: 2
  - source: 1

Signed-off-by: Clemens Korner <clemens.korner@gmail.com>
@TonyXiang8787 TonyXiang8787 added the feature New feature or request label Nov 25, 2025
mgovers
mgovers previously approved these changes Nov 26, 2025
Copy link
Member

@mgovers mgovers left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interesting to see how this shows up in the VSCode editor (see image)

  1. By default, only PowerGridModel (#### components) shows
  2. When hovering over it, the rest also shows.

I think that this is reasonable. The python docs also doesn't explicitly forbid that, so I think it's good as-is.

Image

Signed-off-by: Martijn Govers <martygovers@hotmail.com>
Copy link
Member

@mgovers mgovers left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @kornerc, Another great PR 👍 Thanks again for your contribution!

@mgovers mgovers enabled auto-merge November 26, 2025 07:54
@kornerc
Copy link
Contributor Author

kornerc commented Nov 26, 2025

Hi @kornerc, Another great PR 👍 Thanks again for your contribution!

You're welcome!
Thanks for your responivness and this nice project.

In my previous PR you've asked me about feedback for the contribution process.
I can join one of the upcoming meetings for the feedback and also describe the use-case for which I plan to use PowerGridModel in the future and the features which would be needed for these use-cases.

Unfortunately, I cannot join the meeting today.
I could also schedule - as an alternative - an MS Teams meeting if there is interest.

@mgovers mgovers added this pull request to the merge queue Nov 26, 2025
Merged via the queue into PowerGridModel:main with commit 470ecb0 Nov 26, 2025
29 checks passed
@mgovers
Copy link
Member

mgovers commented Nov 26, 2025

Hi @kornerc, Another great PR 👍 Thanks again for your contribution!

You're welcome! Thanks for your responivness and this nice project.

In my previous PR you've asked me about feedback for the contribution process. I can join one of the upcoming meetings for the feedback and also describe the use-case for which I plan to use PowerGridModel in the future and the features which would be needed for these use-cases.

Unfortunately, I cannot join the meeting today. I could also schedule - as an alternative - an MS Teams meeting if there is interest.

Sounds good! I guess the next community meeting would be perfect for this. Looking forward to it.

@TonyXiang8787 TonyXiang8787 linked an issue Nov 26, 2025 that may be closed by this pull request
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

feature New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[FEATURE] implement __repr__ and __str__

3 participants