Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix a bug in thread management tests #918

Merged
merged 3 commits into from
Sep 16, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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