def awgsettingssquarewave(): global awgsess, seqhandl message = [] # Shaping parameters voltag = [] voltag.append(float(request.args.get('voltag1'))) voltag.append(float(request.args.get('voltag2'))) pointnum = [] pointnum.append(int(request.args.get('pointnum1'))) pointnum.append(int(request.args.get('pointnum2'))) wavefom = ([voltag[0]] * pointnum[0] + [voltag[1]] * pointnum[1]) stat = AWG.CreateArbWaveform(awgsess, wavefom) print(Fore.YELLOW + "Arb Waveform Created: %s" % stat[0]) message += ['Waveform created: %s <%s>' % (stat[1], status_code(stat[0]))] stat = AWG.CreateArbSequence( awgsess, [stat[1]], [1]) # loop# canbe >1 if longer sequence is needed in the future! print(Fore.YELLOW + "Arb Sequence Created: %s" % stat[0]) seqhandl = stat[1] print("seq handle in set-waveform is %s" % seqhandl) message += [ 'Sequence assembled: %s <%s>' % (stat[1], status_code(stat[0])) ] return jsonify(message=message)
def DELAY(session): wrapped = AWG.marker_delay(session) print("\nmarker delay: %s, Error: %s" % (wrapped[1], wrapped[0])) wrapped = AWG.marker_delay(session, action=["Set", 5e-7]) print("SET marker delay: %s, Error: %s" % (wrapped[1], wrapped[0])) wrapped = AWG.marker_delay(session) print("marker delay: %s, Error: %s" % (wrapped[1], wrapped[0]))
def awgreset(): global awgsess awgsess = AWG.InitWithOptions() AWG.Abort_Gen(awgsess) status = AWG.model(awgsess) # model print('Model: %s (%s)' % (status[1], status_code(status[0]))) return jsonify(message=awgsess)
def close(self): '''closing instruments: ''' AWG.Abort_Gen(self.awgsess) AWG.close(self.awgsess) PSGA.rfoutput(self.saga, action=['Set', 0]) PSGA.close(self.saga, False) MXA.close(self.mxa, False)
def awggenerate(): global awgsess message = [] gstatus = AWG.Init_Gen(awgsess) message += ['Generate Pulse: %s' % (status_code(gstatus))] sstatus = AWG.Send_Pulse(awgsess, 1) message += ['Send Pulse: %s' % (status_code(sstatus))] return jsonify(message=message, gstatus=gstatus, sstatus=sstatus)
def SOURC(session): wrapped = AWG.marker_source(session) print(Fore.BLUE + Back.CYAN + "\nmarker source: %s, Error: %s" % (wrapped[1], wrapped[0])) wrapped = AWG.marker_source(session, action=["Set", 10]) print(Fore.CYAN + Back.BLUE + "SET marker source: %s, Error: %s" % (wrapped[1], wrapped[0])) wrapped = AWG.marker_source(session) print(Fore.BLUE + Back.CYAN + "marker source: %s, Error: %s" % (wrapped[1], wrapped[0])) return
def MARK(session): wrapped = AWG.active_marker(session) print(Fore.RED + "\nActive marker(physical name): %s, Error: %s" % (wrapped[1], wrapped[0])) wrapped = AWG.active_marker(session, action=["Set", "3"]) print(Fore.MAGENTA + "SET Active marker(physical name): %s, Error: %s" % (wrapped[1], wrapped[0])) wrapped = AWG.active_marker(session) print(Fore.RED + "Active marker(physical name): %s, Error: %s" % (wrapped[1], wrapped[0])) return
def AWG_Sinewave(ifreq, Ioffset, Qoffset, Iamp, Qamp, Iphase, Qphase): ''' ifreq: IF frequency in MHz ''' AWG.Clear_ArbMemory(awgsess) WAVE = [] ifvoltag = [min(abs(Qamp), 1), min(abs(Iamp), 1)] # contain amplitude within 1V iffunction = ['sin', 'cos'] iffreq = [ifreq, ifreq] ifoffset = [Qoffset, Ioffset] ifphase = [Qphase, Iphase] # construct waveform: for ch in range(2): channel = str(ch + 1) Nperiod = lcm(round(1000 / iffreq[ch] / dt * 100), 800) // 100 print("Waveform contains %s points per sequence" % Nperiod) 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) # 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) return
def awgabout(): global awgsess message = [] status = AWG.model(awgsess) # model message += ['Model: %s (%s)' % (status[1], status_code(status[0]))] status = AWG.active_marker(awgsess) # active marker message += ['Active Marker: %s (%s)' % (status[1], status_code(status[0]))] status = AWG.marker_delay(awgsess) # marker delay message += ['Marker Delay: %s (%s)' % (status[1], status_code(status[0]))] status = AWG.marker_pulse_width(awgsess) # marker pulse width message += [ 'Marker Pulse Width: %s (%s)' % (status[1], status_code(status[0])) ] status = AWG.marker_source(awgsess) # marker source message += ['Marker Source: %s (%s)' % (status[1], status_code(status[0]))] status = AWG.predistortion_enabled(awgsess) # predistortion enabled message += [ 'Predistortion Enabled: %s (%s)' % (status[1], status_code(status[0])) ] status = AWG.output_mode_adv(awgsess) # advanced output mode message += [ 'Advanced Output Mode: %s (%s)' % (status[1], status_code(status[0])) ] status = AWG.arb_sample_rate(awgsess) # sample rate message += ['Sample Rate: %s (%s)' % (status[1], status_code(status[0]))] return jsonify(message=message)
def awgsettingsmain(): global awgsess message = [] refclk = request.args.get('refclk') stat = AWG.ref_clock_source(awgsess, action=['Set',int(refclk)]) message += ['Reference Clock Source: %s <%s>' %(stat[1], status_code(stat[0]))] predist = request.args.get('predist') stat = AWG.predistortion_enabled(awgsess, action=['Set',int(predist)]) message += ['predistortion enabled: %s <%s>' %(stat[1], status_code(stat[0]))] outpmode = request.args.get('outpmode') stat = AWG.output_mode_adv(awgsess, action=['Set',int(outpmode)]) message += ['advanced output mode: %s <%s>' %(stat[1], status_code(stat[0]))] samprat = request.args.get('samprat') stat = AWG.arb_sample_rate(awgsess, action=['Set',float(samprat)]) message += ['sample rate: %s <%s>' %(stat[1], status_code(stat[0]))] # Marker Settings: active = request.args.get('active') stat = AWG.active_marker(awgsess, action=['Set',active]) message += ['active marker: %s <%s>' %(stat[1], status_code(stat[0]))] delay = request.args.get('delay') stat = AWG.marker_delay(awgsess, action=['Set',float(delay)]) message += ['marker delay: %s <%s>' %(stat[1], status_code(stat[0]))] pulsew = request.args.get('pulsew') stat = AWG.marker_pulse_width(awgsess, action=['Set',float(pulsew)]) message += ['marker pulse width: %s <%s>' %(stat[1], status_code(stat[0]))] source = request.args.get('source') stat = AWG.marker_source(awgsess, action=['Set',int(source)]) message += ['marker source: %s <%s>' %(stat[1], status_code(stat[0]))] return jsonify(message=message)
def off(): global session status = AWG.close(session) awgcache.update(Closed=status) return 'Closed: %s' % awgcache \ + "<br/> <a href='/awg'>AWG</a>"
def awgsettingsprepare(): global awgsess message = [] predist = request.args.get('predist') stat = AWG.predistortion_enabled(awgsess, action=['Set', int(predist)]) message += [ 'predistortion enabled: %s <%s>' % (stat[1], status_code(stat[0])) ] outpmode = request.args.get('outpmode') stat = AWG.output_mode_adv(awgsess, action=['Set', int(outpmode)]) message += [ 'advanced output mode: %s <%s>' % (stat[1], status_code(stat[0])) ] samprat = request.args.get('samprat') stat = AWG.arb_sample_rate(awgsess, action=['Set', float(samprat)]) message += ['sample rate: %s <%s>' % (stat[1], status_code(stat[0]))] return jsonify(message=message)
def show(): stat = 'No reading' global session if request.method == 'POST': if request.form.get('reset'): status, session = AWG.InitWithOptions() awgcache.update(Initialized=status) if request.form.get('marker'): active = request.form.get('active') status = AWG.active_marker(session, action=['Set', active]) awgcache.update(Marker=status) delay = request.form.get('delay') status = AWG.marker_delay(session, action=['Set', float(delay)]) awgcache.update(Delay=status) if request.form.get('model'): stat = AWG.model(session) return render_template("blog/awgonly.html", stat=stat)
def awgsettingsmarker(): global awgsess message = [] active = request.args.get('active') stat = AWG.active_marker(awgsess, action=['Set', active]) message += ['active marker: %s <%s>' % (stat[1], status_code(stat[0]))] delay = request.args.get('delay') stat = AWG.marker_delay(awgsess, action=['Set', float(delay)]) message += ['marker delay: %s <%s>' % (stat[1], status_code(stat[0]))] pulsew = request.args.get('pulsew') stat = AWG.marker_pulse_width(awgsess, action=['Set', float(pulsew)]) message += [ 'marker pulse width: %s <%s>' % (stat[1], status_code(stat[0])) ] source = request.args.get('source') stat = AWG.marker_source(awgsess, action=['Set', int(source)]) message += ['marker source: %s <%s>' % (stat[1], status_code(stat[0]))] return jsonify(message=message)
def show(): global session status, ans, mark = None, None, {} if request.form.get('model'): stat = AWG.model(session) ans = stat[1] if request.form.get('gemarker'): stat = AWG.active_marker(session) mark = dict(active=stat[1]) stat = AWG.marker_delay(session) mark.update(delay=stat[1]) if request.form.get('reset'): status = AWG.InitWithOptions() session = status[1] return redirect('/') if request.form.get('semarker'): active = request.form.get('active') AWG.active_marker(session, action=['Set', active]) delay = request.form.get('delay') AWG.marker_delay(session, action=['Set', float(delay)]) return redirect('/') if request.form.get('closeawg'): # or x == 1: AWG.close(session) return redirect('/') if request.form.get('esgon'): freq = request.form.get('frequency') powa = request.form.get('power') ESG.control(True, freq, powa) return redirect('/') if request.form.get('esgoff'): ESG.control(False) return redirect('/') return render_template('blog/combo.html', ans=ans, mark=mark) #this is where it really goes
def test(): LO_0 = float((MXA.fpower(mxa, str(5.5) + 'GHz')).split('dBm')[0]) Mirror_0 = float((MXA.fpower(mxa, str(5.475) + 'GHz')).split('dBm')[0]) Initial = [0., 0., 1., 0., 0.] time = 0 OPT = IQ_Cal() OPT.IQparams = array(Initial, dtype=float64) #overwrite initial values result = OPT.nelder_mead(time=time) prev = result[0] no_improv, no_improv_thr, no_improv_break = 0, 1e-5, 4 LO, Mirror, T = [], [], [] while True: time += 1 if time % 2: OPT = IQ_Cal('MR', result[0], ratio=time) else: OPT = IQ_Cal('LO', result[0], ratio=time) result = OPT.nelder_mead(time=time) # if len(result) == 3: # print("Optimized IQ parameters:\n %s" %result) # break LO.append( float((MXA.fpower(mxa, str(5.5) + 'GHz')).split('dBm')[0]) - LO_0) Mirror.append( float((MXA.fpower(mxa, str(5.475) + 'GHz')).split('dBm')[0]) - Mirror_0) print(Back.BLUE + Fore.WHITE + "Mirror has been suppressed for %s from %s" % (Mirror[-1], Mirror_0)) T.append(time) ssq = sum((result[0] - prev)**2) if ssq > no_improv_thr: no_improv = 0 prev = result[0] else: no_improv += 1 if no_improv >= no_improv_break: AWG_Sinewave(25, OPT.IQparams) print(type(OPT.IQparams)) print("Optimized IQ parameters:\n %s" % result) print("Amplitude Imbalance:\n %s" % OPT.IQparams[2]) if OPT.IQparams[3] > OPT.IQparams[ 4] and OPT.IQparams[3] - OPT.IQparams[4] < 180: print("phase skew I-Q:\n %s" % (OPT.IQparams[3] - OPT.IQparams[4])) if OPT.IQparams[3] > OPT.IQparams[ 4] and OPT.IQparams[3] - OPT.IQparams[4] > 180: print("phase skew Q-I:\n %s" % (360 - (OPT.IQparams[3] - OPT.IQparams[4]))) if (OPT.IQparams[4] > OPT.IQparams[3] and OPT.IQparams[4] - OPT.IQparams[3] < 180) or ( OPT.IQparams[3] > OPT.IQparams[4] and OPT.IQparams[3] - OPT.IQparams[4] > 180): print("phase skew Q-I:\n %s" % (OPT.IQparams[4] - OPT.IQparams[3])) if (OPT.IQparams[2] > -1.0) and (OPT.IQparams[2] < 1.0): Iamp = 1 Qamp = Iamp * OPT.IQparams[2] else: Qamp = 1 Iamp = Qamp / OPT.IQparams[2] print("Ioffset:\n %s" % OPT.IQparams[0]) print("Qoffset:\n %s" % OPT.IQparams[1]) print("Iamp:\n %s" % Iamp) print("Qamp:\n %s" % Qamp) print("Iphase:\n %s" % OPT.IQparams[3]) print("Qphase:\n %s" % OPT.IQparams[4]) break curve(T, LO, 'LO Leakage vs time', 'T(#)', 'DLO(dB)') curve(T, Mirror, 'Mirror Image vs time', 'T(#)', 'DMirror(dB)') # closing instruments: ans = input("Press any keys to close AWG, PSGA and RSA-5 ") AWG.Abort_Gen(awgsess) AWG.close(awgsess) PSGA.rfoutput(saga, action=['Set', 0]) PSGA.close(saga, False) MXA.close(mxa, False)
from flask import Blueprint, render_template, request, redirect, jsonify import random, json, ctypes, requests from pathlib import Path # Initialize before Blueprint from pyqum.instrument.modular import VSA, AWG status, session = AWG.InitWithOptions() # VISA conflicts the DLL Libraries! # Hence it has to come AFTER Initiated the IVI-C Connection from pyqum.instrument.benchtop import ESG bp = Blueprint('combo', __name__) @bp.route('/comb', methods=['POST', 'GET']) #this will appear as the web address def show(): global session status, ans, mark = None, None, {} if request.form.get('model'): stat = AWG.model(session) ans = stat[1] if request.form.get('gemarker'): stat = AWG.active_marker(session) mark = dict(active=stat[1]) stat = AWG.marker_delay(session) mark.update(delay=stat[1])
def CLOS(session): closestatus = AWG.close(session) print(Fore.RED + "\nAWG is closed. Error: %s" % closestatus)
def RESOURC(session): wrapped = AWG.resource_descriptor(session) print(Fore.RED + Back.YELLOW + "\nResource Descriptor: %s, Error: %s" % (wrapped[1], wrapped[0])) return
def NAME(session): wrapped = AWG.logical_name(session) print(Fore.CYAN + "\nLogical Name: %s, Error: %s" % (wrapped[1], wrapped[0])) name = wrapped[1] return name
def awgabort(): global awgsess status = AWG.Abort_Gen(awgsess) return jsonify(message=status)
def MODEL(session): wrapped = AWG.model(session) print(Fore.BLACK + Back.WHITE + "Inquired instrument's model: %s, Error: %s" % (wrapped[1], wrapped[0])) return
def AWG_Sinewave(ifreq, IQparams): ''' ifreq: IF frequency in MHz ''' AWG.Clear_ArbMemory(awgsess) WAVE = [] Ioffset, Qoffset, ampratio, Iphase, Qphase = IQparams if (ampratio > -1.0) and (ampratio < 1.0): Iamp = 1 Qamp = Iamp * ampratio else: Qamp = 1 Iamp = Qamp / ampratio ifvoltag = [min(abs(Qamp), 1), min(abs(Iamp), 1)] # contain amplitude within 1V iffunction = ['sin', 'cos'] iffreq = [ifreq, ifreq] ifoffset = [Qoffset, Ioffset] ifphase = [Qphase, Iphase] # construct waveform: for ch in range(2): channel = str(ch + 1) Nperiod = int(1000 / iffreq[ch] / dt) # of points per period Nperiod *= 8 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) ] createdwave = AWG.CreateArbWaveform(awgsess, wavefom) WAVE.append(createdwave[1]) # Building Sequences: for ch in range(2): channel = str(ch + 1) createdseqhandl = AWG.CreateArbSequence( awgsess, [WAVE[ch]], [1]) # loop# canbe >1 if longer sequence is needed in the future! # Channel Assignment: AWG.arb_sequence_handle(awgsess, RepCap=channel, action=["Set", createdseqhandl[1]]) # 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) return
def Initialize(self): # Initialize instruments: # PSGA self.saga = PSGA.Initiate() PSGA.rfoutput(self.saga, action=['Set', 1]) PSGA.frequency(self.saga, action=['Set', "5.5" + "GHz"]) PSGA.power(self.saga, action=['Set', "12" + "dBm"]) # SA self.mxa = MXA.Initiate() MXA.frequency(self.mxa, action=['Set', '5.525GHz']) MXA.fspan(self.mxa, action=['Set', '150MHz']) MXA.rbw(self.mxa, action=['Set', '1MHz']) MXA.vbw(self.mxa, action=['Set', '100kHz']) MXA.trigger_source(self.mxa, action=['Set', 'EXTernal1']) # AWG self.awgsess = AWG.InitWithOptions() AWG.Abort_Gen(self.awgsess) AWG.ref_clock_source(self.awgsess, action=['Set', int(1)]) # External 10MHz clock-reference AWG.predistortion_enabled(self.awgsess, action=['Set', True]) AWG.output_mode_adv(self.awgsess, action=['Set', int(2)]) # Sequence output mode AWG.arb_sample_rate(self.awgsess, action=['Set', float(1250000000) ]) # maximum sampling rate AWG.active_marker(self.awgsess, action=['Set', '3']) # master AWG.marker_delay(self.awgsess, action=['Set', float(0)]) AWG.marker_pulse_width(self.awgsess, action=['Set', float(1e-7)]) AWG.marker_source(self.awgsess, action=['Set', int(7)]) samplingrate = AWG.arb_sample_rate(self.awgsess)[1] dt = 1e9 / samplingrate # in ns # PRESET Output: for ch in range(2): channel = str(ch + 1) AWG.output_config(self.awgsess, RepCap=channel, action=["Set", 0]) # Single-ended AWG.output_filter_bandwidth(self.awgsess, RepCap=channel, action=["Set", 0]) AWG.arb_gain(self.awgsess, RepCap=channel, action=["Set", 0.5]) AWG.output_impedance(self.awgsess, RepCap=channel, action=["Set", 50]) # output settings: for ch in range(2): channel = str(ch + 1) AWG.output_enabled(self.awgsess, RepCap=channel, action=["Set", int(1)]) # ON AWG.output_filter_enabled(self.awgsess, RepCap=channel, action=["Set", True]) AWG.output_config(self.awgsess, RepCap=channel, action=["Set", int(2)]) # Amplified 1:2 AWG.output_filter_bandwidth(self.awgsess, RepCap=channel, action=["Set", 0]) AWG.arb_gain(self.awgsess, RepCap=channel, action=["Set", 0.5]) AWG.output_impedance(self.awgsess, RepCap=channel, action=["Set", 50])
def __init__(self, LO_freq, LO_powa, IF_freq): ''' Initialize relevant instruments: LO_freq: LO frequency in GHz LO_powa: LO power in dBm IF_freq: IF frequency in GHz ''' self.LO_freq, self.LO_powa, self.IF_freq = LO_freq, LO_powa, IF_freq # SA self.mxa = MXA.Initiate() MXA.frequency(self.mxa, action=['Set', '%sGHz' % (LO_freq + IF_freq)]) MXA.fspan(self.mxa, action=['Set', '150MHz']) MXA.rbw(self.mxa, action=['Set', '1MHz']) MXA.vbw(self.mxa, action=['Set', '100kHz']) MXA.trigger_source(self.mxa, action=['Set', 'EXTernal1']) # PSGA self.saga = PSGA.Initiate() PSGA.rfoutput(self.saga, action=['Set', 1]) PSGA.frequency(self.saga, action=['Set', "%sGHz" % LO_freq]) PSGA.power(self.saga, action=['Set', "%sdBm" % LO_powa]) # AWG self.awgsess = AWG.InitWithOptions() AWG.Abort_Gen(self.awgsess) AWG.ref_clock_source(self.awgsess, action=['Set', int(1)]) # External 10MHz clock-reference AWG.predistortion_enabled(self.awgsess, action=['Set', True]) AWG.output_mode_adv(self.awgsess, action=['Set', int(2)]) # Sequence output mode AWG.arb_sample_rate(self.awgsess, action=['Set', float(1250000000) ]) # maximum sampling rate AWG.active_marker(self.awgsess, action=['Set', '3']) # master AWG.marker_delay(self.awgsess, action=['Set', float(0)]) AWG.marker_pulse_width(self.awgsess, action=['Set', float(1e-7)]) AWG.marker_source(self.awgsess, action=['Set', int(7)]) # PRESET Output: for ch in range(2): channel = str(ch + 1) AWG.output_config(self.awgsess, RepCap=channel, action=["Set", 0]) # Single-ended AWG.output_filter_bandwidth(self.awgsess, RepCap=channel, action=["Set", 0]) AWG.arb_gain(self.awgsess, RepCap=channel, action=["Set", 0.5]) AWG.output_impedance(self.awgsess, RepCap=channel, action=["Set", 50]) # output settings: for ch in range(2): channel = str(ch + 1) AWG.output_enabled(self.awgsess, RepCap=channel, action=["Set", int(1)]) # ON AWG.output_filter_enabled(self.awgsess, RepCap=channel, action=["Set", True]) AWG.output_config(self.awgsess, RepCap=channel, action=["Set", int(2)]) # Amplified 1:2 AWG.output_filter_bandwidth(self.awgsess, RepCap=channel, action=["Set", 0]) AWG.arb_gain(self.awgsess, RepCap=channel, action=["Set", 0.5]) AWG.output_impedance(self.awgsess, RepCap=channel, action=["Set", 50])
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
# Initialize instruments: # PSGA saga = PSGA.Initiate() PSGA.rfoutput(saga, action=['Set', 1]) PSGA.frequency(saga, action=['Set', "5.5" + "GHz"]) PSGA.power(saga, action=['Set', "12" + "dBm"]) # SA mxa = MXA.Initiate() MXA.frequency(mxa, action=['Set', '5.525GHz']) MXA.fspan(mxa, action=['Set', '150MHz']) MXA.rbw(mxa, action=['Set', '1MHz']) MXA.vbw(mxa, action=['Set', '100kHz']) MXA.trigger_source(mxa, action=['Set', 'EXTernal1']) # AWG 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', '3']) # 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)]) samplingrate = AWG.arb_sample_rate(awgsess)[1] dt = 1e9 / samplingrate # in ns # PRESET Output: for ch in range(2):
def run(): start = time.time() print("location of '2':", id(2)) print("location of '4':", id(4)) print("location of '6':", id(6)) print("location of '8':", id(8)) def INIT(): initstatus, session = AWG.InitWithOptions() print(Fore.GREEN + "\nAWG is initialized at session: %s, Error: %s" % (session, initstatus)) #status=0 means no error print(Fore.YELLOW + "location of session:", id(session)) return session def MODEL(session): wrapped = AWG.model(session) print(Fore.BLACK + Back.WHITE + "Inquired instrument's model: %s, Error: %s" % (wrapped[1], wrapped[0])) return # Testing Get/Set String def MARK(session): wrapped = AWG.active_marker(session) print(Fore.RED + "\nActive marker(physical name): %s, Error: %s" % (wrapped[1], wrapped[0])) wrapped = AWG.active_marker(session, action=["Set", "3"]) print(Fore.MAGENTA + "SET Active marker(physical name): %s, Error: %s" % (wrapped[1], wrapped[0])) wrapped = AWG.active_marker(session) print(Fore.RED + "Active marker(physical name): %s, Error: %s" % (wrapped[1], wrapped[0])) return # Testing Get String def NAME(session): wrapped = AWG.logical_name(session) print(Fore.CYAN + "\nLogical Name: %s, Error: %s" % (wrapped[1], wrapped[0])) name = wrapped[1] return name # Testing Get String def RESOURC(session): wrapped = AWG.resource_descriptor(session) print(Fore.RED + Back.YELLOW + "\nResource Descriptor: %s, Error: %s" % (wrapped[1], wrapped[0])) return # Testing Get/Set Int32 def SOURC(session): wrapped = AWG.marker_source(session) print(Fore.BLUE + Back.CYAN + "\nmarker source: %s, Error: %s" % (wrapped[1], wrapped[0])) wrapped = AWG.marker_source(session, action=["Set", 10]) print(Fore.CYAN + Back.BLUE + "SET marker source: %s, Error: %s" % (wrapped[1], wrapped[0])) wrapped = AWG.marker_source(session) print(Fore.BLUE + Back.CYAN + "marker source: %s, Error: %s" % (wrapped[1], wrapped[0])) return # Testing Get/Set Real64 def DELAY(session): wrapped = AWG.marker_delay(session) print("\nmarker delay: %s, Error: %s" % (wrapped[1], wrapped[0])) wrapped = AWG.marker_delay(session, action=["Set", 5e-7]) print("SET marker delay: %s, Error: %s" % (wrapped[1], wrapped[0])) wrapped = AWG.marker_delay(session) print("marker delay: %s, Error: %s" % (wrapped[1], wrapped[0])) def CLOS(session): closestatus = AWG.close(session) print(Fore.RED + "\nAWG is closed. Error: %s" % closestatus) s = INIT() n = NAME(s) MODEL(n) RESOURC(s) MARK(s) SOURC(s) DELAY(s) CLOS(s) for i in range(0): initstatus, s = AWG.InitWithOptions() print("\nAWG is initialized at session: %s, Error: %s" % (s, initstatus)) print("location of session:", id(s)) closestatus = AWG.close(s) print("\nAWG is closed. Error: ", closestatus) end = time.time() duration = end - start print("\nIt took {:.5f}s to complete".format(duration))
from pyqum.instrument.modular import AWG from IPython import embed e, s = AWG.InitWithOptions() print("AWG initialized") print(("...Error...", "***Success***")[e == 0]) print("Session<s>: {}".format(s)) print("Starting Interactive Console...") embed()
def INIT(): initstatus, session = AWG.InitWithOptions() print(Fore.GREEN + "\nAWG is initialized at session: %s, Error: %s" % (session, initstatus)) #status=0 means no error print(Fore.YELLOW + "location of session:", id(session)) return session