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')
and your second circuit:
circ2 = QuantumCircuit(1, 1)
circ2.measure(0, 0)
circ2.draw('mpl')
that is
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:
the output using a quantum simulator is:
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
.