0
$\begingroup$

I'm trying to create and run parallel execution using the instruction here. However, when I implement it, it tells me that I shouldn't be using compile anymore since

DeprecationWarning: qiskit.compile() is deprecated and will be removed in Qiskit Terra 0.9. Please use qiskit.compiler.transpile() to transform circuits and qiskit.compiler.assemble() to produce a runnable qobj. DeprecationWarning)

So how do I go about doing this using the new modules? Thank you!

Here's the code in the link for creating parallel executions:

from qiskit import QuantumRegister, ClassicalRegister, QuantumCircuit
from qiskit import Aer, compile
from qiskit.backends.jobstatus import JOB_FINAL_STATES

n_qubits = 5
qc_list = []
for i in range(n_qubits):
    qr = QuantumRegister(n_qubits)
    cr = ClassicalRegister(n_qubits)
    qc = QuantumCircuit(qr, cr)
    qc.x(qr[i])
    qc.measure(qr, cr)
    qc_list.append(qc)

backend = Aer.get_backend('qasm_simulator')
qobj_list = [compile(qc, backend) for qc in qc_list]
job_list = [backend.run(qobj) for qobj in qobj_list]

while job_list:
    for job in job_list:
        if job.status() in JOB_FINAL_STATES:
            job_list.remove(job)
            print(job.result().get_counts())
$\endgroup$

1 Answer 1

4
$\begingroup$

Yes, compile is deprecated in favor of transpile and assemble. For your code, using these two new functions would look something like this:

# Add to your import statements
from qiskit.compiler import transpile, assemble

# After creating qc_list
backend = Aer.get_backend('qasm_simulator')
transpiled_circs = transpile(qc_list, backend=backend)
qobjs = assemble(transpiled_circs, backend=backend)
job_info = backend.run(qobjs)

# To get the results
for circ_index in range(len(transpiled_circs)):
    print(job_info.result().get_counts(transpiled_circs[circ_index]))

About the code

qc_list is still a list of circuits. transpiled_circs is a list of transpiled circuits from qc_list. qobjs is a single qobj with information for each circuit in transpiled_circs. job_info is job that is returned from backend.run(qobjs) it is a single job object.

Since job_info is a single job, the results for each circuit are located job_info.result().get_counts(). You just need to provide get_counts with a circuit to return the specific results for that circuit. That is what the for loop provides.

About transpile and assemble

transpile takes in a QuantumCircuit or list of QuantumCircuits and runs through certain PassManagers which optimize the circuit for the specific backend given. This can include rearranging gates, compressing sets of gates, deleting unnecessary gates, rearranging CX connections, etc. It returns a new circuit, or list of circuits

assemble takes in a QuantumCircuit of a list of QuantumCircuits and compresses them into a qobj

The source code for both functions can be found here: transpile, assemble

$\endgroup$

Your Answer

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

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