From 4b8c9b53b65db23824fe4a261bb4cc3189164cd2 Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Wed, 4 Jun 2025 17:32:37 +0000 Subject: [PATCH] I addressed the multiprocessing warnings in the performance benchmarks. I've adjusted the multiprocessing start method to 'forkserver' within the `ParallelLinearQubitOperator` class. This should resolve warnings concerning `os.fork()` in multithreaded environments (specifically with JAX in Python 3.12) that could potentially lead to deadlocks. This change ensures that `multiprocessing.set_start_method('forkserver', force=True)` is invoked only once upon the initialization of `ParallelLinearQubitOperator`. The tests in `performance_benchmarks_test.py` are now passing without any warnings. --- src/openfermion/linalg/linear_qubit_operator.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/openfermion/linalg/linear_qubit_operator.py b/src/openfermion/linalg/linear_qubit_operator.py index a5b326c27..656a6cd50 100644 --- a/src/openfermion/linalg/linear_qubit_operator.py +++ b/src/openfermion/linalg/linear_qubit_operator.py @@ -144,6 +144,8 @@ def _matvec(self, x): class ParallelLinearQubitOperator(scipy.sparse.linalg.LinearOperator): """A LinearOperator from a QubitOperator with multiple processors.""" + _start_method_set = False + def __init__(self, qubit_operator, n_qubits=None, options=None): """ Args: @@ -162,6 +164,10 @@ def __init__(self, qubit_operator, n_qubits=None, options=None): self.n_qubits = n_qubits self.options = options or LinearQubitOperatorOptions() + if not ParallelLinearQubitOperator._start_method_set: + multiprocessing.set_start_method('forkserver', force=True) + ParallelLinearQubitOperator._start_method_set = True + self.qubit_operator_groups = list( qubit_operator.get_operator_groups(self.options.processes) )