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

Warn user with DeprecationWarning too avoid using deprecated functions #823

Open
leuchtum opened this issue Sep 5, 2024 · 3 comments
Open
Labels
bug Something isn't working

Comments

@leuchtum
Copy link

leuchtum commented Sep 5, 2024

Describe the current behavior

When running the following, the values of get_reference_voltages and get_reference_flows are the same:

import pypowsybl

LINES_OF_INTEREST = [
    "L1-2-1",
    "L13-14-1",
    "T4-7-1",
    "T4-9-1",
]
LOADS_OF_INTEREST = [
    "B5-L",
    "B10-L",
    "B11-L",
]

net = pypowsybl.network.create_ieee14()
pypowsybl.loadflow.run_ac(net)

analysis = pypowsybl.sensitivity.create_ac_analysis()
analysis.add_branch_flow_factor_matrix(
    branches_ids=LINES_OF_INTEREST,
    variables_ids=LOADS_OF_INTEREST,
)
result = analysis.run(net)

flows = result.get_reference_flows()
voltages = result.get_reference_voltages()
sens = result.get_sensitivity_matrix()

print("\nFLOWS\n", flows)
print("\nVOLTAGES\n", voltages)
print("\nSENSITIVITY\n", sens)

# FLOWS
#                       L1-2-1  L13-14-1     T4-7-1     T4-9-1
# reference_flows  156.882888  5.643851  28.074177  16.079758
# 
# VOLTAGES
#                          L1-2-1  L13-14-1     T4-7-1     T4-9-1
# reference_voltages  156.882888  5.643851  28.074177  16.079758
# 
# SENSITIVITY
#           L1-2-1  L13-14-1    T4-7-1    T4-9-1
# B5-L  -0.673961  0.005229 -0.009223 -0.005006
# B10-L -0.729866 -0.074030 -0.407654 -0.232379
# B11-L -0.714910  0.020536 -0.304432 -0.173739

Describe the expected behavior

First of all, let's address the elephant in the room. It doesn't make sense to ask for the reference voltages when looking for branch flow sensitivities. Nevertheless, I am of the opinion that the output of get_reference_voltages is incorrect, because the values for the reference voltage are definitely wrong.

What I would expect is that an empty DataFrame is returned or an exception is raised.

Describe the steps

No response

Environment

pypowsybl version is 1.7.0.dev1 on commit 984e527

Relevant Log Output

No response

Extra Information

No response

@leuchtum leuchtum added the bug Something isn't working label Sep 5, 2024
@leuchtum leuchtum changed the title Misleading output of get_reference_voltagesin sensitivity analysis Misleading output of get_reference_voltages in sensitivity analysis Sep 5, 2024
@leuchtum
Copy link
Author

leuchtum commented Sep 5, 2024

Just tested what happens if you ask for voltage sensitivities. The same happens, but now the values for get_reference_flows are wrong.

import pypowsybl

BUSES_OF_INTEREST = [
    "VL1_0",
    "VL2_0",
    "VL3_0",
    "VL13_0",
    "VL14_0",
]
GENS_OF_INTEREST = [
    "B1-G",
    "B3-G",
    "B8-G",
]

net = pypowsybl.network.create_ieee14()
pypowsybl.loadflow.run_ac(net)

analysis = pypowsybl.sensitivity.create_ac_analysis()
analysis.add_bus_voltage_factor_matrix(
    bus_ids=BUSES_OF_INTEREST,
    target_voltage_ids=GENS_OF_INTEREST,
)
result = analysis.run(net)

flows = result.get_reference_flows()
voltages = result.get_reference_voltages()
sens = result.get_sensitivity_matrix()

print("\nFLOWS\n", flows)
print("\nVOLTAGES\n", voltages)
print("\nSENSITIVITY\n", sens)

# FLOWS
#                   VL1_0    VL2_0   VL3_0     VL13_0     VL14_0
# reference_flows  143.1  141.075  136.35  12.604581  12.426359
# 
# VOLTAGES
#                      VL1_0    VL2_0   VL3_0     VL13_0     VL14_0
# reference_voltages  143.1  141.075  136.35  12.604581  12.426359
# 
# SENSITIVITY
#        VL1_0  VL2_0  VL3_0    VL13_0    VL14_0
# B1-G    1.0    0.0    0.0  0.000712  0.003062
# B3-G    0.0    0.0    1.0  0.001353  0.005884
# B8-G    0.0    0.0    0.0  0.028720  0.124654

@leuchtum
Copy link
Author

leuchtum commented Sep 5, 2024

I just saw in the depths of the documentation that get_reference_voltages and get_reference_flows are deprecated in favor of get_reference_matrix. I would highly suggest to make this more visible by informing the user with an explicit DeprecationWarning.

@leuchtum leuchtum changed the title Misleading output of get_reference_voltages in sensitivity analysis Warn user with DeprecationWarning too avoid using deprecated functions Sep 5, 2024
@colinepiloquet
Copy link
Member

Hello, I don't understand why you don't get the deprecation warnings as they are already in the code. Thanks for pointing it out, I will look into it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants