def MBI_fidelity(name): m = BSM.ElectronRabiMsmt(name) # BSM.ElectronRabiMsmt(name) BSM.prepare(m) leftline = m.params['AWG_MBI_MW_pulse_mod_frq'] HF = 2.19290e6 m.params['AWG_MBI_MW_pulse_mod_frq'] = leftline pts = 4 m.params['pts'] = pts m.params['reps_per_ROsequence'] = 1000 m.params['MW_pulse_multiplicities'] = np.ones(pts).astype(int) * 1 m.params['MW_pulse_delays'] = np.ones(pts) * 100e-9 # MW pulses m.params['MW_pulse_durations'] = np.ones(pts) * 2800e-9 m.params['MW_pulse_amps'] = np.array([0.0213, 0.0218, 0.0218, 0.0218]) * 0 m.params['MW_pulse_mod_frqs'] = np.array([leftline, leftline + HF, leftline + 2*HF, leftline + 3*HF]) # for the autoanalysis m.params['sweep_name'] = 'MW mod frq (MHz)' m.params['sweep_pts'] = m.params['MW_pulse_mod_frqs'] BSM.finish(m, debug=False)
def MBI_fidelity(name): m = BSM.ElectronRabiMsmt(name) # BSM.ElectronRabiMsmt(name) BSM.prepare(m) leftline = m.params['AWG_MBI_MW_pulse_mod_frq'] HF = 2.19290e6 m.params['AWG_MBI_MW_pulse_mod_frq'] = leftline pts = 4 m.params['pts'] = pts m.params['reps_per_ROsequence'] = 1000 m.params['MW_pulse_multiplicities'] = np.ones(pts).astype(int) * 1 m.params['MW_pulse_delays'] = np.ones(pts) * 100e-9 # MW pulses m.params['MW_pulse_durations'] = np.ones(pts) * 2800e-9 m.params['MW_pulse_amps'] = np.array([0.0213, 0.0218, 0.0218, 0.0218]) * 0 m.params['MW_pulse_mod_frqs'] = np.array( [leftline, leftline + HF, leftline + 2 * HF, leftline + 3 * HF]) # for the autoanalysis m.params['sweep_name'] = 'MW mod frq (MHz)' m.params['sweep_pts'] = m.params['MW_pulse_mod_frqs'] BSM.finish(m, debug=False)
def run_electron_rabi(name): m = BSM.ElectronRabiMsmt(name) # BSM.ElectronRabiMsmt(name) BSM.prepare(m) leftline = m.params['AWG_MBI_MW_pulse_mod_frq'] HF = 2.19290e6 m.params['AWG_MBI_MW_pulse_mod_frq'] = leftline pts = 21 m.params['pts'] = pts m.params['reps_per_ROsequence'] = 1000 m.params['MW_pulse_multiplicities'] = np.ones(pts).astype(int) * 1 m.params['MW_pulse_delays'] = np.ones(pts) * 100e-9 # MW pulses m.params['MW_pulse_durations'] = np.linspace(0, 150e-9, pts) + 10e-9 m.params['MW_pulse_amps'] = np.ones(pts) * 0.7 m.params['MW_pulse_mod_frqs'] = np.ones(pts) * \ m.params['AWG_MBI_MW_pulse_mod_frq'] # for the autoanalysis m.params['sweep_name'] = 'MW pulse length (ns)' m.params['sweep_pts'] = m.params['MW_pulse_durations'] * 1e9 funcs.finish(m, debug=False)
def tomo_debug(): m = TomoDebug('debug') BSM.prepare(m) m.params['reps_per_ROsequence'] = 1000 m.params['pts'] = 3 # must be 3 for any N-tomography msmt BSM.finish(m, debug=False)
def hadamard_tomo(name): m = HadamardTomo(name) BSM.prepare(m) m.params['reps_per_ROsequence'] = 1000 m.params['pts'] = 3 # must be 3 for any N-tomography msmt BSM.finish(m, debug=False, upload=True)
def phase_check(name): m = NPhaseCheck(name) BSM.prepare(m) m.params['reps_per_ROsequence'] = 1000 m.params['phases'] = np.array([0, 180, 90]) m.params['pts'] = len(m.params['phases']) # for the autoanalysis m.params['sweep_name'] = 'second pi2 phase (deg)' m.params['sweep_pts'] = m.params['phases'] BSM.finish(m, debug=False)
def phase_check(name): m = NPhaseCheck(name) BSM.prepare(m) m.params['reps_per_ROsequence'] = 1000 m.params['phases'] = np.array([0,180,90]) m.params['pts'] = len(m.params['phases']) # for the autoanalysis m.params['sweep_name'] = 'second pi2 phase (deg)' m.params['sweep_pts'] = m.params['phases'] BSM.finish(m, debug=False)
def H_phase_sweep(name): m = HadamardPhaseSweep(name) BSM.prepare(m) m.params['reps_per_ROsequence'] = 1000 m.params['phases'] = np.linspace(0, 360, 9) m.params['pts'] = len(m.params['phases']) m.params['N_rabi_frequency'] = 5.532e3 # for the autoanalysis m.params['sweep_name'] = 'second pi2 phase (deg)' m.params['sweep_pts'] = m.params['phases'] BSM.finish(m, debug=False, upload=False)
def CNOT_phase_check_sweep_CNOT_phase(): m = CNOTPhaseCheckSweepCNOTphase('CNOT_phase') BSM.prepare(m) pts = 17 m.params['pts'] = pts m.params['reps_per_ROsequence'] = 1000 # MW pulses m.params['CNOT_phase'] = np.linspace(0,360,pts) # for the autoanalysis m.params['sweep_name'] = 'first CNOT phase' m.params['sweep_pts'] = m.params['CNOT_phase'] funcs.finish(m, debug=False, upload=True)
def CNOT_phase_check_sweep_time(): m = CNOTPhaseCheckSweepTime('CNOT_to_pi2') BSM.prepare(m) pts = 17 m.params['pts'] = pts m.params['reps_per_ROsequence'] = 1000 # MW pulses m.params['CNOT_to_pi2_time'] = np.linspace(150e-9, 250e-9, pts) # for the autoanalysis m.params['sweep_name'] = 'second_CNOT_to_pi2_time' m.params['sweep_pts'] = m.params['CNOT_to_pi2_time'] funcs.finish(m, debug=False, upload=True)
def generate_sequence(self, upload=True): self._pulse_defs() seq = pulsar.Sequence('{}_{} sequence'.format(self.mprefix, self.name)) elements = [] elements.append(self.mbi_elt) elements.append(self.sync_elt) e = element.Element('H pulse', pulsar=qt.pulsar) e.append(self.T) e.append(self.shelving_pulse) e.append(pulse.cp(self.T, length=100e-9)) n = e.append( pulse.cp(self.N_pulse, frequency=self.N_pi.frequency - self.params['N_rabi_frequency'], length=self.N_pi.length / np.sqrt(2), amplitude=1)) t = e.length() - e.pulse_start_time(n, 'RF') e2 = element.Element('pi2', pulsar=qt.pulsar) e2.append( pulse.cp(self.N_pi2, phase=BSM.phaseref(self.N_pi2.frequency, t))) e2.append(self.TN) e2.append(pulse.cp(self.pi2pi_m1)) elements.append(e2) for i in range(self.params['pts']): seq.append(name='MBI-{}'.format(i), wfname=self.mbi_elt.name, trigger_wait=True, goto_target='MBI-{}'.format(i), jump_target='H-{}'.format(i)) e = element.Element('H pulse-{}'.format(i), pulsar=qt.pulsar) e.append(self.T) e.append(self.shelving_pulse) e.append(pulse.cp(self.T, length=100e-9)) n = e.append( pulse.cp(self.N_pulse, frequency=self.N_pi.frequency - self.params['N_rabi_frequency'], length=self.N_pi.length / np.sqrt(2), amplitude=1, phase=self.params['phases'][i])) elements.append(e) seq.append(name='H-{}'.format(i), wfname=e.name, trigger_wait=True) seq.append(name='pi2-{}'.format(i), wfname=e2.name) seq.append(name='sync-{}'.format(i), wfname=self.sync_elt.name) # program AWG if upload: qt.pulsar.upload(*elements) qt.pulsar.program_sequence(seq)
def CNOT_phase_check_sweep_time(): m = CNOTPhaseCheckSweepTime('CNOT_to_pi2') BSM.prepare(m) pts = 17 m.params['pts'] = pts m.params['reps_per_ROsequence'] = 1000 # MW pulses m.params['CNOT_to_pi2_time'] = np.linspace(150e-9,250e-9,pts) # for the autoanalysis m.params['sweep_name'] = 'second_CNOT_to_pi2_time' m.params['sweep_pts'] = m.params['CNOT_to_pi2_time'] funcs.finish(m, debug=False, upload=True)
def CNOT_phase_check_sweep_CNOT_phase(): m = CNOTPhaseCheckSweepCNOTphase('CNOT_phase') BSM.prepare(m) pts = 17 m.params['pts'] = pts m.params['reps_per_ROsequence'] = 1000 # MW pulses m.params['CNOT_phase'] = np.linspace(0, 360, pts) # for the autoanalysis m.params['sweep_name'] = 'first CNOT phase' m.params['sweep_pts'] = m.params['CNOT_phase'] funcs.finish(m, debug=False, upload=True)
def CNOT_phase_check_mI0_both_pi2_phases(): m = CNOTPhaseCheckmI0BothPi2Phases('mI0_pi2_phases_sweep_both') BSM.prepare(m) pts = 16 m.params['pts'] = pts m.params['reps_per_ROsequence'] = 1000 # MW pulses m.params['analysis_phases'] = - 62 + np.linspace(0,360,pts) m.params['prepare_phases'] = - m.params['analysis_phases'] # for the autoanalysis m.params['sweep_name'] = 'second pi/2 phase' m.params['sweep_pts'] = m.params['analysis_phases'] funcs.finish(m, debug=False, upload=True)
def get_sweep_elements(self): e = element.Element('Hadamard', pulsar=qt.pulsar) e.append(self.T) e.append(self.shelving_pulse) e.append(pulse.cp(self.T, length=100e-9)) # this is for using the detuned pi pulse # prep_name = e.append(pulse.cp(self.N_pi2, # phase = BSM.phaseref(self.N_pi2.frequency, # -self.N_pi2.length) - 90., # amplitude = 1)) # hadamard_name = e.append(pulse.cp(self.N_pulse, # frequency = self.N_pi.frequency - self.params['N_rabi_frequency'], # length = self.N_pi.length / np.sqrt(2), # amplitude = 1, # phase = 36.5)) # t = e.length()-e.pulse_start_time(hadamard_name, 'RF') # this is by using two rotations around x/y -- This works much better! prep_name = e.append(pulse.cp(self.N_pi2, phase=-90, amplitude=1)) # first a pi/2 over +Y h_pi2_name = e.append( pulse.cp(self.N_pi2, phase=BSM.phaseref(self.N_pi2.frequency, e.pulse_length(prep_name)), amplitude=1)) # then a pi over +X h_pi_name = e.append( pulse.cp( self.N_pi, phase=BSM.phaseref( self.N_pi2.frequency, e.pulse_length(prep_name) + e.pulse_length(h_pi2_name)) + 90., amplitude=1)) self.element = e self.params['tomo_time_offset'] = e.length() - e.pulse_start_time( prep_name, 'RF') return BSM.NTomo.get_sweep_elements(self)
def CNOT_phase_check(): m = CNOTPhaseCheck('2_times_CNOT') BSM.prepare(m) pts = 17 m.params['pts'] = pts m.params['reps_per_ROsequence'] = 1000 # MW pulses m.params['multiplicity'] = 2 #number of CNOT pulses m.params['analysis_phases'] = np.linspace(0, 360, pts) # for the autoanalysis m.params['sweep_name'] = 'second pi/2 phase' m.params['sweep_pts'] = m.params['analysis_phases'] funcs.finish(m, debug=False, upload=True)
def CNOT_phase_check(): m = CNOTPhaseCheck('2_times_CNOT') BSM.prepare(m) pts = 17 m.params['pts'] = pts m.params['reps_per_ROsequence'] = 1000 # MW pulses m.params['multiplicity'] = 2 #number of CNOT pulses m.params['analysis_phases'] = np.linspace(0,360,pts) # for the autoanalysis m.params['sweep_name'] = 'second pi/2 phase' m.params['sweep_pts'] = m.params['analysis_phases'] funcs.finish(m, debug=False, upload=True)
def CNOT_phase_check_mI0_both_pi2_phases(): m = CNOTPhaseCheckmI0BothPi2Phases('mI0_pi2_phases_sweep_both') BSM.prepare(m) pts = 16 m.params['pts'] = pts m.params['reps_per_ROsequence'] = 1000 # MW pulses m.params['analysis_phases'] = -62 + np.linspace(0, 360, pts) m.params['prepare_phases'] = -m.params['analysis_phases'] # for the autoanalysis m.params['sweep_name'] = 'second pi/2 phase' m.params['sweep_pts'] = m.params['analysis_phases'] funcs.finish(m, debug=False, upload=True)
def run_CORPSE_echo_phase_sweep(name): m = CORPSEEchoPhaseSweep(name) BSM.prepare(m) phases = np.linspace(0, 360, 25) pts = len(phases) m.params['pts'] = pts m.params['reps_per_ROsequence'] = 500 m.params['delay'] = 50.9e-6 m.params['phases'] = phases # for the autoanalysis m.params['sweep_name'] = 'CORPSE relative phase shift (deg)' m.params['sweep_pts'] = phases BSM.finish(m, debug=False)
def run_CORPSE_echo_phase_sweep(name): m = CORPSEEchoPhaseSweep(name) BSM.prepare(m) phases = np.linspace(0,360,25) pts = len(phases) m.params['pts'] = pts m.params['reps_per_ROsequence'] = 500 m.params['delay'] = 50.9e-6 m.params['phases'] = phases # for the autoanalysis m.params['sweep_name'] = 'CORPSE relative phase shift (deg)' m.params['sweep_pts'] = phases BSM.finish(m, debug=False)
def do_N_FT_Polarisation_check(): m = N_FT_Polarisation_Check('pulsed') BSM.prepare(m,yellow=True) #preparation line: m.params['init_line'] = '-1' #readout pulse line: m.params['readout_line']='-1' m.name=m.name+'_init_'+ m.params['init_line']+'_ro_'+m.params['readout_line'] m.params['FT_element_repetitions'] = np.array([1,1000,2000,3000,4000]) pts = len(m.params['FT_element_repetitions']) m.params['pts'] = pts m.params['reps_per_ROsequence'] = 1000 m.params['sp_duration'] = 20e-6 m.params['FT_pulse_power']=100e-9 m.params['FT_pulse_amp']=\ m.A_aom.power_to_voltage(m.params['FT_pulse_power'], controller='sec') m.params['yellow_pulse_power'] = 50e-9 m.params['yellow_pulse_amp'] =\ m.yellow_aom.power_to_voltage(m.params['yellow_pulse_power'], controller='sec') # for the autoanalysis m.params['sweep_name'] = 'FT_element_repetitions' m.params['sweep_pts'] = m.params['FT_element_repetitions'] if m.params['init_line'] == '-1': m.params['AWG_MBI_MW_pulse_mod_frq']=m.params['mIm1_mod_frq'] #ms=-1 elif m.params['init_line'] == '0': m.params['AWG_MBI_MW_pulse_mod_frq']=m.params['mI0_mod_frq'] #ms=0 elif m.params['init_line'] == '+1': m.params['AWG_MBI_MW_pulse_mod_frq']=m.params['mIp1_mod_frq']#ms=+1 print 'dont use this --> CORPSE is bad for +1' else: raise(Exception('Unknown init line' + str(m.params['init_line']))) funcs.finish(m, debug=False, upload=True)
def pi_position_sweep(name): m = EchoSweepPiPosition(name) BSM.prepare(m) m.params['2tau'] = 3000e-9 shifts = np.linspace(-500e-9, 500e-9, 21) pts = len(shifts) m.params['pts'] = pts m.params['reps_per_ROsequence'] = 2500 # m.params['CORPSE_pi_phase_shift'] = 65.2 m.params['pi_position_shifts'] = shifts # for the autoanalysis m.params['sweep_name'] = 'position shift of the pi-pulse (ns)' m.params['sweep_pts'] = shifts * 1e9 BSM.finish(m, debug=False, upload=True)
def echo_phase_sweep(name): m = Echo('_PhaseSweep_{}'.format(name)) BSM.prepare(m) phases = np.linspace(0,360,25) # reps = np.arange(1, 12, 2) pts = len(phases) m.params['pts'] = pts m.params['reps_per_ROsequence'] = 500 m.params['delay_repetitions'] = np.ones(pts) * 51 m.params['second_pi2_phases'] = phases # for the autoanalysis m.params['sweep_name'] = 'Phase of second pi-pulse (deg)' m.params['sweep_pts'] = m.params['second_pi2_phases'] BSM.finish(m, debug=False)
def echo_delay_sweep(name): m = Echo('_DelaySweep_{}'.format(name)) BSM.prepare(m) reps = np.arange(30,72,2) # reps = np.arange(1, 12, 2) pts = len(reps) m.params['pts'] = pts m.params['reps_per_ROsequence'] = 500 m.params['delay_repetitions'] = reps m.params['second_pi2_phases'] = zeros(pts) # for the autoanalysis m.params['sweep_name'] = 'Interpulse delay (us)' m.params['sweep_pts'] = m.params['delay_repetitions'] BSM.finish(m, debug=False)
def echo_phase_sweep(name): m = Echo('_PhaseSweep_{}'.format(name)) BSM.prepare(m) phases = np.linspace(0, 360, 25) # reps = np.arange(1, 12, 2) pts = len(phases) m.params['pts'] = pts m.params['reps_per_ROsequence'] = 500 m.params['delay_repetitions'] = np.ones(pts) * 51 m.params['second_pi2_phases'] = phases # for the autoanalysis m.params['sweep_name'] = 'Phase of second pi-pulse (deg)' m.params['sweep_pts'] = m.params['second_pi2_phases'] BSM.finish(m, debug=False)
def echo_delay_sweep(name): m = Echo('_DelaySweep_{}'.format(name)) BSM.prepare(m) reps = np.arange(30, 72, 2) # reps = np.arange(1, 12, 2) pts = len(reps) m.params['pts'] = pts m.params['reps_per_ROsequence'] = 500 m.params['delay_repetitions'] = reps m.params['second_pi2_phases'] = zeros(pts) # for the autoanalysis m.params['sweep_name'] = 'Interpulse delay (us)' m.params['sweep_pts'] = m.params['delay_repetitions'] BSM.finish(m, debug=False)
def get_sweep_elements(self): e = element.Element('Hadamard', pulsar=qt.pulsar) e.append(self.T) e.append(self.shelving_pulse) e.append(pulse.cp(self.T, length=100e-9)) # this is for using the detuned pi pulse # prep_name = e.append(pulse.cp(self.N_pi2, # phase = BSM.phaseref(self.N_pi2.frequency, # -self.N_pi2.length) - 90., # amplitude = 1)) # hadamard_name = e.append(pulse.cp(self.N_pulse, # frequency = self.N_pi.frequency - self.params['N_rabi_frequency'], # length = self.N_pi.length / np.sqrt(2), # amplitude = 1, # phase = 36.5)) # t = e.length()-e.pulse_start_time(hadamard_name, 'RF') # this is by using two rotations around x/y -- This works much better! prep_name = e.append(pulse.cp(self.N_pi2, phase = -90, amplitude = 1)) # first a pi/2 over +Y h_pi2_name = e.append(pulse.cp(self.N_pi2, phase = BSM.phaseref(self.N_pi2.frequency, e.pulse_length(prep_name)), amplitude = 1)) # then a pi over +X h_pi_name = e.append(pulse.cp(self.N_pi, phase = BSM.phaseref(self.N_pi2.frequency, e.pulse_length(prep_name)+e.pulse_length(h_pi2_name)) + 90., amplitude = 1)) self.element = e self.params['tomo_time_offset'] = e.length() - e.pulse_start_time(prep_name, 'RF') return BSM.NTomo.get_sweep_elements(self)
def N_rabi(name): m = NRabi(name) # BSM.ElectronRabiMsmt(name) BSM.prepare(m) pts = 17 m.params['pts'] = pts m.params['reps_per_ROsequence'] = 500 m.params['RF_pulse_multiplicities'] = np.ones(pts).astype(int) * 1 m.params['RF_pulse_delays'] = np.ones(pts) * 1e-6 # MW pulses m.params['RF_pulse_durations'] = np.linspace(1e-6, 181e-6, pts) m.params['RF_pulse_amps'] = np.ones(pts) * 1 m.params['RF_pulse_frqs'] = np.ones(pts) * m.params['N_0-1_splitting_ms-1'] # for the autoanalysis m.params['sweep_name'] = 'RF duration (us)' m.params['sweep_pts'] = m.params['RF_pulse_durations'] * 1e6 BSM.finish(m, debug=False)
def run_nmr_rabi(name): m = BSM.NRabiMsmt('Nuclear_rabi_' + name) # BSM.ElectronRabiMsmt(name) BSM.prepare(m) pts = 26 m.params['pts'] = pts m.params['reps_per_ROsequence'] = 500 m.params['RF_pulse_multiplicities'] = np.ones(pts).astype(int) * 1 m.params['RF_pulse_delays'] = np.ones(pts) * 1e-6 # MW pulses m.params['RF_pulse_durations'] = np.linspace(1e-6, 361e-6, pts) m.params['RF_pulse_amps'] = np.ones(pts) * 1 m.params['RF_pulse_frqs'] = np.ones(pts) + m.params['N_0-1_splitting_ms-1'] # for the autoanalysis m.params['sweep_name'] = 'RF duration (us)' m.params['sweep_pts'] = m.params['RF_pulse_durations'] * 1e6 BSM.finish(m, debug=False)
def run_nmr_frq_scan(name): m = BSM.NRabiMsmt('NMR_frq_scan_' + name) # BSM.ElectronRabiMsmt(name) BSM.prepare(m) pts = 21 m.params['pts'] = pts m.params['reps_per_ROsequence'] = 500 m.params['RF_pulse_multiplicities'] = np.ones(pts).astype(int) * 1 m.params['RF_pulse_delays'] = np.ones(pts) * 1e-6 # MW pulses m.params['RF_pulse_durations'] = np.ones(pts) * 70e-6 m.params['RF_pulse_amps'] = np.ones(pts) * 1 m.params['RF_pulse_frqs'] = np.linspace(7.12e6, 7.15e6, pts) # for the autoanalysis m.params['sweep_name'] = 'RF frequency (MHz)' m.params['sweep_pts'] = m.params['RF_pulse_frqs'] * 1e-6 funcs.finish(m, debug=False)
def run_nmr_frq_scan(name): m = BSM.NRabiMsmt('NMR_frq_scan_'+name) # BSM.ElectronRabiMsmt(name) BSM.prepare(m) pts = 21 m.params['pts'] = pts m.params['reps_per_ROsequence'] = 500 m.params['RF_pulse_multiplicities'] = np.ones(pts).astype(int) * 1 m.params['RF_pulse_delays'] = np.ones(pts) * 1e-6 # MW pulses m.params['RF_pulse_durations'] = np.ones(pts) * 70e-6 m.params['RF_pulse_amps'] = np.ones(pts) * 1 m.params['RF_pulse_frqs'] = np.linspace(7.12e6, 7.15e6, pts) # for the autoanalysis m.params['sweep_name'] = 'RF frequency (MHz)' m.params['sweep_pts'] = m.params['RF_pulse_frqs'] * 1e-6 funcs.finish(m, debug=False)
def run_N_uncond_rot_calib(name): m = NitrogenUnconditonalRotationCalib(name) BSM.prepare(m) delays = 51.1e-6 + np.linspace(-0.5e-6, 0.5e-6, 17) pts = len(delays) m.params['pts'] = pts m.params['reps_per_ROsequence'] = 500 # DEBUG # m.params['CORPSE_pi_amp'] = 0. m.params['CORPSE_pi_phase_shift'] = 65.2 m.params['delays'] = delays # for the autoanalysis m.params['sweep_name'] = 'Interpulse delay (us)' m.params['sweep_pts'] = delays * 1e6 BSM.finish(m, debug=False)
def estimate(self): # initialize N = len(self.z) # use close market's value t_init = 0 y_init = self.z[t_init] # BSM model model = bsm.BSM(N, self.params["mu"], self.params["sgm"], t_init, y_init, self.seed) y = model.predict() loss = model.calc_loss(np.array(self.z, dtype=float)) return loss, y
def estimate_last(self, args): # initialize N = len(self.z) # use close market's value t_init = 0 y_init = self.z[t_init] # BSM model model = bsm.BSM(N, args.mu, args.sigma, t_init, y_init, self.seed) y = model.predict() #print(float(y[-1]),float(self.z[-1]),(float(y[-1])-float(self.z[-1]))) error = (float(y[-1]) - float(self.z[-1]))**2 return error
def run_NUrot_vs_timing(name): m = NitrogenURotVsTiming(name) BSM.prepare(m) delays = 50.9e-6 + np.linspace(-0.5e-6, 0.5e-6, 26) # DEBUG # m.params['N_pi2_amp'] = 0 pts = len(delays) m.params['pts'] = pts m.params['reps_per_ROsequence'] = 1000 m.params['CORPSE_pi_phase_shift'] = 65.2 m.params['CORPSE_pi_phase_shifts'] = \ np.ones(pts) * m.params['CORPSE_pi_phase_shift'] m.params['e_delays'] = delays # for the autoanalysis m.params['sweep_name'] = 'Interpulse delay (us)' m.params['sweep_pts'] = delays * 1e6 BSM.finish(m, debug=True)
def import_iv(): # set option param spot = 2.483 today = dt.date(2015, 1, 27) risk_free = 0.05 qList = [] # 读取行情 with open('option_20150127.csv') as f: f_csv = csv.reader(f) headers = next(f_csv) for row in f_csv: price = float(row[5]) if (row[10] == "PO"): mytype = -1 elif (row[10] == "CO"): mytype = 1 else: print "error" strike = float(row[11]) T = (dt.datetime.strptime(row[9], "%Y/%m/%d").date() - today).days / 365.0 qList.append(Quote(price, strike, T, mytype)) ivList = [] for i in qList: # print (i.optionType, i.strike, riskFree, i.T, spot, i.optionPrice) bsm = BSM.BSM(i.optionType, i.strike, risk_free, i.T, spot) ivList.append(bsm.get_iv(i.optionType, i.optionPrice)) svi_sample_list = [] for i in range(0, len(ivList)): svi_sample_list.append( Svi_sample(ivList[i], (math.log(qList[i].strike / spot)))) #svi_sample_list_sub = svi_sample_list[1:6]+svi_sample_list[28:34] svi_sample_list_sub = svi_sample_list[0:7] + svi_sample_list[28:35] for i6 in svi_sample_list_sub: print i6.iv, ",", i6.k return svi_sample_list_sub
def get_sweep_elements(self): e = element.Element('e1', pulsar=qt.pulsar) e.append(self.T) e.append(self.shelving_pulse) e.append(pulse.cp(self.T, length=100e-9)) n = e.append(self.N_pi2) t = e.length()-e.pulse_start_time(n, 'RF') elts = [] for i in range(self.params['pts']): e2 = element.Element('e2-{}'.format(i), pulsar=qt.pulsar) e2.append(pulse.cp(self.N_pi2, phase = BSM.phaseref(self.N_pi2.frequency,t) + self.params['phases'][i])) e2.append(self.TN) # e2.append(self.pi2pi_m1) elts.append([e,e2]) return elts
def get_sweep_elements(self): e = element.Element('e1', pulsar=qt.pulsar) e.append(self.T) e.append(self.shelving_pulse) e.append(pulse.cp(self.T, length=100e-9)) n = e.append(self.N_pi2) t = e.length() - e.pulse_start_time(n, 'RF') elts = [] for i in range(self.params['pts']): e2 = element.Element('e2-{}'.format(i), pulsar=qt.pulsar) e2.append( pulse.cp(self.N_pi2, phase=BSM.phaseref(self.N_pi2.frequency, t) + self.params['phases'][i])) e2.append(self.TN) # e2.append(self.pi2pi_m1) elts.append([e, e2]) return elts
def generate_sequence(self, upload=True): self._pulse_defs() elements = [] for i in range(self.params['pts']): e = element.Element('Echo-{}'.format(i), pulsar=qt.pulsar) e.append(pulse.cp(self.TIQ, length=500e-9)) e.append(pulse.cp(self.pi2_4MHz, lock_phase_to_element_time=False)) e.append(pulse.cp(self.TIQ, length = self.params['2tau']/2. + \ self.params['pi_position_shifts'][i])) ### for doing a CORPSE pi pi_phase = BSM.phaseref(self.pi2_4MHz.frequency, self.pi2_4MHz.effective_length() + self.params['2tau']/2. + \ self.params['pi_position_shifts'][i]) e.append( pulse.cp(self.CORPSE_pi, phase=pi_phase, frequency=self.pi2_4MHz.frequency)) ### regular pi # pi_phase = BSM.phaseref(self.pi2_4MHz.frequency, # self.pi2_4MHz.effective_length() + self.params['2tau']/2. + \ # self.params['pi_position_shifts'][i]) # e.append(pulse.cp(self.pi_4MHz, # lock_phase_to_element_time = False, # phase = pi_phase)) e.append(pulse.cp(self.TIQ, length = self.params['2tau']/2. - \ self.params['pi_position_shifts'][i])) ### pay attention here with which pi pulse we're using! second_pi2_phase = BSM.phaseref(self.pi2_4MHz.frequency, self.pi2_4MHz.effective_length() + self.params['2tau'] + \ self.CORPSE_pi.effective_length()) # second_pi2_phase = BSM.phaseref(self.pi2_4MHz.frequency, # self.pi2_4MHz.effective_length() + self.params['2tau'] + \ # self.pi_4MHz.effective_length()) e.append( pulse.cp(self.pi2_4MHz, lock_phase_to_element_time=False, phase=second_pi2_phase)) e.append(pulse.cp(self.TIQ, length=500e-9)) elements.append(e) # e.print_overview() seq = seq = pulsar.Sequence('{}_{} sequence'.format( self.mprefix, self.name)) for i, e in enumerate(elements): seq.append(name='MBI-{}'.format(i), wfname=self.mbi_elt.name, trigger_wait=True, goto_target='MBI-{}'.format(i), jump_target='Echo-{}'.format(i)) seq.append(name='Echo-{}'.format(i), wfname=e.name, trigger_wait=True) seq.append(name='sync-{}'.format(i), wfname=self.sync_elt.name) # program AWG if upload: qt.pulsar.upload(self.mbi_elt, self.sync_elt, *elements) qt.pulsar.program_sequence(seq)
def get_iv(self): bsm = BSM.BSM(self.option_type, self.strike, self.interest, self.param_t, self.future_price) return bsm.get_iv(self.option_type, self.quote.last_price)
def generate_sequence(self, upload=True): self._pulse_defs() elements = [] for i in range(self.params['pts']): e = element.Element('Echo-{}'.format(i), pulsar = qt.pulsar) e.append(pulse.cp(self.TIQ, length=500e-9)) e.append(pulse.cp(self.pi2_4MHz, lock_phase_to_element_time = False)) e.append(pulse.cp(self.TIQ, length = self.params['2tau']/2. + \ self.params['pi_position_shifts'][i])) ### for doing a CORPSE pi pi_phase = BSM.phaseref(self.pi2_4MHz.frequency, self.pi2_4MHz.effective_length() + self.params['2tau']/2. + \ self.params['pi_position_shifts'][i]) e.append(pulse.cp(self.CORPSE_pi, phase = pi_phase, frequency = self.pi2_4MHz.frequency)) ### regular pi # pi_phase = BSM.phaseref(self.pi2_4MHz.frequency, # self.pi2_4MHz.effective_length() + self.params['2tau']/2. + \ # self.params['pi_position_shifts'][i]) # e.append(pulse.cp(self.pi_4MHz, # lock_phase_to_element_time = False, # phase = pi_phase)) e.append(pulse.cp(self.TIQ, length = self.params['2tau']/2. - \ self.params['pi_position_shifts'][i])) ### pay attention here with which pi pulse we're using! second_pi2_phase = BSM.phaseref(self.pi2_4MHz.frequency, self.pi2_4MHz.effective_length() + self.params['2tau'] + \ self.CORPSE_pi.effective_length()) # second_pi2_phase = BSM.phaseref(self.pi2_4MHz.frequency, # self.pi2_4MHz.effective_length() + self.params['2tau'] + \ # self.pi_4MHz.effective_length()) e.append(pulse.cp(self.pi2_4MHz, lock_phase_to_element_time = False, phase = second_pi2_phase)) e.append(pulse.cp(self.TIQ, length = 500e-9)) elements.append(e) # e.print_overview() seq = seq = pulsar.Sequence('{}_{} sequence'.format(self.mprefix, self.name)) for i,e in enumerate(elements): seq.append(name = 'MBI-{}'.format(i), wfname = self.mbi_elt.name, trigger_wait = True, goto_target = 'MBI-{}'.format(i), jump_target = 'Echo-{}'.format(i)) seq.append(name = 'Echo-{}'.format(i), wfname = e.name, trigger_wait = True) seq.append(name = 'sync-{}'.format(i), wfname = self.sync_elt.name) # program AWG if upload: qt.pulsar.upload(self.mbi_elt, self.sync_elt, *elements) qt.pulsar.program_sequence(seq)
def generate_sequence(self, upload=True): self._pulse_defs() seq = pulsar.Sequence('{}_{} sequence'.format(self.mprefix, self.name)) elements = [] elements.append(self.mbi_elt) elements.append(self.sync_elt) e = element.Element('H pulse', pulsar=qt.pulsar) e.append(self.T) e.append(self.shelving_pulse) e.append(pulse.cp(self.T, length=100e-9)) n = e.append(pulse.cp(self.N_pulse, frequency = self.N_pi.frequency - self.params['N_rabi_frequency'], length = self.N_pi.length / np.sqrt(2), amplitude = 1)) t = e.length()-e.pulse_start_time(n, 'RF') e2 = element.Element('pi2', pulsar=qt.pulsar) e2.append(pulse.cp(self.N_pi2, phase = BSM.phaseref( self.N_pi2.frequency, t))) e2.append(self.TN) e2.append(pulse.cp(self.pi2pi_m1)) elements.append(e2) for i in range(self.params['pts']): seq.append(name = 'MBI-{}'.format(i), wfname = self.mbi_elt.name, trigger_wait = True, goto_target = 'MBI-{}'.format(i), jump_target = 'H-{}'.format(i)) e = element.Element('H pulse-{}'.format(i), pulsar=qt.pulsar) e.append(self.T) e.append(self.shelving_pulse) e.append(pulse.cp(self.T, length=100e-9)) n = e.append(pulse.cp(self.N_pulse, frequency = self.N_pi.frequency - self.params['N_rabi_frequency'], length = self.N_pi.length / np.sqrt(2), amplitude = 1, phase = self.params['phases'][i])) elements.append(e) seq.append(name = 'H-{}'.format(i), wfname = e.name, trigger_wait = True) seq.append(name = 'pi2-{}'.format(i), wfname = e2.name) seq.append(name = 'sync-{}'.format(i), wfname = self.sync_elt.name) # program AWG if upload: qt.pulsar.upload(*elements) qt.pulsar.program_sequence(seq)
parser.add_argument("-se", "--seed", type=int, default=-1) args = parser.parse_args() z = list() # read csv file with open(args.csvfile, "r") as file: reader = csv.reader(file) header = next(reader) for row in reader: z.append(float(row[4])) Nt = len(z) init = z[0] # calc BSM model model = bsm.BSM(Nt, args.mu, args.sigma, y_init=init, seed=args.seed) y = model.predict() # plot t = range(Nt) # plot BSM model plt.plot(t, y, "ro-", label="BSM model", markeredgecolor="black") # plot BTC data plt.plot(t, z, "bs:", label="market price", markeredgecolor="black") plt.yscale("log") plt.xlabel("time") plt.ylabel("BTC") plt.legend() plt.show()
import BSM T=34/365 r=None spot=2.3440 option_dict={} bsm_list=[] #read data file_name="D://option.csv" with open(file_name) as f: f_csv = csv.reader(f) headers = next(f_csv) for row in f_csv: if(row[0]=="C"): temp=1 elif row[0]=="P": temp=-1 else: print "error" exit(0) option_dict[(temp,float(row[1]))]=tuple([float(x) for x in row[5:11]]) for i in option_dict: bsm=BSM.BSM(i[0],i[1],r,T,spot) bsm.update bsm_list.append()
# read csv file with open(args.csvfile, "r") as file: reader = csv.reader(file) header = next(reader) for row in reader: z.append(float(row[4])) Nt = len(z) init = z[0] # calc BSM model fig = plt.figure(figsize=(16, 10)) t = range(Nt) for i in range(args.Nsample): model = bsm.BSM(Nt, args.mu, args.sigma, t_init=0.0, y_init=init) y = model.predict() rows = args.Nsample / 2 cols = args.Nsample / rows plt.subplot(cols, rows, i + 1) # plot BTC data plt.plot(t, z, "bs:", markeredgecolor="black") # plot BSM model plt.plot(t, y, "ro-", markeredgecolor="black") plt.xlabel("time") plt.ylabel("BTC") plt.yscale("log") del model fig.suptitle("(mu,sigma)=(" + str(args.mu) + "," + str(args.sigma) + ")", fontsize=30) plt.savefig("BTC_BSM_mu" + str(args.mu) + "_s" + str(args.sigma) + ".png")
option.put.price=si.splev(S0,tck,der=0) if __name__ == "__main__": S0 = 100.0 K = 100.0 r=0.1 sigma = 0.30 T = 3 class param(): def __init__(self): self.NAS = 300 p = param() oc=bsm.optionClass(S0, K, r, sigma, T, False) t=time.time() #FiniteDiff(oc, p) bsm.BlackScholesInfo(oc) elapsed = time.time()-t print(elapsed) print(oc.call.price) print(oc.put.price)