Search code examples
python-3.xbrightway

how big technosphere matrices can be in brightway2


How big technosphere matrices can be in Brightway2 and still be invertible? From what I understood here Brightway uses a wrapper to the Pardiso library to speed up matrix inversion. Compared with standard scipy libraries Pardiso is indeed much faster. But when I tested it I run into memory problems for matrices larger than 10000 rows. To invert the matrix I need to define a numpy array, which cannot be bigger than 1000000 rows on my laptop.

from pypardiso import spsolve
import numpy as np
ar=csc_matrix(np.eye(10000))
%time spsolve(ar,np.eye(10000))

Is it here the limit, or I can get around the use of numpy arrays?

(PS: I tested with standard scipy solvers and I can invert sparse matrices of 10^5 rows but its quite slow).


Solution

  • I know that Adrian Haas worked with a sparse matrix with more than 100 000 rows/columns. The only limit should be the memory in your machine, not in the software itself.

    You can create the inverse column by column in a reasonable time, and get the benefit of much better numerical stability and the speed of pardiso:

    In [1]: from brightway2 import *
    
    In [2]: import pyprind
    
    In [3]: from time import time
    
    In [4]: db = Database("ecoinvent 3.5 cutoff")
    
    In [5]: def invert(database):
       ...:    lca = LCA({database.random(): 1})
       ...:    lca.lci()
       ...:    for act in pyprind.prog_bar(database):
       ...:        lca.redo_lci({act: 1})
       ...:
    
    In [6]: start = time(); invert(db); print(time() - start)
    0%                          100%
    [##############################] | ETA: 00:00:00
    Total time elapsed: 00:03:21
    202.16850423812866
    

    However, in my experience it is very rare that someone actually needs the inverse of the technosphere.