def test_frequency_set(self): """ Test setting the frequency of channel 4 """ server = self.server f = _u.WithUnit(100., 'MHz') server.frequency(4, f) out = server.frequency(4) exp = _u.WithUnit(100., 'MHz') self.assertEquals(exp, out)
def setThresholds(self, ctx, low, high): """ This setting configures the trigger thresholds. If a threshold is exceeded, then an alert is sent. """ if low >= high: return "The minimum threshold cannot be greater than the maximum\ threshold" self.thresholdMax = units.WithUnit(high,' ml / min') self.thresholdMin = units.WithUnit(low,' ml / min') return True
def do_fft(self): tf = self.time[-1] * 1e-6 n = len(self.excitation) x = fft.fft(self.excitation) pos_freq_components = [ U.WithUnit(j, 'Arb') for j in np.abs(x[1:n / 2]) ] freq = [ U.WithUnit(j, 'kHz') for j in (np.arange(1, n / 2) / tf) / 1e3 ] # freq in kHz return freq, pos_freq_components
def test_return_c_unit(self): server = self._get_tester() resp = server.return_c_unit() exp_resp = _u.WithUnit(9.+1j*3., 'Hz') self.assertEqual(resp, exp_resp)
def compute_projection(self, bareRabi): ''' May need a better peak detection algorithm in future ''' wavelength = U.WithUnit(729.0, 'nm') m = 40 * amu chi = 2 * np.pi / wavelength['m'] * np.sqrt( hbar['J*s'] / (2. * m['kg'] * 2. * np.pi * self.trap_frequency['Hz'])) freq_data = list(np.abs(self.pos_freq_components)) maxElemIndex = freq_data.index(max(freq_data)) peakFreq = self.freq[maxElemIndex] * 1e3 # freq in Hz theta = U.WithUnit( np.arccos(peakFreq / (chi * bareRabi['Hz'])) * 180.0 / np.pi, 'deg') return theta
def test_return_c_unitType(self): server = self._get_tester() resp = server.return_c_unit() val = type(resp) exp_val = type(_u.WithUnit(9.+1j*8., 'Hz')) self.assertEqual(val, exp_val)
def __init__(self, trap_frequency, projection, sideband_order,nmax = 1000): from labrad import units as U m = 40 * U.amu hbar = U.hbar wavelength= U.WithUnit(729,'nm') self.sideband_order = sideband_order self.n = np.linspace(0, nmax,nmax +1) self.eta = 2.*np.cos(projection)*np.pi/wavelength['m']*np.sqrt(hbar['J*s']/(2.*m['kg']*2.*np.pi*trap_frequency['Hz'])) self.rabi_coupling=self.rabi_coupling()
def __init__(self, trap_frequency, sideband_order, nmax=1000): m = 40 * U.amu hbar = U.hbar wavelength = U.WithUnit(729, 'nm') self.sideband_order = sideband_order self.n = np.linspace(0, nmax, nmax + 1) self.eta = 2. * np.cos(np.pi / 4) * np.pi / wavelength['m'] * np.sqrt( hbar['J*s'] / (2. * m['kg'] * 2. * np.pi * trap_frequency['Hz'])) self.rabi_coupling = self.effective_rabi_coupling(self.n)
def __init__(self, trap_frequency, sideband_order, nmax=1000): m = 40 * U.amu hbar = U.hbar wavelength = U.WithUnit(729, 'nm') self.sideband_order = sideband_order #0 for carrier, 1 for 1st blue sideband etc self.n = np.linspace(0, nmax, nmax + 1) #how many vibrational states to consider self.eta = 2. * np.cos(np.pi / 4) * np.pi / wavelength['m'] * np.sqrt( hbar['J*s'] / (2. * m['kg'] * 2. * np.pi * trap_frequency['Hz'])) self.rabi_coupling = self.rabi_coupling()
def compute_lines(self, bareRabi): wavelength = U.WithUnit(729.0, 'nm') m = 40 * amu chi = 2 * np.pi / wavelength['m'] * np.sqrt( hbar['J*s'] / (2. * m['kg'] * 2. * np.pi * self.trap_frequency['Hz'])) print chi first = np.cos(np.pi / 4) * chi * bareRabi second = np.sqrt(2) * first print self.freq print first print second
def set_voltage(self, channel, voltage=None): """ Set channel's output voltage. """ channel_str = self.parse_channel(channel) voltage_in_volts = voltage['V'] voltage_in_volts = str(voltage_in_volts) command = 'APPly' + channel_str + ',' + voltage_in_volts + 'V' yield self.write(command) volts = yield self.measure_voltage(channel=channel) units_volts = _units.WithUnit(volts, 'V') returnValue(units_volts)
def fitFunc(self, x, p): from labrad import units as U flop = te.time_evolution(trap_frequency=U.WithUnit(p[4], 'MHz'), projection=p[7], sideband_order=p[5], nmax=p[6]) evolution = flop.state_evolution_fluc(x * 10**-6, p[0], p[1], p[2], p[3], n_fluc=5.0) return evolution
def measure_voltage(self, channel=None): """ Get the output voltage of channel. Parameters ---------- channel: int, channel number """ channel_str = self.parse_channel(channel=channel) command = 'MEAS:VOLT:DC? ' + channel_str yield self.write(command) voltage = yield self.read() voltage = _units.WithUnit(float(voltage), 'V') returnValue(voltage)
def measure_current(self, channel=None): """ Get the output current of channel. Parameters ---------- channel: int, channel number """ channel_str = self.parse_channel(channel=channel) command = 'MEAS:CURRent:DC? ' + channel_str yield self.write(command) current = yield self.read() current = _units.WithUnit(float(current), 'A') returnValue(current)
def testDimensionless(self): ns = units.Unit('ns') GHz = units.Unit('GHz') self.assertTrue(isinstance((5 * ns) * (5 * GHz), float)) self.assertTrue(hasattr((5 * ns) * (5 * GHz), 'inUnitsOf')) self.assertTrue(((5 * ns) * (5 * GHz)).isDimensionless()) self.assertTrue((5 * ns) * (5 * GHz) < 50) self.assertTrue( isinstance(units.WithUnit(5.0, ''), units.DimensionlessFloat)) self.assertTrue((5 * ns * 5j * GHz) == 25j) self.assertTrue((5 * ns * 5j * GHz).isDimensionless())
def set_current(self, channel, current=None): """ Set channel's output current. Parameters ---------- channel: int, channel number current: WithUnit Amps, default(None) """ yield self.set_channel(channel=channel) current_in_amps = current['A'] current_in_amps = str(current_in_amps) command = 'CURRent' + ' ' + current_in_amps + 'A' yield self.write(command) current = yield self.measure_current(channel=channel) units_current = _units.WithUnit(current, 'A') returnValue(units_current)
def getRate(self, dev): """Get flow rate.""" # The string '@U?V' asks the device for the current reading # The '\r' at the end is the carriage return letting the device # know that it was the end of the command. #print("getting rate") yield dev.write_line("@U?V\r") yield sleep(0.5) reading = yield dev.read_line() # Instrument randomly decides not to return, here's a hack. if not reading: returnValue(None) else: # Get the last number in the string. reading.rsplit(None, 1)[-1] # Strip the 'L' off the string. reading = float(reading.lstrip("L")) # Convert the reading to the correct units. gal = units.WithUnit(1, 'gal') output = reading * gal / units.min returnValue(output)
def setRabiFrequencyFromPiTime(self, twopitime): if self.curveName == 'Rabi Flop': # create reasonable guess for rabi frequency based on sideband, trap_frequency trap_frequency = self.parent.savedAnalysisParameters[ self.dataset, self.directory, self.index, 'Rabi Flop'][0]['Trap Frequency'] sideband_order = self.parent.savedAnalysisParameters[ self.dataset, self.directory, self.index, 'Rabi Flop'][0]['Sideband'] nmax = self.parent.savedAnalysisParameters[self.dataset, self.directory, self.index, 'Rabi Flop'][0]['nmax'] # call time evolution via fitRabiflop to get lamb-dicke parameter import timeevolution as te from labrad import units as U eta = te.time_evolution(U.WithUnit(trap_frequency, 'MHz'), sideband_order, nmax).eta self.parent.savedAnalysisParameters[ self.dataset, self.directory, self.index, self.curveName][0]['Rabi Frequency'] = 1.0 / ( (2.0 * eta)**np.abs(sideband_order) * twopitime * 10**-6) self.fitCurves(parameters=self.getParameter(), drawCurves=True) self.onActivated()
'0029_59', '0037_26', '0045_03', '0058_32', '0106_09', '0112_10', '0119_38', '0127_15', '0135_01' ] #Plotting and averaging parameter ymax = 0.1 size = 1 average_until = 24 realtime = True dephasing_time_string = r'$\pi$' folder = 'pi' #parameters and initial guesses for fit sideband = 1.0 amax = 2500.0 f_Rabi_init = U.WithUnit(103.0, 'kHz') nb_init = 0.17 delta_init = U.WithUnit(1000.0, 'Hz') fit_range_min = U.WithUnit(0.0, 'us') fit_range_max = U.WithUnit(347.0, 'us') delta_fluc_init = U.WithUnit(100.0, 'Hz') dephasing_time_offset = U.WithUnit(0, 'us') #actual script starts here class Parameter: def __init__(self, value): self.value = value def set(self, value): self.value = value
'1806_37', '1809_31', '1812_25', '1815_19' ] #provide list of evolutions with different phases - all need to have same x-axis dephase_directory = ['', 'Experiments', 'RamseyDephaseScanSecondPulse', date] dephase_files = [ '1750_43', '1753_37', '1756_31', '1759_26', '1802_19', '1805_13', '1808_08', '1811_02', '1813_56' ] flop_numbers = range(len(flop_files)) dephase_numbers = range(len(dephase_files)) #parameters and initial guesses for fit sideband = 1.0 trap_frequency = U.WithUnit(2.85, 'MHz') amax = 2000.0 f_Rabi_init = U.WithUnit(82.2, 'kHz') nb_init = 3.0 delta_init = U.WithUnit(1.0, 'kHz') fit_range_min = U.WithUnit(0.0, 'us') fit_range_max = U.WithUnit(80.0, 'us') delta_fluc_init = U.WithUnit(0, 'Hz') dephasing_time_offset = U.WithUnit(0.0, 'us') #SET PARAMETERS nb = Parameter(nb_init) f_Rabi = Parameter(f_Rabi_init['Hz']) delta = Parameter(delta_init['Hz']) delta_fluc = Parameter(delta_fluc_init['Hz']) fit_params = [nb, f_Rabi, delta, delta_fluc]
def get_nbar(flop_directory, blue_file, red_file, fit_until=U.WithUnit(1000.0, 'us'), show=False): print 'obtaining nbar from peak ratio of red and blue flop ...', #parameters and initial guesses for fit sideband = 1.0 amax = 2000.0 f_Rabi_init = U.WithUnit(150.0, 'kHz') nb_init = 0.1 delta_init = U.WithUnit(1000.0, 'Hz') fit_range_min = U.WithUnit(0.0, 'us') fit_range_max = fit_until delta_fluc_init = U.WithUnit(100.0, 'Hz') #actual script starts here class Parameter: def __init__(self, value): self.value = value def set(self, value): self.value = value def __call__(self): return self.value def fit(function, parameters, y, x=None): def f(params): i = 0 for p in parameters: p.set(params[i]) i += 1 return y - function(x) if x is None: x = np.arange(y.shape[0]) p = [param() for param in parameters] return optimize.leastsq(f, p) #get access to servers cxn = labrad.connect('192.168.169.197', password='******') dv = cxn.data_vault #get trap frequency dv.cd(flop_directory) dv.cd(blue_file) dv.open(1) sideband_selection = dv.get_parameter('RabiFlopping.sideband_selection') sb = np.array(sideband_selection) trap_frequencies = [ 'TrapFrequencies.radial_frequency_1', 'TrapFrequencies.radial_frequency_2', 'TrapFrequencies.axial_frequency', 'TrapFrequencies.rf_drive_frequency' ] trap_frequency = dv.get_parameter( str(np.array(trap_frequencies)[sb.nonzero()][0])) #SET PARAMETERS nb = Parameter(nb_init) f_Rabi = Parameter(f_Rabi_init['Hz']) delta = Parameter(delta_init['Hz']) delta_fluc = Parameter(delta_fluc_init['Hz']) #which to fit? fit_params = [nb, f_Rabi, delta, delta_fluc] # take Rabi flops data = dv.get().asarray blue_flop_y_axis = data[:, 1] blue_flop_x_axis = data[:, 0] * 10**(-6) dv.cd(1) dv.cd(red_file) dv.open(1) data = dv.get().asarray red_flop_y_axis = data[:, 1] red_flop_x_axis = data[:, 0] * 10**(-6) #fit Rabi Flops to theory blue_evo = tp.time_evolution(trap_frequency, sideband, nmax=amax) def blue_f(x): evolution = blue_evo.state_evolution_fluc(x, nb(), f_Rabi(), delta(), delta_fluc()) return evolution red_evo = tp.time_evolution(trap_frequency, -sideband, nmax=amax) def red_f(x): evolution = red_evo.state_evolution_fluc(x, nb(), f_Rabi(), delta(), delta_fluc()) return evolution #FIT BLUE fitting_region = np.where((blue_flop_x_axis >= fit_range_min['s']) & (blue_flop_x_axis <= fit_range_max['s'])) fit(blue_f, fit_params, y=blue_flop_y_axis[fitting_region], x=blue_flop_x_axis[fitting_region]) blue_nicer_resolution = np.linspace(0, blue_flop_x_axis.max(), 1000) blue_flop_fit_y_axis = blue_evo.state_evolution_fluc( blue_nicer_resolution, nb(), f_Rabi(), delta(), delta_fluc()) m = pylab.unravel_index( np.array(blue_flop_fit_y_axis).argmax(), np.array(blue_flop_fit_y_axis).shape) blue_max = np.array(blue_flop_fit_y_axis).max() fit_params = [nb, delta, delta_fluc] #FIT RED fitting_region = np.where((red_flop_x_axis >= fit_range_min['s']) & (red_flop_x_axis <= fit_range_max['s'])) fit(red_f, fit_params, y=red_flop_y_axis[fitting_region], x=red_flop_x_axis[fitting_region]) red_nicer_resolution = np.linspace(0, red_flop_x_axis.max(), 1000) red_flop_fit_y_axis = red_evo.state_evolution_fluc(red_nicer_resolution, nb(), f_Rabi(), delta(), delta_fluc()) red_max = red_flop_fit_y_axis[m] r = red_max / blue_max ratio_nbar = r / (1 - r) if show: size = 0.8 figure = pyplot.figure() pyplot.plot(blue_nicer_resolution * 10**6, blue_flop_fit_y_axis, 'b-') yerrflop = np.sqrt((1 - blue_flop_y_axis) * blue_flop_y_axis / (100.0)) pyplot.errorbar(blue_flop_x_axis * 10**6, blue_flop_y_axis, yerrflop, xerr=0, fmt='bo') pyplot.xlabel(r'Evolution time in $\mu s$', fontsize=size * 22) pyplot.ylim((0, 1)) pyplot.ylabel('Local Hilbert-Schmidt Distance', fontsize=size * 22) #pyplot.legend() pyplot.plot(red_nicer_resolution * 10**6, red_flop_fit_y_axis, 'r-') yerrflop = np.sqrt((1 - red_flop_y_axis) * red_flop_y_axis / (100.0)) pyplot.errorbar(red_flop_x_axis * 10**6, red_flop_y_axis, yerrflop, xerr=0, fmt='ro') pyplot.text( blue_flop_x_axis.max() * 0.70 * 10**6, 0.80, 'nbar (from ratio at blue peak) = {:.2f}'.format(ratio_nbar)) pyplot.tick_params(axis='x', labelsize=size * 20) pyplot.tick_params(axis='y', labelsize=size * 20) pyplot.show() print 'done.' return ratio_nbar
import labrad from labrad import units as U import timeevolution as te # PROVIDE INFO FOR PLOTS #'dataset' has three levels: # 1st level: plots which need to be averaged (NEED TO SHARE SAME TIME AXIS) # 2nd level: sets to be joined to one plot (CONSECUTIVE TIME AXES) # 3rd level: Dates and Filenames of the parts #82.1919804367 info = { 'plot_type': 'rabi_flop', 'title': 'Rabi-Flop', 'sideband': 1, 'offset_time': U.WithUnit(600.0, 'ns'), 'trap_frequency': U.WithUnit(2.8472, 'MHz'), #ENTER WITHOUT 2Pi FACTOR 'nmax': 1000, 'fit_until': U.WithUnit(80, 'us'), 'fit_from': U.WithUnit(2, 'us'), 'folder': 'RabiFlopping', #'datasets':[[['2013Feb05','1137_00'],['2013Feb05','1138_55']]], #'datasets':[[['2013Feb05','1433_43']],[['2013Feb05','1431_49']],[['2013Feb05','1435_40']]], 'datasets': [[['2013Mar08', '2224_13']]], #0034_31 0033_00 'fit_init_nbar': 3, # 'take_init_fRabi_from_Pi_time':U.WithUnit(16,'us'), 'fit_init_fRabi': U.WithUnit(82.191, 'kHz'), 'fit_init_delta': U.WithUnit(1, 'kHz'), 'fit_init_delta_fluc': U.WithUnit(1, 'kHz'), 'fit_fRabi': True, 'fit_nbar': True,
dephase_directory = ['','Experiments','RamseyDephaseScanSecondPulse',date] dephase_files = ['1722_33','1724_43','1727_44','1729_54','1732_47','1734_57','1737_58','1740_08','1743_01'] #,'2123_59' number nine slightly off, not taken into account #Plotting and averaging parameter ymax = 0.2 size = 0.75 average_until = 20 realtime = True dephasing_time_string = r'$2\pi$' folder = '2pi' #parameters and initial guesses for fit sideband = 1.0 amax=2500.0 f_Rabi_init = U.WithUnit(179907.219777,'Hz') nb_init = 4.33773335305 delta_init = U.WithUnit(1000.0,'Hz') fit_range_min=U.WithUnit(0.0,'us') fit_range_max=U.WithUnit(150.0,'us') delta_fluc_init=U.WithUnit(100.0,'Hz') dephasing_time_offset=U.WithUnit(0,'us') #actual script starts here class Parameter: def __init__(self, value): self.value = value def set(self, value): self.value = value
nbars.append(x[0]) enbars.append(x[1]) times.append(x[2]) etimes.append(x[3]) averages.append(x[4]) errors.append(x[5]) trap_frequencies.append(x[6]) etas.append(x[7]) print nbars print enbars size = .85 nbar = np.average(nbars) trap_frequency = U.WithUnit(np.average(trap_frequencies), 'MHz') eta = np.average(etas) enbar = 1.0 / len(nbars) * np.sqrt(np.sum(np.array(enbars)**2)) print 'nbar = {:.3f}+-{:.3f}'.format(nbar, enbar) sideband = 1.0 evo = tp.time_evolution(trap_frequency, sideband, nmax=1000) figure = pyplot.figure(figsize=(16.5, 5.5)) figure.subplots_adjust(left=0.07, right=0.95, bottom=0.225, top=0.95) ax1 = figure.add_subplot(111) fake_f = 100000
# 'sideband':-1, # 'offset_time': U.WithUnit(600,'ns'), # 'trap_frequency': U.WithUnit(2.8, 'MHz'), #ENTER WITHOUT 2Pi FACTOR (UNLIKE THEORY PREDICTION) # 'nmax':5000, # 'fit_until':U.WithUnit(80,'us'), # 'folder':'RabiFlopping', # #'datasets':[[['2013Feb05','1137_00'],['2013Feb05','1138_55']]], # #'datasets':[[['2013Feb05','1433_43']],[['2013Feb05','1431_49']],[['2013Feb05','1435_40']]], # 'datasets':[[['2013Mar01','1842_01']]], # 'fit_init_nbar':5, # 'fit_init_RabiTime':U.WithUnit(24,'us'), # 'plot_initial_values':False} info = { 'plot_type': 'ramsey_fringe', 'title': 'Ramsey Fringes', 'fit_from': U.WithUnit(0, 'us'), 'fit_until': U.WithUnit(150, 'us'), 'folder': 'RamseyScanGap', #'datasets':[[['2013Jan17','1731_45'],['2013Jan17','1733_00']]], #'datasets':[[['2012Dec20','2105_00']]], #'datasets':[[['2012Dec20','2121_24'],['2012Dec20','2123_16']]], 'datasets': [[['2013Mar05', '2023_53']]], 'fit_init_period': U.WithUnit(120, 'us'), 'fit_init_T2': U.WithUnit(100, 'us'), 'fit_init_phase': 0, 'fit_init_contrast': 0.9, 'plot_initial_values': False } #optimization
dephase_files = [ '0201_07', '0209_07', '0215_35', '0223_30', '0231_30', '0240_36', '0248_39', '0256_43', '0304_39', '0312_43' ] #Plotting and averaging parameter ymax = 0.5 size = 1 average_until = 23.9 realtime = True dephasing_time_string = r'$\frac{3\pi}{2}$' #parameters and initial guesses for fit sideband = 1.0 amax = 2000.0 f_Rabi_init = U.WithUnit(85.0, 'kHz') nb_init = get_nbar(flop_directory, parameter_file, red_file, fit_until=U.WithUnit(200.0, 'us'), show=True) delta_init = U.WithUnit(1000.0, 'Hz') fit_range_min = U.WithUnit(150.0, 'us') fit_range_max = U.WithUnit(450.0, 'us') delta_fluc_init = U.WithUnit(100.0, 'Hz') dephasing_time_offset = U.WithUnit(0, 'us') #actual script starts here class Parameter: def __init__(self, value):
import timeevolution as te from matplotlib import pyplot import numpy as np from labrad import units as U tmin = 0 tmax = 0.001 t = np.linspace(tmin, tmax, 1000) evo = te.time_evolution(U.WithUnit(2.8, 'MHz'), 1) omega = 180000 nbar = 0.626127382989 #evo.state_evolution(t, 5.0, 20000) nminusone = evo.n - 1 nminusone[0] = 0 omeganminusone = evo.effective_rabi_coupling(nminusone) * omega omeganminusone[0] = 0 omegan = evo.rabi_coupling * omega p = evo.p_thermal(nbar, nshift=False) ones = np.ones_like(t) flop = evo.state_evolution(t, nbar, omega / (2.0 * np.pi)) gg = 0.5 * np.sum(np.outer(p, ones) * (np.cos(np.outer(omegan / 2.0, t))**2 + np.sin(np.outer(omeganminusone / 2.0, t))**2), axis=0) eg = -0.5 * 1.j * np.sum( np.outer(p, ones) * np.cos(np.outer(omeganminusone / 2.0, t)) * (np.cos(np.outer(omegan / 2.0, t)) - 1.j * np.sin(np.outer(omeganminusone / 2.0, t))),
def return_c_unit(self, c): return _u.WithUnit(60.0, 'm')
'2012_22', '2015_45', '2018_33', '2021_55', '2024_44', '2028_06', '2030_55', '2034_27', '2037_06' ] #Plotting and averaging parameter ymax = 0.5 size = 0.75 average_until = 20 realtime = True dephasing_time_string = r'$\frac{3\pi}{4}$' folder = '3piover4' #parameters and initial guesses for fit sideband = 1.0 amax = 2000.0 f_Rabi_init = U.WithUnit(204822.413864, 'Hz') nb_init = 5.08184341765 delta_init = U.WithUnit(5000.0, 'Hz') fit_range_min = U.WithUnit(0.0, 'us') fit_range_max = U.WithUnit(350.0, 'us') delta_fluc_init = U.WithUnit(100.0, 'Hz') dephasing_time_offset = U.WithUnit(0, 'us') #actual script starts here class Parameter: def __init__(self, value): self.value = value def set(self, value): self.value = value
#provide list of evolutions with different phases - all need to have same x-axis dephase_directory = ['','Experiments','RamseyDephaseScanSecondPulse',date] dephase_files = ['1932_03','1936_05','1939_04','1943_06','1946_50','1949_40','1952_30','1955_54','1958_45'] #Plotting and averaging parameter ymax = 0.25 size = 1 average_until = 20 realtime = True dephasing_time_string = r'$\frac{\pi}{4}$' folder='piover4' #parameters and initial guesses for fit sideband = 1.0 amax=2000.0 f_Rabi_init = U.WithUnit(176157.568436,'Hz') nb_init = 5.93398590461 delta_init = U.WithUnit(1000.0,'Hz') fit_range_min=U.WithUnit(0.0,'us') fit_range_max=U.WithUnit(350.0,'us') delta_fluc_init=U.WithUnit(100.0,'Hz') dephasing_time_offset=U.WithUnit(0,'us') #actual script starts here class Parameter: def __init__(self, value): self.value = value def set(self, value): self.value = value