Skip to content

Commit

Permalink
fix a bug in thread management tests (#918)
Browse files Browse the repository at this point in the history
Co-authored-by: Christopher J. Wood <cjwood@us.ibm.com>
Co-authored-by: Victor Villar <59838221+vvilpas@users.noreply.github.com>
  • Loading branch information
3 people authored Sep 16, 2020
1 parent 1804cd6 commit 7856e4b
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions test/terra/backends/qasm_simulator/qasm_thread_management.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,13 +96,21 @@ def test_max_memory_settings(self):
self.assertEqual(max_mem_result, max_mem_target,
msg="Custom 'max_memory_mb' is not being set correctly.")

def available_threads(self):
""""Return the threads reported by the simulator"""
result = execute(self.dummy_circuit(1),
self.SIMULATOR,
shots=1,
backend_options=self.BACKEND_OPTS).result()
return self.threads_used(result)[0]['total']

@requires_omp
@requires_multiprocessing
def test_parallel_thread_defaults(self):
"""Test parallel thread assignment defaults"""

opts = self.BACKEND_OPTS
max_threads = multiprocessing.cpu_count()
max_threads = self.available_threads()

# Test single circuit, no noise
# Parallel experiments and shots should always be 1
Expand Down Expand Up @@ -217,7 +225,7 @@ def test_parallel_thread_assignment_priority(self):
opts['max_parallel_shots'] = 2 * custom_max_threads

# Calculate actual max threads from custom max and CPU number
max_threads = multiprocessing.cpu_count()
max_threads = self.available_threads()
if custom_max_threads > 0:
max_threads = min(max_threads, custom_max_threads)

Expand Down Expand Up @@ -324,7 +332,7 @@ def test_parallel_thread_assignment_priority(self):
def test_parallel_experiment_thread_assignment(self):
"""Test parallel experiment thread assignment"""

max_threads = multiprocessing.cpu_count()
max_threads = self.available_threads()
opts = self.BACKEND_OPTS.copy()
opts['max_parallel_experiments'] = max_threads

Expand Down Expand Up @@ -412,7 +420,7 @@ def test_parallel_experiment_thread_assignment(self):
def test_parallel_shot_thread_assignment(self):
"""Test parallel shot thread assignment"""

max_threads = multiprocessing.cpu_count()
max_threads = self.available_threads()
opts = self.BACKEND_OPTS.copy()
opts['max_parallel_shots'] = max_threads

Expand Down

0 comments on commit 7856e4b

Please sign in to comment.