diff --git a/qiskit/providers/aer/aerprovider.py b/qiskit/providers/aer/aerprovider.py index 31f1f900b5..7846b897bc 100644 --- a/qiskit/providers/aer/aerprovider.py +++ b/qiskit/providers/aer/aerprovider.py @@ -21,6 +21,7 @@ from .backends.statevector_simulator import StatevectorSimulator from .backends.unitary_simulator import UnitarySimulator from .backends.pulse_simulator import PulseSimulator +from .profile import optimize_backend_options class AerProvider(BaseProvider): @@ -56,6 +57,5 @@ def __str__(self): @staticmethod def optimize_backend_options(min_qubits=10, max_qubits=20, ntrials=10): """Set optimal OpenMP and fusion options for backend.""" - from .profile import optimize_backend_options return optimize_backend_options( min_qubits=min_qubits, max_qubits=max_qubits, ntrials=ntrials) diff --git a/qiskit/providers/aer/backends/aerbackend.py b/qiskit/providers/aer/backends/aerbackend.py index b2198cc6a1..80fdec4e80 100644 --- a/qiskit/providers/aer/backends/aerbackend.py +++ b/qiskit/providers/aer/backends/aerbackend.py @@ -237,14 +237,21 @@ def _run_job(self, job_id, qobj, backend_options, noise_model, validate): # Add default OpenMP options if 'statevector_parallel_threshold' not in backend_options and hasattr( self, '_statevector_parallel_threshold'): - backend_options['statevector_parallel_threshold'] = self._statevector_parallel_threshold + backend_options['statevector_parallel_threshold'] = \ + getattr(self, '_statevector_parallel_threshold') # Add default fusion options attr_postfix = '_gpu' if 'gpu' in backend_options.get('method', '') else '' if 'fusion_threshold' not in backend_options and hasattr( - self, f'_fusion_threshold{attr_postfix}'): + self, f'_fusion_threshold{attr_postfix}'): # Set fusion threshold backend_options['fusion_threshold'] = getattr(self, f'_fusion_threshold{attr_postfix}') + for i in range(1, 6): + if f'fusion_cost.{i}' not in backend_options and \ + hasattr(self, f'_fusion_cost{attr_postfix}.{i}'): + # Set cost for each + backend_options[f'fusion_cost.{i}'] = getattr(self, + f'_fusion_cost{attr_postfix}.{i}') # The new function swaps positional args qobj and job id so we do a # type check to swap them back diff --git a/qiskit/providers/aer/profile.py b/qiskit/providers/aer/profile.py index b1e0d17e64..ecbc9b85fb 100644 --- a/qiskit/providers/aer/profile.py +++ b/qiskit/providers/aer/profile.py @@ -13,7 +13,10 @@ Profile backend options for optimal performance """ from qiskit import transpile, assemble, execute +from qiskit.circuit.library import QuantumVolume from .aererror import AerError +from .backends.aerbackend import AerBackend +from .backends.qasm_simulator import QasmSimulator def optimize_backend_options(min_qubits=10, max_qubits=20, ntrials=10): @@ -49,8 +52,6 @@ def optimize_backend_options(min_qubits=10, max_qubits=20, ntrials=10): # TODO: Write profile to a local qiskitaerrc file so this doesn't # need to be re-run on a system and the following can be loaded # in the AerBackend class from the rc file if it is found - from qiskit.providers.aer.backends.aerbackend import AerBackend - if 'statevector_parallel_threshold' in profile: AerBackend._statevector_parallel_threshold = profile[ 'statevector_parallel_threshold'] @@ -66,9 +67,6 @@ def profile_parallel_threshold(min_qubits=10, max_qubits=20, ntrials=10, backend_options=None, return_ratios=False): """Evaluate optimal OMP parallel threshold for current system.""" - from qiskit.circuit.library import QuantumVolume - from qiskit.providers.aer.backends.qasm_simulator import QasmSimulator - simulator = QasmSimulator() opts = {'method': 'statevector', 'max_parallel_experiments': 1, @@ -92,10 +90,10 @@ def profile_parallel_threshold(min_qubits=10, max_qubits=20, ntrials=10, for val in [i - 1, i]: opts['statevector_parallel_threshold'] = val result = simulator.run(qobj, backend_options=opts).result() - t = 0.0 + time_taken = 0.0 for j in range(ntrials): - t += result.results[j].time_taken - times.append(t) + time_taken += result.results[j].time_taken + times.append(time_taken) # Compute ratio ratio = times[1] / times[0] @@ -123,9 +121,6 @@ def profile_fusion_threshold(min_qubits=10, max_qubits=20, ntrials=10, backend_options=None, gpu=False, return_ratios=False): """Evaluate optimal OMP parallel threshold for current system.""" - from qiskit.circuit.library import QuantumVolume - from qiskit.providers.aer.backends.qasm_simulator import QasmSimulator - simulator = QasmSimulator() opts = {'method': 'statevector', 'max_parallel_experiments': 1, @@ -157,10 +152,10 @@ def profile_fusion_threshold(min_qubits=10, max_qubits=20, ntrials=10, for val in [i, i + 1]: opts['fusion_threshold'] = val result = simulator.run(qobj, backend_options=opts).result() - t = 0.0 + time_taken = 0.0 for j in range(ntrials): - t += result.results[j].time_taken - times.append(t) + time_taken += result.results[j].time_taken + times.append(time_taken) # Compute ratio ratio = times[1] / times[0]