summaryrefslogtreecommitdiff
path: root/single_dequantify.py
blob: 99ebdc44b5f60b9fbcff6964ba1b99e3b0007f40 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
import sys
import plot
import math as mth
import cmath as cmt
import numpy as npy
import scipy.linalg as sla

dt = 0.08
iterations = 100
state_num = 3

H = npy.array([[1,0],[0,2]])

if len(sys.argv) == 3:
    alpha = complex(sys.argv[1])
    beta = complex(sys.argv[2])

def init_state(i):
    alpha = 1
    beta  = 1
    if state_num > 1:
        alpha = i / state_num
        beta  = (state_num - i) / state_num
    return (alpha, beta)

def time_evolution(state, dt = dt):
    return npy.dot(state, sla.expm(-1j * dt * H))

def bloch_map(state):
    temp  = npy.conj(state[0] / state[1])
    theta = 2 * npy.arctan(abs(temp))
    phi = cmt.phase(temp)

    return (phi, theta)

def sphere2cart(phi, theta):
        return [
             mth.sin(theta) * mth.cos(phi),
             mth.sin(theta) * mth.sin(phi),
             -1 * mth.cos(theta)
        ]

states = []
for i in range(state_num):
    (alpha, beta) = init_state(i)
    norm  = npy.linalg.norm([alpha, beta])
    state = npy.array([alpha / norm, beta / norm])
    states.append(state)

f = open("data", "w")
for i in range(iterations):
    for j in range(state_num):
        (phi, theta) = bloch_map(states[j])
        coords = sphere2cart(phi, theta)
        colour = i / iterations
        if state_num > 1:
            colour = j / state_num
        f.write(f"{coords[0]}; {coords[1]}; {coords[2]}; 0; 0; {colour}\n")
        states[j] = time_evolution(states[j])
f.close()

plot.plot(1, iterations, state_num, "anim2d.plt")