1
$\begingroup$

I want to run a simple circuit with one qubit and a hadamard gate on a Quantum Machine. I want the result of every shot in a list. It works with a simulator and the get_memory function but this function can‘t be used on IBM Quantum Machines. Maybe somebody can help me

Thanks :)

$\endgroup$
1
  • 1
    $\begingroup$ To my understanding the memory feature is not available for all the devices but it is available for some. I think you can see which of your devices support it by using the backends method filtering. Also remember to set memory=True when you call run. $\endgroup$ Dec 15, 2023 at 16:40

1 Answer 1

0
$\begingroup$

Some backends do support the memory function. First check which all backends you have access to , using:

# Initialize your account 
from qiskit_ibm_runtime import QiskitRuntimeService
service = QiskitRuntimeService()
 
service.backends()

Then shortlist the least_busy and the one with memory, using this:

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

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

This will give you the least busy backend that has the memory function.

Now just write the code and run, like how you do in simulator:

q = QuantumRegister(1)
c = ClassicalRegister(1)
circ = QuantumCircuit(q, c)

circ.h(q)

circ.measure(q,c)

job = execute(circ, Aer.get_backend('qasm_simulator'), shots=100, memory=True)
data = job.result().get_memory()
print(data)

and now for the actual quantum backend:

sampler = Sampler(session=backend)
job = sampler.run(circ,shots=10,memory=True)
data = job.result().get_memory()
print(data)

This will give you what you want.

$\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.