summaryrefslogtreecommitdiff
path: root/single_dequantify.py
blob: 44f2190c68abc3f906d34703dbc1ec0daa94a4b9 (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
#import plotting
import subprocess
import math as mth
import cmath as cmt
import numpy as npy
import scipy.linalg as sla

alpha = 1 / npy.sqrt(2)
beta  = 1 / npy.sqrt(2)
state = npy.array([alpha, beta])

dt = 0.067
iterations = 41

H = npy.array([[2,-1j],[1j,3]])


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) / 2)
    phi = cmt.phase(temp)

    return npy.array([phi, theta])

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

historie = npy.array([bloch_map(state)])
f = open("data", "w")

for i in range(iterations):
    state = time_evolution(state)
    h = npy.dot(state, state)
    historie = npy.vstack([historie,bloch_map(state)])
    coords = bloch_map(state)
    coords = sphere2cart(coords[0], coords[1])
    f.write(f"{coords[0]}; {coords[1]}; {coords[2]}; {(i + 1) / iterations}\n")

f.close()
subprocess.run(["gnuplot", "gnuplot.plt"])