How to apply gates based on a random decision on the IBM quantum computer?

I want to run a circuit on an IBM quantum computer, and this circuit involves gates that are either applied or not based on a (classical) random decision.

As a minimal example, imagine a circuit with one qubit initialized in the state $$|0\rangle$$. In each shot we generate a random bit (0 or 1 with equal probability); apply a Hadamard if the bit is 1; and then measure in the $$Z$$ basis. One would expect an outcome 0 (1) 75% (25%) of the time.

One way to do this would be to make the classical random decisions locally, construct many deterministic circuits, and for each of them send a job with 1 shot each to the IBM computer. Unfortunately, the circuit I want to run involves a large number of random decisions, and the allowance on the IBM platforms is based on number of jobs rather than total number of shots, so I'll run out very quickly.

I hoped that it would be possible to use the conditional operation feature of qiskit to do this, but I can't work out how to randomize the values of the classical register. Does anyone know how I can do this?

• I'm leaving this as a comment rather than an answer because I'm not sure this would work, but since qiskit allows mid-circuit measurements, can't you just apply an Hadamard gate on a quantum register, measure it and condition your gates on the outcome? Sep 17 '21 at 17:04

Based on the idea given by @Tristan Nemoz, you can do something like this in Qiskit code:

from qiskit import QuantumRegister, ClassicalRegister, QuantumCircuit
from numpy import pi

qreg_q = QuantumRegister(1, 'q')
creg_c = ClassicalRegister(1, 'c')
circuit = QuantumCircuit(qreg_q, creg_c)

circuit.h(qreg_q)
circuit.measure(qreg_q, creg_c)
circuit.h(qreg_q).c_if(creg_c, 1)
circuit.measure(qreg_q, creg_c)

In Qiskit Composer you can do like this The results look like this 