%matplotlib notebook

import pew # setting up tools for the pewpew
from microqiskit import QuantumCircuit, simulate # setting up tools for quantum

pew.init() # initialize the game engine...
screen = pew.Pix() # ...and the screen

qc = QuantumCircuit(2,2) # create an empty circuit with two qubits and two output bits

# create circuits with the required measurements, so we can add them in easily
meas = [{},{}]
for j in range(2):
    meas[j]['Z'] = QuantumCircuit(2,2)
    meas[j]['Z'].measure(j,j)
    meas[j]['X'] = QuantumCircuit(2,2)
    meas[j]['X'].h(j)
    meas[j]['X'].measure(j,j)
    
basis = ['Z','Z'] # set the initial measurement basis for each qubit

# loop over the squares centered on (1,2), (6,2) (1,4) and (6,4) and make all dim
for (X,Y) in [(1,2),(6,2),(1,4),(6,4)]:
    for dX in [+1,0,-1]:
        for dY in [+1,0,-1]:
            screen.pixel(X+dX,Y+dY,2)
pew.show(screen)
        
for (X,Y) in [(1,2),(6,2),(1,4),(6,4)]:
    screen.pixel(X,Y,0) # turn off the center pixels of the squares  

old_keys = 0
while True: # loop which checks for user input and responds

    # look for and act upon key presses
    keys = pew.keys() # get current key presses
    if keys!=0 and keys!=old_keys:
        if keys&pew.K_O:
            basis[0] = 'X'*(basis[0]=='Z') + 'Z'*(basis[0]=='X') # toggle basis for right qubit
        if keys&pew.K_X:
            basis[1] = 'X'*(basis[1]=='Z') + 'Z'*(basis[1]=='X') # toggle basis for left qubit
    old_keys = keys 
    
    # execute the circuit and get a single sample of memory for the given measurement bases
    m = simulate(qc+meas[0][basis[0]]+meas[1][basis[1]],shots=1,get='memory')
    
    # turn the pixels (1,2) and (1,4) (depending on basis[1]) on or off (depending on m[0][0])
    if m[0][0]=='1':
        if basis[1]=='Z':
            screen.pixel(1,2,3)
        else:
            screen.pixel(1,4,3)
    else:
        if basis[1]=='Z':
            screen.pixel(1,2,0)
        else:
            screen.pixel(1,4,0)
    # do the same for pixels (6,2) and (6,4)
    if m[0][1]=='1':
        if basis[0]=='Z':
            screen.pixel(6,2,3)
        else:
            screen.pixel(6,4,3)
    else:
        if basis[0]=='Z':
            screen.pixel(6,2,0)
        else:
            screen.pixel(6,4,0)
            
    # turn the pixels not used to display m[0] to dim
    if basis[1]=='Z':
        screen.pixel(1,4,2)
    else:
        screen.pixel(1,2,2)
    if basis[0]=='Z':
        screen.pixel(6,4,2)
    else:
        screen.pixel(6,2,2)

    pew.show(screen) # update screen to display the above changes

    pew.tick(1/6) # pause for a sixth of a second

import pew # setting up tools for the pewpew
from microqiskit import QuantumCircuit, simulate # setting up tools for quantum

pew.init() # initialize the game engine...
screen = pew.Pix() # ...and the screen

qc = QuantumCircuit(2,2) # create an empty circuit with two qubits and two output bits

# create circuits with the required measurements, so we can add them in easily
meas = [{},{}]
for j in range(2):
    meas[j]['Z'] = QuantumCircuit(2,2)
    meas[j]['Z'].measure(j,j)
    meas[j]['X'] = QuantumCircuit(2,2)
    meas[j]['X'].h(j)
    meas[j]['X'].measure(j,j)
    
basis = ['Z','Z'] # set the initial measurement basis for each qubit

# loop over the squares centered on (1,2), (6,2) (1,4) and (6,4) and make all dim
for (X,Y) in [(1,2),(6,2),(1,4),(6,4)]:
    for dX in [+1,0,-1]:
        for dY in [+1,0,-1]:
            screen.pixel(X+dX,Y+dY,2)
pew.show(screen)
        
for (X,Y) in [(1,2),(6,2),(1,4),(6,4)]:
    screen.pixel(X,Y,0) # turn off the center pixels of the squares  

old_keys = 0
while True: # loop which checks for user input and responds

    # look for and act upon key presses
    keys = pew.keys() # get current key presses
    if keys!=0 and keys!=old_keys:
        if keys&pew.K_O:
            basis[0] = 'X'*(basis[0]=='Z') + 'Z'*(basis[0]=='X') # toggle basis for right qubit
        if keys&pew.K_X:
            basis[1] = 'X'*(basis[1]=='Z') + 'Z'*(basis[1]=='X') # toggle basis for left qubit
        if keys&pew.K_UP:
            qc.x(0) # x for qubit 0 when UP is pressed
        if keys&pew.K_LEFT:
            qc.x(1) # x for qubit 1 when LEFT is pressed
        if keys&pew.K_RIGHT:
            qc.h(0) # h for qubit 0 when RIGHT is pressed
        if keys&pew.K_DOWN:
            qc.h(1) # h for qubit 1 when DOWN is pressed
    old_keys = keys 
    
    # execute the circuit and get a single sample of memory for the given measurement bases
    m = simulate(qc+meas[0][basis[0]]+meas[1][basis[1]],shots=1,get='memory')
    
    # turn the pixels (1,2) and (1,4) (depending on basis[1]) on or off (depending on m[0][0])
    if m[0][0]=='1':
        if basis[1]=='Z':
            screen.pixel(1,2,3)
        else:
            screen.pixel(1,4,3)
    else:
        if basis[1]=='Z':
            screen.pixel(1,2,0)
        else:
            screen.pixel(1,4,0)
    # do the same for pixels (6,2) and (6,4)
    if m[0][1]=='1':
        if basis[0]=='Z':
            screen.pixel(6,2,3)
        else:
            screen.pixel(6,4,3)
    else:
        if basis[0]=='Z':
            screen.pixel(6,2,0)
        else:
            screen.pixel(6,4,0)
            
    # turn the pixels not used to display m[0] to dim
    if basis[1]=='Z':
        screen.pixel(1,4,2)
    else:
        screen.pixel(1,2,2)
    if basis[0]=='Z':
        screen.pixel(6,4,2)
    else:
        screen.pixel(6,2,2)

    pew.show(screen) # update screen to display the above changes

    pew.tick(1/6) # pause for a sixth of a second

import pew # setting up tools for the pewpew
from microqiskit import QuantumCircuit, simulate # setting up tools for quantum

pew.init() # initialize the game engine...
screen = pew.Pix() # ...and the screen

qc = QuantumCircuit(2,2) # create an empty circuit with two qubits and two output bits
qc.h(0)
qc.cx(0,1)

# create circuits with the required measurements, so we can add them in easily
meas = [{},{}]
for j in range(2):
    meas[j]['Z'] = QuantumCircuit(2,2)
    meas[j]['Z'].measure(j,j)
    meas[j]['X'] = QuantumCircuit(2,2)
    meas[j]['X'].h(j)
    meas[j]['X'].measure(j,j)
    
basis = ['Z','Z'] # set the initial measurement basis for each qubit

# loop over the squares centered on (1,2), (6,2) (1,4) and (6,4) and make all dim
for (X,Y) in [(1,2),(6,2),(1,4),(6,4)]:
    for dX in [+1,0,-1]:
        for dY in [+1,0,-1]:
            screen.pixel(X+dX,Y+dY,2)
pew.show(screen)
        
for (X,Y) in [(1,2),(6,2),(1,4),(6,4)]:
    screen.pixel(X,Y,0) # turn off the center pixels of the squares  

old_keys = 0
while True: # loop which checks for user input and responds

    # look for and act upon key presses
    keys = pew.keys() # get current key presses
    if keys!=0 and keys!=old_keys:
        if keys==pew.K_O:
            basis[0] = 'X'*(basis[0]=='Z') + 'Z'*(basis[0]=='X') # toggle basis for right qubit
        if keys==pew.K_X:
            basis[1] = 'X'*(basis[1]=='Z') + 'Z'*(basis[1]=='X') # toggle basis for left qubit
        if keys==pew.K_UP:
            qc.x(0) # x for qubit 0 when UP is pressed
        if keys==pew.K_LEFT:
            qc.x(1) # x for qubit 1 when LEFT is pressed
        if keys==pew.K_RIGHT:
            qc.h(0) # h for qubit 0 when RIGHT is pressed
        if keys==pew.K_DOWN:
            qc.h(1) # h for qubit 1 when DOWN is pressed
    old_keys = keys 
    
    # execute the circuit and get a single sample of memory for the given measurement bases
    m = simulate(qc+meas[0][basis[0]]+meas[1][basis[1]],shots=1,get='memory')
    
    # turn the pixels (1,2) and (1,4) (depending on basis[1]) on or off (depending on m[0][0])
    if m[0][0]=='1':
        if basis[1]=='Z':
            screen.pixel(1,2,3)
        else:
            screen.pixel(1,4,3)
    else:
        if basis[1]=='Z':
            screen.pixel(1,2,0)
        else:
            screen.pixel(1,4,0)
    # do the same for pixels (6,2) and (6,4)
    if m[0][1]=='1':
        if basis[0]=='Z':
            screen.pixel(6,2,3)
        else:
            screen.pixel(6,4,3)
    else:
        if basis[0]=='Z':
            screen.pixel(6,2,0)
        else:
            screen.pixel(6,4,0)
            
    # turn the pixels not used to display m[0] to dim
    if basis[1]=='Z':
        screen.pixel(1,4,2)
    else:
        screen.pixel(1,2,2)
    if basis[0]=='Z':
        screen.pixel(6,4,2)
    else:
        screen.pixel(6,2,2)
        
    # flag up the '11' output by lighting up pixels in the bottom-center
    if m[0]=='11':
        screen.pixel(3,6,3)
        screen.pixel(4,6,3)
    else:
        screen.pixel(3,6,0)
        screen.pixel(4,6,0)
    # same with '00' and the top center
    if m[0]=='00':
        screen.pixel(3,0,3)
        screen.pixel(4,0,3)
    else:
        screen.pixel(3,0,0)
        screen.pixel(4,0,0)  

    pew.show(screen) # update screen to display the above changes

    pew.tick(1/6) # pause for a sixth of a second

import pew # setting up tools for the pewpew
from microqiskit import QuantumCircuit, simulate # setting up tools for quantum

pew.init() # initialize the game engine...
screen = pew.Pix() # ...and the screen

qc = QuantumCircuit(2,2) # create an empty circuit with two qubits and two output bits
qc.initialize([0,0.57735,0.57735,0.57735])

# create circuits with the required measurements, so we can add them in easily
meas = [{},{}]
for j in range(2):
    meas[j]['Z'] = QuantumCircuit(2,2)
    meas[j]['Z'].measure(j,j)
    meas[j]['X'] = QuantumCircuit(2,2)
    meas[j]['X'].h(j)
    meas[j]['X'].measure(j,j)
    
basis = ['Z','Z'] # set the initial measurement basis for each qubit

# loop over the squares centered on (1,2), (6,2) (1,4) and (6,4) and make all dim
for (X,Y) in [(1,2),(6,2),(1,4),(6,4)]:
    for dX in [+1,0,-1]:
        for dY in [+1,0,-1]:
            screen.pixel(X+dX,Y+dY,2)
pew.show(screen)
        
for (X,Y) in [(1,2),(6,2),(1,4),(6,4)]:
    screen.pixel(X,Y,0) # turn off the center pixels of the squares  

old_keys = 0
while True: # loop which checks for user input and responds

    # look for and act upon key presses
    keys = pew.keys() # get current key presses
    if keys!=0 and keys!=old_keys:
        if keys&pew.K_O:
            basis[0] = 'X'*(basis[0]=='Z') + 'Z'*(basis[0]=='X') # toggle basis for right qubit
        if keys&pew.K_X:
            basis[1] = 'X'*(basis[1]=='Z') + 'Z'*(basis[1]=='X') # toggle basis for left qubit
        if keys&pew.K_UP:
            qc.x(0) # x for qubit 0 when UP is pressed
        if keys&pew.K_LEFT:
            qc.x(1) # x for qubit 1 when LEFT is pressed
        if keys&pew.K_RIGHT:
            qc.h(0) # h for qubit 0 when RIGHT is pressed
        if keys&pew.K_DOWN:
            qc.h(1) # h for qubit 1 when DOWN is pressed
    old_keys = keys 
    
    # execute the circuit and get a single sample of memory for the given measurement bases
    m = simulate(qc+meas[0][basis[0]]+meas[1][basis[1]],shots=1,get='memory')
    
    # turn the pixels (1,2) and (1,4) (depending on basis[1]) on or off (depending on m[0][0])
    if m[0][0]=='1':
        if basis[1]=='Z':
            screen.pixel(1,2,3)
        else:
            screen.pixel(1,4,3)
    else:
        if basis[1]=='Z':
            screen.pixel(1,2,0)
        else:
            screen.pixel(1,4,0)
    # do the same for pixels (6,2) and (6,4)
    if m[0][1]=='1':
        if basis[0]=='Z':
            screen.pixel(6,2,3)
        else:
            screen.pixel(6,4,3)
    else:
        if basis[0]=='Z':
            screen.pixel(6,2,0)
        else:
            screen.pixel(6,4,0)
            
    # turn the pixels not used to display m[0] to dim
    if basis[1]=='Z':
        screen.pixel(1,4,2)
    else:
        screen.pixel(1,2,2)
    if basis[0]=='Z':
        screen.pixel(6,4,2)
    else:
        screen.pixel(6,2,2)
        
    # flag up the '11' output by lighting up pixels in the bottom-center
    if m[0]=='11':
        screen.pixel(3,6,3)
        screen.pixel(4,6,3)
    else:
        screen.pixel(3,6,0)
        screen.pixel(4,6,0)
    # same with '00' and the top center
    if m[0]=='00':
        screen.pixel(3,0,3)
        screen.pixel(4,0,3)
    else:
        screen.pixel(3,0,0)
        screen.pixel(4,0,0)  

    pew.show(screen) # update screen to display the above changes

    pew.tick(1/6) # pause for a sixth of a second

