2021-11-08 08:35:18 -06:00
|
|
|
|
2021-11-08 11:56:52 -06:00
|
|
|
#import required libraries
|
2021-11-08 08:35:18 -06:00
|
|
|
from Adafruit_Thermal import *
|
|
|
|
from qiskit import QuantumCircuit, execute, Aer, IBMQ
|
|
|
|
import qiskit as q
|
|
|
|
from qiskit.tools.monitor import job_monitor, backend_overview
|
|
|
|
from qiskit.providers.ibmq import least_busy
|
|
|
|
import time
|
|
|
|
|
2021-11-08 11:56:52 -06:00
|
|
|
#You can add remove or edit prompts from this list.
|
|
|
|
DeathList = ["Bees","Sour milk","Cuteness","Monsters from\nthe Deep","In space,\nAlone","In Sleep","Peacefully","Toilet","Furnace","Rollercoaster","Extreme cold","Bear","Heat death of\nthe universe","Goose attack","sneezing","Boat accident"]
|
2021-11-08 08:35:18 -06:00
|
|
|
|
2021-11-08 11:56:52 -06:00
|
|
|
#load account from disk
|
|
|
|
provider = IBMQ.load_account()
|
2021-11-08 08:35:18 -06:00
|
|
|
|
2021-11-08 11:56:52 -06:00
|
|
|
#4 qubits 4 classical bits
|
|
|
|
qc = q.QuantumCircuit(4,4)
|
2021-11-08 08:35:18 -06:00
|
|
|
qc.h(0)
|
|
|
|
qc.h(1)
|
|
|
|
qc.h(2)
|
|
|
|
qc.h(3)
|
|
|
|
#qc.h(4)
|
|
|
|
qc.measure([0, 1, 2, 3],[0, 1, 2, 3])
|
|
|
|
|
2021-11-08 11:56:52 -06:00
|
|
|
#Print all avaliable quantum computers
|
2021-11-08 08:35:18 -06:00
|
|
|
print("\nAll backends overview:\n")
|
|
|
|
backend_overview()
|
2021-11-08 11:56:52 -06:00
|
|
|
#find the least busy quantum computer and print it.
|
2021-11-08 08:35:18 -06:00
|
|
|
backend = least_busy(provider.backends(n_qubits=5, operational=True, simulator=False))
|
|
|
|
print("\nLeast busy 5-qubit backend:", backend.name())
|
|
|
|
#backend = provider.get_backend('ibmq_belem')
|
|
|
|
|
2021-11-08 11:56:52 -06:00
|
|
|
#number of shots for the quantum computer. We are only throwing the dice once.
|
2021-11-08 08:35:18 -06:00
|
|
|
shots = 1
|
2021-11-08 11:56:52 -06:00
|
|
|
#execute the circuit on the avaliable quantum computer
|
2021-11-08 08:35:18 -06:00
|
|
|
job = execute(qc, backend, shots=shots, memory=True)
|
2021-11-08 11:56:52 -06:00
|
|
|
#monitor the process
|
2021-11-08 08:35:18 -06:00
|
|
|
job_monitor(job)
|
2021-11-08 11:56:52 -06:00
|
|
|
#get the result and store it in result.
|
2021-11-08 08:35:18 -06:00
|
|
|
result = job.result()
|
2021-11-08 11:56:52 -06:00
|
|
|
#get the qubits from the result and store it in dice
|
2021-11-08 08:35:18 -06:00
|
|
|
dice=result.get_memory(qc)
|
2021-11-08 11:56:52 -06:00
|
|
|
#print the received qubits
|
2021-11-08 08:35:18 -06:00
|
|
|
print("Received qubits: " + dice[0])
|
2021-11-08 11:56:52 -06:00
|
|
|
#the int command here will turn the binary to a decimal
|
2021-11-08 08:35:18 -06:00
|
|
|
print("Quantum dice roll result: " + str(int(dice[0],2)))
|
|
|
|
time.sleep(4)
|
2021-11-08 11:56:52 -06:00
|
|
|
#define and wake the Thermal printer
|
2021-11-08 08:35:18 -06:00
|
|
|
printer = Adafruit_Thermal("/dev/serial0", 9600, timeout=5)
|
|
|
|
printer.wake()
|
|
|
|
|
2021-11-08 11:56:52 -06:00
|
|
|
#print the result
|
2021-11-08 08:35:18 -06:00
|
|
|
print("Printing Result..")
|
|
|
|
printer.justify('C')
|
|
|
|
printer.feed(1)
|
2021-11-08 11:56:52 -06:00
|
|
|
printer.setSize('L')
|
2021-11-08 08:35:18 -06:00
|
|
|
printer.setSize('M')
|
|
|
|
printer.println("This is how")
|
|
|
|
printer.setSize('L')
|
|
|
|
printer.println("YOU DIE")
|
|
|
|
import gfx.arrow as arrow
|
|
|
|
printer.printBitmap(arrow.width, arrow.height, arrow.data)
|
|
|
|
printer.setSize("L")
|
|
|
|
printer.println("---------------")
|
|
|
|
printer.println(DeathList[(int(dice[0],2))])
|
|
|
|
printer.println("---------------")
|
|
|
|
printer.feed(1)
|
|
|
|
printer.setSize("S")
|
|
|
|
printer.print("Your Qubits: ")
|
|
|
|
printer.println(dice)
|
|
|
|
|
|
|
|
printer.feed(3)
|
|
|
|
|
|
|
|
printer.sleep() # Tell printer to sleep
|
|
|
|
#printer.wake() # Call wake() before printing again, even if reset
|
|
|
|
printer.setDefault() # Restore printer to defaults
|