PyPSA / PyPSA

PyPSA: Python for Power System Analysis
https://pypsa.readthedocs.io
MIT License
1.25k stars 456 forks source link

Bus power equality doesn't trigger if bus doesn't exist, solves anyway #505

Closed Cellophil closed 3 months ago

Cellophil commented 1 year ago

Hi,

We found a small bug, pypsa 0.21.1:

#%%
import pypsa

n = pypsa.Network()
n.set_snapshots(np.arange(10))
n.add('Generator', name='test', bus='nobus', p_nom=100)
n.add('Bus', name='bus')
n.add('Generator', name='test2', bus='bus', p_nom=100)
n.lopf(solver_name='glpk')

#%%
from pypsa.linopt import define_constraints, get_var, linexpr
def extra(network, snapshots):
    define_constraints(network, linexpr((1, get_var(network, 'Generator', 'p').loc[:, 'test'])), '>=', 40, 'test')

n.lopf(solver_name='glpk', extra_functionality=extra)

A generator is put at a bus that doesn't exist - I guess a frequent thing in models due to data issues, and certainly captured by consistency_check. First stage solves normally and you could assume it just creates a virtual bus, equalizing power to zero there. It might be good if that was a bit stricter there...

Second one is a bit more puzzling, you can force the generator to produce power into the void. It solves normally. Not the most frequent scenario, but maybe worth a look.

Best, Andreas

fneum commented 3 months ago

I'm closing this as it is a user error captured as a warning by the consistency checks.