From 98c588bbb04f11b05324b6e415ec358305f06f7a Mon Sep 17 00:00:00 2001 From: Dennis Kobert Date: Sat, 30 Nov 2019 13:15:01 +0100 Subject: Normalize alpha and beta --- single_dequantify.py | 30 +++++++++++++++++------------- 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/single_dequantify.py b/single_dequantify.py index 44f2190..fa5f017 100644 --- a/single_dequantify.py +++ b/single_dequantify.py @@ -5,14 +5,18 @@ 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]) +#alpha = 1 / npy.sqrt(2) +alpha = 1 +#beta = 1 / npy.sqrt(2) +beta = 1 -dt = 0.067 -iterations = 41 +norm = npy.linalg.norm([alpha, beta]) +state = npy.array([alpha / norm, beta / norm]) -H = npy.array([[2,-1j],[1j,3]]) +dt = 0.1 +iterations = 61 + +H = npy.array([[2,0],[0,3]]) def time_evolution(state, dt = dt): @@ -20,16 +24,16 @@ def time_evolution(state, dt = dt): def bloch_map(state): temp = npy.conj(state[0] / state[1]) - theta = 2 * npy.arctan(abs(temp) / 2) + theta = 2 * npy.arctan(abs(temp)) phi = cmt.phase(temp) - return npy.array([phi, theta]) + return (phi, theta) def sphere2cart(phi, theta): return [ - mth.cos(theta) * mth.cos(phi), - mth.cos(theta) * mth.sin(phi), - mth.sin(theta) + mth.sin(theta) * mth.cos(phi), + mth.sin(theta) * mth.sin(phi), + mth.cos(theta) ] historie = npy.array([bloch_map(state)]) @@ -39,8 +43,8 @@ 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]) + (phi, theta) = bloch_map(state) + coords = sphere2cart(phi, theta) f.write(f"{coords[0]}; {coords[1]}; {coords[2]}; {(i + 1) / iterations}\n") f.close() -- cgit v1.2.3-54-g00ecf