Skip to content

Memory increase until out-of-memory during Monte Carlo simulation via IPC server #41

@jonathanlarochelle

Description

@jonathanlarochelle

When running a Monte Carlo simulation via the IPC Server, the memory increases after each iteration until no memory is available. This does not occur using the app.

Version: 2.5.0
Operating system: Windows 11 Enterprise, 24H2
Python: 3.13
olca-ipc: 2.4.0
olca_schema: 2.4.0

Here is an example with a random process from Ecoinvent 3.8 (cutoff, unit).

Expected behavior (via the app)

  1. Open the database
  2. Create a product system from a process (any process will do)
  3. Select the new product system
  4. Click on "Calculate"
    • Impact assessment method = any
    • Monte Carlo Simulation
    • Number of iterations = 1000
  5. Click on "Finish"
  6. In the Monte Carlo Simulation window, click on "Start".
  7. Observe that the RAM for openLCA.exe stays constant.

Observed behavior (via IPC and Python)
On the app:

  1. Open the database
  2. Create a product system from a process (any process will do)
  3. Click on "Tools" > "Developer tools" > "IPC Server" > Start

On Python:

  1. Execute the following code and observe that the RAM for openLCA.exe increases with every iteration. Stopping the execution of the code or stopping the IPC server does not lower the memory.
import olca_ipc as ipc
import olca_schema as o
import time

client = ipc.Client()

# schedule a first iteration
print("run iteration 1")
result = client.simulate(
    o.CalculationSetup(
        target=o.Ref(
            ref_type=o.RefType.ProductSystem,
            id="7887d5df-9401-415f-be4a-e4b2e946d8a6",
        ),
        impact_method=o.Ref(id="2e5cd15d-d539-3141-a950-56d75df9d579"),
    )
)
result.wait_until_ready()

# collect the values from 999 more iterations
for i in range(0, 999):
    print(f"run iteration {i+2}")
    iteration_start = time.time()
    result.simulate_next()
    result.wait_until_ready()
    print(f"\ttime = {time.time()-iteration_start} seconds")

result.dispose()

Workaround
I found that setuping and running a series of 1-iteration Monte Carlo Simulations keeps the memory under control. However, this takes longer than running the Monte Carlo in the expected way (~7x longer per iteration). Observe that the RAM usage for openLCA.exe stays constant.

import olca_ipc as ipc
import olca_schema as o
import time

client = ipc.Client()

# Run 1000 iterations
for i in range(0, 1000):
    print(f"run iteration {i+1}")
    iteration_start = time.time()
    result = client.simulate(
        o.CalculationSetup(
            target=o.Ref(
                ref_type=o.RefType.ProductSystem,
                id="7887d5df-9401-415f-be4a-e4b2e946d8a6",
            ),
            impact_method=o.Ref(id="2e5cd15d-d539-3141-a950-56d75df9d579"),
        )
    )
    result.wait_until_ready()
    result.dispose()
    print(f"\ttime = {time.time()-iteration_start} seconds")

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions