Rolling Dice

Introduction to Quantum Computing

Create a Quantum Circuit to Simulate Rolling a Single Die

Overview:

The goal is to create a simple quantum circuit to simulate the rolling of a die.  This will require a series of zero's (0) and one's (1) to map the six (6) possible values on a die.  

Remember, computers work with zero's (0) and one's (1).  So, one bit or qubit, when measured, can have two values - either a 0 or a 1.  Two bits or qubits would provide four values - 00, 01, 10, or 11.  Three bits or qubits will provide eight values -- 000, 001, 010, 011, 100, 101, 110, or 111.  

But a die needs only six values and 2 bits/qubits provides 4 values and 3 bits/qubits provides 8 values.  So, this strategy would not work.  

Another option to consider would be to run the quantum circuit six (6) times and record the results by adding up the number of one's (1) obtained to represent the value of the die coming up.  For example, if the set of numbers such as this occurred, ['1', '1', '0', '0', '1', '0'], then the three ones would represent a roll of the die and a three coming up.  

Quantum Circuit:

One way to accomplish this would be to create a circuit with a Hadamard gate and measure it.  Then run the circuit six times and record the outcome.  

from ibm_quantum_widgets import CircuitComposer
from qiskit import QuantumRegister, ClassicalRegister, QuantumCircuit, assemble, Aer
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.draw()

This would create a circuit that looks like ...

aer_sim = Aer.get_backend('aer_simulator')

qobj = assemble(circuit, shots=6)
job = aer_sim.run(qobj, memory=True)
samples = job.result().get_memory()
print(samples)

The output would be a series of numbers such as ... 

['1', '1', '0', '0', '0', '0']

References: