This repository demonstrates two ways to run the same multi-method life-cycle assessment in Brightway 2.5. The baseline implementation is intentionally repetitive; the optimized implementation avoids repeating activity-search and inventory work that is unchanged between impact methods.
The example creates or reuses a foreground activity named Manual pre-clean,
connects it to 1 kg of ecoinvent soap production for the RoW location, and
calculates 25 EF v3.1 impact methods, excluding the no LT variants.
upstream-bw-lca/
|-- main.py
|-- requirements.txt
|-- env_bw25.yml
|-- Init/
| `-- db.py
|-- Searcher/
| |-- find_flow.py
| `-- methods.py
|-- Comparison/
| |-- lca_model.py
| |-- run_lca_baseline.py
| `-- run_lca_optimized.py
`-- Outputs/
|-- methods_list.txt
|-- results_baseline.csv
`-- results_optimized.csv
The root main.py is the primary entry point: it runs the baseline and
optimized implementations, verifies that their LCIA scores match, and compares
their runtimes. Database setup, discovery utilities, implementation details,
and generated artifacts are kept in separate directories.
Both programs use the same project, database, foreground activity, input, and
impact methods from Comparison/lca_model.py. They differ only in how they
find the input activity and perform the calculations:
| Phase | Comparison/run_lca_baseline.py |
Comparison/run_lca_optimized.py |
|---|---|---|
| Activity lookup | Iterates through every activity in the ecoinvent database | Uses Brightway's local search index, followed by exact filtering |
| Inventory calculation | Creates a new LCA object and runs LCI for every impact method |
Creates one LCA object and runs LCI once |
| Impact calculation | Runs LCIA after every repeated LCI | Switches characterization method and reuses the same inventory |
| Output | Outputs/results_baseline.csv |
Outputs/results_optimized.csv |
The life-cycle inventory is the calculated list of elementary flows caused by the functional unit. It does not change when only the impact method changes. The optimized implementation therefore calculates this inventory once and applies each characterization method to it.
Conceptually, the baseline does:
for each impact method:
create LCA
calculate LCI
calculate LCIA
The optimized implementation does:
create LCA
calculate LCI once
for each impact method:
switch characterization method
calculate LCIA
Run the reproducible comparison without overwriting either results CSV:
conda activate env_bw25
python main.py --repeats 3The comparison alternates execution order between rounds, reports median timings, and fails if the implementations calculate different method sets or scores.
The benchmark was run in the following environment:
| Component | Tested configuration |
|---|---|
| CPU | 12th Gen Intel Core i7-12700H, 14 physical cores and 20 logical processors |
| RAM | 31.68 GiB installed (nominally 32 GB) |
| Storage | WD PC SN810 SDCPNRY-1T00-1006, 954 GiB NVMe |
| Operating system | Microsoft Windows 11 Home, 64-bit, version 10.0.26200 (build 26200) |
| Python | 3.11.14 in Conda environment env_bw25 |
| Brightway | bw2data 4.0.dev56, bw2calc 2.0.dev22, bw2io 0.9.dev38 |
| Numerical stack | numpy 1.26.4, scipy 1.17.1, pandas 3.0.1 |
| Brightway project | e10bio |
| Brightway database | ecoinvent-3.10-cutoff |
| Compared workload | 25 EF v3.1 methods, excluding no LT variants |
On this configuration, the median of three alternating-order rounds was:
| Phase | Baseline | Optimized | Speedup |
|---|---|---|---|
| Activity search | 1.503 s | 0.032 s | 46.42x |
| LCI and LCIA | 8.759 s | 0.364 s | 24.09x |
| End to end | 10.382 s | 0.408 s | 25.44x |
Both implementations returned identical scores for all 25 methods. These figures describe this machine and warm local Brightway project; hardware, filesystem cache, database size, and installed package versions can change the absolute timings.
- Conda or Miniconda
- A licensed copy of the ecoinvent 3.10 ecoSpold2 datasets
- Access to the required Brightway biosphere project
The ecoinvent database is licensed data and is therefore not included in this repository.
The recommended installation method is the supplied env_bw25.yml, because
the project was developed with specific Brightway development versions:
conda env create -f env_bw25.yml
conda activate env_bw25A pinned requirements.txt is also provided as a pip alternative:
python -m pip install -r requirements.txtThe two LCA implementations and runtime comparison expect:
Brightway project: e10bio
Brightway database: ecoinvent-3.10-cutoff
Init/db.py is a separate import helper configured for the APOS system model
and project e10bio-apos. Ensure its project and system model match the
calculations you intend to run. Then provide the location of your licensed
ecoSpold2 datasets through an environment variable and run the initializer from
the repository root:
$env:ECOINVENT_DATASETS_DIR = "C:\path\to\ecoinvent\datasets"
python -m Init.dbThe local path remains outside the source code and is not committed. Database import should normally be performed only once.
Search the configured Brightway database by activity name, with optional unit, location, and partial-name filters:
python -m Searcher.find_flow --name "soap production" --location RoW --unit kilogramExport every available LCIA method identifier for the project configured in the script:
python -m Searcher.methodsThe method list is written to Outputs/methods_list.txt.
Run the comparison from the repository root:
python main.py --repeats 3The comparison does not overwrite the saved CSV files. It alternates execution order, checks that both implementations return equivalent scores, and reports median runtimes and speedups.
Run only the baseline implementation:
python -m Comparison.run_lca_baselineThis writes Outputs/results_baseline.csv and prints the full-scan,
calculation, and end-to-end timings.
Run only the optimized implementation:
python -m Comparison.run_lca_optimizedThis writes Outputs/results_optimized.csv and prints the indexed-search,
calculation, and end-to-end timings. Use this implementation for normal
calculations; the baseline is retained to make the optimization measurable and
educational.
Runs both implementations without writing result files, verifies that their scores are identical, and reports median runtime and speedup.
Defines the shared Brightway project, source and foreground databases, soap input, foreground exchange, EF v3.1 method selection, and result format used by both comparison implementations.
Installs the configured biosphere project and imports an ecoinvent ecoSpold2 database into Brightway. It should normally be run only during initial setup.
Writes every available LCIA method identifier to
Outputs/methods_list.txt and prints method counts for the project configured
inside the script.
Searches the configured Brightway database by activity name, with optional unit, location, and partial-name filters.
Outputs/results_baseline.csv: results from the repeated-LCI baseline.Outputs/results_optimized.csv: results from the one-LCI optimized implementation.Outputs/methods_list.txt: LCIA method identifiers generated bySearcher/methods.py.
Generated results depend on the selected Brightway project, ecoinvent version and system model, and installed LCIA methods. Do not commit licensed ecoinvent datasets or local Brightway project data.