Error with Example 2

601 views
Skip to first unread message

Aidan O'Sullivan

unread,
Jun 15, 2016, 10:16:47 AM6/15/16
to pypsa
Hi All,

First of all congratulations to the whole PyPSA team for putting together such a wonderful tool! I'm really keen to get playing with it however i ran into a problem when using network.lopf in example 2 of the quick start, building a minimal network for optimal power flow. I'd really appreciate any help or guidance you could provide as to what i'm doing wrong the keyerror returned is: and the

KeyError: 'the label [My bus 2] is not in the [index]'

and the whole message is below, many thanks


---------------------------------------------------------------------------
KeyError                                  Traceback (most recent call last)
/Users/BSEER/anaconda/lib/python3.5/site-packages/pandas/core/indexing.py in _has_valid_type(self, key, axis)
   1394                 if key not in ax:
-> 1395                     error()
   1396             except TypeError as e:

/Users/BSEER/anaconda/lib/python3.5/site-packages/pandas/core/indexing.py in error()
   1389                 raise KeyError("the label [%s] is not in the [%s]" %
-> 1390                                (key, self.obj._get_axis_name(axis)))
   1391 

KeyError: 'the label [My bus 2] is not in the [index]'

During handling of the above exception, another exception occurred:

KeyError                                  Traceback (most recent call last)
<ipython-input-7-5dc45b3bcb12> in <module>()
----> 1 network.lopf()

/Users/BSEER/anaconda/lib/python3.5/site-packages/pypsa/opf.py in network_lopf(network, snapshots, solver_name, verbose, skip_pre, extra_functionality, solver_options, keep_files, formulation, ptdf_tolerance)
    751 
    752     if not skip_pre:
--> 753         network.determine_network_topology()
    754         calculate_dependent_values(network)
    755         for sub_network in network.sub_networks.obj:

/Users/BSEER/anaconda/lib/python3.5/site-packages/pypsa/components.py in determine_network_topology(self, skip_pre)
    765 
    766             #grab data from first bus
--> 767             sub_network.current_type = self.buses.loc[next(sub_graph.nodes_iter()), "current_type"]
    768 
    769             for bus in sub_graph.nodes():

/Users/BSEER/anaconda/lib/python3.5/site-packages/pandas/core/indexing.py in __getitem__(self, key)
   1292 
   1293         if type(key) is tuple:
-> 1294             return self._getitem_tuple(key)
   1295         else:
   1296             return self._getitem_axis(key, axis=0)

/Users/BSEER/anaconda/lib/python3.5/site-packages/pandas/core/indexing.py in _getitem_tuple(self, tup)
    782     def _getitem_tuple(self, tup):
    783         try:
--> 784             return self._getitem_lowerdim(tup)
    785         except IndexingError:
    786             pass

/Users/BSEER/anaconda/lib/python3.5/site-packages/pandas/core/indexing.py in _getitem_lowerdim(self, tup)
    906         for i, key in enumerate(tup):
    907             if is_label_like(key) or isinstance(key, tuple):
--> 908                 section = self._getitem_axis(key, axis=i)
    909 
    910                 # we have yielded a scalar ?

/Users/BSEER/anaconda/lib/python3.5/site-packages/pandas/core/indexing.py in _getitem_axis(self, key, axis)
   1464 
   1465         # fall thru to straight lookup
-> 1466         self._has_valid_type(key, axis)
   1467         return self._get_label(key, axis=axis)
   1468 

/Users/BSEER/anaconda/lib/python3.5/site-packages/pandas/core/indexing.py in _has_valid_type(self, key, axis)
   1401                 raise
   1402             except:
-> 1403                 error()
   1404 
   1405         return True

/Users/BSEER/anaconda/lib/python3.5/site-packages/pandas/core/indexing.py in error()
   1388                                     "key")
   1389                 raise KeyError("the label [%s] is not in the [%s]" %
-> 1390                                (key, self.obj._get_axis_name(axis)))
   1391 
   1392             try:

KeyError: 'the label [My bus 2] is not in the [index]'

Tom Brown

unread,
Jun 15, 2016, 11:17:44 AM6/15/16
to py...@googlegroups.com
Dear Aidan,

It looks like a problem with pandas, a package on which PyPSA heavily
depends.

I wasn't able to reproduce your error using Python 3.4.3 and pandas 0.18.

Can you tell us which version of pandas you have installed?

import pandas

print(pandas.__version__)

If the version is below 0.18, you should definitely upgrade pandas
(conda update pandas).

Otherwise, double-check that you executed all of the lines of code in
the example above the network.lopf.

If the problem persists, open a bug report at

https://github.com/FRESNA/PyPSA/issues

along with the complete code example and the complete output.

Thanks!

Best,

Tom


On 15/06/16 16:16, Aidan O'Sullivan wrote:
> Hi All,
>
> First of all congratulations to the whole PyPSA team for putting
> together such a wonderful tool! I'm really keen to get playing with it
> however i ran into a problem when using network.lopf in example 2 of the
> quick start, building a minimal network for optimal power flow. I'd
> really appreciate any help or guidance you could provide as to what i'm
> doing wrong the keyerror returned is: and the
>
> KeyError: 'the label [My bus 2] is not in the [index]'
>
>
> and the whole message is below, many thanks
>
>
> ---------------------------------------------------------------------------
> KeyError Traceback (most recent call last)
> /Users/BSEER/anaconda/lib/python3.5/site-packages/pandas/core/indexing.py in _has_valid_type(self, key, axis) 1394 if key not in ax:->
> 1395error()1396 except TypeError as
> e:/Users/BSEER/anaconda/lib/python3.5/site-packages/pandas/core/indexing.py
> in error() 1389 raise KeyError("the label [%s] is not in the [%s]" % ->
> 1390(key, self.obj._get_axis_name(axis))) 1391 KeyError: 'the label [My
> bus 2] is not in the [index]' During handling of the above exception,
> another exception occurred: KeyError Traceback (most recent call last)
> <ipython-input-7-5dc45b3bcb12> in <module>() ---->
> 1network.lopf()/Users/BSEER/anaconda/lib/python3.5/site-packages/pypsa/opf.py
> in network_lopf(network, snapshots, solver_name, verbose, skip_pre,
> extra_functionality, solver_options, keep_files, formulation,
> ptdf_tolerance) 751 752 if not skip_pre:-->
> 753network.determine_network_topology()754
> calculate_dependent_values(network)755 for sub_network in
> network.sub_networks.obj:/Users/BSEER/anaconda/lib/python3.5/site-packages/pypsa/components.py
> in determine_network_topology(self, skip_pre) 765 766 #grab data from
> first bus--> 767sub_network.current_type =
> self.buses.loc[next(sub_graph.nodes_iter()), "current_type"]768 769 for
> bus in
> sub_graph.nodes():/Users/BSEER/anaconda/lib/python3.5/site-packages/pandas/core/indexing.py
> in __getitem__(self, key) 1292 1293 if type(key) is tuple:-> 1294return
> self._getitem_tuple(key)1295 else:1296 return self._getitem_axis(key,
> axis=0)/Users/BSEER/anaconda/lib/python3.5/site-packages/pandas/core/indexing.py
> in _getitem_tuple(self, tup) 782 def _getitem_tuple(self, tup):783
> try:--> 784return self._getitem_lowerdim(tup)785 except
> IndexingError:786
> pass/Users/BSEER/anaconda/lib/python3.5/site-packages/pandas/core/indexing.py
> in _getitem_lowerdim(self, tup) 906 for i, key in enumerate(tup):907 if
> is_label_like(key) or isinstance(key, tuple):--> 908section =
> self._getitem_axis(key, axis=i)909 910 # we have yielded a scalar
> ?/Users/BSEER/anaconda/lib/python3.5/site-packages/pandas/core/indexing.py
> in _getitem_axis(self, key, axis) 1464 1465 # fall thru to straight
> lookup-> 1466self._has_valid_type(key, axis)1467 return
> self._get_label(key, axis=axis)1468
> /Users/BSEER/anaconda/lib/python3.5/site-packages/pandas/core/indexing.py in
> _has_valid_type(self, key, axis) 1401 raise1402 except:->
> 1403error()1404 1405 return
> True/Users/BSEER/anaconda/lib/python3.5/site-packages/pandas/core/indexing.py
> in error() 1388 "key") 1389 raise KeyError("the label [%s] is not in the
> [%s]" % -> 1390(key, self.obj._get_axis_name(axis))) 1391 1392
> try:KeyError: 'the label [My bus 2] is not in the [index]'
>
> --
> You received this message because you are subscribed to the Google
> Groups "pypsa" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to pypsa+un...@googlegroups.com
> <mailto:pypsa+un...@googlegroups.com>.
> To post to this group, send email to py...@googlegroups.com
> <mailto:py...@googlegroups.com>.
> To view this discussion on the web, visit
> https://groups.google.com/d/msgid/pypsa/674d68e0-d565-465d-92ba-253e1259ed18%40googlegroups.com
> <https://groups.google.com/d/msgid/pypsa/674d68e0-d565-465d-92ba-253e1259ed18%40googlegroups.com?utm_medium=email&utm_source=footer>.
> For more options, visit https://groups.google.com/d/optout.

--
Tom Brown
Postdoctoral Researcher
Frankfurt Institute of Advanced Studies
https://fias.uni-frankfurt.de/physics/schramm/complex-renewable-energy-networks/
Personal site: http://www.nworbmot.org
Phone: +49 69 798 47693

Aidan O'Sullivan

unread,
Jun 15, 2016, 11:43:04 AM6/15/16
to pypsa
Hi Tom,

Thanks for your quick response I'm using Python 3.5 and Pandas 0.18.1. I've run through the code again but i'm still getting the same error full code attached in case you can see where i'm going wrong. Really appreciate the help:



import pypsa
import numpy as np
network=pypsa.Network()
# add three buses 
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=.0001,
               s_nom=60)
    
print(network.lines)
               bus0  s_nom_min  capital_cost s_nom_extendable  s_nom_opt  \
name                                                                       
My line 0  My bus 0        0.0           0.0            False        0.0   
My line 1  My bus 1        0.0           0.0            False        0.0   
My line 2  My bus 2        0.0           0.0            False        0.0   

           s_nom_max  s_nom      bus1    g       x       ...        r_pu  \
name                                                     ...               
My line 0        NaN   60.0  My bus 1  0.0  0.0001       ...         0.0   
My line 1        NaN   60.0  My bus 2  0.0  0.0001       ...         0.0   
My line 2        NaN   60.0  My bus 0  0.0  0.0001       ...         0.0   

           v_ang_min  b_pu  sub_network  v_ang_max    r  x_pu    b  length  \
name                                                                         
My line 0        NaN   0.0                     NaN  0.0   0.0  0.0     1.0   
My line 1        NaN   0.0                     NaN  0.0   0.0  0.0     1.0   
My line 2        NaN   0.0                     NaN  0.0   0.0  0.0     1.0   

                      obj  
name                       
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]
In [22]:
#add a generator at bus0
network.add("Generator","My gen 0",
           bus="My bus 0",
           p_nom=100,
           marginal_cost=50)
#add a generator at bus1
network.add("Generator","My gen 1",
           bus="My bus 1",
           p_nom=100,
           marginal_cost=25)
print(network.generators)
print(network.generators_t.p_set)
               bus  sign control  p_nom p_nom_extendable  capital_cost  \
name                                                                     
My gen 0  My bus 0   1.0      PQ  100.0            False           0.0   
My gen 1  My bus 1   1.0      PQ  100.0            False           0.0   

          p_nom_opt  p_nom_max  p_nom_min source  dispatch  efficiency  \
name                                                                     
My gen 0        0.0        NaN        0.0         flexible         1.0   
My gen 1        0.0        NaN        0.0         flexible         1.0   

          p_min_pu_fixed  p_max_pu_fixed  marginal_cost                 obj  
name                                                                         
My gen 0             0.0             1.0           50.0  Generator My gen 0  
My gen 1             0.0             1.0           25.0  Generator My gen 1  
name  My gen 0  My gen 1
now        0.0       0.0
In [23]:
# add a load at bus 2 
network.add("Load","My load",
           bus="My bus 2",
           p_set=100)
print(network.loads)
              bus  sign           obj
name                                 
My load  My bus 2  -1.0  Load My load
In [24]:
print(network.loads_t.p_set)
name  My load
now     100.0
In [25]:
print(network.generators_t.p_set)
name  My gen 0  My gen 1
now        0.0       0.0
In [26]:
network.lopf()
---------------------------------------------------------------------------
KeyError                                  Traceback (most recent call last)
/Users/BSEER/anaconda/lib/python3.5/site-packages/pandas/core/indexing.py in 
_has_valid_type(self, key, axis)

   1394                 if key not in ax:
-> 1395                     error()
   1396             except TypeError as e:

/Users/BSEER/anaconda/lib/python3.5/site-packages/pandas/core/indexing.py in 
error()

   1389                 raise KeyError("the label [%s] is not in the [%s]" %
-> 1390                                (key, self.obj._get_axis_name(axis)))
   1391 

KeyError: 'the label [My bus 2] is not in the [index]'

During handling of the above exception, another exception occurred:

KeyError                                  Traceback (most recent call last)
<ipython-input-26-5dc45b3bcb12> in <module>()

Aidan O'Sullivan

unread,
Jun 15, 2016, 11:47:07 AM6/15/16
to pypsa
Sorry that didn't come out very well, here's the code attached hopefully a bit more readable. Again many thanks. 


On Wednesday, 15 June 2016 15:16:47 UTC+1, Aidan O'Sullivan wrote:
Example 2.ipynb

Tom Brown

unread,
Jun 15, 2016, 11:55:07 AM6/15/16
to py...@googlegroups.com
Hi Aidan,

I think you missed the lines of code that add the buses when copying
over the example:

http://pypsa.org/doc/quick_start.html#build-a-minimal-network-for-optimal-power-flow

You missed the lines:

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

print(network.buses)


This should fix the problem.

Best,

Tom

On 15/06/16 17:47, Aidan O'Sullivan wrote:
> Sorry that didn't come out very well, here's the code attached hopefully
> a bit more readable. Again many thanks.
>
> On Wednesday, 15 June 2016 15:16:47 UTC+1, Aidan O'Sullivan wrote:
>
> Hi All,
>
> First of all congratulations to the whole PyPSA team for putting
> together such a wonderful tool! I'm really keen to get playing with
> it however i ran into a problem when using network.lopf in example 2
> of the quick start, building a minimal network for optimal power
> flow. I'd really appreciate any help or guidance you could provide
> as to what i'm doing wrong the keyerror returned is: and the
>
> KeyError: 'the label [My bus 2] is not in the [index]'
>
>
> and the whole message is below, many thanks
>
>
> ---------------------------------------------------------------------------
> KeyError Traceback (most recent call last)
> /Users/BSEER/anaconda/lib/python3.5/site-packages/pandas/core/indexing.py in _has_valid_type(self, key, axis) 1394 if key not in ax:->
> 1395error()1396 except TypeError as
> e:/Users/BSEER/anaconda/lib/python3.5/site-packages/pandas/core/indexing.py
> in error() 1389 raise KeyError("the label [%s] is not in the [%s]" %
> -> 1390(key, self.obj._get_axis_name(axis))) 1391 KeyError: 'the
> label [My bus 2] is not in the [index]' During handling of the above
> exception, another exception occurred: KeyError Traceback (most
> recent call last) <ipython-input-7-5dc45b3bcb12> in <module>() ---->
> 1network.lopf()/Users/BSEER/anaconda/lib/python3.5/site-packages/pypsa/opf.py
> in network_lopf(network, snapshots, solver_name, verbose, skip_pre,
> extra_functionality, solver_options, keep_files, formulation,
> ptdf_tolerance) 751 752 if not skip_pre:-->
> 753network.determine_network_topology()754
> calculate_dependent_values(network)755 for sub_network in
> network.sub_networks.obj:/Users/BSEER/anaconda/lib/python3.5/site-packages/pypsa/components.py
> in determine_network_topology(self, skip_pre) 765 766 #grab data
> from first bus--> 767sub_network.current_type =
> self.buses.loc[next(sub_graph.nodes_iter()), "current_type"]768 769
> for bus in
> sub_graph.nodes():/Users/BSEER/anaconda/lib/python3.5/site-packages/pandas/core/indexing.py
> in __getitem__(self, key) 1292 1293 if type(key) is tuple:->
> 1294return self._getitem_tuple(key)1295 else:1296 return
> self._getitem_axis(key,
> axis=0)/Users/BSEER/anaconda/lib/python3.5/site-packages/pandas/core/indexing.py
> in _getitem_tuple(self, tup) 782 def _getitem_tuple(self, tup):783
> try:--> 784return self._getitem_lowerdim(tup)785 except
> IndexingError:786
> pass/Users/BSEER/anaconda/lib/python3.5/site-packages/pandas/core/indexing.py
> in _getitem_lowerdim(self, tup) 906 for i, key in enumerate(tup):907
> if is_label_like(key) or isinstance(key, tuple):--> 908section =
> self._getitem_axis(key, axis=i)909 910 # we have yielded a scalar
> ?/Users/BSEER/anaconda/lib/python3.5/site-packages/pandas/core/indexing.py
> in _getitem_axis(self, key, axis) 1464 1465 # fall thru to straight
> lookup-> 1466self._has_valid_type(key, axis)1467 return
> self._get_label(key, axis=axis)1468
> /Users/BSEER/anaconda/lib/python3.5/site-packages/pandas/core/indexing.py
> in _has_valid_type(self, key, axis) 1401 raise1402 except:->
> 1403error()1404 1405 return
> True/Users/BSEER/anaconda/lib/python3.5/site-packages/pandas/core/indexing.py
> in error() 1388 "key") 1389 raise KeyError("the label [%s] is not in
> the [%s]" % -> 1390(key, self.obj._get_axis_name(axis))) 1391 1392
> try:KeyError: 'the label [My bus 2] is not in the [index]'
>
> --
> You received this message because you are subscribed to the Google
> Groups "pypsa" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to pypsa+un...@googlegroups.com
> <mailto:pypsa+un...@googlegroups.com>.
> To post to this group, send email to py...@googlegroups.com
> <mailto:py...@googlegroups.com>.
> To view this discussion on the web, visit
> https://groups.google.com/d/msgid/pypsa/b156124a-cb21-4c50-bcb0-75a38cfe2deb%40googlegroups.com
> <https://groups.google.com/d/msgid/pypsa/b156124a-cb21-4c50-bcb0-75a38cfe2deb%40googlegroups.com?utm_medium=email&utm_source=footer>.

Aidan O'Sullivan

unread,
Jun 15, 2016, 12:20:48 PM6/15/16
to pypsa
Ah! thanks tom how foolish of me. That explains the error.

Now i'm having an issue with network.lopf() which i get for the same example using the code i downloaded from your site, it seems to be due to glpk i'm using version 4.6 are there any issues with that? Sorry for the additional question and thanks again for the support

the main traceback is: ValueError: Error parsing solution data file, line 1

No slack generator found, using My gen 0 as the slack generator
Slack bus is My bus 0
['now']
invalid literal for int() with base 10: 'c'
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
/Users/BSEER/anaconda/lib/python3.5/site-packages/pyomo/solvers/plugins/solvers/GLPK.py in process_soln_file(self, results)
    367             prows, pcols = f.readline().split()
--> 368             prows = int(prows)  # fails if not a number; intentional
    369             pcols = int(pcols)  # fails if not a number; intentional

ValueError: invalid literal for int() with base 10: 'c'

During handling of the above exception, another exception occurred:

ValueError                                Traceback (most recent call last)
<ipython-input-13-1de7e7a5e44b> in <module>()
      5 
      6 
----> 7 network.lopf(extra_functionality=my_f)

/Users/BSEER/anaconda/lib/python3.5/site-packages/pypsa/opf.py in network_lopf(network, snapshots, solver_name, verbose, skip_pre, extra_functionality, solver_options, keep_files, formulation, ptdf_tolerance)
    801     opt = SolverFactory(solver_name)
    802 
--> 803     network.results = opt.solve(network.model,suffixes=["dual"],keepfiles=keep_files,options=solver_options)
    804 
    805     if verbose:

/Users/BSEER/anaconda/lib/python3.5/site-packages/pyomo/opt/base/solvers.py in solve(self, *args, **kwds)
    578             solve_completion_time = time.time()
    579 
--> 580             result = self._postsolve()
    581             result._smap_id = self._smap_id
    582             result._smap = None

/Users/BSEER/anaconda/lib/python3.5/site-packages/pyomo/opt/solver/shellcmd.py in _postsolve(self)
    265 
    266         if self._results_format is not None:
--> 267             results = self.process_output(self._rc)
    268             #
    269             # If keepfiles is true, then we pop the

/Users/BSEER/anaconda/lib/python3.5/site-packages/pyomo/opt/solver/shellcmd.py in process_output(self, rc)
    327                   % (log_file_completion_time - start_time))
    328         if self._results_reader is None:
--> 329             self.process_soln_file(results)
    330             soln_file_completion_time = time.time()
    331             if self._report_timing is True:

/Users/BSEER/anaconda/lib/python3.5/site-packages/pyomo/solvers/plugins/solvers/GLPK.py in process_soln_file(self, results)
    452             print(sys.exc_info()[1])
    453             msg = "Error parsing solution data file, line %d" % raw_line_count
--> 454             raise ValueError(msg)
    455         finally:
    456             f.close()

ValueError: Error parsing solution data file, line 1

On Wednesday, 15 June 2016 15:16:47 UTC+1, Aidan O'Sullivan wrote:

Jonas Hoersch

unread,
Jun 15, 2016, 12:45:45 PM6/15/16
to Aidan O'Sullivan, pypsa
Hi Aidan,

pyomo, which we rely on for building the optimization problem, is broken
with glpk >= 4.58

Official ticket is at:

https://software.sandia.gov/trac/pyomo/ticket/4641

Also reported here:

https://groups.google.com/forum/#!topic/pyomo-forum/AbpBqHJzdqo
https://github.com/FRED-2/OptiType/issues/28

You will have to downgrade glpk until they fix the bug or use a
different solver.

Best,
Jonas



On Wed, Jun 15 2016, Aidan O'Sullivan wrote:

> Ah! thanks tom how foolish of me. That explains the error.
>
> Now i'm having an issue with network.lopf() which i get for the same
> example using the code i downloaded from your site, it seems to be due to
> glpk i'm using version 4.6 are there any issues with that? Sorry for the
> additional question and thanks again for the support
>
> the main traceback is: ValueError: Error parsing solution data file, line 1
>
> No slack generator found, using My gen 0 as the slack generator
> Slack bus is My bus 0
> ['now']
> invalid literal for int() with base 10: 'c'
>
> ---------------------------------------------------------------------------ValueError Traceback (most recent call last)/Users/BSEER/anaconda/lib/python3.5/site-packages/pyomo/solvers/plugins/solvers/GLPK.py in process_soln_file(self, results) 367 prows, pcols = f.readline().split()--> 368 prows = int(prows) # fails if not a number; intentional 369 pcols = int(pcols) # fails if not a number; intentional
> ValueError: invalid literal for int() with base 10: 'c'
>
> During handling of the above exception, another exception occurred:
> ValueError Traceback (most recent call last)<ipython-input-13-1de7e7a5e44b> in <module>() 5 6 ----> 7 network.lopf(extra_functionality=my_f)
> /Users/BSEER/anaconda/lib/python3.5/site-packages/pypsa/opf.py in network_lopf(network, snapshots, solver_name, verbose, skip_pre, extra_functionality, solver_options, keep_files, formulation, ptdf_tolerance) 801 opt = SolverFactory(solver_name) 802 --> 803 network.results = opt.solve(network.model,suffixes=["dual"],keepfiles=keep_files,options=solver_options) 804 805 if verbose:
> /Users/BSEER/anaconda/lib/python3.5/site-packages/pyomo/opt/base/solvers.py in solve(self, *args, **kwds) 578 solve_completion_time = time.time() 579 --> 580 result = self._postsolve() 581 result._smap_id = self._smap_id 582 result._smap = None
> /Users/BSEER/anaconda/lib/python3.5/site-packages/pyomo/opt/solver/shellcmd.py in _postsolve(self) 265 266 if self._results_format is not None:--> 267 results = self.process_output(self._rc) 268 # 269 # If keepfiles is true, then we pop the
> /Users/BSEER/anaconda/lib/python3.5/site-packages/pyomo/opt/solver/shellcmd.py in process_output(self, rc) 327 % (log_file_completion_time - start_time)) 328 if self._results_reader is None:--> 329 self.process_soln_file(results) 330 soln_file_completion_time = time.time() 331 if self._report_timing is True:
> /Users/BSEER/anaconda/lib/python3.5/site-packages/pyomo/solvers/plugins/solvers/GLPK.py in process_soln_file(self, results) 452 print(sys.exc_info()[1]) 453 msg = "Error parsing solution data file, line %d" % raw_line_count--> 454 raise ValueError(msg) 455 finally: 456 f.close()
> ValueError: Error parsing solution data file, line 1
>
>
> On Wednesday, 15 June 2016 15:16:47 UTC+1, Aidan O'Sullivan wrote:
>>
>> Hi All,
>>
>> First of all congratulations to the whole PyPSA team for putting together
>> such a wonderful tool! I'm really keen to get playing with it however i ran
>> into a problem when using network.lopf in example 2 of the quick start,
>> building a minimal network for optimal power flow. I'd really appreciate
>> any help or guidance you could provide as to what i'm doing wrong the
>> keyerror returned is: and the
>>
>> KeyError: 'the label [My bus 2] is not in the [index]'
>>
>>
>> and the whole message is below, many thanks
>>
>>
>> ---------------------------------------------------------------------------KeyError Traceback (most recent call last)/Users/BSEER/anaconda/lib/python3.5/site-packages/pandas/core/indexing.py in _has_valid_type(self, key, axis) 1394 if key not in ax:-> 1395 error() 1396 except TypeError as e:
>> /Users/BSEER/anaconda/lib/python3.5/site-packages/pandas/core/indexing.py in error() 1389 raise KeyError("the label [%s] is not in the [%s]" %-> 1390 (key, self.obj._get_axis_name(axis))) 1391
>> KeyError: 'the label [My bus 2] is not in the [index]'
>>
>> During handling of the above exception, another exception occurred:
>> KeyError Traceback (most recent call last)<ipython-input-7-5dc45b3bcb12> in <module>()----> 1 network.lopf()
>> /Users/BSEER/anaconda/lib/python3.5/site-packages/pypsa/opf.py in network_lopf(network, snapshots, solver_name, verbose, skip_pre, extra_functionality, solver_options, keep_files, formulation, ptdf_tolerance) 751 752 if not skip_pre:--> 753 network.determine_network_topology() 754 calculate_dependent_values(network) 755 for sub_network in network.sub_networks.obj:
>> /Users/BSEER/anaconda/lib/python3.5/site-packages/pypsa/components.py in determine_network_topology(self, skip_pre) 765 766 #grab data from first bus--> 767 sub_network.current_type = self.buses.loc[next(sub_graph.nodes_iter()), "current_type"] 768 769 for bus in sub_graph.nodes():
>> /Users/BSEER/anaconda/lib/python3.5/site-packages/pandas/core/indexing.py in __getitem__(self, key) 1292 1293 if type(key) is tuple:-> 1294 return self._getitem_tuple(key) 1295 else: 1296 return self._getitem_axis(key, axis=0)
>> /Users/BSEER/anaconda/lib/python3.5/site-packages/pandas/core/indexing.py in _getitem_tuple(self, tup) 782 def _getitem_tuple(self, tup): 783 try:--> 784 return self._getitem_lowerdim(tup) 785 except IndexingError: 786 pass
>> /Users/BSEER/anaconda/lib/python3.5/site-packages/pandas/core/indexing.py in _getitem_lowerdim(self, tup) 906 for i, key in enumerate(tup): 907 if is_label_like(key) or isinstance(key, tuple):--> 908 section = self._getitem_axis(key, axis=i) 909 910 # we have yielded a scalar ?
>> /Users/BSEER/anaconda/lib/python3.5/site-packages/pandas/core/indexing.py in _getitem_axis(self, key, axis) 1464 1465 # fall thru to straight lookup-> 1466 self._has_valid_type(key, axis) 1467 return self._get_label(key, axis=axis) 1468
>> /Users/BSEER/anaconda/lib/python3.5/site-packages/pandas/core/indexing.py in _has_valid_type(self, key, axis) 1401 raise 1402 except:-> 1403 error() 1404 1405 return True
>> /Users/BSEER/anaconda/lib/python3.5/site-packages/pandas/core/indexing.py in error() 1388 "key") 1389 raise KeyError("the label [%s] is not in the [%s]" %-> 1390 (key, self.obj._get_axis_name(axis))) 1391 1392 try:
>> KeyError: 'the label [My bus 2] is not in the [index]'
>>
>>
>
> --
> You received this message because you are subscribed to the Google Groups "pypsa" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to pypsa+un...@googlegroups.com.
> To post to this group, send an email to py...@googlegroups.com.
> To view this discussion on the web, visit https://groups.google.com/d/msgid/pypsa/63d149bc-a321-4fb8-9ab0-0a6cb4aaf8bc%40googlegroups.com.
signature.asc

Aidan O'Sullivan

unread,
Jun 15, 2016, 12:49:43 PM6/15/16
to pypsa
Hi Jonas,

Thanks i reinstalled an older version and everything works perfectly, congrats again on a great project! And thanks for all the assistance! Do you guys have a published academic paper on pypsa?

all the best,
aidan


On Wednesday, 15 June 2016 15:16:47 UTC+1, Aidan O'Sullivan wrote:

Tom Brown

unread,
Jun 16, 2016, 10:11:50 AM6/16/16
to py...@googlegroups.com
Hi Aidan,

At the moment there is no published paper on PyPSA and we're not
planning to write one, just because the software doesn't implement
anything novel (at least not yet).

We're currently figuring out how to make the project citable (probably
some figshare/zenodo repository with a DOI) and will share the details
as soon as we've found a good solution.

Thanks for your interest in the project!

Best wishes,

Tom

On 15/06/16 18:49, Aidan O'Sullivan wrote:
> Hi Jonas,
>
> Thanks i reinstalled an older version and everything works perfectly,
> congrats again on a great project! And thanks for all the assistance! Do
> you guys have a published academic paper on pypsa?
>
> all the best,
> aidan
>
> On Wednesday, 15 June 2016 15:16:47 UTC+1, Aidan O'Sullivan wrote:
>
> Hi All,
>
> First of all congratulations to the whole PyPSA team for putting
> together such a wonderful tool! I'm really keen to get playing with
> it however i ran into a problem when using network.lopf in example 2
> of the quick start, building a minimal network for optimal power
> flow. I'd really appreciate any help or guidance you could provide
> as to what i'm doing wrong the keyerror returned is: and the
>
> KeyError: 'the label [My bus 2] is not in the [index]'
>
>
> and the whole message is below, many thanks
>
>
> ---------------------------------------------------------------------------
> KeyError Traceback (most recent call last)
> /Users/BSEER/anaconda/lib/python3.5/site-packages/pandas/core/indexing.py in _has_valid_type(self, key, axis) 1394 if key not in ax:->
> 1395error()1396 except TypeError as
> e:/Users/BSEER/anaconda/lib/python3.5/site-packages/pandas/core/indexing.py
> in error() 1389 raise KeyError("the label [%s] is not in the [%s]" %
> -> 1390(key, self.obj._get_axis_name(axis))) 1391 KeyError: 'the
> label [My bus 2] is not in the [index]' During handling of the above
> exception, another exception occurred: KeyError Traceback (most
> recent call last) <ipython-input-7-5dc45b3bcb12> in <module>() ---->
> 1network.lopf()/Users/BSEER/anaconda/lib/python3.5/site-packages/pypsa/opf.py
> in network_lopf(network, snapshots, solver_name, verbose, skip_pre,
> extra_functionality, solver_options, keep_files, formulation,
> ptdf_tolerance) 751 752 if not skip_pre:-->
> 753network.determine_network_topology()754
> calculate_dependent_values(network)755 for sub_network in
> network.sub_networks.obj:/Users/BSEER/anaconda/lib/python3.5/site-packages/pypsa/components.py
> in determine_network_topology(self, skip_pre) 765 766 #grab data
> from first bus--> 767sub_network.current_type =
> self.buses.loc[next(sub_graph.nodes_iter()), "current_type"]768 769
> for bus in
> sub_graph.nodes():/Users/BSEER/anaconda/lib/python3.5/site-packages/pandas/core/indexing.py
> in __getitem__(self, key) 1292 1293 if type(key) is tuple:->
> 1294return self._getitem_tuple(key)1295 else:1296 return
> self._getitem_axis(key,
> axis=0)/Users/BSEER/anaconda/lib/python3.5/site-packages/pandas/core/indexing.py
> in _getitem_tuple(self, tup) 782 def _getitem_tuple(self, tup):783
> try:--> 784return self._getitem_lowerdim(tup)785 except
> IndexingError:786
> pass/Users/BSEER/anaconda/lib/python3.5/site-packages/pandas/core/indexing.py
> in _getitem_lowerdim(self, tup) 906 for i, key in enumerate(tup):907
> if is_label_like(key) or isinstance(key, tuple):--> 908section =
> self._getitem_axis(key, axis=i)909 910 # we have yielded a scalar
> ?/Users/BSEER/anaconda/lib/python3.5/site-packages/pandas/core/indexing.py
> in _getitem_axis(self, key, axis) 1464 1465 # fall thru to straight
> lookup-> 1466self._has_valid_type(key, axis)1467 return
> self._get_label(key, axis=axis)1468
> /Users/BSEER/anaconda/lib/python3.5/site-packages/pandas/core/indexing.py
> in _has_valid_type(self, key, axis) 1401 raise1402 except:->
> 1403error()1404 1405 return
> True/Users/BSEER/anaconda/lib/python3.5/site-packages/pandas/core/indexing.py
> in error() 1388 "key") 1389 raise KeyError("the label [%s] is not in
> the [%s]" % -> 1390(key, self.obj._get_axis_name(axis))) 1391 1392
> try:KeyError: 'the label [My bus 2] is not in the [index]'
>
> --
> You received this message because you are subscribed to the Google
> Groups "pypsa" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to pypsa+un...@googlegroups.com
> <mailto:pypsa+un...@googlegroups.com>.
> To post to this group, send email to py...@googlegroups.com
> <mailto:py...@googlegroups.com>.
> To view this discussion on the web, visit
> https://groups.google.com/d/msgid/pypsa/5b7d96f0-4a23-41f4-9ddf-9fb9d6c51404%40googlegroups.com
> <https://groups.google.com/d/msgid/pypsa/5b7d96f0-4a23-41f4-9ddf-9fb9d6c51404%40googlegroups.com?utm_medium=email&utm_source=footer>.
> For more options, visit https://groups.google.com/d/optout.

kostas syranidis

unread,
Jul 19, 2016, 5:24:33 AM7/19/16
to pypsa
Hi all,

I recently ran some conda updates and now the minimal lopf does not run for me also. I wonder if anyone has encountered this before.

The error comes from scipy when trying network.lopf - adjacency matrix and gives:

C:\Users\k.syranidis\AppData\Local\Continuum\Anaconda3\lib\site-packages\scipy\sparse\coo.py in _check(self)
    238                 raise ValueError('column index exceeds matrix dimensions')
    239             if self.row.min() < 0:
--> 240                 raise ValueError('negative row index found')
    241             if self.col.min() < 0:
    242                 raise ValueError('negative column index found')

ValueError: negative row index found

It seems there was a problem with version earlier than 0.14 but I currently use 0.17, therefore it should not be there.

Other packages version in case they are relevant are:
mkl 11.3
numpy 1.11
pandas 0.18
pyomo 4.3
scikit-learn 0.17
scipy 0.17

python 3.5

By the way, I wanted to ask if there is any specific reason why you did not include the 'import_components_from_dataframe' to the network methods.

Thank you,
Kostas



Jonas Hörsch

unread,
Jul 19, 2016, 5:40:19 PM7/19/16
to kostas syranidis, pypsa
Hi Kostas,

I don't think a scipy update is at the core of what you are
experiencing. We/I recently switched out a good part of the graph
functionality to replace the slow networkx code with a few better suited
functions from scipy.sparse.csgraph.

The error you're describing, i.e. "negative row index found", usually
means that bus names which were referenced in network.lines.bus0 or bus1
(or another of the branch components) could not be resolved to actual
buses in network.buses. (We will have to catch this error and replace it
with a more helpful error message soon, sorry!).

Could you please describe a bit better what minimal example you are
running! minimal_example_lopf.ipynb from

http://pypsa.org/examples/index.html

seems to be running fine for me.

Thanks,
Jonas
> --
> You received this message because you are subscribed to the Google Groups "pypsa" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to pypsa+un...@googlegroups.com.
> To post to this group, send an email to py...@googlegroups.com.
> To view this discussion on the web, visit https://groups.google.com/d/msgid/pypsa/2f12b0c8-4198-4e2d-bfba-57681074f1d0%40googlegroups.com.
signature.asc

kostas syranidis

unread,
Jul 19, 2016, 7:00:22 PM7/19/16
to pypsa, ksyr...@gmail.com, hoe...@fias.uni-frankfurt.de
OK, this is embarrassing. Your comment is right, I wrote the example from scratch by myself and missed a capital letter... I will try to be more careful next time.

Thank you for the quick reply anyway,
Kostas

Thorben Meiners

unread,
Oct 5, 2016, 11:04:38 AM10/5/16
to pypsa, ksyr...@gmail.com, hoe...@fias.uni-frankfurt.de
Hi all,

I got a problem with the minimal example of power flow and would appreciate your help.
I run through the installation described on the pypsa webpage and just continued with the example.
The error:

"
Traceback (most recent call last):
  File "/home/tmeiners/pypsa_env/lib/python3.4/site-packages/pandas/indexes/base.py", line 2104, in get_loc
    return self._engine.get_loc(key)
  File "pandas/index.pyx", line 139, in pandas.index.IndexEngine.get_loc (pandas/index.c:4160)
  File "pandas/index.pyx", line 161, in pandas.index.IndexEngine.get_loc (pandas/index.c:4024)
  File "pandas/src/hashtable_class_helper.pxi", line 732, in pandas.hashtable.PyObjectHashTable.get_item (pandas/hashtable.c:13161)
  File "pandas/src/hashtable_class_helper.pxi", line 740, in pandas.hashtable.PyObjectHashTable.get_item (pandas/hashtable.c:13115)
KeyError: 'name'


During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "minpf.py", line 43, in <module>
    network.pf()
  File "/home/tmeiners/pypsa_env/lib/python3.4/site-packages/pypsa/pf.py", line 98, in network_pf
    _network_prepare_and_run_pf(network, snapshots, verbose, skip_pre, sub_network_pf, calculate_Y, x_tol=x_tol, use_seed=use_seed)
  File "/home/tmeiners/pypsa_env/lib/python3.4/site-packages/pypsa/pf.py", line 69, in _network_prepare_and_run_pf
    find_bus_controls(sub_network, verbose=verbose)
  File "/home/tmeiners/pypsa_env/lib/python3.4/site-packages/pypsa/pf.py", line 421, in find_bus_controls
    pvs = gens[gens.control == 'PV'].reset_index().groupby('bus').first()['name']
  File "/home/tmeiners/pypsa_env/lib/python3.4/site-packages/pandas/core/frame.py", line 2057, in __getitem__
    return self._getitem_column(key)
  File "/home/tmeiners/pypsa_env/lib/python3.4/site-packages/pandas/core/frame.py", line 2064, in _getitem_column
    return self._get_item_cache(key)
  File "/home/tmeiners/pypsa_env/lib/python3.4/site-packages/pandas/core/generic.py", line 1386, in _get_item_cache
    values = self._data.get(item)
  File "/home/tmeiners/pypsa_env/lib/python3.4/site-packages/pandas/core/internals.py", line 3520, in get
    loc = self.items.get_loc(item)
  File "/home/tmeiners/pypsa_env/lib/python3.4/site-packages/pandas/indexes/base.py", line 2106, in get_loc
    return self._engine.get_loc(self._maybe_cast_indexer(key))
  File "pandas/index.pyx", line 139, in pandas.index.IndexEngine.get_loc (pandas/index.c:4160)
  File "pandas/index.pyx", line 161, in pandas.index.IndexEngine.get_loc (pandas/index.c:4024)
  File "pandas/src/hashtable_class_helper.pxi", line 732, in pandas.hashtable.PyObjectHashTable.get_item (pandas/hashtable.c:13161)
  File "pandas/src/hashtable_class_helper.pxi", line 740, in pandas.hashtable.PyObjectHashTable.get_item (pandas/hashtable.c:13115)
KeyError: 'name'
"

appeared directly after:

"
No slack generator found, using My gen as the slack generator

Slack bus is My bus 0
"

My current virtualenv config is:

"
Cython==0.24.1
PyUtilib==5.4
Pygments==2.1.3
Pyomo==4.4.1
appdirs==1.4.0
decorator==4.0.10
ipython==5.1.0
ipython-genutils==0.1.0
networkx==1.11
nose==1.3.7
numpy==1.11.2
pandas==0.19.0
pexpect==4.2.1
pickleshare==0.7.4
ply==3.9
prompt-toolkit==1.0.7
ptyprocess==0.5.1
py==1.4.31
pypsa==0.6.1
pytest==3.0.3
python-dateutil==2.5.3
pytz==2016.7
scipy==0.18.1
simplegeneric==0.8.1
six==1.10.0
traitlets==4.3.1
wcwidth==0.1.7
"

I think the reason is the missing glpk, but I don't manage to install it in my virtualenv (where I don't have the permission to install via sudo).
I would be very happy if you have any suggestions.

Kind regards,
Thorben

Jonas Hoersch

unread,
Oct 5, 2016, 11:25:05 AM10/5/16
to Thorben Meiners, pypsa
Hi Thorben,

Please downgrade pandas to 0.18.1, until I fix the offending line

pvs = gens[gens.control == 'PV'].reset_index().groupby('bus').first()['name']

next week.

For the pf function you will not need any solver, but you will for an lopf.

Best,
Jonas


--
Jonas Hörsch
Frankfurt Institute for Advanced Studies
Ruth-Moufang-Str. 1
60438 Frankfurt am Main, Germany

Tel.: +49 69 798 47605
hoe...@fias.uni-frankfurt.de
signature.asc
Reply all
Reply to author
Forward
0 new messages