-
Notifications
You must be signed in to change notification settings - Fork 2
/
rabi_flop_fitter.py
178 lines (165 loc) · 9 KB
/
rabi_flop_fitter.py
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
"""
Fitter for Carrier and Sideband Rabi Flopping
"""
from motional_distribution import motional_distribution as md
import numpy as np
from scipy.special.orthogonal import eval_genlaguerre as laguerre
class rabi_flop_time_evolution(object):
def __init__(self, sideband_order, eta, nmax = 3000):
self.sideband_order = sideband_order #0 for carrier, 1 for 1st sideband etc
self.eta = eta
self.nmax = nmax
self.rabi_coupling = self.compute_rabi_coupling()
def compute_rabi_coupling(self):
'''
Rabi couplings, see Leibfried (2003), eq:70
'''
eta = self.eta
if self.sideband_order == 0:
coupling_func = lambda n: np.exp(-1./2*eta**2) * laguerre(n, 0, eta**2)
elif self.sideband_order == 1:
coupling_func = lambda n: np.exp(-1./2*eta**2) * eta**(1)*(1./(n+1.))**0.5 * laguerre(n, 1, eta**2)
elif self.sideband_order == 2:
coupling_func = lambda n: np.exp(-1./2*eta**2) * eta**(2)*(1./((n+1.)*(n+2)))**0.5 * laguerre(n, 2, eta**2)
elif self.sideband_order == 3:
coupling_func = lambda n: np.exp(-1./2*eta**2) * eta**(3)*(1./((n+1)*(n+2)*(n+3)))**0.5 * laguerre(n, 3 , eta**2)
elif self.sideband_order == 4:
coupling_func = lambda n: np.exp(-1./2*eta**2) * eta**(4)*(1./((n+1)*(n+2)*(n+3)*(n+4)))**0.5 * laguerre(n, 4 , eta**2)
elif self.sideband_order == 5:
coupling_func = lambda n: np.exp(-1./2*eta**2) * eta**(5)*(1./((n+1)*(n+2)*(n+3)*(n+4)*(n+5)))**0.5 * laguerre(n, 5 , eta**2)
elif self.sideband_order == -1:
coupling_func = lambda n: 0 if n == 0 else np.exp(-1./2*eta**2) * eta**(1)*(1./(n))**0.5 * laguerre(n - 1, 1, eta**2)
elif self.sideband_order == -2:
coupling_func = lambda n: 0 if n <= 1 else np.exp(-1./2*eta**2) * eta**(2)*(1./((n)*(n-1.)))**0.5 * laguerre(n - 2, 2, eta**2)
elif self.sideband_order == -3:
coupling_func = lambda n: 0 if n <= 2 else np.exp(-1./2*eta**2) * eta**(3)*(1./((n)*(n-1.)*(n-2)))**0.5 * laguerre(n -3, 3, eta**2)
elif self.sideband_order == -4:
coupling_func = lambda n: 0 if n <= 3 else np.exp(-1./2*eta**2) * eta**(4)*(1./((n)*(n-1.)*(n-2)*(n-3)))**0.5 * laguerre(n -4, 4, eta**2)
elif self.sideband_order == -5:
coupling_func = lambda n: 0 if n <= 4 else np.exp(-1./2*eta**2) * eta**(5)*(1./((n)*(n-1.)*(n-2)*(n-3)*(n-4)))**0.5 * laguerre(n -5, 5, eta**2)
else:
raise NotImplementedError("Can't calculate rabi couplings sideband order {}".format(self.sideband_order))
return np.array([coupling_func(n) for n in range(self.nmax)])
def compute_evolution_thermal(self, nbar, delta, time_2pi, t, excitation_scaling = 1.):
'''returns the state evolution for temperature nbar, detuning delta, rabi frequency T_Rabi for times t'''
omega = self.rabi_coupling
ones = np.ones_like(t)
p_n = md.thermal(nbar, self.nmax)
if 1 - p_n.sum() > 1e-6:
print 'Hilbert space too small, missing population'
# self.nmax = self.nmax * 100
# print 'ENLARGED Hilbert space to: ' + str(self.nmax)
# p_n = md.thermal(nbar, self.nmax)
# omega = self.compute_rabi_coupling()
# raise Exception ('Hilbert space too small, missing population')
if delta == 0:
#prevents division by zero if delta == 0, omega == 0
effective_omega = 1
else:
effective_omega = omega/np.sqrt(omega**2+delta**2)
result = np.outer(p_n * effective_omega, ones) * (np.sin( np.outer( np.sqrt(omega**2+delta**2)*np.pi/time_2pi, t ))**2)
result = np.sum(result, axis = 0)
result = excitation_scaling * result
return result
def compute_evolution_decay_thermal(self, coherence_time, nbar, delta, time_2pi, t, excitation_scaling = 1.):
bsb_exc = self.compute_evolution_thermal(nbar, delta, time_2pi, t, excitation_scaling)
decay = np.exp(-t/coherence_time)
return (bsb_exc - .5) * decay + .5
def compute_evolution_coherent(self, nbar, alpha, delta, time_2pi, t, excitation_scaling = 1.):
'''returns the state evolution for temperature nbar, detuning delta, rabi frequency T_Rabi for times t'''
omega = self.rabi_coupling
ones = np.ones_like(t)
p_n = md.displaced_thermal(alpha, nbar, self.nmax)
print 'got array'
if 1 - p_n.sum() > 1e-6:
raise Exception ('Hilbert space too small, missing population')
if delta == 0:
#prevents division by zero if delta == 0, omega == 0
effective_omega = 1
else:
effective_omega = np.abs(omega)/np.sqrt(omega**2+delta**2)
print 'looking for result'
result = np.outer(p_n * effective_omega, ones) * (np.sin( np.outer( np.sqrt(omega**2+delta**2)*np.pi/time_2pi, t ))**2)
print 'summing'
result = np.sum(result, axis = 0)
print 'scaling'
result = excitation_scaling * result
print 'done'
return result
if __name__ == '__main__':
from matplotlib import pyplot
def decay_example():
eta = 0.05
nbar = 3
times = np.linspace(0, 300, 100)
coh_t = 100.
te = rabi_flop_time_evolution(-1 ,eta)
prob_red = te.compute_evolution_decay_thermal(coh_t, nbar = nbar, delta = 0, time_2pi = 15, t = times)
te = rabi_flop_time_evolution(1 ,eta)
prob_blue = te.compute_evolution_decay_thermal(coh_t, nbar = nbar, delta = 0, time_2pi = 15, t = times)
te = rabi_flop_time_evolution(0 ,eta)
prob_car = te.compute_evolution_decay_thermal(coh_t, nbar = nbar, delta = 0, time_2pi = 15, t = times)
pyplot.plot(times, prob_red, label = 'red sideband')
pyplot.plot(times, prob_blue, label = 'carrier')
pyplot.plot(times, prob_car, label = 'blue sideband')
pyplot.legend()
pyplot.show()
#extracting back the temperature from the ratio of sidebands
ratio_nbar = prob_red[1:] /(prob_blue[1:] - prob_red[1:])
print 'nbar from sideband ratio', ratio_nbar[0]
def thermal_example():
eta = 0.05
nbar = 3
times = np.linspace(0, 300, 100)
te = rabi_flop_time_evolution(-1 ,eta)
prob_red = te.compute_evolution_thermal(nbar = nbar, delta = 0, time_2pi = 15, t = times)
te = rabi_flop_time_evolution(1 ,eta)
prob_blue = te.compute_evolution_thermal(nbar = nbar, delta = 0, time_2pi = 15, t = times)
te = rabi_flop_time_evolution(0 ,eta)
prob_car = te.compute_evolution_thermal(nbar = nbar, delta = 0, time_2pi = 15, t = times)
pyplot.plot(times, prob_red, label = 'red sideband')
pyplot.plot(times, prob_blue, label = 'carrier')
pyplot.plot(times, prob_car, label = 'blue sideband')
pyplot.legend()
pyplot.show()
#extracting back the temperature from the ratio of sidebands
ratio_nbar = prob_red[1:] /(prob_blue[1:] - prob_red[1:])
print 'nbar from sideband ratio', ratio_nbar[0]
def displaced_thermal_example():
eta = 0.05
for alpha in np.linspace(0, 25, 6):
times = np.linspace(0, 50, 300)
pyplot.subplot(211)
te = rabi_flop_time_evolution(-1 ,eta)
prob_blue = te.compute_evolution_coherent(nbar = 3, alpha = alpha, delta = 0, time_2pi = 15, t = times)
pyplot.plot(times, prob_blue, label = 'alpha a = {}'.format(alpha))
pyplot.subplot(212)
te = rabi_flop_time_evolution(-2 ,eta)
prob_blue = te.compute_evolution_coherent(nbar = 3, alpha = alpha, delta = 0, time_2pi = 15, t = times)
pyplot.plot(times, prob_blue, label = 'alpha a = {}'.format(alpha))
pyplot.subplot(211)
pyplot.title('First order red sideband', fontsize = 24)
pyplot.subplot(212)
pyplot.title('Second order red sideband', fontsize = 24)
pyplot.tight_layout()
pyplot.legend(prop={'size':16})
pyplot.xlabel('Excitation Time (arb)', fontsize = 20)
pyplot.ylabel('Excitation', fontsize = 20)
pyplot.tick_params(axis='both', which='major', labelsize=14)
pyplot.show()
def display_rabi_coupling():
eta = 0.05
for sideband in [-1,-2,-3,-4,-5]:
te = rabi_flop_time_evolution(sideband ,eta)
couplings = te.compute_rabi_coupling()
couplings = np.abs(couplings)
pyplot.plot(couplings, label = 'sideband {}'.format(sideband))
pyplot.title('Rabi Coupling Strength', fontsize = 24)
pyplot.xlabel('n', fontsize = 24)
pyplot.ylabel(u'$\Omega_n$ / $\Omega_0$', fontsize = 24)
pyplot.legend()
pyplot.show()
decay_example()
# thermal_example()
# displaced_thermal_example()
# display_rabi_coupling()