openlca-python-tutorial icon indicating copy to clipboard operation
openlca-python-tutorial copied to clipboard

OutOfMemoryError during Calculation using API

Open slothyoung opened this issue 6 years ago • 3 comments

I am currently working with the OpenLCA API in Eclipse. But with some Processes/Product Systems, I encounter an OutOfMemoryError during the Calculation of a ProductSystem.

The following is the Print-Stack: Exception in thread "Thread-0" java.lang.OutOfMemoryError: Java heap space at org.apache.commons.math3.linear.Array2DRowRealMatrix.copyOut(Array2DRowRealMatrix.java:528) at org.apache.commons.math3.linear.Array2DRowRealMatrix.getData(Array2DRowRealMatrix.java:253) at org.apache.commons.math3.linear.LUDecomposition.(LUDecomposition.java:92) at org.apache.commons.math3.linear.LUDecomposition.(LUDecomposition.java:75) at org.openlca.core.matrix.solvers.JavaSolver.solve(JavaSolver.java:23) at org.openlca.core.math.LcaCalculator.calculateContributions(LcaCalculator.java:73)

The line causing the error is the following: ContributionResult result = calculator.calculateContributions(setup);

I was monitoring my RAM Usage (8GB Machine) and RAM was not required more than 80% shortly before the crash. I do not have this behavior with every calculation, but with many. In OpenLCA itself, the calculations finishes without problems.

The question I ask myself now is, how to remedy this Error?

slothyoung avatar Jul 29 '18 15:07 slothyoung

You can increase the heap space for your Python script in Eclipse under Run > Run Configuration. There you can set the max. heap space parameter for the JVM via the -Xmx flag, e.g. -Xmx2048M would set it to 2048 megabytes. See also this answer on Stackoverflow.

Also, you could use the native library and the DenseSolver for faster calculations (see line 113 in the example script).

msrocka avatar Aug 13 '18 10:08 msrocka

Thanks for the reply!

I am afraid to have not explained my case well enough. I am not trying to run Python Scripts inside OpenLCA, but rather use the APIs in Eclipse, basically following this tutorial: https://github.com/GreenDelta/openlca-python-tutorial/blob/master/ide_setup.md

However, I do not use Jython, but Java directly. And in this situation, the Exceptions are thrown. I already raised the Maximum Heap Size, but that unfortunately did not help. The DenseSolver did not work for me either because i get an UnsatisfiedLinkError. Maybe there is something that I am missing.

slothyoung avatar Aug 13 '18 17:08 slothyoung

Maybe you just need to assign more memory; what happens if you set it to 6G? (for an ecoinvent 3.4 system, openLCA currently needs ~3.5 GB of memory.)

Regarding the link error: as in the Python script, you first need to load the native library before you can use it. So, before you use the dense solver, you would load the library like this:

NativeLibrary.loadFromDir(new File("path/to/native/lib/folder"))

msrocka avatar Aug 15 '18 09:08 msrocka