added comments
This commit is contained in:
		
							parent
							
								
									05522f2c7d
								
							
						
					
					
						commit
						798eb2f15b
					
				@ -1,20 +1,20 @@
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
 | 
					#import required libraries
 | 
				
			||||||
from Adafruit_Thermal import *
 | 
					from Adafruit_Thermal import *
 | 
				
			||||||
from qiskit import QuantumCircuit, execute, Aer, IBMQ
 | 
					from qiskit import QuantumCircuit, execute, Aer, IBMQ
 | 
				
			||||||
import qiskit as q
 | 
					import qiskit as q
 | 
				
			||||||
from qiskit.tools.monitor import job_monitor, backend_overview
 | 
					from qiskit.tools.monitor import job_monitor, backend_overview
 | 
				
			||||||
from qiskit.providers.ibmq import least_busy
 | 
					from qiskit.providers.ibmq import least_busy
 | 
				
			||||||
import time
 | 
					import time
 | 
				
			||||||
import warnings
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
warnings.filterwarnings("ignore")
 | 
					#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"]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#load account from disk
 | 
				
			||||||
 | 
					provider = IBMQ.load_account()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
DeathList = ["Bees","Sour milk","Natural Causes","Monsters from\nthe Deep","In space,\nAlone","In Sleep","Peacefully","Pooping","Furnace","Rollercoaster","Extreme cold","Bear","Heat death of\nthe universe","Goose attack","sneezing","Boat accident"]
 | 
					#4 qubits 4 classical bits
 | 
				
			||||||
 | 
					qc = q.QuantumCircuit(4,4)
 | 
				
			||||||
provider = IBMQ.load_account() #load account from disk
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
qc = q.QuantumCircuit(4,4) #5 qubits 5 classical bits
 | 
					 | 
				
			||||||
qc.h(0)
 | 
					qc.h(0)
 | 
				
			||||||
qc.h(1)
 | 
					qc.h(1)
 | 
				
			||||||
qc.h(2)
 | 
					qc.h(2)
 | 
				
			||||||
@ -22,46 +22,48 @@ qc.h(3)
 | 
				
			|||||||
#qc.h(4)
 | 
					#qc.h(4)
 | 
				
			||||||
qc.measure([0, 1, 2, 3],[0, 1, 2, 3])
 | 
					qc.measure([0, 1, 2, 3],[0, 1, 2, 3])
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#Print all avaliable quantum computers
 | 
				
			||||||
print("\nAll backends overview:\n")
 | 
					print("\nAll backends overview:\n")
 | 
				
			||||||
backend_overview()
 | 
					backend_overview()
 | 
				
			||||||
 | 
					#find the least busy quantum computer and print it.
 | 
				
			||||||
backend = least_busy(provider.backends(n_qubits=5, operational=True, simulator=False))
 | 
					backend = least_busy(provider.backends(n_qubits=5, operational=True, simulator=False))
 | 
				
			||||||
print("\nLeast busy 5-qubit backend:", backend.name())
 | 
					print("\nLeast busy 5-qubit backend:", backend.name())
 | 
				
			||||||
#backend = provider.get_backend('ibmq_belem')
 | 
					#backend = provider.get_backend('ibmq_belem')
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#number of shots for the quantum computer. We are only throwing the dice once.
 | 
				
			||||||
shots = 1
 | 
					shots = 1
 | 
				
			||||||
 | 
					#execute the circuit on the avaliable quantum computer
 | 
				
			||||||
job = execute(qc, backend, shots=shots, memory=True)
 | 
					job = execute(qc, backend, shots=shots, memory=True)
 | 
				
			||||||
 | 
					#monitor the process
 | 
				
			||||||
job_monitor(job)
 | 
					job_monitor(job)
 | 
				
			||||||
 | 
					#get the result and store it in result.
 | 
				
			||||||
result = job.result()
 | 
					result = job.result()
 | 
				
			||||||
 | 
					#get the qubits from the result and store it in dice
 | 
				
			||||||
dice=result.get_memory(qc)
 | 
					dice=result.get_memory(qc)
 | 
				
			||||||
 | 
					#print the received qubits
 | 
				
			||||||
print("Received qubits: " + dice[0])
 | 
					print("Received qubits: " + dice[0])
 | 
				
			||||||
 | 
					#the int command here will turn the binary to a decimal
 | 
				
			||||||
print("Quantum dice roll result: " + str(int(dice[0],2)))
 | 
					print("Quantum dice roll result: " + str(int(dice[0],2)))
 | 
				
			||||||
time.sleep(4)
 | 
					time.sleep(4)
 | 
				
			||||||
 | 
					#define and wake the Thermal printer
 | 
				
			||||||
printer = Adafruit_Thermal("/dev/serial0", 9600, timeout=5)
 | 
					printer = Adafruit_Thermal("/dev/serial0", 9600, timeout=5)
 | 
				
			||||||
printer.wake()
 | 
					printer.wake()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#print the result
 | 
				
			||||||
print("Printing Result..")
 | 
					print("Printing Result..")
 | 
				
			||||||
printer.justify('C')
 | 
					printer.justify('C')
 | 
				
			||||||
printer.feed(1)
 | 
					printer.feed(1)
 | 
				
			||||||
printer.setSize('L')   # Set type size, accepts 'S', 'M', 'L'
 | 
					printer.setSize('L')
 | 
				
			||||||
#printer.println("---------------")
 | 
					 | 
				
			||||||
printer.setSize('M')
 | 
					printer.setSize('M')
 | 
				
			||||||
printer.println("This is how")
 | 
					printer.println("This is how")
 | 
				
			||||||
printer.setSize('L')
 | 
					printer.setSize('L')
 | 
				
			||||||
printer.println("YOU DIE")
 | 
					printer.println("YOU DIE")
 | 
				
			||||||
import gfx.arrow as arrow
 | 
					import gfx.arrow as arrow
 | 
				
			||||||
printer.printBitmap(arrow.width, arrow.height, arrow.data)
 | 
					printer.printBitmap(arrow.width, arrow.height, arrow.data)
 | 
				
			||||||
#printer.println("---------------")
 | 
					 | 
				
			||||||
printer.setSize("L")
 | 
					printer.setSize("L")
 | 
				
			||||||
#printer.justify('L')
 | 
					 | 
				
			||||||
#printer.feed(1)
 | 
					 | 
				
			||||||
printer.println("---------------")
 | 
					printer.println("---------------")
 | 
				
			||||||
#printer.println(DeathList[0])
 | 
					 | 
				
			||||||
printer.println(DeathList[(int(dice[0],2))])
 | 
					printer.println(DeathList[(int(dice[0],2))])
 | 
				
			||||||
printer.println("---------------")
 | 
					printer.println("---------------")
 | 
				
			||||||
#printer.println("Old Age,\nSurrounded by\nLoved Ones")
 | 
					 | 
				
			||||||
#printer.println("\uD83D\uDC80")
 | 
					 | 
				
			||||||
printer.feed(1)
 | 
					printer.feed(1)
 | 
				
			||||||
printer.setSize("S")
 | 
					printer.setSize("S")
 | 
				
			||||||
printer.print("Your Qubits: ")
 | 
					printer.print("Your Qubits: ")
 | 
				
			||||||
@ -69,7 +71,6 @@ printer.println(dice)
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
printer.feed(3)
 | 
					printer.feed(3)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#testing
 | 
					 | 
				
			||||||
printer.sleep()      # Tell printer to sleep
 | 
					printer.sleep()      # Tell printer to sleep
 | 
				
			||||||
#printer.wake()       # Call wake() before printing again, even if reset
 | 
					#printer.wake()       # Call wake() before printing again, even if reset
 | 
				
			||||||
printer.setDefault() # Restore printer to defaults
 | 
					printer.setDefault() # Restore printer to defaults
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
		Reference in New Issue
	
	Block a user