2
$\begingroup$

I am trying to run multiple circuits in parallel using the documentation here. My codes are:

from qiskit import QuantumCircuit
from qiskit.circuit.quantumregister import QuantumRegister
from qiskit.circuit.classicalregister import ClassicalRegister
from qiskit import Aer, execute
from qiskit.providers.aer.backends import QasmSimulator

def apply_measurement(circ):
    c = ClassicalRegister(len(circ.qubits), 'c')
    meas = QuantumCircuit(circ.qregs[0], c)
    meas.barrier(circ.qubits)
    meas.measure(circ.qubits,c)
    qc = circ+meas
    return qc

qr = QuantumRegister(4)
circ = QuantumCircuit(qr)
for i in range(4):
    for j in range(i+1,4):
        circ.cx(i,j)

qc = apply_measurement(circ)
circuits = [qc for i in range(3)]
num_shots = int(1e6)

backend = Aer.get_backend('qasm_simulator')
backend_options = {'method': 'automatic','max_parallel_threads':1,'max_parallel_experiments':1,'max_parallel_shots':1}
noiseless_qasm_result = execute(circuits, backend, shots=num_shots, backend_options=backend_options).result()
print(noiseless_qasm_result)

backend = Aer.get_backend('qasm_simulator')
backend_options = {'method': 'automatic','max_parallel_threads':1,'max_parallel_experiments':3,'max_parallel_shots':1}
noiseless_qasm_result = execute(circuits, backend, shots=num_shots, backend_options=backend_options).result()
print(noiseless_qasm_result)

Where I am running three copies of the same circuit. I did not see any changes in the result object obtained, nor is there any runtime improvement. Both take about 10 seconds. What should be the proper way to run those three circuits in parallel?

$\endgroup$

1 Answer 1

2
$\begingroup$

Try changing your max_parallel_threads value to more than 1.

Quoting from the documentation:

max_parallel_threads (int): Sets the maximum number of CPU cores used by OpenMP for parallelization. If set to 0 the maximum will be set to the number of CPU cores (Default: 0).

max_parallel_experiments (int): Sets the maximum number of qobj experiments that may be executed in parallel up to the max_parallel_threads value. If set to 1 parallel circuit execution will be disabled. If set to 0 the maximum will be automatically set to max_parallel_threads (Default: 1).

$\endgroup$
4
  • $\begingroup$ That does change the parallel_state_update, but there still is no runtime improvement. It still takes about 10 seconds to run. $\endgroup$
    – FSeed
    Dec 15, 2019 at 4:19
  • $\begingroup$ Could you also change the max_parallalel_shots and check $\endgroup$
    – ss09
    Dec 15, 2019 at 4:21
  • $\begingroup$ Another option I would try is to change everything to defaults and check the behavior according to the documentation. $\endgroup$
    – ss09
    Dec 15, 2019 at 4:22
  • 1
    $\begingroup$ It seems like max_parallel_experiments is the only parameter that does something. I get the best runtime when set max_parallel_threads to be the default 0 and max_parallel_shots to be the default 1. Setting max_parallel_experiments to be 0 does nothing, you have to explicitly set it to number of CPUs. The documentation is wrong for the default cases. $\endgroup$
    – FSeed
    Dec 15, 2019 at 4:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.