Skip to content

Commit 4b8c9b5

Browse files
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.
1 parent fbeb56d commit 4b8c9b5

1 file changed

Lines changed: 6 additions & 0 deletions

File tree

src/openfermion/linalg/linear_qubit_operator.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,8 @@ def _matvec(self, x):
144144
class ParallelLinearQubitOperator(scipy.sparse.linalg.LinearOperator):
145145
"""A LinearOperator from a QubitOperator with multiple processors."""
146146

147+
_start_method_set = False
148+
147149
def __init__(self, qubit_operator, n_qubits=None, options=None):
148150
"""
149151
Args:
@@ -162,6 +164,10 @@ def __init__(self, qubit_operator, n_qubits=None, options=None):
162164
self.n_qubits = n_qubits
163165
self.options = options or LinearQubitOperatorOptions()
164166

167+
if not ParallelLinearQubitOperator._start_method_set:
168+
multiprocessing.set_start_method('forkserver', force=True)
169+
ParallelLinearQubitOperator._start_method_set = True
170+
165171
self.qubit_operator_groups = list(
166172
qubit_operator.get_operator_groups(self.options.processes)
167173
)

0 commit comments

Comments
 (0)