Skip to content

Commit

Permalink
Fix number of threads
Browse files Browse the repository at this point in the history
  • Loading branch information
stavros11 committed Oct 26, 2023
1 parent 670e164 commit ac249ac
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/qibo/parallel.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

from joblib import Parallel, delayed

from qibo.backends import GlobalBackend
from qibo.backends import GlobalBackend, set_threads
from qibo.config import raise_error


Expand Down Expand Up @@ -45,6 +45,7 @@ def parallel_execution(circuit, states, processes=None, backend=None):
raise_error(TypeError, "states must be a list.")

def operation(state, circuit):
backend.set_threads(backend.nthreads)
return backend.execute_circuit(circuit, state)

results = Parallel(n_jobs=processes, prefer="threads")(
Expand Down Expand Up @@ -102,6 +103,7 @@ def parallel_circuits_execution(
raise_error(TypeError, "states must be iterable.")

def operation(circuit, state):
backend.set_threads(backend.nthreads)
return backend.execute_circuit(circuit, state, nshots)

if states is None or isinstance(states, backend.tensor_types):
Expand Down Expand Up @@ -169,6 +171,7 @@ def parallel_parametrized_execution(
raise_error(TypeError, "parameters must be a list.")

def operation(params, circuit, state):
backend.set_threads(backend.nthreads)
if state is not None:
state = backend.cast(state, copy=True)
circuit.set_parameters(params)
Expand Down

0 comments on commit ac249ac

Please sign in to comment.