bw2calc.monte_carlo#
Classes#
First draft approach at comparative LCA |
|
Base class to use iterative techniques instead of LU factorization in Monte Carlo. |
|
Monte Carlo uncertainty analysis with separate random number generators (RNGs) for each set of parameters. |
|
This is a class for the efficient calculation of many demand vectors from |
|
Split a Monte Carlo calculation into parallel jobs |
Functions#
|
|
|
Calculate a single Monte Carlo iteration for many demands. |
|
|
|
Module Contents#
- class bw2calc.monte_carlo.ComparativeMonteCarlo(demands, *args, **kwargs)[source]#
Bases:
IterativeMonteCarlo
First draft approach at comparative LCA
Create a new LCA calculation.
- Parameters:
demand (*) – The demand or functional unit. Needs to be a dictionary to indicate amounts, e.g.
{("my database", "my process"): 2.5}.method (*) – LCIA Method tuple, e.g.
("My", "great", "LCIA", "method"). Can be omitted if only interested in calculating the life cycle inventory.
- Returns:
A new LCA object
- class bw2calc.monte_carlo.DirectSolvingMixin(demand, method=None, iter_solver=cgs, seed=None, *args, **kwargs)[source]#
Bases:
IterativeMonteCarlo
Base class to use iterative techniques instead of LU factorization in Monte Carlo.
Create a new LCA calculation.
- Parameters:
demand (*) – The demand or functional unit. Needs to be a dictionary to indicate amounts, e.g.
{("my database", "my process"): 2.5}.method (*) – LCIA Method tuple, e.g.
("My", "great", "LCIA", "method"). Can be omitted if only interested in calculating the life cycle inventory.
- Returns:
A new LCA object
- solve_linear_system()[source]#
Master solution function for linear system \(Ax=B\).
To most numerical analysts, matrix inversion is a sin.
—Nicolas Higham, Accuracy and Stability of Numerical Algorithms, Society for Industrial and Applied Mathematics, Philadelphia, PA, USA, 2002, p. 260.
We use UMFpack, which is a very fast solver for sparse matrices.
If the technosphere matrix has already been factorized, then the decomposed technosphere (
self.solver) is reused. Otherwise the calculation is redone completely.
- class bw2calc.monte_carlo.DirectSolvingMonteCarloLCA(demand, method=None, iter_solver=cgs, seed=None, *args, **kwargs)[source]#
Bases:
MonteCarloLCA,DirectSolvingMixin
Monte Carlo uncertainty analysis with separate random number generators (RNGs) for each set of parameters.
Create a new LCA calculation.
- Parameters:
demand (*) – The demand or functional unit. Needs to be a dictionary to indicate amounts, e.g.
{("my database", "my process"): 2.5}.method (*) – LCIA Method tuple, e.g.
("My", "great", "LCIA", "method"). Can be omitted if only interested in calculating the life cycle inventory.
- Returns:
A new LCA object
- class bw2calc.monte_carlo.IterativeMonteCarlo(demand, method=None, iter_solver=cgs, seed=None, *args, **kwargs)[source]#
Bases:
bw2calc.lca.LCA
Base class to use iterative techniques instead of LU factorization in Monte Carlo.
Create a new LCA calculation.
- Parameters:
demand (*) – The demand or functional unit. Needs to be a dictionary to indicate amounts, e.g.
{("my database", "my process"): 2.5}.method (*) – LCIA Method tuple, e.g.
("My", "great", "LCIA", "method"). Can be omitted if only interested in calculating the life cycle inventory.
- Returns:
A new LCA object
- solve_linear_system()[source]#
Master solution function for linear system \(Ax=B\).
To most numerical analysts, matrix inversion is a sin.
—Nicolas Higham, Accuracy and Stability of Numerical Algorithms, Society for Industrial and Applied Mathematics, Philadelphia, PA, USA, 2002, p. 260.
We use UMFpack, which is a very fast solver for sparse matrices.
If the technosphere matrix has already been factorized, then the decomposed technosphere (
self.solver) is reused. Otherwise the calculation is redone completely.
- class bw2calc.monte_carlo.MonteCarloLCA(demand, method=None, iter_solver=cgs, seed=None, *args, **kwargs)[source]#
Bases:
IterativeMonteCarlo
Monte Carlo uncertainty analysis with separate random number generators (RNGs) for each set of parameters.
Create a new LCA calculation.
- Parameters:
demand (*) – The demand or functional unit. Needs to be a dictionary to indicate amounts, e.g.
{("my database", "my process"): 2.5}.method (*) – LCIA Method tuple, e.g.
("My", "great", "LCIA", "method"). Can be omitted if only interested in calculating the life cycle inventory.
- Returns:
A new LCA object
- class bw2calc.monte_carlo.MultiMonteCarlo(demands, method, iterations, cpus=None)[source]#
Bases:
objectThis is a class for the efficient calculation of many demand vectors from each Monte Carlo iteration.
- Parameters:
dictionaries (* args is a list of demand)
method (* method is a LCIA)
desired (* iterations is the number of Monte Carlo iterations)
the (* cpus is)
The input list can have complex demands, so
[{('foo', 'bar'): 1, ('foo', 'baz'): 1}, {('foo', 'another'): 1}]is OK.Call
.calculate()to generate results.- calculate(worker=multi_worker)[source]#
Calculate Monte Carlo results for many demand vectors.
Returns a list of results with the format:
[(demand dictionary, [lca scores])]
There is no guarantee that the results are returned in the same order as the
demandinput variable.
- class bw2calc.monte_carlo.ParallelMonteCarlo(demand, method, iterations=1000, chunk_size=None, cpus=None, log_config=None)[source]#
Bases:
objectSplit a Monte Carlo calculation into parallel jobs