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

Fix handling of quantities in input sequences #146

Closed
wants to merge 1 commit into from
Closed

Conversation

alihamdan
Copy link
Member

Fixes #145

This required a few setters to abandon the ureg.wraps decorator but the alternative is very simple so I don't see a problem. I also tested other alternative like Q_.from_sequence but these don't always work as expected.

@alihamdan alihamdan added the bug Something isn't working label Nov 3, 2023
@alihamdan alihamdan self-assigned this Nov 3, 2023
@alihamdan
Copy link
Member Author

@benoit9126 did you have some time to take a look at this PR? I think we should cut a release after it is merged to fix several warnings from new pandas versions.

@benoit9126
Copy link
Member

Yes, and both @Saelyos and I don't manage to reproduce this bug on our computer with Python 3.11 or Python 3.12. Could you please provide us the version of numpy and pint that you are using? The problem may be solved by modifying the dependencies requirements.

@alihamdan
Copy link
Member Author

  1. Checkout the develop branch
  2. Create a python file bug.py with:
import numpy as np
from roseau.load_flow import *

# Create two buses
source_bus = Bus(id="sb", phases="abcn")
load_bus = Bus(id="lb", phases="abcn")

# Define the reference of potentials to be the neutral of the source bus
ground = Ground(id="gnd")
# Fix the potential of the ground at 0 V
pref = PotentialRef(id="pref", element=ground)
ground.connect(source_bus, phase="n")

# Create a LV source at the first bus
# Volts (phase-to-neutral because the source is connected to the neutral)
un = Q_(0.4 / np.sqrt(3), "kV")
source_voltages = [un, un * np.exp(-2j * np.pi / 3), un * np.exp(2j * np.pi / 3)]
vs = VoltageSource(id="vs", bus=source_bus, voltages=source_voltages)

# Add a load at the second bus
load = PowerLoad(id="load", bus=load_bus, powers=[10e3 + 0j, 10e3, 10e3])  # VA

# Add a LV line between the source bus and the load bus
# R = 0.1 Ohm/km, X = 0
lp = LineParameters("lp", z_line=(0.1 + 0.0j) * np.eye(4, dtype=complex))
line = Line(id="line", bus1=source_bus, bus2=load_bus, parameters=lp, length=2.0)
  1. run python bug.py

Versions:

$ python --version
Python 3.11.5
$ poetry show | grep -E '(numpy|pint)'
numpy                         1.26.1       Fundamental package for array co...
pint                          0.22         Physical quantities module

This also reproduced with Python 3.12 and the latest version of pint and numpy 3 weeks ago

@benoit9126
Copy link
Member

@alihamdan: @Saelyos is on it. He will rewrite a part of the wrapper to handle the case "array of quantities". Two advantages:

  1. the feature will be available everywhere.
  2. the improvements in the wrapper (Improve wraps performances hgrecco/pint#1866 and Wraps benchmark hgrecco/pint#1862) will be immediately available in RLF.

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

Successfully merging this pull request may close these issues.

BUG: DimensionalityError when voltage of the source is Quantity
3 participants