# import the drawing methods
from matplotlib.pyplot import plot, figure, show

# draw a figure
figure(figsize=(6,6), dpi=80)

# include our predefined functions
%run qlatvia.py

# draw the axes
draw_axes()

# draw the origin
plot(0,0,'ro') # a point in red color

# draw these quantum states as points (in blue, green, yellow, and cyan colors)
plot(1,0,'bo') 
plot(0,1,'go')
plot(-1,0,'yo')
plot(0,-1,'co')

show()

# import the drawing methods
from matplotlib.pyplot import figure, arrow, show

# draw a figure
figure(figsize=(6,6), dpi=80)

# include our predefined functions
%run qlatvia.py

# draw the axes
draw_axes()

# draw the quantum states as vectors (in red, blue, green, and yellow colors)
arrow(0,0,0.92,0,head_width=0.04, head_length=0.08, color="r")
arrow(0,0,0,0.92,head_width=0.04, head_length=0.08, color="b")
arrow(0,0,-0.92,0,head_width=0.04, head_length=0.08, color="g")
arrow(0,0,0,-0.92,head_width=0.04, head_length=0.08, color="y")

show()

# import the drawing methods
from matplotlib.pyplot import plot, figure

# draw a figure
figure(figsize=(6,6), dpi=60) 

# draw the origin
plot(0,0,'ro') 

from random import randrange
colors = ['ro','bo','go','yo','co','mo','ko']

#
# your solution is here
#
# randomly creating a 2-dimensional quantum state
from random import randrange
def random_quantum_state():
    first_entry = randrange(-100,101)
    second_entry = randrange(-100,101)
    length_square = first_entry**2+second_entry**2
    while length_square == 0:
        first_entry = randrange(-100,101)
        second_entry = randrange(-100,101)
        length_square = first_entry**2+second_entry**2
    first_entry = first_entry / length_square**0.5
    second_entry = second_entry / length_square**0.5
    return [first_entry,second_entry]

# import the drawing methods
from matplotlib.pyplot import plot, figure, show

# draw a figure
figure(figsize=(6,6), dpi=60) 

# draw the origin
plot(0,0,'ro') 

from random import randrange
colors = ['ro','bo','go','yo','co','mo','ko']

for i in range(500):
    # create a random quantum state
    quantum_state = random_quantum_state(); 
    # draw a blue point for the random quantum state
    x = quantum_state[0];
    y = quantum_state[1];
    plot(x,y,colors[randrange(len(colors))]) 

show()

# import the drawing methods
from matplotlib.pyplot import plot, figure, arrow

# draw a figure
figure(figsize=(6,6), dpi=60) 

# include our predefined functions
%run qlatvia.py

# draw the axes
draw_axes()

# draw the origin
plot(0,0,'ro') 

from random import randrange
colors = ['r','b','g','y','b','c','m']

#
# your solution is here
#
# randomly creating a 2-dimensional quantum state
from random import randrange
def random_quantum_state():
    first_entry = randrange(-100,101)
    second_entry = randrange(-100,101)
    length_square = first_entry**2+second_entry**2
    while length_square == 0:
        first_entry = randrange(-100,101)
        second_entry = randrange(-100,101)
        length_square = first_entry**2+second_entry**2
    first_entry = first_entry / length_square**0.5
    second_entry = second_entry / length_square**0.5
    return [first_entry,second_entry]



# import the drawing methods
from matplotlib.pyplot import plot, figure, arrow, show

%run qlatvia.py

# draw a figure
figure(figsize=(6,6), dpi=60) 

draw_axes();

# draw the origin
plot(0,0,'ro') 

from random import randrange
colors = ['r','b','g','y','b','c','m']

for i in range(500):
    # create a random quantum state
    quantum_state = random_quantum_state(); 
    # draw a blue vector for the random quantum state
    x = quantum_state[0];
    y = quantum_state[1];
    # shorten the line length to 0.92
    #     line_length + head_length (0.08) should be 1
    x = 0.92 * x
    y = 0.92 * y
    arrow(0,0,x,y,head_width=0.04,head_length=0.08,color=colors[randrange(len(colors))])

show()

# import the drawing methods
from matplotlib.pyplot import figure

figure(figsize=(6,6), dpi=80) # size of the figure

# include our predefined functions
%run qlatvia.py

# draw axes
draw_axes()

# draw the unit circle
draw_unit_circle()

%run qlatvia.py

draw_qubit()

draw_quantum_state(3/5,4/5,"|v>")

%run qlatvia.py

draw_qubit()

draw_quantum_state(3/5,4/5,"|v>")

from matplotlib.pyplot import arrow, text, gca

# the projection on |0>-axis
arrow(0,0,3/5,0,color="blue",linewidth=1.5)
arrow(0,4/5,3/5,0,color="blue",linestyle='dotted')
text(0.1,-0.1,"cos(a)=3/5")

# the projection on |1>-axis
arrow(0,0,0,4/5,color="blue",linewidth=1.5)
arrow(3/5,0,0,4/5,color="blue",linestyle='dotted')
text(-0.1,0.55,"sin(a)=4/5",rotation="90")

# drawing the angle with |0>-axis
from matplotlib.patches import Arc
gca().add_patch( Arc((0,0),0.4,0.4,angle=0,theta1=0,theta2=53) )
text(0.08,0.05,'.',fontsize=30)
text(0.21,0.09,'a')

# set the angle

from random import randrange
myangle = randrange(361)

################################################

from matplotlib.pyplot import figure,gca
from matplotlib.patches import Arc
from math import sin,cos,pi

# draw a figure
figure(figsize=(6,6), dpi=60)

%run qlatvia.py

draw_axes()

print("the selected angle is",myangle,"degrees")

ratio_of_arc = ((1000*myangle/360)//1)/1000

print("it is",ratio_of_arc,"of a full circle")

print("its length is",ratio_of_arc,"x 2\u03C0","=",ratio_of_arc*2*pi)

myangle_in_radian = 2*pi*(myangle/360)

print("its radian value is",myangle_in_radian)

gca().add_patch( Arc((0,0),0.2,0.2,angle=0,theta1=0,theta2=myangle,color="red",linewidth=2) )

gca().add_patch( Arc((0,0),2,2,angle=0,theta1=0,theta2=myangle,color="brown",linewidth=2) )

x = cos(myangle_in_radian)
y = sin(myangle_in_radian)

draw_quantum_state(x,y,"|v>")

# the projection on |0>-axis
arrow(0,0,x,0,color="blue",linewidth=1)
arrow(0,y,x,0,color="blue",linestyle='dashed')

# the projection on |1>-axis
arrow(0,0,0,y,color="blue",linewidth=1)
arrow(x,0,0,y,color="blue",linestyle='dashed')

print()
print("the amplitude of state |0> is",x)
print("the amplitude of state |1> is",y)
print()
print("the probability of observing state |0> is",x*x)
print("the probability of observing state |1> is",y*y)
print("the total probability is",round(x*x+y*y,6))

# %%writefile FILENAME.py 
# your function is here

from math import cos, sin, pi
from random import randrange
def random_quantum_state2():
    angle_degree = randrange(360)
    angle_radian = 2*pi*angle_degree/360
    return [cos(angle_radian),sin(angle_radian)]

# include our predefined functions
%run qlatvia.py

# draw the axes
draw_qubit()

for i in range(6):
    [x,y]=random_quantum_state2()
    draw_quantum_state(x,y,"|v"+str(i)+">")

# include our predefined functions
%run qlatvia.py

# draw the axes
draw_qubit()

for i in range(100):
    [x,y]=random_quantum_state2()
    draw_quantum_state(x,y,"")