How to order results after multi-circuit qiskit.execute parallel run?

I'm kinda new to qiskit and I find really fascinating its parallelization capabilities, then I'm trying to creating all the needed circuits for my application at once and transpile, assemble and execute them all at once using the execute method.

Basically,

qcircuits = []
# construct my circuits and append to qcircuits
# ...
backend: backend: BaseBackend = qiskit.Aer.get_backend('qasm_simulator')

n_shots = 1024
job = qiskit.execute(
qcircuits,
backend,
optimization_level=optimization_level,
shots=n_shots
)

counts = job.result().get_counts()


Nevertheless, I noticed that the job.result().get_couts() output is not deterministic as, I guess, it runs all the circuits using a parallel_map and appends in the returned list in the order they finish. Is there any way to force the execute method respecting the order of qcircuits ? If it is not the case, is there any way to label the execution results so that I can sort them myself afterwards ? Thanks in advance.

• Are you looking for a way to do so that still allows you to run in parallel? Because if not, and running the circuits sequentially is ok, you could do jobs = [qiskit.execute(qcircuit, backend, ...) for qcircuit in qcircuits] followed by counts = [job.result().get_counts() for job in jobs], but obviously, this isn't ideal for large numbers of circuits. Dec 22 '21 at 20:23

Each qiskit.QuantumCircuit has a name attribute that is also accessible through each qiskit.result.Result. So, you can do the following to match the circuits to the measurement counts after running in parallel:

for circuit in qcircuits:
print(circuit.name)

result_dict = jobs.result().to_dict()["results"]
result_counts = jobs.result().get_counts()
for i in range(len(qcircuits)):
counts = result_counts[i]
print(f"{name}: {counts}")


Before running your circuits, you could also assign your own descriptive names, e.g.

for i in range(len(qcircuits)):
qcircuits[i].name = "mycircuit"+str(i)


Edit:

Combining the ideas above to show how to order the results:

# number input circuits in ascending order
for i in range(len(qcircuits)):
qcircuits[i].name = "circuit_"+str(i)

job = qiskit.execute(qcircuits, backend, ...)

result_dict = job.result().to_dict()["results"]
result_counts = job.result().get_counts()

# initialize list to store ordered results
results_ordered = [None] * len(qcircuits)

for i in range(len(qcircuits)):