2
$\begingroup$

How can I know the number of qubits used in a job in qiskit?

I can always do something like

retrieve_job = provider.backend.retrieve_job(job_id)
retrieve_job.circuits()[i].draw(),

where i is the ith-circuit. However, if I have a large number of circuits in a job, I don't want to check manually which qubits my circuit used (I am sure that before the transpilation I never use all of the qubits).

$\endgroup$
7
  • $\begingroup$ To clarify, you're trying to find the qubits that were used for each circuit sent to the job? Could you maybe give an example of a circuit before/after transpilation, and use that to describe the metric you're looking for? $\endgroup$
    – ryanhill1
    Jun 13, 2022 at 14:19
  • $\begingroup$ Uhmm it's not even a metric, I just would like to check which qubits were used after the transpilation. My guess is that there should be a built-in method to say "you used qubits 12,4 of the device ibmq_something, but I may be wrong in that the method exists. $\endgroup$ Jun 13, 2022 at 18:38
  • $\begingroup$ Ohh, I see, so for example, you submitted a job that used a 2-qubit circuit to a 5-qubit QPU, you're interested in finding out which 2 qubits were used on the actual hardware to execute the job. Is that correct? $\endgroup$
    – ryanhill1
    Jun 13, 2022 at 18:45
  • $\begingroup$ Yes, exactly, that's it. $\endgroup$ Jun 13, 2022 at 19:42
  • $\begingroup$ Got it. I'm not personally aware of any feature that enables this, but perhaps a qiskit developer would know more .. $\endgroup$
    – ryanhill1
    Jun 13, 2022 at 22:45

1 Answer 1

1
$\begingroup$

You could write a function that outputs this exact quantity. This can be achieved by just reading the documentation provided by qiskit. In case that the measurements are not applied on every qubit but only on the active ones, this function for example would provide you valid results:

def find_active_qubits(circuit):

   dag = circuit_to_dag(circuit)
   active_qubits = [qubit.index for qubit in circuit.qubits 
                    if qubit not in dag.idle_wires()]

   return active_qubits
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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