Closed SamMugel closed 4 years ago
The parallel computing backend options for the simulated device don't seem to do anything.
This issue was already pointed out here:
https://quantumcomputing.stackexchange.com/questions/9209/how-to-use-parallel-executions-of-circuits
Here is the code I ran. I observed no significant differences between runs
from qiskit import BasicAer from qiskit.aqua import QuantumInstance from qiskit.finance.ising import portfolio from qiskit.finance.data_providers import RandomDataProvider from qiskit.aqua.algorithms import VQE from qiskit.aqua.components.optimizers import COBYLA from qiskit.aqua.components.variational_forms import RY import time import matplotlib.pyplot as plt from matplotlib import rcParams rcParams.update({'figure.autolayout': True}) # set number of assets (= number of qubits) num_assets = 1 # Generate expected return and covariance matrix from (random) time-series stocks = [("TICKER%s" % i) for i in range(num_assets)] data = RandomDataProvider(tickers=stocks) data.run() mu = data.get_period_return_mean_vector() sigma = data.get_period_return_covariance_matrix() q = 0.5 # set risk factor budget = int(num_assets / 2) # set budget penalty = num_assets # set parameter to scale the budget penalty term qubitOp, offset = portfolio.get_operator(mu, sigma, q, budget, penalty) backend = BasicAer.get_backend("statevector_simulator") seed = 50 cobyla = COBYLA(maxiter=50) def run_vqe(backend_options, max_evals_grouped): ry = RY(qubitOp.num_qubits, depth=3, entanglement="full") vqe = VQE(qubitOp, ry, cobyla, max_evals_grouped=max_evals_grouped) vqe.random_seed = seed quantum_instance = QuantumInstance( backend=backend, seed_simulator=seed, seed_transpiler=seed, backend_options=backend_options, ) vqe.run(quantum_instance, backend_options=backend_options) num_processors = 4 backend_options = { "no parallel": {"max_parallel_threads": 1, "max_parallel_experiments": 1, "max_parallel_shots": 1}, "parallel shots": {"max_parallel_threads": 4, "max_parallel_experiments": 1, "max_parallel_shots": 4}, "parallel exp": {"max_parallel_threads": 4, "max_parallel_experiments": 4, "max_parallel_shots": 1}, } runtimes = [] for key, options in backend_options.items(): for max_evals_grouped in (1, num_processors): start = time.process_time() run_vqe(options, max_evals_grouped) runtime = time.process_time() - start runtimes.append(runtime)
Only the Aer simulator has those parallel options not the BasicAer simulator.
from qiskit import ~Basic~Aer ... backend = ~Basic~Aer.get_backend("statevector_simulator")
Informations
What is the current behavior?
The parallel computing backend options for the simulated device don't seem to do anything.
This issue was already pointed out here:
https://quantumcomputing.stackexchange.com/questions/9209/how-to-use-parallel-executions-of-circuits
Steps to reproduce the problem
Here is the code I ran. I observed no significant differences between runs
What is the expected behavior?
Suggested solutions