Giter Club home page Giter Club logo

pypsa / pypsa Goto Github PK

View Code? Open in Web Editor NEW
1.2K 72.0 439.0 42.91 MB

PyPSA: Python for Power System Analysis

Home Page: https://pypsa.readthedocs.io

License: MIT License

Python 100.00%
python loadflow optimisation pyomo energy-system power-systems-analysis optimal-power-flow powerflow energy energy-systems pypsa power-flow power-systems renewable-energy electrical-engineering capacity-expansion-planning clean-energy climate-change renewables electricity

pypsa's Introduction

PyPSA - Python for Power System Analysis

PyPI version Conda version Python Version from PEP 621 TOML Tests Code coverage Documentation Status License Zenodo pre-commit.ci status Ruff Discord Contributor Covenant Stack Exchange questions

PyPSA stands for "Python for Power System Analysis". It is pronounced "pipes-ah".

PyPSA is an open source toolbox for simulating and optimising modern power and energy systems that include features such as conventional generators with unit commitment, variable wind and solar generation, storage units, coupling to other energy sectors, and mixed alternating and direct current networks. PyPSA is designed to scale well with large networks and long time series.

This project is maintained by the Department of Digital Transformation in Energy Systems at the Technical University of Berlin. Previous versions were developed by the Energy System Modelling group at the Institute for Automation and Applied Informatics at the Karlsruhe Institute of Technology funded by the Helmholtz Association, and by the Renewable Energy Group at FIAS to carry out simulations for the CoNDyNet project, financed by the German Federal Ministry for Education and Research (BMBF) as part of the Stromnetze Research Initiative.

Functionality

PyPSA can calculate:

  • static power flow (using both the full non-linear network equations and the linearised network equations)
  • linear optimal power flow (least-cost optimisation of power plant and storage dispatch within network constraints, using the linear network equations, over several snapshots)
  • security-constrained linear optimal power flow
  • total electricity/energy system least-cost investment optimisation (using linear network equations, over several snapshots and investment periods simultaneously for optimisation of generation and storage dispatch and investment in the capacities of generation, storage, transmission and other infrastructure)

It has models for:

  • meshed multiply-connected AC and DC networks, with controllable converters between AC and DC networks
  • standard types for lines and transformers following the implementation in pandapower
  • conventional dispatchable generators and links with unit commitment
  • generators with time-varying power availability, such as wind and solar generators
  • storage units with efficiency losses
  • simple hydroelectricity with inflow and spillage
  • coupling with other energy carriers (e.g. resistive Power-to-Heat (P2H), Power-to-Gas (P2G), battery electric vehicles (BEVs), Fischer-Tropsch, direct air capture (DAC))
  • basic components out of which more complicated assets can be built, such as Combined Heat and Power (CHP) units and heat pumps.

Documentation

Installation

pip:

pip install pypsa

conda/mamba:

conda install -c conda-forge pypsa

Additionally, install a solver (see here).

Usage

import pypsa

# create a new network
n = pypsa.Network()
n.add("Bus", "mybus")
n.add("Load", "myload", bus="mybus", p_set=100)
n.add("Generator", "mygen", bus="mybus", p_nom=100, marginal_cost=20)

# load an example network
n = pypsa.examples.ac_dc_meshed()

# run the optimisation
n.optimize()

# plot results
n.generators_t.p.plot()
n.plot()

# get statistics
n.statistics()
n.statistics.energy_balance()

There are more extensive examples available as Jupyter notebooks. They are also available as Python scripts in examples/notebooks/ directory.

Screenshots

PyPSA-Eur optimising capacities of generation, storage and transmission lines (9% line volume expansion allowed) for a 95% reduction in CO2 emissions in Europe compared to 1990 levels

image

SciGRID model simulating the German power system for 2015.

image

image

Dependencies

PyPSA is written and tested to be compatible with Python 3.9 and above. The last release supporting Python 2.7 was PyPSA 0.15.0.

It leans heavily on the following Python packages:

  • pandas for storing data about components and time series
  • numpy and scipy for calculations, such as linear algebra and sparse matrix calculations
  • networkx for some network calculations
  • matplotlib for static plotting
  • linopy for preparing optimisation problems (currently only linear and mixed integer linear optimisation)
  • cartopy for plotting the baselayer map
  • pytest for unit testing
  • logging for managing messages

Find the full list of dependencies in the dependency graph.

The optimisation uses interface libraries like linopy which are independent of the preferred solver. You can use e.g. one of the free solvers HiGHS, GLPK and CLP/CBC or the commercial solver Gurobi for which free academic licenses are available.

Contributing and Support

We strongly welcome anyone interested in contributing to this project. If you have any ideas, suggestions or encounter problems, feel invited to file issues or make pull requests on GitHub.

  • In case of code-related questions, please post on stack overflow.
  • For non-programming related and more general questions please refer to the mailing list.
  • To discuss with other PyPSA users, organise projects, share news, and get in touch with the community you can use the discord server.
  • For bugs and feature requests, please use the PyPSA Github Issues page.
  • For troubleshooting, please check the troubleshooting in the documentation.

Detailed guidelines can be found in the Contributing section of our documentation.

Code of Conduct

Please respect our code of conduct.

Citing PyPSA

If you use PyPSA for your research, we would appreciate it if you would cite the following paper:

Please use the following BibTeX:

@article{PyPSA,
   author = {T. Brown and J. H\"orsch and D. Schlachtberger},
   title = {{PyPSA: Python for Power System Analysis}},
   journal = {Journal of Open Research Software},
   volume = {6},
   issue = {1},
   number = {4},
   year = {2018},
   eprint = {1707.09913},
   url = {https://doi.org/10.5334/jors.188},
   doi = {10.5334/jors.188}
}

If you want to cite a specific PyPSA version, each release of PyPSA is stored on Zenodo with a release-specific DOI. The release-specific DOIs can be found linked from the overall PyPSA Zenodo DOI for Version 0.17.1 and onwards:

image

or from the overall PyPSA Zenodo DOI for Versions up to 0.17.0:

image

Licence

Copyright 2015-2024 PyPSA Developers

PyPSA is licensed under the open source MIT License.

pypsa's People

Contributors

afuetterer avatar alex-neve avatar bje- avatar bourbl avatar coroa avatar drifter089 avatar ekatef avatar energyls avatar enricogiglio avatar euronion avatar fabianhofmann avatar fneum avatar fwitte avatar gailin-p avatar irieo avatar jesslryan avatar juliangeis avatar koen-vg avatar lisazeyen avatar lkstrp avatar martacki avatar nmartensen avatar nworbmot avatar p-glaum avatar peterklein11 avatar pre-commit-ci[bot] avatar pz-max avatar schlachtberger avatar smdumlao avatar yerbol-akhmetov avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

pypsa's Issues

unable to turn of lopf logging

I have an issue with the logging output generated from lopf. It also reproduces In the logging demo (https://pypsa.org/examples/logging-demo.html).

If I change input 5 to:
pypsa.opf.logger.setLevel(logging.ERROR)

I would expect no output after input 6. However I get the same output as when the warning level was set.

Only setting it to logging.NOTSET will surpress the output again.

No module named 'resource' on Windows

After upgrading to 0.7.0 importing PyPSA raises the error:

Traceback (most recent call last):

  File "<ipython-input-1-204dc4f75877>", line 1, in <module>
    import pypsa

  File "C:\Users\Marius\Anaconda3\lib\site-packages\pypsa\__init__.py", line 27, in <module>
    from . import components

  File "C:\Users\Marius\Anaconda3\lib\site-packages\pypsa\components.py", line 60, in <module>
    from .contingency import (calculate_BODF, network_lpf_contingency,

  File "C:\Users\Marius\Anaconda3\lib\site-packages\pypsa\contingency.py", line 42, in <module>
    from .opt import l_constraint

  File "C:\Users\Marius\Anaconda3\lib\site-packages\pypsa\opt.py", line 37, in <module>
    import resource

ImportError: No module named 'resource'

I'm using Windows 10 and Python 3.5.1 currently, so maybe "resource" is linux only?

CPLEX LP file processing error

Hi, on Mac Os X I have installed the latest GitHub version of PyPSA. I am using conda-based Python 3 with all the latest libraries.
I have tried to run a few examples but most of them does not work.
Here an example:

(py36) $ python unit-commitment.py 
INFO:pypsa.pf:Slack bus for sub-network 0 is bus
INFO:pypsa.opf:Performed preliminary steps
INFO:pypsa.opf:Building pyomo model using `angles` formulation
INFO:pypsa.opf:Solving model using glpk
ERROR: "[base]/site-packages/pyomo/opt/base/solvers.py", 616, solve
	Solver (glpk) returned non-zero return code (1)
ERROR:pyomo.opt:Solver (glpk) returned non-zero return code (1)
ERROR: "[base]/site-packages/pyomo/opt/base/solvers.py", 621, solve
	Solver log:
	GLPSOL: GLPK LP/MIP Solver, v4.63
	Parameter(s) specified in the command line:
	 --write /var/folders/x6/qsstd0cd44x3jhbrbfxkv_7w0000gn/T/tmp8t3bfxle.glpk.raw
	 --wglp /var/folders/x6/qsstd0cd44x3jhbrbfxkv_7w0000gn/T/tmpym96u0i3.glpk.glp
	 --cpxlp /var/folders/x6/qsstd0cd44x3jhbrbfxkv_7w0000gn/T/tmpyg7mrrpa.pyomo.lp
	Reading problem data from '/var/folders/x6/qsstd0cd44x3jhbrbfxkv_7w0000gn/T/tmpyg7mrrpa.pyomo.lp'...
	/var/folders/x6/qsstd0cd44x3jhbrbfxkv_7w0000gn/T/tmpyg7mrrpa.pyomo.lp:13: constraints section missing
	CPLEX LP file processing error
ERROR:pyomo.opt:Solver log:
GLPSOL: GLPK LP/MIP Solver, v4.63
Parameter(s) specified in the command line:
 --write /var/folders/x6/qsstd0cd44x3jhbrbfxkv_7w0000gn/T/tmp8t3bfxle.glpk.raw
 --wglp /var/folders/x6/qsstd0cd44x3jhbrbfxkv_7w0000gn/T/tmpym96u0i3.glpk.glp
 --cpxlp /var/folders/x6/qsstd0cd44x3jhbrbfxkv_7w0000gn/T/tmpyg7mrrpa.pyomo.lp
Reading problem data from '/var/folders/x6/qsstd0cd44x3jhbrbfxkv_7w0000gn/T/tmpyg7mrrpa.pyomo.lp'...
/var/folders/x6/qsstd0cd44x3jhbrbfxkv_7w0000gn/T/tmpyg7mrrpa.pyomo.lp:13: constraints section missing
CPLEX LP file processing error

Traceback (most recent call last):
  File "unit-commitment.py", line 36, in <module>
    nu.lopf(nu.snapshots)
  File "/Users/matteodefelice/miniconda2/envs/py36/lib/python3.6/site-packages/pypsa-0.11.0-py3.6.egg/pypsa/opf.py", line 1452, in network_lopf
    return network_lopf_solve(network, snapshots, formulation=formulation, solver_options=solver_options, keep_files=keep_files, free_memory=free_memory)
  File "/Users/matteodefelice/miniconda2/envs/py36/lib/python3.6/site-packages/pypsa-0.11.0-py3.6.egg/pypsa/opf.py", line 1377, in network_lopf_solve
    network.results = network.opt.solve(*args, suffixes=["dual"], keepfiles=keep_files, options=solver_options) 
  File "/Users/matteodefelice/miniconda2/envs/py36/lib/python3.6/site-packages/pyomo/opt/base/solvers.py", line 623, in solve
    "Solver (%s) did not exit normally" % self.name)
pyutilib.common._exceptions.ApplicationError: Solver (glpk) did not exit normally

GLPK has been installed with MacPorts.

Operating Reserves Co-Optimization

Hi, I was wondering if this is currently possible.

Example with 2 generators

Objective: min{ MC_p1*P_1 + MC_p2*P_2 + MC_r2*R_1 + MC_r2*R_2 }
with MC = Marginal Cost

Constraints:
P_1 + P_2 = Demand
R_1 + R_2 >= Min_System_Reserve

0<= P_1 + R_1 <= Max_nom_P_1
0<= P_2 + R_2 <= Max_nom_P_2
0<= R_1 <= Max_nom_R1
0<= R_2 <= Max_nom_R2

With default of max_nom_reserve as 0.

I couldn't find anything in the documentation about reserves.

Export to IEEE common data format

An option to export the network to the IEEE CDF (https://ieeexplore.ieee.org/document/4075293/) would be nice. It appears to be limited but it's also supported by other applications, which makes it very practical.

You could, for example, run your load flows in pypsa and then run short circuit and arc flash analyses in a commercial software, until it's available in pypsa.

Warning because bus is not copied first in network.copy()

Since network,copy() iterates over all_components in random order, the method raises the import_components_from_dataframe warning "The following {component} have buses which are not defined" for components which are copied before the "Bus" component is created for the network copy.
Having iterate_components() start with "Bus" would solve the issue - e.g. with a sorted dict for all_components

network.lopf() with remote solver (ssh)

Hi together,
this is rather a question than an issue, but I want to tell you.
We are using PyPSA to build a model and use network.lopf to solve it. To get this done, there seem to be two possibilities for us. We are building the models locally on our machines. To solve the model we can use open source solvers like glpk also locally, which works great but is to slow to solve the whole model. So this is only an option for test cases. The alternative is to build the model locally and solve it using our remote server and our commercial solver. The server is accessible via ssh.
As this is a real challenge to us, I would like to ask, if you have any idea, how to run PyPSA with a custom remote access solver.

Thanks in advance!

Allow links to have a time delay for chained run-of-river plants

Allow links to extract energy from a bus in one hour, and feed it into another bus in another hour. This would allow to represent, for example, a river connecting two run-of-river plants, where the water takes a non-trivial amount of time to flow from one plant to the other.
Introduce an integer attribute "delay" to the Link component which specifies how many snapshots ahead/behind the energy supply to bus1 is.
Also need a boolean attribute "cyclic" to specify what to do with the energy at the start and end of the period under consideration.

Impedance in calculate_B_H

In this line, for a DC network the attribute selected is r_pu:
https://github.com/FRESNA/PyPSA/blob/master/pypsa/pf.py#L622

This function is inspired by the equivalent PYPOWER (and by extension MATPOWER) makeBdc functions.

Based on MATPOWER and PyPOWER, I think this should be x_pu for a DC network.

https://github.com/rwl/PYPOWER/blob/master/pypower/makeBdc.py#L52
http://www.pserc.cornell.edu/matpower/docs/ref/matpower5.0/makeBdc.html (L71)

Is the output of this function used as part of the LOPF ?

Memory leak on windows, python

Consecutive PyPSA runs accumulate a dictionary, increasing memory use.
PyPSA_test_leak attached results in the following mem_top(limit = 3) output. The most referenced dict is the memory leak.
Failed solutions:
gc.collect()
Deleting graph = GraphDesc() lines in components.py
Updating packages (pyomo, scipy, pandas, networkx) - see attached installed packages list

Occurs in windows 7 and 10, python 3.4.4

pip list.txt
PyPSA_test_leak.txt

mem_top() output:

refs:
3562 <class 'dict'> {218600272: [197884176], 212671344: [193626240], 217596272: [197558288], 220658144: [198935936], 189
3006 <class 'dict'> {497410048: <weakref at 0x00000000020DF0E8; to 'type' at 0x000000001DA5E000 (islice)>, 8791215081472
2590 <class 'dict'> {'ERROR_USER_PROFILE_LOAD': 500, 'MK_E_NOINVERSE': -2147221012, 'E_INVALIDARG': -2147024809, 'ERROR_

Transformer nominal ratings not respected in network.pf()

Hi
I have a CIGRE MV network. The transformer is rated at 25MVA, but I can conviniently send much, much higher powers (~70MW) through it by increasing loads. Technically, the load flow should not converge. Running the same network powerflow in pandapower results in LoadFlowNotConvergedError, which seems reasonable.

I assume this is because transformer s_nom isn't factored in when performing load flow? The load flow fails when lines are under-rated. Doesnt seem to be the case with transformer ratings.

Getting started with PyPsa. AttributeError: 'tuple' object has no attribute 'bus0'

Hello,

after successfully installing PyPsa on a clean Anaconda distribution I tried to run the first minimal example ("Build a minimal network for power flow"). However, already here I am running into problems.

Python 2.7.11 |Anaconda 2.5.0 (32-bit)| (default, Jan 29 2016, 15:36:56) [MSC v.1500 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
Anaconda is brought to you by Continuum Analytics.
Please check out: http://continuum.io/thanks and https://anaconda.org
>>> """
... Created on Tue Mar 08 14:39:24 2016
... 
... @author: bjl
... """
'\nCreated on Tue Mar 08 14:39:24 2016\n\n@author: bjl\n'
>>> 
>>> import pypsa

import numpy as np

network = pypsa.Network()

for i in range(3):
    network.add("Bus","My bus {}".format(i))
>>> >>> >>> >>> >>> >>> ... ... 
Bus My bus 0
Bus My bus 1
Bus My bus 2
>>> 
>>> print(network.buses)
C:\Anaconda2\lib\site-packages\pandas\core\format.py:1995: RuntimeWarning: invalid value encountered in absolute
  abs_vals = np.abs(self.values)

         control sub_network  y  v_mag_pu_min current_type  v_nom  \
My bus 0      PQ              0             0           AC      1   
My bus 1      PQ              0             0           AC      1   
My bus 2      PQ              0             0           AC      1   

          v_mag_pu_max  x           obj  
My bus 0           NaN  0  Bus My bus 0  
My bus 1           NaN  0  Bus My bus 1  
My bus 2           NaN  0  Bus My bus 2  
C:\Anaconda2\lib\site-packages\pandas\core\format.py:1998: RuntimeWarning: invalid value encountered in greater
  has_large_values = (abs_vals > 1e8).any()
C:\Anaconda2\lib\site-packages\pandas\core\format.py:1999: RuntimeWarning: invalid value encountered in less
  has_small_values = ((abs_vals < 10 ** (-self.digits)) &
C:\Anaconda2\lib\site-packages\pandas\core\format.py:2000: RuntimeWarning: invalid value encountered in greater
  (abs_vals > 0)).any()
>>> >>> for i in range(3):
...     network.add("Line","My line {}".format(i),
...                 bus0="My bus {}".format(i),
...                 bus1="My bus {}".format((i+1)%3),
...                 x=0.0001)
... 
Line My line 0
Line My line 1
Line My line 2
>>> 
>>> print(network.lines)
           s_nom_min      bus0      bus1  capital_cost s_nom_extendable  \
My line 0          0  My bus 0  My bus 1             0            False   
My line 1          0  My bus 1  My bus 2             0            False   
My line 2          0  My bus 2  My bus 0             0            False   

           s_nom_opt  s_nom  s_nom_max sub_network  x_pu       ...        b  \
My line 0          0      0        NaN                 0       ...        0   
My line 1          0      0        NaN                 0       ...        0   
My line 2          0      0        NaN                 0       ...        0   

           g  v_ang_min  r_pu  terrain_factor  length  r       x  v_ang_max  \
My line 0  0        NaN     0               1       1  0  0.0001        NaN   
My line 1  0        NaN     0               1       1  0  0.0001        NaN   
My line 2  0        NaN     0               1       1  0  0.0001        NaN   

                      obj  
My line 0  Line My line 0  
My line 1  Line My line 1  
My line 2  Line My line 2  

[3 rows x 22 columns]
>>> 
>>> network.add("Generator","My gen",
...             bus="My bus 0",
...             p_set=100)
Generator My gen
>>> 
>>> print(network.generators)
             bus  sign control  p_min_pu_fixed  capital_cost p_nom_extendable  \
My gen  My bus 0     1      PQ               0             0            False   

        dispatch  p_nom_max  p_nom  p_nom_opt  p_nom_min  p_max_pu_fixed  \
My gen  flexible        NaN      0          0          0               1   

        efficiency source  marginal_cost               obj  
My gen           1                     0  Generator My gen  
>>> 
>>> print(network.generators_t.p_set)
     My gen
now     100
>>> 
>>> network.add("Load","My load",
...             bus="My bus 1",
...             p_set=100)
Load My load
>>> 
>>> print(network.loads)
              bus  sign           obj
My load  My bus 1    -1  Load My load
>>> 
>>> print(network.loads_t.p_set)
     My load
now      100
>>> 
>>> network.pf()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Anaconda2\lib\site-packages\pypsa\pf.py", line 78, in network_pf
    network.build_graph()
  File "C:\Anaconda2\lib\site-packages\pypsa\components.py", line 697, in build_graph
    for t in self.iterate_components(branch_types)
  File "C:\Anaconda2\lib\site-packages\networkx\classes\multigraph.py", line 403, in add_edges_from
    for e in ebunch:
  File "C:\Anaconda2\lib\site-packages\pypsa\components.py", line 698, in <genexpr>

    for branch in t.df.itertuples())
AttributeError: 'tuple' object has no attribute 'bus0'
>>> >>> print(network.lines_t.p0)
     My line 0  My line 1  My line 2
now          0          0          0
>>> 
>>> print(network.buses_t.v_ang*180/np.pi)
     My bus 0  My bus 1  My bus 2
now         0         0         0
>>> 

Plotting with cartopy requires cartopy>=0.16

Using PyPSA's plotting functionality with cartopy requires a cartopy version higher than 0.16, since the with_scale(...) function on a NaturalEarthFeature was introduced only then.
https://scitools.org.uk/cartopy/docs/latest/whats_new.html#what-s-new-in-cartopy-0-16

The function is used in draw_map(...)

PyPSA/pypsa/plot.py

Lines 335 to 345 in 46954b1

if cartopy_present:
resolution = '50m' if isinstance(geomap, bool) else geomap
assert resolution in ['10m', '50m', '110m'], (
"Resolution has to be one of '10m', '50m', '110m'")
gmap = ax.projection
data_projection = get_projection_from_crs(network.srid)
ax.set_extent([x1, x2, y1, y2], crs=data_projection)
ax.coastlines(linewidth=0.4, zorder=-1, resolution=resolution)
border = cartopy.feature.BORDERS.with_scale(resolution)
ax.add_feature(border, linewidth=0.3)

Would it be an option to assert the version while trying to import?

PyPSA/pypsa/plot.py

Lines 54 to 61 in 46954b1

cartopy_present = True
try:
import cartopy
import cartopy.crs as ccrs
import cartopy.mpl.geoaxes
import requests
except ImportError:
cartopy_present = False

It should probably not end up in the requirements.yaml.

lpf error with PyPSA 13.2

Since updating to PyPSA 13.2 I get an error in the lpf() without having changed anything in the code:

File "", line 1, in
net.lpf()

File "/home/christian/anaconda3/lib/python3.6/site-packages/pypsa/pf.py", line 411, in network_lpf
_network_prepare_and_run_pf(network, snapshots, skip_pre, linear=True)

File "/home/christian/anaconda3/lib/python3.6/site-packages/pypsa/pf.py", line 94, in _network_prepare_and_run_pf
network.determine_network_topology()

File "/home/christian/anaconda3/lib/python3.6/site-packages/pypsa/components.py", line 786, in determine_network_topology
self.add("SubNetwork", i, carrier=carrier)

File "/home/christian/anaconda3/lib/python3.6/site-packages/pypsa/components.py", line 448, in add
new_df = cls_df.append(obj_df, sort=False)

TypeError: append() got an unexpected keyword argument 'sort'

Non-optimal solution not writing output

I am solving a lopf using the Barrier method from Gurobi (with the crossover turned off, since it takes too long otherwise) and I get just a sub-optimal solution. Then PyPSA prints:

WARNING:pypsa.opf:WARNING! Optimization might be sub-optimal. Writing output anyway

but it does not write any output. It seems to be problem with the format that the sub-optimal solution is given (maybe having some differences with the way an optimal solution is given).

Side note: I am using "extendable" storage and I am mainly interested in the "p_nom_opt" that the solver would give me.

Python 3.7 compatibility & low-voltage example

Dear all,

I've recently switched to python 3.7 and suddenly had some issues with PyPSA.

  1. Does PyPSA 0.13.2 support python 3.7? Or will a later version be compatible with 3.7?

  2. What are the fundamental obstacles for PyPSA to support python 3.7?

  3. In case I use PyPSA after using other packages (like SPADE) that only runs in 3.7, how to switch the environment back to 3.6 to run PyPSA codes? Especially, I'm using Jupyter Notebook and such changes of kernel becomes a problem.

A bonus question: I've been modeling a low-voltage distribution network with PyPSA. I think the model might interest other researchers who want to try PyPSA for medium or low-voltage applications. It's based on the "IEEE European low-voltage distribution test feeder" where the network and the load profiles are open source. Do you think it'll make sense if we include it as an example of PyPSA applications?

Thank you very much!

Best regards,
Piao

==========
update 28.03.2019

Issue solved. PyPSA supports python 3.7, but you need to upgrade the package PYOMO. Previous versions might contain a variable named "async" which is not allowed any more from python 3.7 on.

Thanks for the hints from Nis Martensen and Johannes Hampp (via google group) : )

Plotting with cartopy ironically breaks with `geomap=False`

@FabianHofmann :)

Traceback (most recent call last):
   File "/home/pypsa/pypsa-eur/.snakemake/scripts/tmprhs9nf08.plot_network.py", line 127, in <module>
     ax=ax)
   File "/home/.conda/envs/pypsa-eur/lib/python3.7/site-packages/pypsa/plot.py", line 173, in plot
     if use_cartopy and geomap:
 UnboundLocalError: local variable 'use_cartopy' referenced before assignment

Would you please rewrite

if geomap:
         [ ... ]

if use_cartopy and geomap:
         [ .... ]

to:

if geomap:
         [......]

         if use_cartopy:
              [......]

And make sure, the code still works with geomap = False.

Gracias

MILP OPF objective function value

For MILP problems the lower bound of the problem is the relaxed/best bound, at least in CPLEX. Thus the objective value of network.results["Problem"][0]["Lower bound"] for unit commitment problems is lower than the integer objective value. For MILP problems network.results["Problem"][0]["Upper bound"] can retrieve the correct value.
This can be verified in the unit-commitment test file by disabling any problem presolve and introducing a large enough optimality gap tolerance, in order to generate different upper and lower bounds. e.g. for CPLEX:

nu.lopf(nu.snapshots, solver_name='cplex', solver_options={'mip_tolerances_mipgap': 0.5,'preprocessing_presolve':'no'})

With tee=True in the opf.py file there will be a difference in the upper and lower bounds.

opf.txt
unit-commitment.txt

Multi-Horizon Investment

As of Version 13.1, PyPSA only considers investment in one horizon, e.g. for a single year. We'd like to implement investment over multiple horizons simultaneously, e.g. for 2020, 2025, 2030, 2035, etc., to optimise investments dynamically over several years e.g. under tightening CO2 constraints. The objective function then becomes the discounted net present value (NPV) of energy system costs. Other open models such as OSeMOSYS, Genesys, DIETER (I think) and SWITCH do this already; we can copy their implementations and avoid reinventing the wheel.

On the data side:

i) We need a second index for snapshots that gives the investment year, e.g.
snapshots = [(2020, "windy day"), (2020, "sunny day"), (2030, "windy day"), (2030, "sunny day")]
The representative weather for each investment year may change with the year (e.g. due to climate change); the number of representative snapshots for each investment year may also change.

ii) We need different CO2/renewable constraints for different investment years.

iii) For assets, we need to take account of build years and lifetimes for generation, storage and transmission assets, e.g. we need additional fields

name, build year, life time, cost
wind-in-2020, 2020, 20, 1200
wind-in-2025, 2025, 20, 1000
wind-in-2030, 2030, 25, 900

Then in the code we need to activate assets in the constraints depending on whether they are around in the investment year or not.
We also need to take account of the discount rate as a pre-factor to get the NPV for each investment year.
Perhaps this should be linked to issue #37 of separating the snapshot_weighting from the duration of each snapshot, which was discussed on the PyPSA mailing list before.
BEWARE 1): The final investment horizon has to be treated carefully, to avoid end-of-horizon effects whereby assets are only built for the final horizon and have no value for the rest of their lifetimes. Either model 20 years further (with lower intra-year resolution) or have a "salvage value" for investments made in the final investment horizon (I think OSeMOSYS had this).
BEWARE 2): p_nom_max may become linked between different generators as potentials are used up.

voltage dependency of loads

I think it would be nice to add a dependency of loads_t.p and loads_t.q of the connected buses_t.v_mag_pu for power flow calculations. Did anyone already work on this?

My first idea would be to:

  1. add two attributes to loads: ratio of p/q that is dependent on the voltage (default 0)
  2. build loop around pf with p_set/q_set being recalculated from the pf-result for buses_t.v_mag_pu as long as they change significantly.

I could try to implement this, if you think it is useful. If so: Do you think the approach is suitable and are there any preliminary works that could help?

Unit testing for Python 2.7 with pandapower 2.1.0 fails

Tests for Python 2.7 fail in 7038b76 as it was the first CI run with the recent pandapower v2.1.0 (https://travis-ci.org/PyPSA/PyPSA/jobs/557399790).

While pandapower v2.0.0 already officially dropped Python 2.7 support, the unit tests of pypsa work with up to pandapower v2.0.1 (https://github.com/e2nIEE/pandapower/releases and discussion in e2nIEE/pandapower#224).

  1. A proposal would be to fix the version in environment_dev.yaml to pandapower==2.0.1 until the Python 2.7 countdown has run down (https://pythonclock.org/) on January 1, 2020. We make a final release tested for Python 2.7 then, and allow again to pull most recent pandapower.
  2. An alternative is to create Python version specific environment_dev.yaml files; e.g. environment_dev_python2.yaml and environment_dev_python3.yaml.
  3. Another option is to drop Python 2.7 support right now.

Other opinions/options?

Can PyPSA read MATPOWER case files?

First, thanks for this package.

Is there a straightforward way to read MATPOWER case files? Or alternatively, do you know the easiest way to translate MATPOWER files to PyPSA? Thanks.

pf() convergence indication

When running a few hundred load flows in a loop, it would be nice to catch the cases where the load flow did not converge. I couldn't find a way to do this, is there any? Unless this is a bad idea for some other reason, I'd like to request a return value to be added to the pf() function.

plot cartopy with different projection distorts bus circles

The problem accounts for plotting with cartopy in non-default projection and adding pie plots for buses. One the one hand they are way too big now (because off a unnecessary rescaling), on the other they are distorted.

Example code

import pypsa, os
import cartopy.crs as ccrs
import matplotlib.pyplot as plt

n = pypsa.Network(os.path.abspath(pypsa.__path__[0] + '/../examples/ac-dc-meshed/ac-dc-data/'))
n.lopf()

gen = n.generators.assign(g = n.generators_t.p.mean()).groupby(['bus', 'carrier']).g.sum()

n.plot(bus_sizes=gen/1e3, bus_colors={'gas':'r', 'wind':'b'})
plt.show()

n.plot(bus_sizes=gen/1e3, bus_colors={'gas':'r', 'wind':'b'}, projection=ccrs.EckertI())
plt.show()

It is caused by the axis_transform applied to matplotlib patch collections, after plotting them. The transformation distorts the pies, which were round before and are only round according to the default projection.

Suggestion: plot the pies without axis_transforming them. This requires, similar to the basemap plotting, transformation of the x,y - data and keeping the rescaling factor.

pyomo 5.6.2 import error

It seems with version 5.6.2 there has been another change at pyomos LConstraint object.
I just installed PyPSA 13.2 with the newest pyomo and got an import error because the workaround import for pyomo5.6.1 not exist anymore:
from pyomo.core.expr import expr_pyomo5

A downgrade to pyomo==5.6.1 helps, if anyone runs into this issue.

implementation of asymmetric impedance

Hi,
I would like to use PyPSA with reduced networks, where the external network is represented by equivalent elements. One of these elements is an asymmetrical impedance. Here the impedance going from bus0 to bus1 differs from the impedance going from bus1 to bus0.
This would be similar to the impedance element in pandapower.

Are there currently any plans in implementing this or am I overlooking something and is this currently already possible?

Prevent network.pf() failing on single-bus sub-networks

If there are sub-networks with only a single bus, i.e. a single bus with no connected lines or transformers, the non-linear power flow network.pf() will fail because the admittance matrix Y for this sub-network is zero. We need to add an escape for this case, whereby the slack generator balances everything at single-node sub-networks.

AttributeError: type object 'ConfigBlock' has no attribute '_all_slots'

hi, I imported pypsa, and installed it first with pip and it get me this error, after that I installed manually and again this error appear! I really need help, thanks
Error:

File "/usr/local/lib/python2.7/dist-packages/pyomo/pysp/util/config.py", line 151, in setattr
if name in ConfigBlock._all_slots: AttributeError: type object 'ConfigBlock' has no attribute '_all_slots'

cartopy dependency issues with pip

Installing pypsa with pip install pypsa causes problems if the cartopy requirements GEOS and PROJ are not installed as reported on the mailing list.

cartopy was added to setup.py requirements in #59 to enforce a version of cartopy>=0.16.

Two alternative ways to close this issue:

  1. Add to installation instructions with pip in the documentation to install cartopy requirements first (https://scitools.org.uk/cartopy/docs/latest/installing.html#requirements). This is easy for linux:
apt-get install libgeos++ proj-bin libproj-dev

(but presumably more difficult in windows)

  1. Remove cartopy from requirements in setup.py and revert to alternative solution of issue #59.

Opinions @FabianHofmann @coroa @nworbmot?

(installation via conda is unaffected by this)

Load Flow problem

Hello.

I have problem with my code created in PyPSA. I want to do power flow of this 14 bus system. When I run this code I get an error: INFO:pypsa.pf:Newton-Raphson solved in 0 iterations with error of nan in 0.003990 seconds.
I am new in Python. I am student and I want to expand Python at our department. Where is problem, please?
Thanks for reply.

################
import pypsa
import numpy as np
from pandas import DataFrame

#Vytvorenie siete
network = pypsa.Network()

#Vytvorenie zbernic a ich parametrizacia
network.add("Bus", "bus1", v_nom=69, v_mag_pu_min=0.94, v_mag_pu_max=1.06)
network.add("Bus", "bus2", v_nom=69, v_mag_pu_min=0.94, v_mag_pu_max=1.06)
network.add("Bus", "bus3", v_nom=69, v_mag_pu_min=0.94, v_mag_pu_max=1.06)
network.add("Bus", "bus4", v_nom=69, v_mag_pu_min=0.94, v_mag_pu_max=1.06)
network.add("Bus", "bus5", v_nom=69, v_mag_pu_min=0.94, v_mag_pu_max=1.06)
network.add("Bus", "bus6", v_nom=13.8, v_mag_pu_min=0.94, v_mag_pu_max=1.06)
network.add("Bus", "bus7", v_nom=13.8, v_mag_pu_min=0.94, v_mag_pu_max=1.06)
network.add("Bus", "bus8", v_nom=18, v_mag_pu_min=0.94, v_mag_pu_max=1.06)
network.add("Bus", "bus9", v_nom=13.8, v_mag_pu_min=0.94, v_mag_pu_max=1.06)
network.add("Bus", "bus10", v_nom=13.8, v_mag_pu_min=0.94, v_mag_pu_max=1.06)
network.add("Bus", "bus11", v_nom=13.8, v_mag_pu_min=0.94, v_mag_pu_max=1.06)
network.add("Bus", "bus12", v_nom=13.8, v_mag_pu_min=0.94, v_mag_pu_max=1.06)
network.add("Bus", "bus13", v_nom=13.8, v_mag_pu_min=0.94, v_mag_pu_max=1.06)
network.add("Bus", "bus14", v_nom=13.8, v_mag_pu_min=0.94, v_mag_pu_max=1.06)

#vypis zbernic
print(network.buses)

#Vytvorenie generatorov a ich parametrizacia
network.add("Generator", "gen1", bus="bus1", control="Slack", p_set=232.4 ,p_max_pu=2, p_min_pu=0, marginal_cost=20)
network.add("Generator", "gen2", bus="bus2", control="PV", p_set=40, p_max_pu=1.4, p_min_pu=0, marginal_cost=20)
network.add("Generator", "gen3", bus="bus3", control="PV", p_set=0, p_max_pu=1, p_min_pu=0, marginal_cost=40)
network.add("Generator", "gen4", bus="bus6", control="PV", p_set=0, p_max_pu=1, p_min_pu=0, marginal_cost=40)
network.add("Generator", "gen5", bus="bus8", control="PV", p_set=0, p_max_pu=1, p_min_pu=0, marginal_cost=40)

#vypis generatorov
print(network.generators)

#Vytvorenie prenosovych vedeni a ich parametrizacia
network.add("Line", "line1", bus0="bus1", bus1="bus2", r=0.922488, x=2.816492, b=0.001109244,
length=17,s_nom=120)
network.add("Line", "line2", bus0="bus1", bus1="bus5", r=2.571828, x=10.616704, b=0.001033613,
length=52, s_nom=65)
network.add("Line", "line3", bus0="bus2", bus1="bus3", r=2.236724, x=9.423372, b=0.000920168,
length=46, s_nom=36)
network.add("Line", "line4", bus0="bus2", bus1="bus4", r=2.766036, x=8.392832, b=0.000785714,
length=50, s_nom=65)
network.add("Line", "line5", bus0="bus2", bus1="bus5", r=2.71082, x=8.276688, b=0.000714286,
length=50, s_nom=50)
network.add("Line", "line6", bus0="bus3", bus1="bus4", r=3.189676, x=8.141028, b=0.000726891,
length=56, s_nom=65)
network.add("Line", "line7", bus0="bus4", bus1="bus5", r=0.63546, x=2.004436, b=0.000268908,
length=12, s_nom=45)
network.add("Line", "line11", bus0="bus6", bus1="bus11", r=4.521048, x=9.46764, b=0,
length=16.5, s_nom=18)
network.add("Line", "line12", bus0="bus6", bus1="bus12", r=5.850516, x=11.996152, b=0,
length=21, s_nom=32)
network.add("Line", "line13", bus0="bus6", bus1="bus13", r=3.14874, x=6.200852, b=0,
length=11.5, s_nom=32)
network.add("Line", "line15", bus0="bus7", bus1="bus9", r=0, x=5.236476, b=0,
length=1, s_nom=32)
network.add("Line", "line16", bus0="bus9", bus1="bus10", r=1.514156, x=4.0222, b=0,
length=16, s_nom=32)
network.add("Line", "line17", bus0="bus9", bus1="bus14", r=6.050436, x=12.870088, b=0,
length=22.5, s_nom=32)
network.add("Line", "line18", bus0="bus10", bus1="bus11", r=3.90558, x=9.142532, b=0,
length=15.5, s_nom=12)
network.add("Line", "line19", bus0="bus12", bus1="bus13", r=10.515792, x=9.514288, b=0,
length=21, s_nom=12)
network.add("Line", "line20", bus0="bus13", bus1="bus14", r=8.136268, x=16.565752, b=0,
length=28, s_nom=12)

#vypis prenosovych vedeni
print(network.lines)

#Vytvorenie prenosovych transformatorov
network.add("Transformer","transformer 1",bus0="bus4",bus1="bus9", r=0, x=9.954112, b=0, tap_ratio=0.978, s_nom=32, tap_side=0)
network.add("Transformer","transformer 2",bus0="bus5",bus1="bus6", r=0, x=26.474168, b=0, tap_ratio=0.969, s_nom=45, tap_side=0)
network.add("Transformer","transformer 3",bus0="bus4",bus1="bus7", r=0, x=9.95, b=0, tap_ratio=0.932, s_nom=55, tap_side=0)
network.add("Transformer","transformer 4",bus0="bus4",bus1="bus8", r=0, x=8.38474, b=0, tap_ratio=0.932, tap_side=0)

#vypis prenosovych vedeni
print(network.transformers)

#Vytvorenie zatazi a ich parametrizacia
network.add("Load", "load 1", bus="bus2", p_set=21.7, q_set=12.7)
network.add("Load", "load 2", bus="bus3", p_set=94.2, q_set=19)
network.add("Load", "load 3", bus="bus4", p_set=47.8, q_set=-3.9)
network.add("Load", "load 4", bus="bus5", p_set=7.6, q_set=1.6)
network.add("Load", "load 5", bus="bus6", p_set=11.2, q_set=7.5)
network.add("Load", "load 6", bus="bus9", p_set=29.5, q_set=16.6)
network.add("Load", "load 7", bus="bus10", p_set=9, q_set=5.8)
network.add("Load", "load 8", bus="bus11", p_set=3.5, q_set=1.8)
network.add("Load", "load 9", bus="bus12", p_set=6.1, q_set=1.6)
network.add("Load", "load 10", bus="bus13", p_set=13.5, q_set=5.8)
network.add("Load", "load 11", bus="bus14", p_set=14.9, q_set=5)

#vypis zatazi
print(network.loads)

network.pf()

print(network.lines_t.p0)
print(network.buses_t.v_ang*180/np.pi)

What is glpk or how to solve the minimal-example-lopf can not outpu

I am green hand, when i run the example minimal-example-lopf,there is a question:
File "D:\Anaconda3\lib\site-packages\pyomo\opt\solver\shellcmd.py", line 126, in available
raise ApplicationError(msg % self.name)

ApplicationError: No executable found for solver 'glpk'
I hope you can help me!
Thanks!

Matrix is exactly singular in simple example

Am I incorrectly setting up the problem? I'm trying to solve this example.

import pypsa
import numpy as np

def simple_system():
    network = pypsa.Network()

    ## Buses
    network.add("Bus", "B1", v_mag_pu_set=1.05)
    network.add("Bus", "B2")
    network.add("Bus", "B3", v_mag_pu_set=1.04)

    ## Generators
    # Generator at slack bus
    network.add("Generator", "G1", bus="B1", control="Slack")

    # Generator at B3
    network.add("Generator", "G3", bus="B3")

    ## Loads
    # Load at B2
    network.add("Load", "D2", bus="B2", p_set=400, q_set=250)

    # Load at B3
    network.add("Load", "D3", bus="B3", p_set=-200)

    ## Lines
    # Line connecting B1 to B2
    network.add("Line", "L12", bus0="B1", bus1="B2", r=0.02, x=0.04)

    # Line connecting B1 to B3
    network.add("Line", "L13", bus0="B1", bus1="B3", r=0.01, x=0.03)

    # Line connecting B2 to B3
    network.add("Line", "L23", bus0="B2", bus1="B3", r=0.0125, x=0.025)

    ## Print network before solving PF equations
    print("Network before PF Solution...")
    print(network.buses)
    print(network.generators)
    print(network.loads)
    print(network.lines)

    ## Solve PF problem
    network.lpf()
    network.pf(use_seed=True)

    ## Print network after solving PF equations
    print("Network PF Solution...")
    print("P")
    print(network.buses_t.p)
    print("Q")
    print(network.buses_t.q)
    print("|V| pu")
    print(network.buses_t.v_mag_pu)
    print("theta")
    print(network.buses_t.v_ang * 180 / np.pi)


if __name__ == "__main__":
    simple_system()

Output from PF analysis:

INFO:pypsa.pf:Slack bus for sub-network 0 is B1
INFO:pypsa.pf:Performing linear load-flow on AC sub-network SubNetwork 0 for snapshot(s) Index(['now'], dtype='object')
INFO:pypsa.pf:Slack bus for sub-network 0 is B1
INFO:pypsa.pf:Performing non-linear load-flow on AC sub-network SubNetwork 0 for snapshots Index(['now'], dtype='object')
C:\Users\abreucb\AppData\Local\Continuum\anaconda3\lib\site-packages\scipy\sparse\linalg\dsolve\linsolve.py:192: MatrixRankWarning:

Matrix is exactly singular

INFO:pypsa.pf:Newton-Raphson solved in 86 iterations with error of nan in 0.644996 seconds

I installed pypsa 0.13.0 today using pip.

Multiple Slack Generators / Buses

Is there a trick to introduce more than one bus with slack generator behaviour?
When I modelled in SINCAL I sometimes used more than one slack bus for e.g. modelling the connection to other countries in a very abstract and ideal way.
I am asking in context of performing the lpf() and pf().
When introducing a storage or store/link component the p_set would define the dispatch right up front by the input data. So is there a way to trick the components towards a slack bahaviour?

Implement Generator Reactive Power Limits

Implement generator reactive power limits for generators attached to PV buses.

Could orient oneself to the outer loop implementation in PYPOWER https://github.com/rwl/PYPOWER/blob/master/pypower/runpf.py (beginning "while repeat").

Essentially you need an outer loop for the power flow which in each loop:

i) Calculates load flow for PV buses ignoring Q limits.
ii) If any PV bus exceeds generator Q limits, give generator upper/lower Q limit (i.e. whichever limit is closest to dispatched Q from i)) as a set point.
iii) Convert bus from PV to PQ.

Rerun i) -> iii). Similarly for storage units.

Complication: If multiple generators/storage units are attached at each PV bus, you need to distribute the Q between them.

Installation on Anaconda/Conda fails due to broken cartopy

When I install PyPSA with pip,this happened

C:\Users\Kevin_xo>pip install pypsa
Collecting pypsa
Using cached https://files.pythonhosted.org/packages/46/62/958b6dcc30531fd34cec8e3a85cdc3e4f010860198f5b1b82ee99cc87601/pypsa-0.14.0.tar.gz
Requirement already satisfied: numpy in c:\programdata\anaconda3\lib\site-packages (from pypsa) (1.15.4)
Collecting pyomo>=5.3 (from pypsa)
Using cached https://files.pythonhosted.org/packages/bd/16/db99b5042af1697e1df61fee9b8a1b95b6e2bfb4f74968844f6b26d0468d/Pyomo-5.6.4-py3-none-any.whl
Requirement already satisfied: scipy in c:\programdata\anaconda3\lib\site-packages (from pypsa) (1.1.0)
Requirement already satisfied: pandas>=0.19.0 in c:\programdata\anaconda3\lib\site-packages (from pypsa) (0.23.4)
Requirement already satisfied: networkx>=1.10 in c:\programdata\anaconda3\lib\site-packages (from pypsa) (2.2)
Collecting cartopy>=0.16 (from pypsa)
Using cached https://files.pythonhosted.org/packages/e5/92/fe8838fa8158931906dfc4f16c5c1436b3dd2daf83592645b179581403ad/Cartopy-0.17.0.tar.gz
Installing build dependencies ... done
Complete output from command python setup.py egg_info:
C:\Users\Kevin_xo\AppData\Local\Temp\pip-install-mhc6osxg\cartopy\setup.py:171: UserWarning: Unable to determine GEOS version. Ensure you have 3.3.3 or later installed, or installation may fail.
'.'.join(str(v) for v in GEOS_MIN_VERSION), ))
Proj 4.9.0 must be installed.

----------------------------------------

Command "python setup.py egg_info" failed with error code 1 in C:\Users\Kevin_xo\AppData\Local\Temp\pip-install-mhc6osxg\cartopy\

Please help me to solve the problem,thanks a lot.

Separate snapshot weighting from elapsed time

It was discussed on the PyPSA mailing list to separate the snapshot_weighting for each snapshot into two separate values, one that determines the prefactor for all snapshot-specific quantities in the objecting function, and one that corresponds to the snapshot duration, used e.g. by storage to determine how much energy is stored for a given power in each snapshot. This seems like a good idea. network.snapshot_weightings would then become a DataFrame rather than a series.

Implement transformer automatic voltage regulator

There doesn't seem to be a mechanic to simulate a voltage regulator action on a transformer's onload tap changer.

It can be handled by the script calling the PF simulation, i.e. by iterating between PF simulations and tap position adjustments, but it would be better to have it integrated into the network.of() method.

Basically, the transformer should have a control attribute similar to the generator's (but not identical).

ERROR IN RUNNING EXAMPLE

I am just install Python 3.7, I did all what was written in "Installation". But when I'm trying to runn Example from Quick start - I get this message:

Traceback (most recent call last):
File "C:/Users/Me_OnlyME/AppData/Local/Programs/Python/Python37-32/examples/minimal_example_pf.py", line 8, in
import pypsa
File "C:\Users\Me_OnlyME\AppData\Local\Programs\Python\Python37-32\pypsa_init_.py", line 28, in
from . import components, descriptors
File "C:\Users\Me_OnlyME\AppData\Local\Programs\Python\Python37-32\pypsa\components.py", line 63, in
from .contingency import (calculate_BODF, network_lpf_contingency,
File "C:\Users\Me_OnlyME\AppData\Local\Programs\Python\Python37-32\pypsa\contingency.py", line 42, in
from .opt import l_constraint
File "C:\Users\Me_OnlyME\AppData\Local\Programs\Python\Python37-32\pypsa\opt.py", line 41, in
from pyomo.environ import Constraint, Objective, Var, ComponentUID
File "C:\Users\Me_OnlyME\AppData\Local\Programs\Python\Python37-32\lib\site-packages\pyomo\environ_init_.py", line 89, in
import_packages()
File "C:\Users\Me_OnlyME\AppData\Local\Programs\Python\Python37-32\lib\site-packages\pyomo\environ_init
.py", line 59, in _import_packages
do_import(pname)
File "C:\Users\Me_OnlyME\AppData\Local\Programs\Python\Python37-32\lib\site-packages\pyomo\environ_init
.py", line 16, in do_import
importlib.import_module(pkg_name)
File "C:\Users\Me_OnlyME\AppData\Local\Programs\Python\Python37-32\lib\importlib_init
.py", line 127, in import_module
return bootstrap.gcd_import(name[level:], package, level)
File "C:\Users\Me_OnlyME\AppData\Local\Programs\Python\Python37-32\lib\site-packages\pyomo\pysp_init
.py", line 25, in
import pyomo.pysp.scenariotree
File "C:\Users\Me_OnlyME\AppData\Local\Programs\Python\Python37-32\lib\site-packages\pyomo\pysp\scenariotree_init
.py", line 18, in
import pyomo.pysp.scenariotree.manager
File "C:\Users\Me_OnlyME\AppData\Local\Programs\Python\Python37-32\lib\site-packages\pyomo\pysp\scenariotree\manager.py", line 969
async=False,
^
SyntaxError: invalid syntax

Process finished with exit code 1

Can you help me? What should I do to fix this problem...

Verify network settings

Hi all, I am working on adapting the PyPSA for use with neural networks. Is there a function to easily update the parameters of the network's components and verify the performance/detect invalid settings?

Error in running example

I just installed PyPSA and I'm trying out the first example in the quick start. I copied everything up until the first print statement and pasted in into my IDE.

So the code just looks like this:

import pypsa
import numpy as np

network = pypsa.Network

# add three buses
for i in range(3):
    network.add("Bus","My bus {}".format(i))

print(network.buses)

I got an error that says:

TypeError: add() missing 1 required positional argument: 'name'

I don't understand what I could be doing wrong, I literally just copied and pasted code from the example. I'm using Python 3.5.1.

ac-dc-lopf bug with Pyomo 4.4.1

Running the ac-dc-lopf example with Pyomo 4.4.1 yields the following error:
ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()

The example runs correctly with Pyomo 4.3.11388.
Full output attached.

output_pyomo4.4.1.txt

Deal with non-linear power flow in direct current networks without work-around

If you want to compute the non-linear power flow in a meshed direct current network, you have to pretend it is an AC network and set all complex parts of the impedance (x and b) to zero, so that we only have the real resistances, and all load/generator reactive power set points to zero. All buses should be PQ controlled. Then the AC power flow will give the same answer as the DC power flow.
It would be better to do the Newton-Raphson with the correct non-linear DC power flow equations.
See https://www.pypsa.org/doc/power_flow.html#non-linear-power-flow-for-dc-networks and the mailing list discussion https://groups.google.com/d/msg/pypsa/L_MndTvxwBA/L8WU-YGGCwAJ.

Unable to add extra constrains

Hi,

I want to add more constrains to the linear optimal Power Flow
network.lopf(snapshots=network.snapshots,extra_functionality=constrains,keep_files=True)
My constraints function looks like

def constrains():
         network = Constraint( (network.generators.p_min_pu * network.generators.p_nom ) <= network.generators.p_nom )

The constrained is not reflected in the optimisation process does anyone know what i am doing wrong ?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.