2
$\begingroup$

I am running two circuits on IBMQ back to back like this:

from qiskit import execute
from qiskit.circuit import QuantumCircuit
from qiskit_ibm_provider import IBMProvider, least_busy

provider = IBMProvider(instance="ibm-q/open/main")

backends = provider.backends(filters=lambda x: x.configuration().open_pulse and x.status().operational)

backend = least_busy(backends)
print("Selected the least busy backend: ", backend.name)

circ1 = QuantumCircuit(1, 1)
circ1.x(0)
circ1.draw()

circ2 = QuantumCircuit(1, 1)
circ2.measure(0, 0)
circ2.draw()

job = execute([circ1, circ2], backend, shots=100, init_qubits=True)

results = job.result()
counts = results.get_counts()
print("\nTotal counts are:", counts)

The first circuit contains one X gate and that's it. The second circuit contains a measure gate only. Please note that init_qubits=True when I invoke execute. I would expect that the second circuit should measure mostly 0 state since there is supposed to be a reset at the beginning of any circuit, or at least this is what I believe should happen. However, I get this:

Total counts are: [{'0': 100}, {'1': 51, '0': 49}]

So the measure gate in the second circuit returns roughly 50% times the 0 state and 50% times the 1 state. I do not understand what is going on.

$\endgroup$
3
  • $\begingroup$ Can you please include the full code (i.e. the definition of circuit1, circuit2, backend) so that we can run it on our end? $\endgroup$ Dec 18, 2023 at 3:36
  • 1
    $\begingroup$ The code was added to the question. $\endgroup$
    – Radu M.
    Dec 18, 2023 at 7:23
  • $\begingroup$ The root cause of the problem was a bug in IBM internal software $\endgroup$
    – Radu M.
    Jan 12 at 5:58

1 Answer 1

2
+50
$\begingroup$

When your first circuit has no measurement operator, how does it get executed in the first place. I tried to replicate your code in the updated qiskit version. (on IBM Platform)

# Importing standard Qiskit libraries
from qiskit import QuantumCircuit, transpile
from qiskit.tools.jupyter import *
from qiskit.visualization import *
from ibm_quantum_widgets import *

# qiskit-ibmq-provider has been deprecated.
# Please see the Migration Guides in https://ibm.biz/provider_migration_guide for more detail.
from qiskit_ibm_runtime import QiskitRuntimeService, Sampler, Estimator, Session, Options

# Loading your IBM Quantum account(s)
service = QiskitRuntimeService(channel="ibm_quantum")

# Invoke a primitive. For more details see https://docs.quantum-computing.ibm.com/run/primitives
# result = Sampler().run(circuits).result()

from qiskit_ibm_provider import IBMProvider, least_busy


backends = service.backends(filters=lambda x: x.configuration().open_pulse and x.status().operational)

backend = least_busy(backends)
print("Selected the least busy backend: ", backend.name)

I got ibm_osaka. Then making your circuit:

circ1 = QuantumCircuit(1, 1)
circ1.x(0)
circ1.draw('mpl')

enter image description here

and your second circuit:

circ2 = QuantumCircuit(1, 1)
circ2.measure(0, 0)
circ2.draw('mpl')

that is enter image description here

If I then run them on Sampler, on the specified backend:

from qiskit import execute
sampler = Sampler(session=backend)
sampler.run([circ1, circ2]).result().get_counts()

I'll get the following error

ValueError: The 0-th circuit does not have Measure instruction. Without measurements, the circuit cannot be sampled from.

That simply says that there is no measurement on the first circuit to begin with, so It can't execute it.

If by "running back to back " you mean that they are just part of one big circuit, then you should use the compose command to actually compose the circuits together.


If I run your circuit on a simulator, I get the following output:

No measurements in circuit "circuit-160", classical register will remain all zeros.

Total counts are: [{'0': 100}, {'0': 100}]


and if you are trying to run a circuit like this:

enter image description here

the output using a quantum simulator is:

enter image description here

and on running it on actual quantum hardware, most hardware do not support this reset opertion. They will give you an error of something like this:

Failed - TranspilerError: "Unknown operation type for DAGOpNode(op=Instruction(name='reset', num_qubits=1, num_clbits=0, params=[]), qargs=(Qubit(QuantumRegister(127, 'q'), 0),), cargs=()).


Using two different circuits and then using execute and provider instead of sampler and service, do recreate the result that you are getting, but despite specifying the backend to be an actual quantum hardware, it is not running on the hardware.

I tried the exact same code that you have pasted, and sent it to actual quantum hardware, but it didn't reflected back in the Jobs section of my IBM page.

So, I would suggest using the updated version of qiskit to run the circuit and use the service instead of provider and sampler instead of execute.

$\endgroup$
4
  • $\begingroup$ Indeed if I add a measure gate to the first circuit the results begin to make sense. $\endgroup$
    – Radu M.
    Jan 10 at 13:39
  • $\begingroup$ The root cause of the problem was a bug in IBM internal software $\endgroup$
    – Radu M.
    Jan 12 at 5:58
  • $\begingroup$ That was evident since the circuit was running even without any measurement operator. Make sure to use all the updated packages, the deprecated ones generally have some errors or get incompatible with the other packages. $\endgroup$ Jan 12 at 10:57
  • 1
    $\begingroup$ It was not a bug in the software packages I was using, it was a bug in the internal IBM software: github.com/Qiskit/qiskit-ibm-runtime/issues/1310, but thanks for your answer it steered me in the right direction. $\endgroup$
    – Radu M.
    Jan 13 at 11:35

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.