import sys
sys.path.append('../')
import CreativeQiskit

grid = CreativeQiskit.random_grid(5,4)

grid.neighbours( (2,2) )

grid_stats,grid_data = grid.get_samples(shots=3)

for sample in grid_stats:
    print(grid_stats[sample],'shots returned the grid state\n')
    print(sample,'\n')

for sample in grid_data:
    print(sample,'\n')

grid.NOT((0,0))

grid.NOT((4,3),frac=0.5)

control = (4,3)
for target in grid.neighbours( control ):
    grid.CNOT(control,target)

grid_stats,grid_data = grid.get_samples(shots=10)
def show_results (grid):
    for sample in grid_stats:
        print(grid_stats[sample],'shots returned the grid state\n')
        print(sample,'\n')
        
show_results(grid)

grid.NOT( (0,3) )
grid.CNOT((0,3), (1,3), frac=0.5)

grid_stats,grid_data = grid.get_samples(shots=10)
show_results(grid)

grid = CreativeQiskit.random_grid(2,2)

grid.NOT( (0,0), frac=0.5, axis='x' )
grid.NOT( (0,0), frac=0.5, axis='x' )
    
grid_stats,grid_data = grid.get_samples(shots=10)
show_results(grid)

grid = CreativeQiskit.random_grid(2,2)

grid.NOT( (0,0), frac=0.5, axis='y' )
grid.NOT( (0,0), frac=0.5, axis='y' )
    
grid_stats,grid_data = grid.get_samples(shots=10)
show_results(grid)

grid = CreativeQiskit.random_grid(2,2)

grid.NOT( (0,0), frac=0.5, axis='x' )
grid.NOT( (0,0), frac=0.5, axis='y' )
    
grid_stats,grid_data = grid.get_samples(shots=10)
show_results(grid)

from qiskit import IBMQ
IBMQ.load_accounts()

grid = CreativeQiskit.random_grid(5,5)

grid.NOT( (0,0), frac=0.5, )
for j in range(5):
    control = (j,j)
    grid.NOT( control, frac=(1/(j+1)) )
    for target in grid.neighbours( control ):
        grid.CNOT(control,target)

grid_stats,grid_data = grid.get_samples(shots=10,device='ibmq_qasm_simulator')    
show_results(grid)