def test_qasm_seq_echo(self): qasm_file = sq_qasm.echo(self.qubit_name, self.times) asm_file = qta.qasm_to_asm(qasm_file.name, self.operation_dict) asm = Assembler.Assembler(asm_file.name) instructions = asm.convert_to_instructions() qasm_file = sq_qasm.echo(self.qubit_name, self.times) asm_file = qta.qasm_to_asm(qasm_file.name, self.operation_dict) asm = Assembler.Assembler(asm_file.name) instructions = asm.convert_to_instructions() qasm_file = sq_qasm.echo(self.qubit_name, self.times, artificial_detuning=4/self.times[-4]) asm_file = qta.qasm_to_asm(qasm_file.name, self.operation_dict) asm = Assembler.Assembler(asm_file.name) instructions = asm.convert_to_instructions() qasm_file = sq_qasm.echo(self.qubit_name, self.times, artificial_detuning=None) asm_file = qta.qasm_to_asm(qasm_file.name, self.operation_dict) asm = Assembler.Assembler(asm_file.name) instructions = asm.convert_to_instructions() qasm_file = sq_qasm.echo(self.qubit_name, self.times, cal_points=False) asm_file = qta.qasm_to_asm(qasm_file.name, self.operation_dict) asm = Assembler.Assembler(asm_file.name) instructions = asm.convert_to_instructions()
def test_qasm_function_with_function_arg(self): ext_op_dict = deepcopy(self.operation_dict) def Rx_codeword(amp, min_amp=-.5, max_amp=0.5): """ maps an amp to a codeword, defining a function like this is NOT the responsibility of the qasm compiler """ amp = float(amp) codeword = int((amp-min_amp)/(max_amp - min_amp) * 127) return 'Trigger {:07b}, 2 , \n'.format(codeword) ext_op_dict['Rx'] = { self.qubit_name: {'instruction': Rx_codeword, 'duration': 2}} filename = join(self.base_qasm_path, 'argument.qasm') qasm_file = mopen(filename, mode='w') qasm_file.writelines('qubit {} \n'.format(self.qubit_name)) # test wait argument qasm_file.writelines('I {} 12\n'.format( self.qubit_name)) qasm_file.writelines('I {} 4\n'.format( self.qubit_name)) qasm_file.close() qta.qasm_to_asm(qasm_file.name, ext_op_dict)
def test_qasm_function_with_function_arg(self): ext_op_dict = deepcopy(self.operation_dict) def Rx_codeword(amp, min_amp=-.5, max_amp=0.5): """ maps an amp to a codeword, defining a function like this is NOT the responsibility of the qasm compiler """ amp = float(amp) codeword = int((amp - min_amp) / (max_amp - min_amp) * 127) return 'Trigger {:07b}, 2 \n'.format(codeword) ext_op_dict['Rx'] = { self.qubit_name: { 'instruction': Rx_codeword, 'duration': 2 } } filename = join(self.base_qasm_path, 'argument.qasm') qasm_file = mopen(filename, mode='w') qasm_file.writelines('qubit {} \n'.format(self.qubit_name)) # test wait argument qasm_file.writelines('I {} 12\n'.format(self.qubit_name)) qasm_file.writelines('I {} 4\n'.format(self.qubit_name)) qasm_file.close() qta.qasm_to_asm(qasm_file.name, ext_op_dict)
def test_qasm_seq_echo(self): qasm_file = sq_qasm.echo(self.qubit_name, self.times) asm_file = qta.qasm_to_asm(qasm_file.name, self.operation_dict) asm = Assembler.Assembler(asm_file.name) instructions = asm.convert_to_instructions() qasm_file = sq_qasm.echo(self.qubit_name, self.times) asm_file = qta.qasm_to_asm(qasm_file.name, self.operation_dict) asm = Assembler.Assembler(asm_file.name) instructions = asm.convert_to_instructions() qasm_file = sq_qasm.echo(self.qubit_name, self.times, artificial_detuning=4 / self.times[-4]) asm_file = qta.qasm_to_asm(qasm_file.name, self.operation_dict) asm = Assembler.Assembler(asm_file.name) instructions = asm.convert_to_instructions() qasm_file = sq_qasm.echo(self.qubit_name, self.times, artificial_detuning=None) asm_file = qta.qasm_to_asm(qasm_file.name, self.operation_dict) asm = Assembler.Assembler(asm_file.name) instructions = asm.convert_to_instructions() qasm_file = sq_qasm.echo(self.qubit_name, self.times, cal_points=False) asm_file = qta.qasm_to_asm(qasm_file.name, self.operation_dict) asm = Assembler.Assembler(asm_file.name) instructions = asm.convert_to_instructions()
def test_qasm_seq_butterfly(self): qasm_file = sq_qasm.butterfly(self.qubit_name, initialize=False) asm_file = qta.qasm_to_asm(qasm_file.name, self.operation_dict) asm = Assembler.Assembler(asm_file.name) instructions = asm.convert_to_instructions() qasm_file = sq_qasm.butterfly(self.qubit_name, initialize=True) asm_file = qta.qasm_to_asm(qasm_file.name, self.operation_dict) asm = Assembler.Assembler(asm_file.name) instructions = asm.convert_to_instructions()
def test_invalid_command(self): filename = join(self.base_qasm_path, 'invalid_command.qasm') qasm_file = mopen(filename, mode='w') qasm_file.writelines('qubit {} \n'.format(self.qubit_name)) qasm_file.writelines('Xbla {} # invalid cmd\n'.format( self.qubit_name)) qasm_file.close() with self.assertRaises(ValueError): qta.qasm_to_asm(qasm_file.name, self.operation_dict)
def test_invalid_command(self): filename = join(self.base_qasm_path, 'invalid_command.qasm') qasm_file = mopen(filename, mode='w') qasm_file.writelines('qubit {} \n'.format(self.qubit_name)) qasm_file.writelines('Xbla {} # invalid cmd\n'.format( self.qubit_name)) qasm_file.close() with self.assertRaises(ValueError): qta.qasm_to_asm(qasm_file.name, self.operation_dict)
def test_qasm_seq_butterfly(self): qasm_file = sq_qasm.butterfly(self.qubit_name, initialize=False) asm_file = qta.qasm_to_asm(qasm_file.name, self.operation_dict) asm = Assembler.Assembler(asm_file.name) instructions = asm.convert_to_instructions() qasm_file = sq_qasm.butterfly(self.qubit_name, initialize=True) asm_file = qta.qasm_to_asm(qasm_file.name, self.operation_dict) asm = Assembler.Assembler(asm_file.name) instructions = asm.convert_to_instructions()
def test_qasm_function_with_string_format_arg(self): ext_op_dict = deepcopy(self.operation_dict) filename = join(self.base_qasm_path, 'argument.qasm') qasm_file = mopen(filename, mode='w') qasm_file.writelines('qubit {} \n'.format(self.qubit_name)) # test wait argument qasm_file.writelines('I {} 12\n'.format(self.qubit_name)) qasm_file.writelines('I {} 4\n'.format(self.qubit_name)) qasm_file.close() qta.qasm_to_asm(qasm_file.name, ext_op_dict)
def test_too_many_args_command(self): filename = join(self.base_qasm_path, 'too_many_args.qasm') qasm_file = mopen(filename, mode='w') qasm_file.writelines('qubit {} \n'.format(self.qubit_name)) # leaving out the \n prevents the line from breaking qasm_file.writelines('X180 {}'.format(self.qubit_name)) qasm_file.writelines('X180 {}'.format(self.qubit_name)) qasm_file.writelines('Y180 {}'.format(self.qubit_name)) qasm_file.close() with self.assertRaises(ValueError): qta.qasm_to_asm(qasm_file.name, self.operation_dict)
def test_qasm_function_with_string_format_arg(self): ext_op_dict = deepcopy(self.operation_dict) filename = join(self.base_qasm_path, 'argument.qasm') qasm_file = mopen(filename, mode='w') qasm_file.writelines('qubit {} \n'.format(self.qubit_name)) # test wait argument qasm_file.writelines('I {} 12\n'.format( self.qubit_name)) qasm_file.writelines('I {} 4\n'.format( self.qubit_name)) qasm_file.close() qta.qasm_to_asm(qasm_file.name, ext_op_dict)
def test_qasm_seq_MotzoiXY(self): qasm_file = sq_qasm.MotzoiXY(self.qubit_name, motzois=np.linspace(-.5, .5, 21), cal_points=False) asm_file = qta.qasm_to_asm(qasm_file.name, self.operation_dict) asm = Assembler.Assembler(asm_file.name) instructions = asm.convert_to_instructions() qasm_file = sq_qasm.MotzoiXY(self.qubit_name, motzois=np.linspace(-.5, .5, 21), cal_points=True) asm_file = qta.qasm_to_asm(qasm_file.name, self.operation_dict) asm = Assembler.Assembler(asm_file.name) instructions = asm.convert_to_instructions()
def test_qasm_seq_MotzoiXY(self): qasm_file = sq_qasm.MotzoiXY( self.qubit_name, motzois=np.linspace(-.5, .5, 21), cal_points=False) asm_file = qta.qasm_to_asm(qasm_file.name, self.operation_dict) asm = Assembler.Assembler(asm_file.name) instructions = asm.convert_to_instructions() qasm_file = sq_qasm.MotzoiXY( self.qubit_name, motzois=np.linspace(-.5, .5, 21), cal_points=True) asm_file = qta.qasm_to_asm(qasm_file.name, self.operation_dict) asm = Assembler.Assembler(asm_file.name) instructions = asm.convert_to_instructions()
def test_too_many_args_command(self): filename = join(self.base_qasm_path, 'too_many_args.qasm') qasm_file = mopen(filename, mode='w') qasm_file.writelines('qubit {} \n'.format(self.qubit_name)) # leaving out the \n prevents the line from breaking qasm_file.writelines('X180 {}'.format( self.qubit_name)) qasm_file.writelines('X180 {}'.format( self.qubit_name)) qasm_file.writelines('Y180 {}'.format( self.qubit_name)) qasm_file.close() with self.assertRaises(ValueError): qta.qasm_to_asm(qasm_file.name, self.operation_dict)
def test_qasm_seq_randomized_benchmarking(self): nr_cliffords = (2**(np.arange(10)+1)) nr_seeds = 10 qasm_file = sq_qasm.randomized_benchmarking(self.qubit_name, nr_cliffords, nr_seeds, double_curves=True) asm_file = qta.qasm_to_asm(qasm_file.name, self.operation_dict) asm = Assembler.Assembler(asm_file.name) instructions = asm.convert_to_instructions() qasm_file = sq_qasm.randomized_benchmarking(self.qubit_name, nr_cliffords, nr_seeds, double_curves=False) asm_file = qta.qasm_to_asm(qasm_file.name, self.operation_dict) asm = Assembler.Assembler(asm_file.name) instructions = asm.convert_to_instructions()
def test_empty_qasm_file(self): filename = join(self.base_qasm_path, 'empty.qasm') qasm_file = mopen(filename, mode='w') qasm_file.writelines('qubit {} \n'.format(self.qubit_name)) qasm_file.close() asm_file = qta.qasm_to_asm(qasm_file.name, self.operation_dict) asm = Assembler.Assembler(asm_file.name) instructions = asm.convert_to_instructions()
def test_empty_qasm_file(self): filename = join(self.base_qasm_path, 'empty.qasm') qasm_file = mopen(filename, mode='w') qasm_file.writelines('qubit {} \n'.format(self.qubit_name)) qasm_file.close() asm_file = qta.qasm_to_asm(qasm_file.name, self.operation_dict) asm = Assembler.Assembler(asm_file.name) instructions = asm.convert_to_instructions()
def test_qasm_seq_randomized_benchmarking(self): nr_cliffords = (2**(np.arange(10) + 1)) nr_seeds = 10 qasm_file = sq_qasm.randomized_benchmarking(self.qubit_name, nr_cliffords, nr_seeds, double_curves=True) asm_file = qta.qasm_to_asm(qasm_file.name, self.operation_dict) asm = Assembler.Assembler(asm_file.name) instructions = asm.convert_to_instructions() qasm_file = sq_qasm.randomized_benchmarking(self.qubit_name, nr_cliffords, nr_seeds, double_curves=False) asm_file = qta.qasm_to_asm(qasm_file.name, self.operation_dict) asm = Assembler.Assembler(asm_file.name) instructions = asm.convert_to_instructions()
def test_complete_sequence_loading_simple(self): ''' Tests all the loading with an AllXY sequence that contains all the basic steps but does not require mapping the allowed operations. ''' qasm_file = self.AllXY_qasm_file ops = qta.extract_required_operations(qasm_file.name) # # config needs to contain enough info to generate mapping operation_dict = qta.create_operation_dict(ops, self.pulse_pars) # operation_mapping = qta.create_operation_mapping(required_ops) # # uploads all operations in op dict with Capturing() as output: qta.prepare_operations(operation_dict) qta.qasm_to_asm(qasm_file.name, operation_dict)
def test_complete_sequence_loading_simple(self): ''' Tests all the loading with an AllXY sequence that contains all the basic steps but does not require mapping the allowed operations. ''' qasm_file = self.AllXY_qasm_file ops = qta.extract_required_operations(qasm_file.name) # # config needs to contain enough info to generate mapping operation_dict = qta.create_operation_dict(ops, self.pulse_pars) # operation_mapping = qta.create_operation_mapping(required_ops) # # uploads all operations in op dict with Capturing() as output: qta.prepare_operations(operation_dict) qta.qasm_to_asm(qasm_file.name, operation_dict)
def prepare(self, **kw): self.CBox.trigger_source('internal') if self.upload: qumis_file = qta.qasm_to_asm(self.filename, self.op_dict) self.CBox.load_instructions(qumis_file.name)
def test_qasm_two_elt_MotzoiXY(self): qasm_file = sq_qasm.two_elt_MotzoiXY(self.qubit_name) asm_file = qta.qasm_to_asm(qasm_file.name, self.operation_dict) asm = Assembler.Assembler(asm_file.name) instructions = asm.convert_to_instructions()
def test_qasm_seq_T1(self): qasm_file = sq_qasm.T1(self.qubit_name, self.times) asm_file = qta.qasm_to_asm(qasm_file.name, self.operation_dict) asm = Assembler.Assembler(asm_file.name) instructions = asm.convert_to_instructions()
def test_two_qubit_AllXY(self): qasm_file = mq_qasm.two_qubit_AllXY(self.qubits[0], self.qubits[1]) asm_file = qta.qasm_to_asm(qasm_file.name, self.operation_dict) asm = Assembler.Assembler(asm_file.name) asm.convert_to_instructions()
def mixer_skewness_calibration_CBoxV3(SH, source, LutMan, MC, CBox, f_mod, name='mixer_skewness_calibration_CBox'): ''' Inputs: SH (instrument) the signal hound source (instrument) MW-source used for driving LutMan (instrument) LutMan responsible for loading pulses CBox (instrument) responsible for loading qumis and f_mod (float Hz) Modulation frequency returns: alpha, phi the coefficients that go in the predistortion matrix Loads a continuous wave in the lookuptable and changes the predistortion to minimize the power in the spurious sideband. For details, see Leo's notes on mixer skewness calibration in the docs ''' # phi and alpha are the coefficients that go in the predistortion matrix # Load the pulses required for a conintuous tone LutMan.lut_mapping()[0] = 'ModBlock' Mod_Block_len = 500e-9 LutMan.Q_modulation(f_mod) LutMan.Q_block_length(Mod_Block_len) LutMan.Q_ampCW(.5) # not 1 as we want some margin for the alpha correction LutMan.load_pulses_onto_AWG_lookuptable() # load the QASM/QuMis sequence Mod_Block_len_clk = ins_lib.convert_to_clocks(Mod_Block_len) - 1 # -1 is a hack to fix some problems with the CBox AWG output # 19-07-2017 XFU & MAR operation_dict = {} operation_dict['Pulse'] = { 'duration': Mod_Block_len_clk, 'instruction': ins_lib.cbox_awg_pulse( codeword=0, awg_channels=[LutMan.awg_nr()], duration=Mod_Block_len_clk)} # this generates a SSB coninuous wave sequence cw_tone_elt = sqqs.CW_tone() cw_tone_asm = qta.qasm_to_asm(cw_tone_elt.name, operation_dict) CBox.load_instructions(cw_tone_asm.name) CBox.start() frequency = source.frequency() - f_mod alpha_swf = cbs.Lutman_par_with_reload_single_pulse( LutMan=LutMan, parameter=LutMan.mixer_alpha, pulse_names=['ModBlock']) phi_swf = cbs.Lutman_par_with_reload_single_pulse( LutMan=LutMan, parameter=LutMan.mixer_phi, pulse_names=['ModBlock']) d = det.Signal_Hound_fixed_frequency(SH, frequency) ad_func_pars = {'adaptive_function': nelder_mead, 'x0': [1.0, 0.0], 'initial_step': [.4, 20], 'no_improv_break': 10, 'minimize': True, 'maxiter': 500} MC.set_sweep_functions([alpha_swf, phi_swf]) MC.set_detector_function(d) MC.set_adaptive_function_parameters(ad_func_pars) MC.set_adaptive_function_parameters(ad_func_pars) MC.run(name=name, mode='adaptive') a = ma.OptimizationAnalysis(label=name) ma.OptimizationAnalysis_v2(label=name) alpha = a.optimization_result[0][0] phi = a.optimization_result[0][1] return phi, alpha
def test_qasm_seq_Rabi(self): amps = np.linspace(-.4, .5, 51) # in V qasm_file = sq_qasm.Rabi(self.qubit_name, amps) asm_file = qta.qasm_to_asm(qasm_file.name, self.operation_dict) asm = Assembler.Assembler(asm_file.name) instructions = asm.convert_to_instructions()
def prepare_motzoi_seq_CC(qubit_name, op_dict): motzoi_elt = sqs.two_elt_MotzoiXY(qubit_name) single_pulse_asm = qta.qasm_to_asm(motzoi_elt.name, op_dict) asm_file = single_pulse_asm CBox.load_instructions(asm_file.name)
def RB_prepare(nr_cliffords, op_dict, CBox, nr_seeds=1): RB_qasm = sq_qasm.randomized_benchmarking('AncT_CB', nr_cliffords=nr_cliffords, nr_seeds=nr_seeds, double_curves=False) asm_file = qta.qasm_to_asm(RB_qasm.name, op_dict) CBox.load_instructions(asm_file.name) return RB_qasm, asm_file
def test_qasm_seq_AllXY(self): qasm_file = sq_qasm.AllXY(self.qubit_name) asm_file = qta.qasm_to_asm(qasm_file.name, self.operation_dict) asm = Assembler.Assembler(asm_file.name) instructions = asm.convert_to_instructions()
def test_qasm_seq_Rabi(self): amps = np.linspace(-.4, .5, 51) # in V qasm_file = sq_qasm.Rabi(self.qubit_name, amps) asm_file = qta.qasm_to_asm(qasm_file.name, self.operation_dict) asm = Assembler.Assembler(asm_file.name) instructions = asm.convert_to_instructions()
def prepare_rabi_seq_CC(qubit_name, op_dict): single_pulse_elt = sqs.single_elt_on('AncT_CB') single_pulse_asm = qta.qasm_to_asm(single_pulse_elt.name, op_dict) asm_file = single_pulse_asm CBox.load_instructions(asm_file.name)
def prepare(self, **kw): self.CBox.trigger_source('internal') if self.upload: asm_file = qta.qasm_to_asm(self.filename, self.op_dict) self.CBox.load_instructions(asm_file.name)