def sweep(bench, wave, pulsewidth=0.035, sweeprate=1.2): ''' sweeprate in V/s or A/s pulsewidth: waiting/staying/settling/stabilization time in sec Voltage Range (AUTO): R2: 10mV; R3: 100mV; R4: 1V; R5: 10V; R6: 30V ''' GPIBspeed = 62 #pts/s Vdata = waveform(wave).data SweepTime = abs(waveform(wave).data[0] - waveform(wave).data[-1]) / sweeprate + pulsewidth * waveform(wave).count for i,V in enumerate(Vdata): v_prev = float(previous(bench)) if i == 0: Startime = time() try: #smoothen the transition by interpolating points as much as possible: SweepRange = waveform("%sto%s*%s" %(v_prev, V, int(abs(V-v_prev) * GPIBspeed / sweeprate))).data for v in SweepRange: bench.write('SA%.8fE'%v) #Set Voltage (V) or Current (A) if eval(debugger): print(Fore.YELLOW + "Staying %.5fV..." %V) with suppress(NameError): print(Fore.BLUE + "Time remaining: %.3fs" %(SweepTime - time() + Startime)) sleep(pulsewidth) except: print("Error setting V") return Vdata, SweepTime
def accesstructure(self): '''Get User-Data's container & location from LOG Pre-requisite: pqfile (from selectmoment / selectday) ''' try: self.filesize = stat(self.pqfile).st_size with open(self.pqfile, 'rb') as datapie: i = 0 while i < (self.filesize): datapie.seek(i) bite = datapie.read(7) if bite == b'\x02' + bytes("ACTS", 'utf-8') + b'\x03\x04': # ACTS self.datalocation = i break else: i += 1 datapie.seek(0) bite = datapie.read(self.datalocation) datacontainer = bite.decode('utf-8') self.writtensize = self.filesize - self.datalocation - 7 self.datacontainer = ast.literal_eval( datacontainer) # library w/o the data yet # Access library keys: self.corder = [x for x in self.datacontainer.values()][0]['c-order'] self.datadensity = [x for x in self.datacontainer.values() ][0]['data-density'] self.comment = [x for x in self.datacontainer.values()][0]['comment'] # Derive judging tools: self.datasize = prod([ waveform(x).count * waveform(x).inner_repeat for x in self.corder.values() ]) * self.datadensity self.data_progress = float(self.writtensize / (self.datasize * 8) * 100) self.data_complete = (self.datasize * 8 == self.writtensize) self.data_overflow = (self.datasize * 8 < self.writtensize) Last_Corder = [i for i in self.corder.values() ][-1] # for the last key of c-order self.data_mismatch = self.writtensize % waveform( Last_Corder).count * waveform( Last_Corder).inner_repeat * 8 # counts & inner-repeats print(Back.WHITE + Fore.BLACK + "Data starts from %s-byth on the file with size of %sbytes" % (self.datalocation, self.filesize)) if not self.writtensize % 8: self.resumepoint = self.writtensize // 8 else: self.resumepoint = self.datasize print(Back.RED + "SKIP SAVING: REPAIR DATA FIRST!") except: raise return
def accesstructure(self): '''Get User-Data's container & location from LOG Pre-requisite: pqfile (from selectmoment / selectday) ''' try: self.filesize = stat(self.pqfile).st_size with open(self.pqfile, 'rb') as datapie: i = 0 while i < (self.filesize): datapie.seek(i) bite = datapie.read(7) if bite == b'\x02' + bytes("ACTS", 'utf-8') + b'\x03\x04': # ACTS self.datalocation = i break else: i += 1 datapie.seek(0) bite = datapie.read(self.datalocation) datacontainer = bite.decode('utf-8') self.writtensize = self.filesize - self.datalocation - 7 self.datacontainer = ast.literal_eval( datacontainer) # library w/o the data yet self.corder = [x for x in self.datacontainer.values()][0]['c-order'] self.datasize = prod( [waveform(x).count for x in self.corder.values()]) self.data_complete = (self.datasize * 8 == self.writtensize) self.data_overflow = (self.datasize * 8 < self.writtensize) self.data_mismatch = self.writtensize % waveform( self.corder['Var']).count * 8 print(Back.WHITE + Fore.BLACK + "Data starts from %s-byth on the file with size of %sbytes" % (self.datalocation, self.filesize)) if not self.writtensize % 8: self.resumepoint = self.writtensize // 8 else: self.resumepoint = self.datasize print(Back.RED + "SKIP SAVING: REPAIR DATA FIRST!") except: raise return
def nasetfreqrange(): natype = request.args.get('natype') freqrange = waveform(request.args.get('freqrange')) frequnit = request.args.get('frequnit').replace("Hz","") NA[natype].sweep(nabench[natype], action=['Set', 'ON', freqrange.count]) fstart, fstop = si_parse(str(freqrange.data[0])+frequnit), si_parse(str(freqrange.data[-1])+frequnit) NA[natype].sweep(nabench[natype], action=['Set', 'ON', freqrange.count]) NA[natype].linfreq(nabench[natype], action=['Set', fstart, fstop]) message = 'frequency: %s to %s' %(fstart, fstop) return jsonify(message=message)
def TESTC( corders={ 'C1': [0, 0, 0], 'C2': [0, 0, 0], 'C3': [0, 0, 0], 'C4': [0, 0, 0], 'C5': [0, 0, 0] }, comment='', dayindex='', taskentry=0, resumepoint=0): '''Serve as a template for other real tasks to come dayindex: {string:access data, -1:new data 0-:manage data} ''' x = 0 C1 = waveform('%s to %s * %s' % tuple(corders['C1'])) C2 = waveform('%s to %s * %s' % tuple(corders['C2'])) C3 = waveform('%s to %s * %s' % tuple(corders['C3'])) C4 = waveform('%s to %s * %s' % tuple(corders['C4'])) C5 = waveform('%s to %s * %s' % tuple(corders['C5'])) datasize = C1.count * C2.count * C3.count * C4.count * C5.count # setting how often the data is logged along the way: buffersize = C5.count yield corders, comment, dayindex, taskentry, buffersize, resumepoint # running measurement: data = [] for i in range(resumepoint, datasize): # print("%s of %s"%(i+1,datasize)) caddress = cdatasearch( i, [C1.count, C2.count, C3.count, C4.count, C5.count]) # Use Cj.data[caddress[j]] for parameters' value here x += 1 # x = C1.data[caddress[0]] + C5.data[caddress[4]]*C2.data[caddress[1]]*sin(pi/2*C3.data[caddress[2]]) + C4.data[caddress[3]] data.append(x) # saving chunck by chunck improves speed a lot! if not (i + 1) % buffersize: #multiples of buffersize yield data data = []
def test(): # Test Amplifier settings A = amplifier() for i in range(1): print(Back.GREEN + Fore.WHITE + "\nSensing Hard Panel #%s:" %(i+1)) A.sensehardpanel() print("SupplyP: %s" %A.SupplyP) print("SupplyN: %s" %A.SupplyN) print("Symmetry: %s" %A.Symmetry) print("Division: %s" %A.Division) print("Rb: %s" %A.Rb) print("Bias Mode: %s" %A.BiasMode) print("V Gain 1: %s" %A.VGain1) print("V Gain 2: %s" %A.VGain2) print("Vg Mode 1: %s" %A.VgMode1) print("Vg Mode 2: %s" %A.VgMode2) A.close() # Test Streaming IV-curve X0 = waveform("0 to -1 *150 to 1 *300 to 0 *150") XX = waveform("1to1*2") print("XX-count: %s\nXX-data:\n%s"%(XX.count,XX.data)) # waveform("0 to 5 *700 to 10*1300 to 0 * 1000"), waveform("0 to 3 *700 to 1*1500 to 7*500 to 0 * 300") #原本的 M = measure(sample_rate=1000, duty_cycle=0.8, samps_per_chan=X0.count) M = measure(sample_rate=1500, duty_cycle=0.825, samps_per_chan=X0.count) # New one read_values = M.IVb(X0.data) V0 = read_values[0] V = read_values[3]/(A.Rb) #curve([range(X0.count),range(V.size)], [array(X0.data)/A.Division,list(V0)], "Channel #0", "arb time", "V(V)", ["-k","or"]) # print(list(V)) # curve([],[list(V)] ,"IRCdelayT","RCdelayT", "I", [".k"]) # New one curve([array(X0.data)/A.Division], [list(V)], "IVb", "V", "I", [".k"]) curve([array(X0.data[:-1])/A.Division], [derivative(array(X0.data)/A.Division, V)[1]], "IVb", "V", "I", [".k"]) M.close() return
def dcmeasureivcurve(): V0, I, Vb = [], [], [] vrange = waveform(request.args.get('vrange')) mdelay = float(request.args.get('mdelay')) mwaiting = float(request.args.get('mwaiting')) ivcurve = DC.measure(delay=mdelay*1e-3, waiting=mwaiting*1e-3, samps_per_chan=vrange.count) print("DC Measurement Started") read_values = ivcurve.IVb(vrange.data) V0 = list(read_values[0]) #ai0 I = list(read_values[3] / Amp_Rb) #ai3 Vb = [x/Amp_Div for x in vrange.data] ivcurve.close() print("DC Measurement Closed") return jsonify(state=ivcurve.state, V0=V0, I=I, Vb=Vb)
def char_fresp_access(): wmoment = int(request.args.get('wmoment')) M_fresp[session['user_name']].selectmoment(wmoment) M_fresp[session['user_name']].accesstructure() data_progress = M_fresp[session['user_name']].data_progress # Measurement time: filetime = getmtime(M_fresp[session['user_name']].pqfile) # in seconds startmeasure = mktime( strptime( M_fresp[session['user_name']].day + " " + M_fresp[session['user_name']].startime(), "%Y-%m-%d(%a) %H:%M")) # made into seconds measureacheta = str( timedelta(seconds=(filetime - startmeasure) / data_progress * (trunc(data_progress / 100 + 1) * 100 - data_progress))) try: cfluxbias = waveform(M_fresp[session['user_name']].corder['Flux-Bias']) except (KeyError): cfluxbias = waveform('opt,') csparam = waveform(M_fresp[session['user_name']].corder['S-Parameter']) cifb = waveform(M_fresp[session['user_name']].corder['IF-Bandwidth']) cpowa = waveform(M_fresp[session['user_name']].corder['Power']) cfreq = waveform(M_fresp[session['user_name']].corder['Frequency']) session['c_fresp_structure'] = [ cfluxbias.count, csparam.count, cifb.count, cpowa.count, cfreq.count * M_fresp[session['user_name']].datadensity ] session['c_fresp_address'] = cdatasearch( M_fresp[session['user_name']].resumepoint - 1, session['c_fresp_structure']) # list each parameter range based on data-progress: cfluxbias_data = cfluxbias.data[0:session['c_fresp_address'][0] + 1] csparam_data = csparam.data[0:session['c_fresp_address'][1] + 1] cifb_data = cifb.data[0:session['c_fresp_address'][2] + 1] cpowa_data = cpowa.data[0:session['c_fresp_address'][3] + 1] cfreq_data = cfreq.data # within buffer return jsonify(data_progress=data_progress, measureacheta=measureacheta, corder=M_fresp[session['user_name']].corder, comment=M_fresp[session['user_name']].comment, cfluxbias_data=cfluxbias_data, csparam_data=csparam_data, cifb_data=cifb_data, cpowa_data=cpowa_data, cfreq_data=cfreq_data)
def test(): # Test Amplifier settings A = amplifier() for i in range(1): print("\nSensing Hard Panel #%s:" % (i + 1)) A.sensehardpanel() print("SupplyP: %s" % A.SupplyP) print("SupplyN: %s" % A.SupplyN) print("Symmetry: %s" % A.Symmetry) print("Division: %s" % A.Division) print("Rb: %s" % A.Rb) print("Bias Mode: %s" % A.BiasMode) print("V Gain 1: %s" % A.VGain1) print("V Gain 2: %s" % A.VGain2) print("Vg Mode 1: %s" % A.VgMode1) print("Vg Mode 2: %s" % A.VgMode2) A.close() # Test Streaming IV-curve X0 = waveform( "0 to -10 *1000 to 10 *2000 to 0 * 1000 " ) # waveform("0 to 5 *700 to 10*1300 to 0 * 1000"), waveform("0 to 3 *700 to 1*1500 to 7*500 to 0 * 300") M = measure(delay=5e-3, waiting=5e-3, samps_per_chan=X0.count) read_values = M.IVb(X0.data) V0 = read_values[0] I = read_values[3] / (A.Rb) curve([range(X0.count), range(I.size)], [array(X0.data) / A.Division, list(V0)], "Channel #0", "arb time", "V(V)", ["-k", "or"]) # print(list(V)) curve([array(X0.data) / A.Division], [list(I)], "IVb", "V", "I", [".k"]) curve([array(X0.data[:-1]) / A.Division], [derivative(array(X0.data) / A.Division, I)[1]], "IVb", "V", "I", [".k"]) M.close() return
def awgsettingsifwave(): global awgsess AWG.Clear_ArbMemory(awgsess) # PENDING MOVE to TABs samplingrate = AWG.arb_sample_rate(awgsess)[1] dt = 1e9 / samplingrate # in ns message, WaveForms = [], [] WAVE = [] # PRESET Output: ''' To get the BEST from AWG (M9331A). It can be considered a bug to such extent that without this, the output amplitude would be somewhat inconsistent and very much suppressed. ''' for ch in range(2): channel = str(ch + 1) AWG.output_config(awgsess, RepCap=channel, action=["Set", 0]) # Single-ended AWG.output_filter_bandwidth(awgsess, RepCap=channel, action=["Set", 0]) AWG.arb_gain(awgsess, RepCap=channel, action=["Set", 0.5]) AWG.output_impedance(awgsess, RepCap=channel, action=["Set", 50]) # Output Settings: outputch = [request.args.get('outputch1'), request.args.get('outputch2')] oupfiltr = [request.args.get('oupfiltr1'), request.args.get('oupfiltr2')] oupconfig = [ request.args.get('oupconfig1'), request.args.get('oupconfig2') ] for ch in range(2): channel = str(ch + 1) stat = AWG.output_enabled(awgsess, RepCap=channel, action=["Set", int(outputch[ch])]) message += [ 'output channel %s: %s <%s>' % (channel, output_code(stat[1]), status_code(stat[0])) ] stat = AWG.output_filter_enabled( awgsess, RepCap=channel, action=["Set", bool(int(oupfiltr[ch]))]) message += [ 'output filter channel %s: %s <%s>' % (channel, output_code(stat[1]), status_code(stat[0])) ] stat = AWG.output_config(awgsess, RepCap=channel, action=["Set", int(oupconfig[ch])]) message += [ 'output configuration %s: %s <%s>' % (channel, output_code(stat[1]), status_code(stat[0])) ] AWG.output_filter_bandwidth(awgsess, RepCap=channel, action=["Set", 0]) AWG.arb_gain(awgsess, RepCap=channel, action=["Set", 0.5]) AWG.output_impedance(awgsess, RepCap=channel, action=["Set", 50]) # Waveform Construction: ifperiod = float(request.args.get('ifperiod')) Nperiod = round(ifperiod / dt) // 8 * 8 + 8 # to ensure multiples of 8 iffunction = request.args.get('iffunction1'), request.args.get( 'iffunction2') ifdesign = request.args.get('ifdesign1'), request.args.get('ifdesign2') iffreq = float(request.args.get('iffreq1')), float( request.args.get('iffreq2')) ifvoltag = float(request.args.get('ifvoltag1')), float( request.args.get('ifvoltag2')) ifoffset = float(request.args.get('ifoffset1')), float( request.args.get('ifoffset2')) ifphase = float(request.args.get('ifphase1')), float( request.args.get('ifphase2')) ifontime = float(request.args.get('ifontime1')), float( request.args.get('ifontime2')) ifscale = float(request.args.get('ifscale1')), float( request.args.get('ifscale2')) sqeifoffset = float(request.args.get('sqeifoffset1')), float( request.args.get('sqeifoffset2')) ifdelay = float(request.args.get('ifdelay1')), float( request.args.get('ifdelay2')) for ch in range(2): channel = str(ch + 1) # Create Waveforms: if iffunction[ch] == 'arb': wavefom = waveform(ifdesign[ch]).data elif iffunction[ch] == 'sqe': wavefom = squarewave(ifperiod, ifontime[ch], ifdelay[ch], ifscale[ch], sqeifoffset[ch]) else: wavefom = [ ifvoltag[ch] * eval(iffunction[ch] + '(x*%s*%s/1000*2*pi + %s/180*pi)' % (dt, iffreq[ch], ifphase[ch])) + ifoffset[ch] for x in range(Nperiod) ] stat, wave = AWG.CreateArbWaveform(awgsess, wavefom) message += [ 'Waveform channel %s: %s <%s>' % (channel, wave, status_code(stat)) ] WAVE.append(wave) WaveForms.append(wavefom * 3) # Collecting waveforms to plot on mach # Building Sequences: for ch in range(2): channel = str(ch + 1) status, seqhandl = AWG.CreateArbSequence( awgsess, [WAVE[ch]], [1]) # loop# canbe >1 if longer sequence is needed in the future! message += [ 'Sequence channel %s: %s <%s>' % (channel, seqhandl, status_code(status)) ] # Channel Assignment: stat = AWG.arb_sequence_handle(awgsess, RepCap=channel, action=["Set", seqhandl]) message += [ 'Sequence channel %s embeded: %s <%s>' % (channel, stat[1], status_code(stat[0])) ] # Trigger Settings: for ch in range(2): channel = str(ch + 1) AWG.operation_mode(awgsess, RepCap=channel, action=["Set", 0]) AWG.trigger_source_adv(awgsess, RepCap=channel, action=["Set", 0]) # AWG.burst_count(awgsess, RepCap=channel, action=["Set", 1000001]) return jsonify(message=message, WaveForms=WaveForms, t=[i * dt for i in range(len(wavefom) * 3)])
Logs = SQE_Pulse('abc') Logs.selectday(Logs.whichday()) m = Logs.whichmoment() Logs.selectmoment(m) print("File selected: %s" % Logs.pqfile) Logs.accesstructure() print("Loading parameters:\n") print(Logs.corder) # select from data Logs.loadata() alldata = Logs.selectedata structure = Logs.corder['C-Structure'] cstructure = [ waveform(Logs.corder[param]).count for param in structure ][:-1] + [waveform(Logs.corder[structure[-1]]).count * Logs.datadensity] print('cstructure: %s' % cstructure) timesweep = range( waveform(Logs.corder['Sampling-Time']).count * Logs.datadensity) # choosing c-parameters: C = dict(xyl='XY-ifLevel', tau='XY-Pulse-Width', xyp='XY-Power', xyf='XY-Frequency', rof='RO-Frequency', flx='Flux-Bias') C_option = input("Choose among c-constants: (%s)" % [x for x in C.keys()]) C_index = input("Enter index 0-%s << " % (waveform(Logs.corder[C[C_option]]).count - 1))
def char_cwsweep_1ddata(): print(Fore.GREEN + "User %s is plotting 1D-Data" % session['user_name']) M_cwsweep[session['user_name']].loadata() selectedata = M_cwsweep[session['user_name']].selectedata # load parameter indexes from json call: irepeat = request.args.get('irepeat') ifluxbias = request.args.get('ifluxbias') ixyfreq = request.args.get('ixyfreq') ixypowa = request.args.get('ixypowa') isparam = request.args.get('isparam') iifb = request.args.get('iifb') ifreq = request.args.get('ifreq') ipowa = request.args.get('ipowa') # pre-transform ipowa: xpowa = waveform(M_cwsweep[session['user_name']].corder['Power']) ipowa_repeat = xpowa.inner_repeat # selecting data: if "x" in ifluxbias: xtitle = "<b>Flux-Bias(V/A)</b>" selected_sweep = M_cwsweep[session['user_name']].corder['Flux-Bias'] if int(irepeat ) < session['c_cwsweep_address'][0]: # address's part before x # print("Well within Progress!") xsweep = range( session['c_cwsweep_structure'][1] ) # can access full-range if selection is well within progress resume-point else: xsweep = range(session['c_cwsweep_address'][1] + 1) # can only access until progress resume-point selected_Ir, selected_Qr = [], [] for i_prepeat in range(ipowa_repeat): r_powa = int( ipowa ) * ipowa_repeat + i_prepeat # from the beginning position of repeating power selected_Ir += [ selectedata[gotocdata([ int(irepeat), x, int(ixyfreq), int(ixypowa), int(isparam), int(iifb), int(ifreq), 2 * r_powa ], session['c_cwsweep_structure'])] for x in xsweep ] selected_Qr += [ selectedata[gotocdata([ int(irepeat), x, int(ixyfreq), int(ixypowa), int(isparam), int(iifb), int(ifreq), 2 * r_powa + 1 ], session['c_cwsweep_structure'])] for x in xsweep ] # AVERAGE up those power repeats: selected_I = list( mean(array(selected_Ir).reshape(ipowa_repeat, len(xsweep)), axis=0)) selected_Q = list( mean(array(selected_Qr).reshape(ipowa_repeat, len(xsweep)), axis=0)) elif "x" in ixyfreq: xtitle = "<b>XY-Frequency(GHz)</b>" selected_sweep = M_cwsweep[session['user_name']].corder['XY-Frequency'] if [int(irepeat), int(ifluxbias) ] < session['c_cwsweep_address'][0:2]: # address's part before x xsweep = range( session['c_cwsweep_structure'][2] ) # can access full-range if selection is well within progress resume-point else: xsweep = range(session['c_cwsweep_address'][2] + 1) # can only access until progress resume-point selected_Ir, selected_Qr = [], [] for i_prepeat in range(ipowa_repeat): r_powa = int( ipowa ) * ipowa_repeat + i_prepeat # from the beginning position of repeating power selected_Ir += [ selectedata[gotocdata([ int(irepeat), int(ifluxbias), x, int(ixypowa), int(isparam), int(iifb), int(ifreq), 2 * r_powa ], session['c_cwsweep_structure'])] for x in xsweep ] selected_Qr += [ selectedata[gotocdata([ int(irepeat), int(ifluxbias), x, int(ixypowa), int(isparam), int(iifb), int(ifreq), 2 * r_powa + 1 ], session['c_cwsweep_structure'])] for x in xsweep ] # AVERAGE up those power repeats: selected_I = list( mean(array(selected_Ir).reshape(ipowa_repeat, len(xsweep)), axis=0)) selected_Q = list( mean(array(selected_Qr).reshape(ipowa_repeat, len(xsweep)), axis=0)) elif "x" in ixypowa: xtitle = "<b>XY-Power(dBm)</b>" selected_sweep = M_cwsweep[session['user_name']].corder['XY-Power'] if [int(irepeat), int(ifluxbias), int(ixyfreq) ] < session['c_cwsweep_address'][0:3]: # address's part before x xsweep = range( session['c_cwsweep_structure'][3] ) # can access full-range if selection is well within progress resume-point else: xsweep = range(session['c_cwsweep_address'][3] + 1) # can only access until progress resume-point selected_Ir, selected_Qr = [], [] for i_prepeat in range(ipowa_repeat): r_powa = int( ipowa ) * ipowa_repeat + i_prepeat # from the beginning position of repeating power selected_Ir += [ selectedata[gotocdata([ int(irepeat), int(ifluxbias), int(ixyfreq), x, int(isparam), int(iifb), int(ifreq), 2 * r_powa ], session['c_cwsweep_structure'])] for x in xsweep ] selected_Qr += [ selectedata[gotocdata([ int(irepeat), int(ifluxbias), int(ixyfreq), x, int(isparam), int(iifb), int(ifreq), 2 * r_powa + 1 ], session['c_cwsweep_structure'])] for x in xsweep ] # AVERAGE up those power repeats: selected_I = list( mean(array(selected_Ir).reshape(ipowa_repeat, len(xsweep)), axis=0)) selected_Q = list( mean(array(selected_Qr).reshape(ipowa_repeat, len(xsweep)), axis=0)) elif "x" in isparam: pass elif "x" in iifb: pass elif "x" in ifreq: xtitle = "<b>frequency(GHz)</b>" selected_sweep = M_cwsweep[session['user_name']].corder['Frequency'] if [ int(irepeat), int(ifluxbias), int(ixyfreq), int(ixypowa), int(isparam), int(iifb) ] < session['c_cwsweep_address'][0:6]: # address's part before x xsweep = range( session['c_cwsweep_structure'][6] ) # can access full-range if selection is well within progress resume-point else: xsweep = range(session['c_cwsweep_address'][6] + 1) # can only access until progress resume-point selected_Ir, selected_Qr = [], [] for i_prepeat in range(ipowa_repeat): r_powa = int( ipowa ) * ipowa_repeat + i_prepeat # from the beginning position of repeating power selected_Ir += [ selectedata[gotocdata([ int(irepeat), int(ifluxbias), int(ixyfreq), int(ixypowa), int(isparam), int(iifb), x, 2 * r_powa ], session['c_cwsweep_structure'])] for x in xsweep ] selected_Qr += [ selectedata[gotocdata([ int(irepeat), int(ifluxbias), int(ixyfreq), int(ixypowa), int(isparam), int(iifb), x, 2 * r_powa + 1 ], session['c_cwsweep_structure'])] for x in xsweep ] # AVERAGE up those power repeats: selected_I = list( mean(array(selected_Ir).reshape(ipowa_repeat, len(xsweep)), axis=0)) selected_Q = list( mean(array(selected_Qr).reshape(ipowa_repeat, len(xsweep)), axis=0)) elif "x" in ipowa: xtitle = "<b>Power(dBm)</b>" xpowa_repeat = ipowa_repeat if [ int(irepeat), int(ifluxbias), int(ixyfreq), int(ixypowa), int(isparam), int(iifb), int(ifreq) ] < session['c_cwsweep_address'][0:7]: # address's part before x xsweep = range( session['c_cwsweep_structure'][7] // 2 ) # can access full-range if selection is well within progress resume-point else: xsweep = range((session['c_cwsweep_address'][7] + 1) // 2) # can only access until progress resume-point selected_Ir = [ selectedata[gotocdata([ int(irepeat), int(ifluxbias), int(ixyfreq), int(ixypowa), int(isparam), int(iifb), int(ifreq), 2 * x ], session['c_cwsweep_structure'])] for x in xsweep ] selected_Qr = [ selectedata[gotocdata([ int(irepeat), int(ifluxbias), int(ixyfreq), int(ixypowa), int(isparam), int(iifb), int(ifreq), 2 * x + 1 ], session['c_cwsweep_structure'])] for x in xsweep ] # AVERAGE up those repeated IQ-pairs: selected_I = list( mean(array(selected_Ir).reshape( len(xsweep) // xpowa_repeat, xpowa_repeat), axis=1)) #--> selected_Q = list( mean(array(selected_Qr).reshape( len(xsweep) // xpowa_repeat, xpowa_repeat), axis=1)) #--> # preparing data: # assembly amplitude & phase: MagPha = [IQAP(x[0], x[1]) for x in zip(selected_I, selected_Q)] Amp, Pha = [], [] for i, j in MagPha: Amp.append(i) Pha.append(j) # x-range: if "x" in ipowa: selected_progress = xpowa.data[0:(len(xsweep) // xpowa_repeat)] else: selected_progress = waveform(selected_sweep).data[0:len(xsweep)] # to avoid exception when encountering recursive parameters: if "c" in ixyfreq + ixypowa + ifluxbias + isparam + iifb + ifreq + ipowa: selected_progress = list(range(len(selected_progress))) x1, y1, yup, yp = selected_progress, Amp, list( UnwraPhase(selected_progress, Pha)), Pha #list(unwrap(Pha)) global data_dict data_dict = { xtitle: x1, 'Amplitude': y1, 'UPhase': yup, 'I': selected_I, 'Q': selected_Q, "exported by": session['user_name'] } return jsonify(x1=x1, y1=y1, yup=yup, yp=yp, x1title=xtitle)
def F_Response(user, tag="", corder={}, comment='', dayindex='', taskentry=0, resumepoint=0, instr=['YOKO', 'ENA'], testeach=False): '''Characterizing Frequency Response: C-Order: Flux-Bias, S-Parameter, IF-Bandwidth, Power, Frequency ''' sample = get_status("MSSN")['sample'] # pushing pre-measurement parameters to settings: yield user, sample, tag, instr, corder, comment, dayindex, taskentry, testeach # User-defined Controlling-PARAMETER(s) ====================================================================================== fluxbias = waveform(corder['Flux-Bias']) Sparam = waveform(corder['S-Parameter']) ifb = waveform(corder['IF-Bandwidth']) powa = waveform(corder['Power']) freq = waveform(corder['Frequency']) # Total data points: datasize = prod([waveform(x).count for x in corder.values() ]) * 2 #data density of 2 due to IQ # Pre-loop settings: # ENA: bench = ENA.Initiate(True) ENA.dataform(bench, action=['Set', 'REAL']) ENA.sweep(bench, action=['Set', 'ON', freq.count]) fstart, fstop = freq.data[0] * 1e9, freq.data[-1] * 1e9 ENA.linfreq(bench, action=['Set', fstart, fstop]) # Linear Freq-sweep-range # YOKO: if "opt" not in fluxbias.data: # check if it is in optional-state yokog = YOKO.Initiate( current=True ) # PENDING option: choose between Voltage / Current output YOKO.output(yokog, 1) # Buffer setting(s) for certain loop(s): buffersize_1 = freq.count * 2 #data density of 2 due to IQ # User-defined Measurement-FLOW ============================================================================================== if testeach: # measure-time contribution from each measure-loop loopcount, loop_dur = [], [] stage, prev = clocker(0) # Marking starting point of time # Registerring parameter(s)-structure cstructure = [fluxbias.count, Sparam.count, ifb.count, powa.count] # set previous parameters based on resumepoint: if resumepoint > 0: caddress = cdatasearch(resumepoint // buffersize_1, cstructure) # Only those involved in virtual for-loop need to be pre-set here: if "opt" not in fluxbias.data: # check if it is in optional-state YOKO.sweep( yokog, str(fluxbias.data[caddress[0]]), pulsewidth=77 * 1e-3, sweeprate=0.0007 ) # A-mode: sweeprate=0.0007 A/s ; V-mode: sweeprate=0.07 V/s ENA.setrace(bench, Mparam=[Sparam.data[caddress[1]]], window='D1') ENA.ifbw(bench, action=['Set', ifb.data[caddress[2]]]) measure_loop_1 = range( resumepoint // buffersize_1, datasize // buffersize_1) # saving chunck by chunck improves speed a lot! while True: for i in measure_loop_1: # Registerring parameter(s) caddress = cdatasearch(i, cstructure) # setting each c-order (From High to Low level of execution): if not i % prod(cstructure[ 1::]): # virtual for-loop using exact-multiples condition if "opt" not in fluxbias.data: # check if it is in optional-state if testeach: # test each measure-loop: loopcount += [fluxbias.count] if fluxbias.count > 1: loop_dur += [ abs(fluxbias.data[0] - fluxbias.data[1]) / 0.2 + 35 * 1e-3 ] else: loop_dur += [0] stage, prev = clocker(stage, prev) # Marking time else: YOKO.sweep( yokog, str(fluxbias.data[caddress[0]]), pulsewidth=77 * 1e-3, sweeprate=0.0007 ) # A-mode: sweeprate=0.0007 A/s ; V-mode: sweeprate=0.07 V/s if not i % prod(cstructure[ 2::]): # virtual for-loop using exact-multiples condition ENA.setrace(bench, Mparam=[Sparam.data[caddress[1]]], window='D1') if not i % prod(cstructure[ 3::]): # virtual for-loop using exact-multiples condition ENA.ifbw(bench, action=['Set', ifb.data[caddress[2]]]) ENA.power(bench, action=['Set', powa.data[caddress[3]] ]) # same as the whole measure-loop # start sweeping: stat = ENA.sweep(bench) #getting the estimated sweeping time print("Time-taken for this loop would be: %s (%spts)" % (stat[1]['TIME'], stat[1]['POINTS'])) print("Operation Complete: %s" % bool(ENA.measure(bench))) # adjusting display on ENA: ENA.autoscal(bench) ENA.selectrace(bench, action=['Set', 'para 1 calc 1']) data = ENA.sdata(bench) # print(Fore.YELLOW + "\rProgress: %.3f%% [%s]" %((i+1)/datasize*100, data), end='\r', flush=True) print(Fore.YELLOW + "\rProgress: %.3f%%" % ((i + 1) / datasize * buffersize_1 * 100), end='\r', flush=True) # test for the last loop if there is if testeach: # test each measure-loop: loopcount += [len(measure_loop_1)] loop_dur += [time() - prev] stage, prev = clocker(stage, prev) # Marking time ENA.close(bench) if "opt" not in fluxbias.data: # check if it is in optional-state YOKO.close(yokog, False) yield loopcount, loop_dur else: if get_status("F_Response")['pause']: break else: yield data if not get_status("F_Response")['repeat']: set_status("F_Response", dict(pause=True)) ENA.close(bench) if "opt" not in fluxbias.data: # check if it is in optional-state YOKO.close(yokog, True) return
from pyqum.instrument.analyzer import IQAP pqfile = get_status("MPW")["pqfile"] datalocation = get_status("MPW")["datalocation"] writtensize = get_status("MPW")["writtensize"] c_cwsweep_structure = get_status("MPW")["c_cwsweep_structure"] irepeat = get_status("MPW")["irepeat"] ifluxbias = get_status("MPW")["ifluxbias"] ixyfreq = get_status("MPW")["ixyfreq"] ixypowa = get_status("MPW")["ixypowa"] isparam = get_status("MPW")["isparam"] iifb = get_status("MPW")["iifb"] ipowa = get_status("MPW")["ipowa"] ifreq = get_status("MPW")["ifreq"] powa_order = get_status("MPW")["powa_order"] powa_wave = waveform(powa_order) powa_repeat = powa_wave.inner_repeat with open(pqfile, 'rb') as datapie: datapie.seek(datalocation + 7) pie = datapie.read(writtensize) selectedata = list(struct.unpack('>' + 'd' * ((writtensize) // 8), pie)) # y: fluxbias, x: repeat def assembler_fluxbias_repeat(args): (y, x) = args I, Q = 0, 0 for i_prepeat in range(powa_repeat): r_powa = int( ipowa
def char_cwsweep_2ddata(): irepeat = request.args.get('irepeat') ifluxbias = request.args.get('ifluxbias') ixyfreq = request.args.get('ixyfreq') ixypowa = request.args.get('ixypowa') isparam = request.args.get('isparam') iifb = request.args.get('iifb') ipowa = request.args.get('ipowa') ifreq = request.args.get('ifreq') # pre-transform ipowa: powa_order = M_cwsweep[session['user_name']].corder['Power'] # preparing MPW dictionary dict_for_MPW = { "pqfile": str(M_cwsweep[session['user_name']].pqfile), "datalocation": M_cwsweep[session['user_name']].datalocation, "writtensize": M_cwsweep[session['user_name']].writtensize, "c_cwsweep_structure": session['c_cwsweep_structure'], "irepeat": irepeat, "ifluxbias": ifluxbias, "ixyfreq": ixyfreq, "ixypowa": ixypowa, "isparam": isparam, "iifb": iifb, "ifreq": ifreq, "ipowa": ipowa, "powa_order": powa_order } set_status("MPW", dict_for_MPW) # Check progress: if not M_cwsweep[session['user_name']].data_progress % 100: offset = 1 print(Fore.GREEN + "The data is complete: we can see the whole picture now") else: offset = 0 # to avoid incomplete array error print(Back.RED + "The data is NOT YET complete!") # Selecting 2D options: # REPEAT: if irepeat == "x" and ifluxbias == "y": x_name, y_name = "repeat", "fluxbias" print("X: REPEAT#, Y: Flux-Bias") xtitle, ytitle = "<b>REPEAT#</b>", "<b>Flux-Bias(V/A)</b>" x, y = list(range(session['c_cwsweep_address'][0] + offset)), waveform( M_cwsweep[session['user_name']].corder['Flux-Bias']).data x_count, y_count = session['c_cwsweep_address'][0] + offset, waveform( M_cwsweep[session['user_name']].corder['Flux-Bias']).count if irepeat == "x" and ixyfreq == "y": x_name, y_name = "repeat", "xyfreq" print("X: REPEAT#, Y: XY-Frequency") xtitle, ytitle = "<b>REPEAT#</b>", "<b>XY-Frequency(GHz)</b>" x, y = list(range(session['c_cwsweep_address'][0] + offset)), waveform( M_cwsweep[session['user_name']].corder['XY-Frequency']).data x_count, y_count = session['c_cwsweep_address'][0] + offset, waveform( M_cwsweep[session['user_name']].corder['XY-Frequency']).count # ONCE: elif ifluxbias == "x" and ixyfreq == "y": x_name, y_name = "fluxbias", "xyfreq" print("X: Flux-Bias, Y: XY-Frequency") xtitle, ytitle = "<b>Flux-Bias(V/A)</b>", "<b>XY-Frequency(GHz)</b>" x, y = waveform( M_cwsweep[session['user_name']].corder['Flux-Bias'] ).data[0:session['c_cwsweep_address'][1] + offset], waveform( M_cwsweep[session['user_name']].corder['XY-Frequency']).data x_count, y_count = session['c_cwsweep_address'][1] + offset, waveform( M_cwsweep[session['user_name']].corder['XY-Frequency']).count elif ixyfreq == "x" and ixypowa == "y": x_name, y_name = "xyfreq", "xypowa" print("X: XY-Frequency, Y: XY-Power") xtitle, ytitle = "<b>XY-Frequency(GHz)</b>", "<b>XY-Power(dBm)</b>" x, y = waveform( M_cwsweep[session['user_name']].corder['XY-Frequency'] ).data[0:session['c_cwsweep_address'][2] + offset], waveform( M_cwsweep[session['user_name']].corder['XY-Power']).data x_count, y_count = session['c_cwsweep_address'][2] + offset, waveform( M_cwsweep[session['user_name']].corder['XY-Power']).count elif ixyfreq == "x" and ifreq == "y": x_name, y_name = "xyfreq", "freq" print("X: XY-Frequency, Y: Frequency") xtitle, ytitle = "<b>XY-Frequency(GHz)</b>", "<b>Probe-Frequency(GHz)</b>" x, y = waveform( M_cwsweep[session['user_name']].corder['XY-Frequency'] ).data[0:session['c_cwsweep_address'][2] + offset], waveform( M_cwsweep[session['user_name']].corder['Frequency']).data x_count, y_count = session['c_cwsweep_address'][2] + offset, waveform( M_cwsweep[session['user_name']].corder['Frequency']).count elif ixyfreq == "x" and ipowa == "y": x_name, y_name = "xyfreq", "powa" print("X: XY-Frequency, Y: Power") xtitle, ytitle = "<b>XY-Frequency(GHz)</b>", "<b>Probing-Power(dBm)</b>" x, y = waveform( M_cwsweep[session['user_name']].corder['XY-Frequency'] ).data[0:session['c_cwsweep_address'][2] + offset], waveform( M_cwsweep[session['user_name']].corder['Power']).data x_count, y_count = session['c_cwsweep_address'][2] + offset, waveform( M_cwsweep[session['user_name']].corder['Power']).count # fast iteration method (parallel computing): stage, prev = clocker(0) CMD = [ "python", "-c", "from pyqum.directive import MP_cwsweep as mp; print(mp.worker(%s,%s,'%s','%s'))" % (y_count, x_count, y_name, x_name) ] with Popen(CMD, stdout=PIPE, shell=True) as proc: doutput = proc.stdout.read().decode("utf-8") output = json.loads(doutput.replace("\'", "\"")) # try: os.kill(os.getppid(), signal.SIGTERM) # terminate parent process # except: pass Amp = output['rA'] Pha = output['rP'] stage, prev = clocker(stage, prev) # Marking time print("x is of length %s and of type %s" % (len(x), type(x))) print("y is of length %s and of type %s" % (len(y), type(y))) print("Amp of shape %s" % str(array(Amp).shape)) ZZA, ZZP = Amp, Pha # x = list(range(len(x))) # for repetitive data return jsonify(x=x, y=y, ZZA=ZZA, ZZP=ZZP, xtitle=xtitle, ytitle=ytitle)
def SQE_Pulse(user, tag="", corder={}, comment='', dayindex='', taskentry=0, resumepoint=0, instr=['YOKO', 'PSGV', 'PSGA', 'AWG', 'VSA'], testeach=False): '''Time-domain Square-wave measurement: C-Structure: ['Flux-Bias', 'Average', 'Pulse-Period', 'ADC-delay', 'LO-Frequency', 'LO-Power', 'RO-Frequency', 'RO-Power', 'RO-ifLevel', 'RO-Pulse-Delay', 'RO-Pulse-Width', 'XY-Frequency', 'XY-Power', 'XY-ifLevel', 'XY-Pulse-Delay', 'XY-Pulse-Width', 'Sampling-Time'] (IQ-Bandwidth (250MHz or its HALFlings) + Acquisition-Time (dt must be multiples of 2ns)) ''' # Loading sample: sample = get_status("MSSN")[session['user_name']]['sample'] # sample = get_status("MSSN")['abc']['sample'] # by-pass HTTP-request before interface is ready # pushing pre-measurement parameters to settings: yield user, sample, tag, instr, corder, comment, dayindex, taskentry, testeach # ***USER_DEFINED*** Controlling-PARAMETER(s) ====================================================================================== structure = corder['C-Structure'] fluxbias = waveform(corder['Flux-Bias']) averaging = waveform(corder['Average']) pperiod = waveform(corder['Pulse-Period']) adcdelay = waveform(corder['ADC-delay']) lofreq = waveform(corder['LO-Frequency']) lopowa = waveform(corder['LO-Power']) rofreq = waveform(corder['RO-Frequency']) ropowa = waveform(corder['RO-Power']) roiflevel = waveform(corder['RO-ifLevel']) ropdelay = waveform(corder['RO-Pulse-Delay']) ropwidth = waveform(corder['RO-Pulse-Width']) xyfreq = waveform(corder['XY-Frequency']) xypowa = waveform(corder['XY-Power']) xyiflevel = waveform(corder['XY-ifLevel']) xypdelay = waveform(corder['XY-Pulse-Delay']) xypwidth = waveform(corder['XY-Pulse-Width']) samptime = waveform(corder['Sampling-Time']) # Total data points: datasize = int( prod([waveform(corder[param]).count for param in structure], dtype='uint64')) * 2 #data density of 2 due to IQ print("data size: %s" % datasize) # Pre-loop settings: # Optionals: # YOKO: if "opt" not in fluxbias.data: # check if it is in optional-state / serious-state yokog = YOKO.Initiate(current=True) # pending option YOKO.output(yokog, 1) # PSGV: if "opt" not in xyfreq.data: # check if it is in optional-state / serious-state sogo = PSG0.Initiate() # pending option PSG0.rfoutput(sogo, action=['Set', 1]) # Basics: # PSGA for LO: saga = PSG1.Initiate() # pending option PSG1.rfoutput(saga, action=['Set', 1]) # AWG for Control: awgsess = AWG.InitWithOptions() AWG.Abort_Gen(awgsess) AWG.ref_clock_source(awgsess, action=['Set', int(1)]) # External 10MHz clock-reference AWG.predistortion_enabled(awgsess, action=['Set', True]) AWG.output_mode_adv(awgsess, action=['Set', int(2)]) # Sequence output mode AWG.arb_sample_rate(awgsess, action=['Set', float(1250000000)]) # maximum sampling rate AWG.active_marker(awgsess, action=['Set', '1']) # master AWG.marker_delay(awgsess, action=['Set', float(0)]) AWG.marker_pulse_width(awgsess, action=['Set', float(1e-7)]) AWG.marker_source(awgsess, action=['Set', int(7)]) # PRESET Output: for ch in range(2): channel = str(ch + 1) AWG.output_config(awgsess, RepCap=channel, action=["Set", 0]) # Single-ended AWG.output_filter_bandwidth(awgsess, RepCap=channel, action=["Set", 0]) AWG.arb_gain(awgsess, RepCap=channel, action=["Set", 0.5]) AWG.output_impedance(awgsess, RepCap=channel, action=["Set", 50]) # output settings: for ch in range(2): channel = str(ch + 1) AWG.output_enabled(awgsess, RepCap=channel, action=["Set", int(1)]) # ON AWG.output_filter_enabled(awgsess, RepCap=channel, action=["Set", True]) AWG.output_config(awgsess, RepCap=channel, action=["Set", int(2)]) # Amplified 1:2 AWG.output_filter_bandwidth(awgsess, RepCap=channel, action=["Set", 0]) AWG.arb_gain(awgsess, RepCap=channel, action=["Set", 0.5]) AWG.output_impedance(awgsess, RepCap=channel, action=["Set", 50]) # VSA for Readout vsasess = VSA.InitWithOptions() # Buffer-size for lowest-bound data-collecting instrument: buffersize_1 = samptime.count * 2 #data density of 2 due to IQ print("Buffer-size: %s" % buffersize_1) # User-defined Measurement-FLOW ============================================================================================== if testeach: # measure-time contribution from each measure-loop loopcount, loop_dur = [], [] stage, prev = clocker(0) # Marking starting point of time # Registerring parameter(s)-structure cstructure = [waveform(corder[param]).count for param in structure ][:-1] # The last one will become a buffer print('cstructure: %s' % cstructure) measure_loop_1 = range( resumepoint // buffersize_1, datasize // buffersize_1) # saving chunck by chunck improves speed a lot! while True: for i in measure_loop_1: print(Back.BLUE + Fore.WHITE + 'measure %s/%s' % (i, datasize // buffersize_1)) # determining the index-locations for each parameters, i.e. the address at any instance caddress = cdatasearch(i, cstructure) # setting each c-order (From High to Low level of execution): # *************************************************************** for j in range( len(cstructure) - 1): # the last one will be run for every i (common sense!) if ( not i % prod(cstructure[j + 1::]) ) or i == resumepoint // buffersize_1: # virtual for-loop using exact-multiples condition # print("entering %s-stage" %j) # Optionals: # YOKO if structure[j] == 'Flux-Bias': if "opt" not in fluxbias.data: # check if it is in optional-state if testeach: # adding instrument transition-time between set-values: loopcount += [fluxbias.count] if fluxbias.count > 1: loop_dur += [ abs(fluxbias.data[0] - fluxbias.data[1]) / 0.2 + 35 * 1e-3 ] # manually calculating time without really setting parameter on the instrument else: loop_dur += [0] stage, prev = clocker(stage, prev) # Marking time else: YOKO.sweep( yokog, str(fluxbias.data[caddress[structure.index( 'Flux-Bias')]]), pulsewidth=77 * 1e-3, sweeprate=0.0007 ) # A-mode: sweeprate=0.0007 A/s ; V-mode: sweeprate=0.07 V/s # PSG if structure[j] == 'XY-Frequency': if "opt" not in xyfreq.data: # check if it is in optional-state PSG0.frequency( sogo, action=[ 'Set', str(xyfreq.data[caddress[structure.index( 'XY-Frequency')]]) + "GHz" ]) if structure[j] == 'XY-Power': if "opt" not in xypowa.data: # check if it is in optional-state PSG0.power(sogo, action=[ 'Set', str(xypowa.data[caddress[ structure.index('XY-Power')]]) + "dBm" ]) if structure[j] == 'RO-Frequency': if "opt" not in rofreq.data: # check if it is in optional-state PSG1.frequency( saga, action=[ 'Set', str(rofreq.data[caddress[structure.index( 'RO-Frequency')]]) + "GHz" ]) if structure[j] == 'RO-Power': if "opt" not in ropowa.data: # check if it is in optional-state PSG1.power(saga, action=[ 'Set', str(ropowa.data[caddress[ structure.index('RO-Power')]]) + "dBm" ]) # AWG (Every-loop) if "opt" not in pperiod.data: # check if it is in optional-state AWG.Clear_ArbMemory(awgsess) WAVE = [] # construct waveform: ifperiod = pperiod.data[caddress[structure.index( 'Pulse-Period')]] ifscale = float( xyiflevel.data[caddress[structure.index('XY-ifLevel')]] ), float( roiflevel.data[caddress[structure.index('RO-ifLevel')]]) if "lockxypwd" in str(ropdelay.data[0]): if '+' in str(ropdelay.data[0]): rooffset = float(ropdelay.data[0].split('+')[1]) else: rooffset = 0 # default value ifdelay = float(xypdelay.data[caddress[structure.index( 'XY-Pulse-Delay')]]), float(xypwidth.data[caddress[ structure.index('XY-Pulse-Width')]]) + rooffset print("RO-Pulse Delays behind XY-Pulse for %sns" % (ifdelay[1] - ifdelay[0])) else: ifdelay = float(xypdelay.data[caddress[structure.index( 'XY-Pulse-Delay')]]), float(ropdelay.data[caddress[ structure.index('RO-Pulse-Delay')]]) ifontime = float( xypwidth.data[caddress[structure.index('XY-Pulse-Width')]] ), float( ropwidth.data[caddress[structure.index('RO-Pulse-Width')]]) for ch in range(2): channel = str(ch + 1) wavefom = squarewave(ifperiod, ifontime[ch], ifdelay[ch], ifscale[ch]) # in ns stat, wave = AWG.CreateArbWaveform(awgsess, wavefom) print('Waveform channel %s: %s <%s>' % (channel, wave, status_code(stat))) WAVE.append(wave) # Building Sequences: for ch in range(2): channel = str(ch + 1) status, seqhandl = AWG.CreateArbSequence( awgsess, [WAVE[ch]], [1] ) # loop# canbe >1 if longer sequence is needed in the future! # print('Sequence channel %s: %s <%s>' %(channel, seqhandl, status_code(status))) # Channel Assignment: stat = AWG.arb_sequence_handle(awgsess, RepCap=channel, action=["Set", seqhandl]) # print('Sequence channel %s embeded: %s <%s>' %(channel, stat[1], status_code(stat[0]))) # Trigger Settings: for ch in range(2): channel = str(ch + 1) AWG.operation_mode(awgsess, RepCap=channel, action=["Set", 0]) AWG.trigger_source_adv(awgsess, RepCap=channel, action=["Set", 0]) AWG.Init_Gen(awgsess) AWG.Send_Pulse(awgsess, 1) # Basic / Buffer: # VSA (Every-loop) VSA.acquisition_time(vsasess, action=['Set', float(samptime.count * 2e-9) ]) # minimum time resolution VSA.preselector_enabled(vsasess, action=[ 'Set', False ]) # disable preselector to allow the highest bandwidth of 250MHz if "lockro" in str(lofreq.data[0]): if '+' in str(lofreq.data[0]): lof_offset = float(lofreq.data[0].split('+')[1]) elif '-' in str(lofreq.data[0]): lof_offset = -float(lofreq.data[0].split('-')[1]) else: lof_offset = 0 # default value VSA.frequency(vsasess, action=[ 'Set', float(rofreq.data[caddress[structure.index( 'RO-Frequency')]]) * 1e9 + lof_offset ]) # freq offset / correction in Hz print("Locking on RO at %sGHz" % (VSA.frequency(vsasess)[1] / 1e9)) else: VSA.frequency(vsasess, action=[ 'Set', float(lofreq.data[caddress[structure.index( 'LO-Frequency')]]) * 1e9 ]) VSA.power( vsasess, action=[ 'Set', float(lopowa.data[caddress[structure.index('LO-Power')]]) ]) VSA.bandwidth( vsasess, action=['Set', 250e6] ) # maximum LO bandwidth of 250MHz (500MHz Sampling-rate gives 2ns of time resolution) VSA.trigger_source(vsasess, action=['Set', int(1)]) # External Trigger (slave) # Delay for Readout if "lockxypwd" in str(ropdelay.data[0]): # trigger-delay sync with xy-pulse-width for Rabi measurement: VSA.trigger_delay(vsasess, action=['Set', float(adcdelay.data[caddress[structure.index('ADC-delay')]]) + \ float(xypwidth.data[caddress[structure.index('XY-Pulse-Width')]])*1e-9 + rooffset*1e-9]) print("ACQ delays with XY-Pulse for %sns" % int(VSA.trigger_delay(vsasess)[1] / 1e-9)) elif "lockropdelay" in str(adcdelay.data[0]): # trigger-delay sync with ro-pulse-delay for T1 measurement: VSA.trigger_delay( vsasess, action=[ 'Set', float(ropdelay.data[caddress[structure.index( 'RO-Pulse-Delay')]]) * 1e-9 ]) print("ACQ delays with RO-Pulse for %sns" % int(VSA.trigger_delay(vsasess)[1] / 1e-9)) else: VSA.trigger_delay(vsasess, action=[ 'Set', float(adcdelay.data[caddress[ structure.index('ADC-delay')]]) ]) VSA.external_trigger_level(vsasess, action=['Set', float(0.3)]) VSA.external_trigger_slope(vsasess, action=['Set', int(1)]) # Positive slope VSA.trigger_timeout(vsasess, action=['Set', int(1000)]) # 1s of timeout stat = VSA.Init_Measure(vsasess) # Initiate Measurement # Start Quantum machine: # Start Averaging Loop: avenum = int(averaging.data[caddress[structure.index('Average')]]) vsasn = VSA.samples_number(vsasess)[1] iqdata = zeros((avenum, 2 * vsasn)) for ave in range(avenum): VSA.Arm_Measure(vsasess) gd = VSA.Get_Data(vsasess, 2 * vsasn) iqdata[ave, :] = array(gd[1]['ComplexData']) iqdata = mean(iqdata, axis=0) print("Operation Complete") print(Fore.YELLOW + "\rProgress: %.3f%%" % ((i + 1) / datasize * buffersize_1 * 100), end='\r', flush=True) # test for the last loop if there is if testeach: # test each measure-loop: loopcount += [len(measure_loop_1)] loop_dur += [time() - prev] stage, prev = clocker(stage, prev) # Marking time VSA.close(vsasess) if "opt" not in pperiod.data: # check if it is in optional-state AWG.close(awgsess) if "opt" not in xyfreq.data: # check if it is in optional-state PSG0.close(sogo, False) if "opt" not in rofreq.data: # check if it is in optional-state PSG1.close(saga, False) if "opt" not in fluxbias.data: # check if it is in optional-state YOKO.close(yokog, False) yield loopcount, loop_dur else: if get_status("SQE_Pulse")['pause']: break else: yield list(iqdata) if not get_status("SQE_Pulse")['repeat']: set_status("SQE_Pulse", dict(pause=True)) VSA.close(vsasess) if "opt" not in pperiod.data: # check if it is in optional-state AWG.Abort_Gen(awgsess) AWG.close(awgsess) if "opt" not in xyfreq.data: # check if it is in optional-state PSG0.rfoutput(sogo, action=['Set', 0]) PSG0.close(sogo, False) if "opt" not in rofreq.data: # check if it is in optional-state PSG1.rfoutput(saga, action=['Set', 0]) PSG1.close(saga, False) if "opt" not in fluxbias.data: # check if it is in optional-state YOKO.output(yokog, 0) YOKO.close(yokog, False) return
def char_fresp_1ddata(): print(Fore.GREEN + "User %s is plotting 1D-Data" % session['user_name']) M_fresp[session['user_name']].loadata() selectedata = M_fresp[session['user_name']].selectedata ifluxbias = request.args.get('ifluxbias') # if ifluxbias == "o": ifluxbias = '0' # for backward compatibility isparam = request.args.get('isparam') iifb = request.args.get('iifb') ipowa = request.args.get('ipowa') ifreq = request.args.get('ifreq') # selecting data if ifluxbias == "x": title = "<b>Flux-Bias(V)</b>" selected_sweep = M_fresp[session['user_name']].corder['Flux-Bias'] selected_progress = waveform( selected_sweep).data[0:session['c_fresp_address'][0] + 1] selected_I = [ selectedata[gotocdata( [x, int(isparam), int(iifb), int(ipowa), 2 * int(ifreq)], session['c_fresp_structure'])] for x in range(session['c_fresp_address'][0] + 1) ] selected_Q = [ selectedata[gotocdata( [x, int(isparam), int(iifb), int(ipowa), 2 * int(ifreq) + 1], session['c_fresp_structure'])] for x in range(session['c_fresp_address'][0] + 1) ] elif isparam == "x": pass elif iifb == "x": pass elif ipowa == "x": title = "<b>Power(dBm)</b>" selected_sweep = M_fresp[session['user_name']].corder['Power'] selected_progress = waveform( selected_sweep).data[0:session['c_fresp_address'][3] + 1] selected_I = [ selectedata[gotocdata( [int(ifluxbias), int(isparam), int(iifb), x, 2 * int(ifreq)], session['c_fresp_structure'])] for x in range(session['c_fresp_address'][3] + 1) ] selected_Q = [ selectedata[gotocdata([ int(ifluxbias), int(isparam), int(iifb), x, 2 * int(ifreq) + 1 ], session['c_fresp_structure'])] for x in range(session['c_fresp_address'][3] + 1) ] elif ifreq == "x": title = "<b>frequency(GHz)</b>" selected_sweep = M_fresp[session['user_name']].corder['Frequency'] selected_progress = waveform(selected_sweep).data # Full sweep selected_I = [ selectedata[gotocdata( [int(ifluxbias), int(isparam), int(iifb), int(ipowa), 2 * x], session['c_fresp_structure'])] for x in range(waveform(selected_sweep).count) ] selected_Q = [ selectedata[gotocdata([ int(ifluxbias), int(isparam), int(iifb), int(ipowa), 2 * x + 1 ], session['c_fresp_structure'])] for x in range(waveform(selected_sweep).count) ] # Preparing data: MagPha = [IQAP(x[0], x[1]) for x in zip(selected_I, selected_Q)] Amp, Pha = [], [] for i, j in MagPha: Amp.append(i) Pha.append(j) x1, y1, y2 = selected_progress, Amp, list( UnwraPhase(selected_progress, Pha)) #list(unwrap(Pha)) global data_dict data_dict = { title: x1, 'Amplitude': y1, 'UPhase': y2, 'I': selected_I, 'Q': selected_Q, "exported by": session['user_name'] } return jsonify(x1=x1, y1=y1, y2=y2, title=title)
def CW_Sweep(user, tag="", corder={}, comment='', dayindex='', taskentry=0, resumepoint=0, instr=['PSG', 'YOKO', 'ENA'], testeach=False): '''Continuous Wave Sweeping: C-Order: Flux-Bias, XY-Frequency, XY-Power, S-Parameter, IF-Bandwidth, Frequency, Power ''' sample = get_status("MSSN")['sample'] # pushing pre-measurement parameters to settings: yield user, sample, tag, instr, corder, comment, dayindex, taskentry, testeach # User-defined Controlling-PARAMETER(s) ====================================================================================== fluxbias = waveform(corder['Flux-Bias']) xyfreq = waveform(corder['XY-Frequency']) xypowa = waveform(corder['XY-Power']) Sparam = waveform(corder['S-Parameter']) ifb = waveform(corder['IF-Bandwidth']) freq = waveform(corder['Frequency']) # special treatment to power in this CW-Mode Sweeping: powa = waveform(corder['Power']) powa_repeat = powa.inner_repeat print("power sequence: %s, length: %s, inner-repeat-counts: %s" % (powa.command, powa.count, powa_repeat)) # input("continue?") # Total data points: datasize = int( prod([ waveform(x).count * waveform(x).inner_repeat for x in corder.values() ], dtype='uint64')) * 2 #data density of 2 due to IQ print("data size: %s" % datasize) # Pre-loop settings: # ENA: bench = ENA.Initiate(True) ENA.dataform(bench, action=['Set', 'REAL']) if powa_repeat == 1: # collect swept power-data every measure-loop ENA.sweep(bench, action=['Set', 'ON', powa.count]) ENA.power(bench, action=['Set', '', powa.data[0], powa.data[-1] ]) # for power sweep (set pstart & pstop) buffersize_1 = powa.count * 2 # (buffer) data density of 2 due to IQ else: # collect repetitive power-data every measure-loop ENA.sweep(bench, action=['Set', 'ON', powa_repeat]) buffersize_1 = powa_repeat * 2 # (buffer) data density of 2 due to IQ # YOKO: if "opt" not in fluxbias.data: # check if it is in optional-state / serious-state yokog = YOKO.Initiate(current=True) # pending option YOKO.output(yokog, 1) # PSG: if "opt" not in xyfreq.data: # check if it is in optional-state / serious-state sogo = PSG0.Initiate() # pending option PSG0.rfoutput(sogo, action=['Set', 1]) # User-defined Measurement-FLOW ============================================================================================== if testeach: # measure-time contribution from each measure-loop loopcount, loop_dur = [], [] stage, prev = clocker(0) # Marking starting point of time # Registerring parameter(s)-structure if powa_repeat == 1: cstructure = [ fluxbias.count, xyfreq.count, xypowa.count, Sparam.count, ifb.count, freq.count, 1 ] # just single CW else: cstructure = [ fluxbias.count, xyfreq.count, xypowa.count, Sparam.count, ifb.count, freq.count, powa.count ] # take CW average by repeating # set previous parameters based on resumepoint: if resumepoint // buffersize_1 > 0: caddress = cdatasearch(resumepoint // buffersize_1, cstructure) # Only those involved in virtual for-loop need to be pre-set here: # Optionals: if "opt" not in fluxbias.data: # check if it is in optional-state / serious-state YOKO.sweep( yokog, str(fluxbias.data[caddress[0]]), pulsewidth=77 * 1e-3, sweeprate=0.0007 ) # A-mode: sweeprate=0.0007 A/s ; V-mode: sweeprate=0.07 V/s if "opt" not in xyfreq.data: # check if it is in optional-state / serious-state PSG0.frequency( sogo, action=['Set', str(xyfreq.data[caddress[1]]) + "GHz"]) PSG0.power(sogo, action=['Set', str(xypowa.data[caddress[2]]) + "dBm"]) # Basics: ENA.setrace(bench, Mparam=[Sparam.data[caddress[3]]], window='D1') ENA.ifbw(bench, action=['Set', ifb.data[caddress[4]]]) ENA.cwfreq(bench, action=['Set', freq.data[caddress[5]] * 1e9]) measure_loop_1 = range( resumepoint // buffersize_1, datasize // buffersize_1) # saving chunck by chunck improves speed a lot! while True: for i in measure_loop_1: # determining the index-locations for each parameters, i.e. the address at any instance caddress = cdatasearch(i, cstructure) # setting each c-order (From High to Low level of execution): # *************************************************************** # Optionals: if not i % prod(cstructure[ 1::]): # virtual for-loop using exact-multiples condition if "opt" not in fluxbias.data: # check if it is in optional-state if testeach: # adding instrument transition-time between set-values: loopcount += [fluxbias.count] if fluxbias.count > 1: loop_dur += [ abs(fluxbias.data[0] - fluxbias.data[1]) / 0.2 + 35 * 1e-3 ] else: loop_dur += [0] stage, prev = clocker(stage, prev) # Marking time else: YOKO.sweep( yokog, str(fluxbias.data[caddress[0]]), pulsewidth=77 * 1e-3, sweeprate=0.0007 ) # A-mode: sweeprate=0.0007 A/s ; V-mode: sweeprate=0.07 V/s if not i % prod(cstructure[ 2::]): # virtual for-loop using exact-multiples condition if "opt" not in xyfreq.data: # check if it is in optional-state PSG0.frequency( sogo, action=['Set', str(xyfreq.data[caddress[1]]) + "GHz"]) if not i % prod(cstructure[ 3::]): # virtual for-loop using exact-multiples condition if "opt" not in xypowa.data: # check if it is in optional-state PSG0.power( sogo, action=['Set', str(xypowa.data[caddress[2]]) + "dBm"]) # Basics: if not i % prod(cstructure[ 4::]): # virtual for-loop using exact-multiples condition ENA.setrace(bench, Mparam=[Sparam.data[caddress[3]]], window='D1') if not i % prod(cstructure[ 5::]): # virtual for-loop using exact-multiples condition ENA.ifbw(bench, action=['Set', ifb.data[caddress[4]]]) if not i % prod(cstructure[ 6::]): # virtual for-loop using exact-multiples condition ENA.cwfreq(bench, action=['Set', freq.data[caddress[5]] * 1e9]) if powa_repeat > 1: ENA.power(bench, action=[ 'Set', '', powa.data[caddress[6]], powa.data[caddress[6]] ]) # same as the whole measure-loop # start sweeping: stat = ENA.sweep(bench) #getting the estimated sweeping time print("Time-taken for this loop would be: %s (%spts)" % (stat[1]['TIME'], stat[1]['POINTS'])) print("Operation Complete: %s" % bool(ENA.measure(bench))) # adjusting display on ENA: ENA.autoscal(bench) ENA.selectrace(bench, action=['Set', 'para 1 calc 1']) data = ENA.sdata(bench) print(Fore.YELLOW + "\rProgress: %.3f%%" % ((i + 1) / datasize * buffersize_1 * 100), end='\r', flush=True) # test for the last loop if there is if testeach: # test each measure-loop: loopcount += [len(measure_loop_1)] loop_dur += [time() - prev] stage, prev = clocker(stage, prev) # Marking time ENA.close(bench) if "opt" not in xyfreq.data: # check if it is in optional-state PSG0.close(sogo, False) if "opt" not in fluxbias.data: # check if it is in optional-state YOKO.close(yokog, False) yield loopcount, loop_dur else: if get_status("CW_Sweep")['pause']: break else: yield data if not get_status("CW_Sweep")['repeat']: set_status("CW_Sweep", dict(pause=True)) ENA.close(bench) if "opt" not in xyfreq.data: # check if it is in optional-state PSG0.rfoutput(sogo, action=['Set', 0]) PSG0.close(sogo, False) if "opt" not in fluxbias.data: # check if it is in optional-state YOKO.output(yokog, 0) YOKO.close(yokog, False) return
def char_fresp_2ddata(): # M_fresp[session['user_name']].loadata() # selectedata = M_fresp[session['user_name']].selectedata ifluxbias = request.args.get('ifluxbias') # if ifluxbias == "o": ifluxbias = '0' # for backward compatibility isparam = request.args.get('isparam') iifb = request.args.get('iifb') ipowa = request.args.get('ipowa') ifreq = request.args.get('ifreq') x, y, ZZ = [], [], [] dict_for_MPW = { "pqfile": str(M_fresp[session['user_name']].pqfile), "datalocation": M_fresp[session['user_name']].datalocation, "writtensize": M_fresp[session['user_name']].writtensize, "c_fresp_structure": session['c_fresp_structure'], "ifluxbias": ifluxbias, "isparam": isparam, "iifb": iifb, "ipowa": ipowa, "ifreq": ifreq, } set_status("MPW", dict_for_MPW) if ifluxbias == "x" and ifreq == "y": print("X: Flux-Bias, Y: Frequency") xtitle, ytitle = "<b>Flux-Bias(V/A)</b>", "<b>Frequency(GHz)</b>" x, y = waveform( M_fresp[session['user_name']].corder['Flux-Bias'] ).data[0:session['c_fresp_address'][0] + 1], waveform( M_fresp[session['user_name']].corder['Frequency']).data x_count, y_count = session['c_fresp_address'][0] + 1, waveform( M_fresp[session['user_name']].corder['Frequency']).count stage, prev = clocker(0) CMD = [ "python", "-c", "from pyqum.directive import MP_fresp as mp; print(mp.worker(%s,%s))" % (y_count, x_count) ] with Popen(CMD, stdout=PIPE, shell=True) as proc: output = json.loads(proc.stdout.read().decode("utf-8").replace( "\'", "\"")) # try: os.kill(os.getppid(), signal.SIGTERM) # terminate parent process # except: pass stage, prev = clocker(stage, prev) # Marking time # slow iteration method: # Amp, Pha = [], [] # for j in range(y_count): # I = [selectedata[gotocdata([x, int(session['isparam']), int(session['iifb']), int(session['ipowa']), 2*j], session['c_fresp_structure'])] for x in range(x_count)] # Q = [selectedata[gotocdata([x, int(session['isparam']), int(session['iifb']), int(session['ipowa']), 2*j+1], session['c_fresp_structure'])] for x in range(x_count)] # amp, pha = [], [] # for i,q in zip(I,Q): # a,p = IQAP(i,q) # amp.append(a); pha.append(p) # Amp += [amp]; Pha += [pha] print("x is of length %s and of type %s" % (len(x), type(x))) print("y is of length %s and of type %s" % (len(y), type(y))) Amp = output['rA'] Pha = output['rP'] print("Amp of shape %s" % str(array(Amp).shape)) ZZA, ZZP = Amp, Pha elif ipowa == "x" and ifreq == "y": print("X: Power, Y: Frequency") xtitle, ytitle = "<b>Power(dBm)</b>", "<b>Frequency(GHz)</b>" x, y = waveform( M_fresp[session['user_name']].corder['Power'] ).data[0:session['c_fresp_address'][3] + 1], waveform( M_fresp[session['user_name']].corder['Frequency']).data x_count, y_count = session['c_fresp_address'][3] + 1, waveform( M_fresp[session['user_name']].corder['Frequency']).count stage, prev = clocker(0) CMD = [ "python", "-c", "from pyqum.directive import MP_fresp as mp; print(mp.worker(%s,%s,%s,%s))" % (y_count, x_count, '"freq"', '"powa"') ] with Popen(CMD, stdout=PIPE, shell=True) as proc: output = json.loads(proc.stdout.read().decode("utf-8").replace( "\'", "\"")) # try: os.kill(os.getppid(), signal.SIGTERM) # terminate parent process # except: pass stage, prev = clocker(stage, prev) # Marking time print("x is of length %s and of type %s" % (len(x), type(x))) print("y is of length %s and of type %s" % (len(y), type(y))) Amp = output['rA'] Pha = output['rP'] print("Amp of shape %s" % str(array(Amp).shape)) ZZA, ZZP = Amp, Pha elif iifb == "x": pass # x = list(range(len(x))) # for repetitive data return jsonify(x=x, y=y, ZZA=ZZA, ZZP=ZZP, xtitle=xtitle, ytitle=ytitle)
def char_cwsweep_access(): wmoment = int(request.args.get('wmoment')) M_cwsweep[session['user_name']].selectmoment(wmoment) M_cwsweep[session['user_name']].accesstructure() data_progress = M_cwsweep[session['user_name']].data_progress data_repeat = data_progress // 100 + int(bool(data_progress % 100)) # Measurement time: filetime = getmtime(M_cwsweep[session['user_name']].pqfile) # in seconds startmeasure = mktime( strptime( M_cwsweep[session['user_name']].day + " " + M_cwsweep[session['user_name']].startime(), "%Y-%m-%d(%a) %H:%M")) # made into seconds measureacheta = str( timedelta(seconds=(filetime - startmeasure) / data_progress * (trunc(data_progress / 100 + 1) * 100 - data_progress))) # Scale-up optional parameters: try: cfluxbias = waveform( M_cwsweep[session['user_name']].corder['Flux-Bias']) except (KeyError): cfluxbias = waveform( 'opt,' ) # create virtual list for the absence of this in older file try: cxyfreq = waveform( M_cwsweep[session['user_name']].corder['XY-Frequency']) except (KeyError): cxyfreq = waveform( 'opt,' ) # create virtual list for the absence of this in older file try: cxypowa = waveform(M_cwsweep[session['user_name']].corder['XY-Power']) except (KeyError): cxypowa = waveform( 'opt,' ) # create virtual list for the absence of this in older file csparam = waveform(M_cwsweep[session['user_name']].corder['S-Parameter']) cifb = waveform(M_cwsweep[session['user_name']].corder['IF-Bandwidth']) cfreq = waveform(M_cwsweep[session['user_name']].corder['Frequency']) cpowa = waveform(M_cwsweep[session['user_name']].corder['Power']) cpowa_repeat = cpowa.inner_repeat session['c_cwsweep_structure'] = [ data_repeat, cfluxbias.count, cxyfreq.count, cxypowa.count, csparam.count, cifb.count, cfreq.count, cpowa.count * cpowa_repeat * M_cwsweep[session['user_name']].datadensity ] session['c_cwsweep_address'] = cdatasearch( M_cwsweep[session['user_name']].resumepoint - 1, session['c_cwsweep_structure']) # list each parameter range based on data-progress: cfluxbias_data = cfluxbias.data[0:session['c_cwsweep_address'][1] + 1] cxyfreq_data = cxyfreq.data[0:session['c_cwsweep_address'][2] + 1] cxypowa_data = cxypowa.data[0:session['c_cwsweep_address'][3] + 1] csparam_data = csparam.data[0:session['c_cwsweep_address'][4] + 1] cifb_data = cifb.data[0:session['c_cwsweep_address'][5] + 1] cfreq_data = cfreq.data[0:session['c_cwsweep_address'][6] + 1] cpowa_data = cpowa.data[0:(session['c_cwsweep_address'][7] + 1) // cpowa_repeat // 2] # (to be adjusted ***) # print("cpowa_data: %s" %cpowa_data) return jsonify(data_progress=data_progress, measureacheta=measureacheta, corder=M_cwsweep[session['user_name']].corder, comment=M_cwsweep[session['user_name']].comment, data_repeat=data_repeat, cfluxbias_data=cfluxbias_data, cxyfreq_data=cxyfreq_data, cxypowa_data=cxypowa_data, csparam_data=csparam_data, cifb_data=cifb_data, cfreq_data=cfreq_data, cpowa_data=cpowa_data)
'Power': '-18 r 100' } case = CW_Sweep('abc') case.selectday(case.whichday()) m = case.whichmoment() case.selectmoment(m) print("File selected: %s" % case.pqfile) case.accesstructure() print("Data progress: %s%%" % case.data_progress) # Scale-up optional parameters: try: cfluxbias = waveform(case.corder['Flux-Bias']) except (KeyError): cfluxbias = waveform( 'opt,') # create virtual list for the absence of this in older file try: cxyfreq = waveform(case.corder['XY-Frequency']) except (KeyError): cxyfreq = waveform( 'opt,') # create virtual list for the absence of this in older file try: cxypowa = waveform(case.corder['XY-Power']) except (KeyError): cxypowa = waveform( 'opt,') # create virtual list for the absence of this in older file csparam = waveform(case.corder['S-Parameter']) cifb = waveform(case.corder['IF-Bandwidth']) cfreq = waveform(case.corder['Frequency']) cpowa = waveform(case.corder['Power']) cpowa_repeat = cpowa.inner_repeat