1
$\begingroup$

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?

$\endgroup$
1
  • 2
    $\begingroup$ 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? $\endgroup$ Sep 17 at 17:04
0
$\begingroup$

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[0])
circuit.measure(qreg_q[0], creg_c[0])
circuit.h(qreg_q[0]).c_if(creg_c, 1)
circuit.measure(qreg_q[0], creg_c[0])

In Qiskit Composer you can do like this Randomized Conditional Hadamard

The results look like this enter image description here

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