Skip to content

Commit

Permalink
Merge pull request #8 from KPRoche/KPRoche-rainbowq
Browse files Browse the repository at this point in the history
Kproche rainbowq
  • Loading branch information
KPRoche authored Dec 17, 2019
2 parents ac18bd9 + e1c0db6 commit d632924
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 5 deletions.
32 changes: 28 additions & 4 deletions QuantumRaspberryTie.qiskit.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@

#Check any command arguments to see if we're forcing the emulator or changing the backend
UseEmulator = False
QWhileThinking = True
print(sys.argv)
print ("Number of arguments: ",len(sys.argv))
# look for a filename option or other starting parameters
Expand All @@ -59,6 +60,7 @@
parameter = sys.argv[p]
if type(parameter) is str:
print("Parameter ",p," ",parameter)
if '-noq' in parameter: QWhileThinking = False
if '-e' in parameter: UseEmulator = True
elif ':' in parameter:
token = parameter.split(':')[0]
Expand Down Expand Up @@ -155,6 +157,17 @@
O, O, O, X, X, O, O, O,
]

QLarray = [
[3],[4],
[10], [13],
[18], [21],
[26], [29],
[34], [37],
[43],[44],
[52],
[59],[60]
]

Arrow = [
O, O, O, X, O, O, O, O,
O, O, X, X, X, O, O, O,
Expand Down Expand Up @@ -217,6 +230,10 @@ def showqubits(pattern='0000000000000000'):

def blinky(time=20,experimentID=''):
global pixels,hues,experiment, Qlogo, showlogo
if QWhileThinking:
mask = QLarray
else:
mask = display
#resetrainbow()
count=0
GoNow=False
Expand All @@ -228,10 +245,17 @@ def blinky(time=20,experimentID=''):
# hsv_to_rgb returns 0..1 floats; convert to ints in the range 0..255
pixels = [(scale(r), scale(g), scale(b)) for r, g, b in pixels]
for p in range(64):
if p in sum(display,[]):
pass
else:
pixels[p]=[0,0,0]
#if QWhileThinking:
# if p in sum(Qlogo,[]):
# pass
# else:
# pixels[p]=[0,0,0]
# else:
if p in sum(mask,[]):
#if p in sum(display,[]):
pass
else:
pixels[p]=[0,0,0]
if (result is not None):
if (result.status=='COMPLETED'):
GoNow=True
Expand Down
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# quantum-raspberry-tie
<img src='rainbow_q.jpg' width='150' alt='display while waiting for results' style='float:right;'><br/>
Your Raspberry Pi running code on the IBM Q quantum processors via Python 3 -- with results displayed courtesy of the 8x8 LED array on a SenseHat (or SenseHat emulator)!
## Third Release: will fail over to SenseHat emulator if no SenseHat hardware is detected. You may opt to send your quantum circuit to an actual quantum processor backend at IBM Q instead of the simulator

Expand Down Expand Up @@ -84,6 +85,9 @@ To start the program, simply call it from its directory (on my system, the defau
+ *-f:qasmfilename*
will attempt to load the circuit specified in the file *qasmfilename*
if it can't load the file, will fail back to *expt.qasm*
+ *-noq*
will display the rainbow wash in the qubit pattern. Without this parameter,
the display will show a Q and run the rainbow wash across that while "thinking"

After loading libraries, the program checks the SenseHat accelerometer to see which way the Pi is oriented. If it is flat on a table, "up" will be towards the power and display connectors on the Pi. If you wish to change the display orientation, simply hold the pi in the orientation you want until an up arrow appears on the display. The program will now use that orientation until the next cycle.

Expand All @@ -106,7 +110,7 @@ To stop the program and shut down the Pi, press and hold (center press) the joy

Both versions run the display by spawning a second thread. As long as the variable *thinking* is True, the rainbow cycle is run. If it is False, the value of the string variable *maxpattern* is translated into the red and blue qubit display.

The "blinky" and "showqubits" functions in the code are generalized to work with a global *display* variable. Setting that to equal the list defining the 5-qubit processor (ibm_qx5) will result in the bowtie display, setting it equal to the 16 (ibm_qx16) will result in the 16 bit display.
The "blinky" and "showqubits" functions in the code are generalized to work with a global *display* variable. Setting that to equal the list defining the 5-qubit processor (ibm_qx5) will result in the bowtie display, setting it equal to the 16 (ibm_qx16) will result in the 16 bit display. New in version 4: the default is for blinky to use the Q logo for the rainbow "thinking" display; specifying -noq as a start parameter will use the qubit pattern instead.

## The OPENQASM code being run
The program being run on the 5-qubit processor is very simple. 5 qubits are initialized to the ground state, a Hadamard gate is applied to each one to place it into a state of full superposition, then each is measured. The net effect is a 5-bit random number generator. Only 10 shots are run, so one pattern should always randomly end up higher in the results. The code is found in the variable *qasm* in both versions. It looks like this:
Expand Down
Binary file added rainbow_q.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit d632924

Please sign in to comment.