activity-browser icon indicating copy to clipboard operation
activity-browser copied to clipboard

AB returns empty life cycle inventory with big matrices

Open MaximeAgez opened this issue 1 year ago • 6 comments

Updating AB

  • [X] Yes, I have updated AB and still experience this issue

What happened?

Hi! I am currently working with big LCI datasets and when launching an LCA calculation with said LCI datasets with AB, the calculation runs for a few minutes (maybe 5?), then "succeeds" (as in no error shows up) but the result is completely empty. Note that the inventory is not filled with zeros but is really empty. I am wondering if the problem would rather be a hardware issue (like my RAM is not big enough for these calculations), but then I would have expected to receive a MemoryError, or is it rather a problem with AB? Maybe there is something in the code that tells AB to stop running a calculation if it goes beyond X minutes? I'd appreciate any input there :)

Hardware system: 3.3GHz CPU 16GB RAM

datasets size: technosphere ~200,000 processes biosphere ~ 65,000 elementary flows

Relevant errors

No response

Operating system

Windows 11

Conda environment

No response

MaximeAgez avatar Jun 25 '24 14:06 MaximeAgez

Hi @MaximeAgez,

Sorry to hear you're encountering issues. Does your console say anything at all?

Kind regards,

Marin

mrvisscher avatar Jun 26 '24 08:06 mrvisscher

The console only said that graphs couldn't be done properly since all data is empty.

MaximeAgez avatar Jun 26 '24 13:06 MaximeAgez

Strange... To answer your earlier question: there is no timeout on LCA calculations, and there should indeed be an error thrown when you run out of resources (e.g. memory). I'd expect the entire AB to crash at that point anyway.

Are you familiar with coding in Brightway2, we could check whether running your LCA there yields any results. That would help narrow down the problem.

mrvisscher avatar Jun 26 '24 13:06 mrvisscher

I had to reduce the size of my system to be able to work for now. I'll regenerate a bigger system later and will test it on brightway2. And since it seems it is apparently more likely related to hardware, I'll try to find a 32GB RAM computer to test it as well.

MaximeAgez avatar Jun 26 '24 13:06 MaximeAgez

Very interesting, keep us updated please!

mrvisscher avatar Jun 26 '24 14:06 mrvisscher

Some news, I was able to remake that big dataset and the problem is the same on brightway itself. The resulting lca.score is nan, and no errors when running LCA.lci(). I'll try to find a computer with double the RAM to see if it really is a hardware issue in the end.

MaximeAgez avatar Jul 08 '24 20:07 MaximeAgez

@mrvisscher It is indeed a MemoryError in disguise, because it runs normally on a laptop with 32GB RAM. I would recommend to return the MemoryError to the user to avoid any confusion. Thanks!

MaximeAgez avatar Jul 15 '24 18:07 MaximeAgez

Actually, the problem resurfaced with way smaller datasets. Turns out the issue is not the RAM, but that my technosphere matrix has a determinant that is infinite, so it can't be inverted, hence why there are only NaNs in the result. To be honest, I did not think it possible because I was expecting brightway to raise an error if the matrix was not invertable.

MaximeAgez avatar Jul 25 '24 14:07 MaximeAgez

Hmm that's too bad.

So linear algebra is not my expertise, but I'm assuming that while you have many more processes in your matrix, you maybe don't have many more exchanges between them, this would mean that your matrix is more sparse, meaning there are -relatively speaking- more zeroes. This indeed leads to an ill-conditioned matrix (LCA matrices are already not exactly well conditioned due to their sparsity). e.g. ecoinvent has ~20k processes and ~500k exchanges, so a fill-rate of (20k2=400M) -> 500k/400M = 0.125%. It could be that the solver interprets your matrix as singular due to the high condition number.

my technosphere matrix has a determinant that is infinite, so it can't be inverted

Also note, that while this doesn't matter too much technically, we don't invert the matrix, but we solve directly for the demand you list in the setup, this is much faster and requires much less RAM (the result of your inverted matrix would take 200k2= 40B numbers * 64bits = 320GB without overhead for dataformats etc). Also note that your LCI result and every LCIA step would take ~104GB per step (200k * 65k * 64) independent of the inversion step, so this is still very likely to cause be RAM issues in AB at some point, even if you manage to fix the matrix conditioning)


All that said, that's not directly useful for you.

  1. We will look if we are somehow blocking an error from being shown, otherwise we will open an issue with Brightway that this should give an error.
  2. I would really suggest using Brightway directly for projects this size, while AB can do some cool things, it's not perfectwhich is an understatement as we both know and things like this are really pushing it's limits. Brightway will be much better suited for things like this.
  3. What could maybe help -in case you haven't done so already- is to normalize all processes (make sure they all produce 1, and scale the inputs accordingly). This could help, as computers don't deal with numerical precision as humans do, for further reading I would suggest this page on floating point arithmetic accuracy and Chapter 10 of The Computational Structure of LCA by Heijungs and Suh email me if you don't have access, but don't tell others I said this ;).

marc-vdm avatar Jul 26 '24 08:07 marc-vdm

Thanks for the pointers @marc-vdm. In the my technosphere had rows of zero. My project is about copying and modifying ecoinvent processes and the function to re-attribute the input exchange didn't work properly on production exchanges. So basically the new processes were still producing the old reference product. It means that there wasn't 1s on all the diagonal and so some rows of zeros. Now it's fixed and I get consistently get the results, even with the big system (the 200k one), so it means AB and a 16GB RAM computer can handle that much at least.

MaximeAgez avatar Jul 26 '24 13:07 MaximeAgez