def test_remove_instance(self): self.gates.close() self.assertEqual(self.gates.instances(), []) with self.assertRaises(KeyError): Instrument.find_instrument('gates') type(self).gates = MockGates(model=self.model, server_name="") self.assertEqual(self.gates.instances(), [self.gates]) self.assertEqual(Instrument.find_instrument('gates'), self.gates)
def execute(file_url: str, tasm_file_url:str, qasm_file_url:str, config_json: str, verbosity_level: int=0): write_to_log('Hello!') options = json.loads(config_json) write_to_log('options:') write_to_log(options) write_to_log(file_url) write_to_log(tasm_file_url) write_to_log(qasm_file_url) if (not new_station): MC = Instrument.find_instrument('Demonstrator_MC') CBox = Instrument.find_instrument('CBox') device = Instrument.find_instrument('Device') qubit = Instrument.find_instrument('QL') num_avg = int(options.get('num_avg', 512)) nr_soft_averages = int(np.round(num_avg/512)) MC.soft_avg(nr_soft_averages) #device.RO_acq_averages(512) qubit.RO_acq_averages(512) qubit.prepare_for_timedomain() qumis_fp = _retrieve_file_from_url(file_url) # Ok, I am assured by stanvn that he will provide me a options with kw sweep_points = options["measurement_points"] s = swf.QuMis_Sweep(filename=qumis_fp, CBox=CBox,parameter_name='Circuit number', unit='#') #d = device.get_correlation_detector() d = qubit.int_avg_det #d.value_names = ['Q0 ', 'Q1 ', 'Corr. (Q0, Q1) '] #d.value_units = ['frac.', 'frac.', 'frac.'] # N.B. hardcoded fixme #cfg = qubit.qasm_config() #qasm_fp = _retrieve_file_from_url(file_url) #sweep_points = _get_qasm_sweep_points(qasm_fp) #s = swf.QASM_Sweep(parameter_name='Circuit number ', unit='#', # qasm_fn=qasm_fp, config=cfg, CBox=CBox, # verbosity_level=verbosity_level) MC.set_sweep_function(s) MC.set_sweep_points(sweep_points) MC.set_detector_function(d) data = MC.run('Starmon_execute') # FIXME <- add the proper name else: qumis_fp = _retrieve_file_from_url(file_url) data = _simulate_quantumsim(qumis_fp, options) return _MC_result_to_chart_dict(data)
def test_instances(self): # copied from the main (server-based) version # make sure it all works the same here instruments = [self.gates, self.source, self.meter] for instrument in instruments: for other_instrument in instruments: instances = instrument.instances() # check that each instrument is in only its own # instances list if other_instrument is instrument: self.assertIn(instrument, instances) else: self.assertNotIn(other_instrument, instances) # check that we can find each instrument from any other # use find_component here to test that it rolls over to # find_instrument if only a name is given self.assertEqual( instrument, other_instrument.find_component(instrument.name)) self.assertEqual( instrument.name, other_instrument.find_component(instrument.name + '.name')) # check that we can find this instrument from the base class self.assertEqual(instrument, Instrument.find_instrument(instrument.name))
def get_channel_awg(self, channel: str) -> Instrument: """Return the AWG corresponding to a channel. Args: channel: Name of the channel. """ return Instrument.find_instrument(self.get(f"{channel}_awg"))
def test_creation_failure(self): # this we already know should fail (see test_max_delay_errors) name = 'gatesFailing' with self.assertRaises(ValueError): GatesBadDelayValue(model=self.model, name=name, server_name='') # this instrument should not be in the instance list with self.assertRaises(KeyError): Instrument.find_instrument(name) # now do the same with a local instrument name = 'gatesFailing2' with self.assertRaises(ValueError): GatesBadDelayValue(model=self.model, name=name, server_name=None) # this instrument should not be in the instance list with self.assertRaises(KeyError): Instrument.find_instrument(name)
def __init__(self): """ 1. setup the VNA as an instrument (if it's not already setup) 2. specify experimental parameters 3. specify paths of the target files: database file and a new folder with raw (txt, png) files """ import pdb; pdb.set_trace() # noqa BREAKPOINT self.vna_name = 'VNA_Keysight' # this is a qcodes VisaInstrument (interface between visa and qcodes) self.vna_class = Keysight_P9373A self.vna_address = "TCPIP0::maip-franck::hislip0,4880::INSTR" # -- check if instrument 'VNA' already exists. If not, create it if Instrument.exist(self.vna_name, self.vna_class): # an instrument is created by qcodes in a global context, # from which it can be retrieved manually using find_instrument self.vna = Instrument.find_instrument( self.vna_name, self.vna_class) else: self.vna = self.vna_class(self.vna_name, self.vna_address, 300e3, 13.5e9, -90, 13, 2) # -- name the experiment -> automatic file names self.exp_name = 'test_exp' # name used by qcodes self.cooldown_date = '20-09-22' self.sample_name = 'test_sample' # -- set experiment parameters (global constants, used in different measurement functions) self.num_freq_points = 2001 # 2001 # number of measurement points self.vnapower = -30 # applied power # 3.7e9 #3.387015e9 #6.608e9-3.5e6 # start frequency of sweep self.start_frequency = 3e9 # 5.7e9 #3.387065e9 #6.611e9 +3.5e6 # stop frequency of sweep self.stop_frequency = 10.e9 self.frequency_span = self.stop_frequency - self.start_frequency self.center_frequency = (self.stop_frequency - self.start_frequency) / \ 2. + self.start_frequency # just used for power sweep self.measuredtrace = 'S21' # spectral density measured between port 1 and 2 # IF Bandwidth, must be in (10,30,50,70,100,300,500,700,1000,3000,5000,7000,10000)Hz self.ifbandwidth = 10 self.powersweepstart = -30 # start for power sweep self.powersweepstop = 13 # stop for powersweep # number of power sweeps (perhaps +/-1) MUST BE AN EVEN NUMBER AT LEAST 6 self.num_power_points = 3 # groupdelayref=0.0000000225 # vna.groupdelay.set(groupdelayref)#resets to 0 instead of working -> rounding to 0 # print(vna.groupdelay.get()) self.create_database_experiment_and_folders() self.ask_what_to_do()
def make_circuit(self, **kw): qubit_name = kw.pop('qubit', self.qubit) qubit = Instrument.find_instrument(qubit_name) amplitude = kw.get('amplitude', self.amplitude) frequency_shift = kw.pop('frequency_shift', self.frequency_shift) off_resonance_amplitude = ('off_resonacne_amplitude', self.off_resonance_amplitude) phase_error = kw.pop('phase_error', self.phase_error) error_gate = kw.pop('error_gate', self.error_gate) g = int(kw.pop('gate', 1) - 1) gate = Bootstrap_array[g] for i in range(len(gate)): amplitude = 0 if gate[i] == 'I' else 1 ''' if gate[i] == 'I': amplitude = off_resonance_amplitude if qubit_name == 'qubit_1' else 0 frequency_shift = -30e6 if qubit_name == 'qubit_1' else 0 ''' axis = [1, 0, 0] if gate[i].startswith('X') else [0, 1, 0] length = qubit.Pi_pulse_length if gate[i].endswith( 'pi') else qubit.halfPi_pulse_length name = 'G%d' % (i + 1) refgate = None if i == 0 else 'G%d' % i if gate[i] == error_gate: self.add_Z(name='error_phase', qubit=qubit, degree=phase_error) self.add_single_qubit_gate(name=name, refgate=refgate, qubit=qubit, axis=axis, amplitude=amplitude, length=length, frequency_shift=frequency_shift) if gate[i] == error_gate: self.add_Z(name='error_phase_2', qubit=qubit, degree=-phase_error) return self
def _get_function(funcStr): if isinstance(funcStr, (types.MethodType, types.FunctionType)): warnings.warn('please set function as a str', DeprecationWarning) f = funcStr elif '.' in funcStr: try: instr_name, method = funcStr.split('.') instr = Instrument.find_instrument(instr_name) f = getattr(instr, method) except Exception as e: f = get_function_from_module(funcStr) else: raise Exception('could not find function %s' % funcStr) return f
def execute_qasm_file(file_url: str, config_json: str, verbosity_level: int = 0): options = json.loads(config_json) MC = Instrument.find_instrument('Demonstrator_MC') CBox = Instrument.find_instrument('CBox') device = Instrument.find_instrument('Starmon') num_avg = int(options.get('num_avg', 512)) nr_soft_averages = int(np.round(num_avg / 512)) MC.soft_avg(nr_soft_averages) device.RO_acq_averages(512) # N.B. hardcoded fixme cfg = device.qasm_config() qasm_fp = _retrieve_file_from_url(file_url) sweep_points = _get_qasm_sweep_points(qasm_fp) s = swf.QASM_Sweep_v2(parameter_name='Circuit number ', unit='#', qasm_fn=qasm_fp, config=cfg, CBox=CBox, verbosity_level=verbosity_level) d = device.get_correlation_detector() d.value_names = ['Q0 ', 'Q1 ', 'Corr. (Q0, Q1) '] d.value_units = ['frac.', 'frac.', 'frac.'] MC.set_sweep_function(s) MC.set_sweep_points(sweep_points) MC.set_detector_function(d) data = MC.run('demonstrator') # FIXME <- add the proper name return _MC_result_to_chart_dict(data)
def test_instances(testdummy, parabola): instruments = [testdummy, parabola] for instrument in instruments: for other_instrument in instruments: instances = instrument.instances() # check that each instrument is in only its own if other_instrument is instrument: assert instrument in instances else: assert other_instrument not in instances # check that we can find each instrument from any other assert instrument is other_instrument.find_instrument(instrument.name) # check that we can find this instrument from the base class assert instrument is Instrument.find_instrument(instrument.name)
def __init__(self, name, pulsar, **kw): super().__init__(name, pulsar, **kw) self.refphase = {} self.qubit = kw.pop('qubit', 'qubit_2') self.qubits = kw.pop('qubits', None) if self.qubits is not None: self.qubits_name = [qubit.name for qubit in self.qubits] self.refphase = {qubit.name: 0 for qubit in self.qubits} self.pulsar = None self.amplitude = kw.pop('amplitude', 1) self.frequency_shift = kw.pop('frequency_shift', 0) qubit_name = kw.pop('qubit', self.qubit) qubit = Instrument.find_instrument(qubit_name) self.length = kw.pop('duration_time', qubit.Pi_pulse_length)
def close_and_remove_instrument(self, instrument: Union[Instrument, str] ) -> None: """ Safely close instrument and remove from station and monitor list """ # remove parameters related to this instrument from the # monitor list if isinstance(instrument, str): instrument = Instrument.find_instrument(instrument) self._monitor_parameters = [v for v in self._monitor_parameters if v.root_instrument is not instrument] # remove instrument from station snapshot self.remove_component(instrument.name) # del will remove weakref and close the instrument instrument.close() del instrument
def make_circuit(self, **kw): qubit_name = kw.pop('qubit', self.qubit) qubit = Instrument.find_instrument(qubit_name) length = kw.get('duration_time', self.length) amplitude = kw.get('amplitude', self.amplitude) frequency_shift = kw.pop('frequency_shift', self.frequency_shift) print('length', length) Pi_length = qubit.Pi_pulse_length Pi_num = length // Pi_length last_length = length % qubit.Pi_pulse_length # driving_length = 0 # while driving_length < length: for i in range(Pi_num): if i % 2 == 0: self.add_single_qubit_gate(name='Rabi_Oscillation_%d' % i, qubit=qubit, amplitude=amplitude, axis=[1, 0, 0], length=length, frequency_shift=frequency_shift) else: self.add_single_qubit_gate(name='Rabi_Oscillation_%d' % i, qubit=qubit, amplitude=amplitude, axis=[-1, 0, 0], length=length, frequency_shift=frequency_shift) self.add_single_qubit_gate( name='Rabi_heating', refgate='Rabi_Oscillation', qubit=qubit, amplitude=amplitude, #axis = [0,1,0], length=3.05e-6 - length, frequency_shift=frequency_shift - 20e6) return self
def test_instances(self): instruments = [self.instrument, self.instrument2] for instrument in instruments: for other_instrument in instruments: instances = instrument.instances() # check that each instrument is in only its own if other_instrument is instrument: self.assertIn(instrument, instances) else: self.assertNotIn(other_instrument, instances) # check that we can find each instrument from any other self.assertEqual( instrument, other_instrument.find_instrument(instrument.name)) # check that we can find this instrument from the base class self.assertEqual(instrument, Instrument.find_instrument(instrument.name))
def test_instances(self): instruments = [self.gates, self.source, self.meter] for instrument in instruments: for other_instrument in instruments: instances = instrument.instances() # check that each instrument is in only its own # instances list # also test type checking in find_instrument, # but we need to use find_component so it executes # on the server if other_instrument is instrument: self.assertIn(instrument, instances) name2 = other_instrument.find_component( instrument.name + '.name', other_instrument._instrument_class) self.assertEqual(name2, instrument.name) else: self.assertNotIn(other_instrument, instances) with self.assertRaises(TypeError): other_instrument.find_component( instrument.name + '.name', other_instrument._instrument_class) # check that we can find each instrument from any other # find_instrument is explicitly mapped in RemoteInstrument # so this call gets executed in the main process self.assertEqual( instrument, other_instrument.find_instrument(instrument.name)) # but find_component is not, so it executes on the server self.assertEqual( instrument.name, other_instrument.find_component(instrument.name + '.name')) # check that we can find this instrument from the base class self.assertEqual(instrument, Instrument.find_instrument(instrument.name))
def AWG_obj(self, **kw): """ Return the AWG object corresponding to a channel or an AWG name. Args: AWG: Name of the AWG Instrument. channel: Name of the channel Returns: An instance of Instrument class corresponding to the AWG requested. """ AWG = kw.get('AWG', None) chan = kw.get('channel', None) if AWG is not None and chan is not None: raise ValueError('Both `AWG` and `channel` arguments passed to ' 'Pulsar.AWG_obj()') elif AWG is None and chan is not None: name = self.channels[chan]['AWG'] elif AWG is not None and chan is None: name = AWG else: raise ValueError('Either `AWG` or `channel` argument needs to be ' 'passed to Pulsar.AWG_obj()') return Instrument.find_instrument(name)
def load_instrument(self, identifier: str, revive_instance: bool = False, **kwargs) -> Instrument: """ Creates an :class:`~.Instrument` instance as described by the loaded config file. Args: identifier: the identfying string that is looked up in the yaml configuration file, which identifies the instrument to be added revive_instance: If true, try to return an instrument with the specified name instead of closing it and creating a new one. **kwargs: additional keyword arguments that get passed on to the __init__-method of the instrument to be added. """ # try to revive the instrument if revive_instance and Instrument.exist(identifier): return Instrument.find_instrument(identifier) # load file # try to reload file on every call. This makes script execution a # little slower but makes the overall workflow more convenient. self.load_config_file(self.config_file) # load from config if identifier not in self._instrument_config.keys(): raise RuntimeError(f'Instrument {identifier} not found in ' 'instrument config file') instr_cfg = self._instrument_config[identifier] # TODO: add validation of config for better verbose errors: # check if instrument is already defined and close connection if instr_cfg.get('enable_forced_reconnect', get_config_enable_forced_reconnect()): with suppress(KeyError): self.close_and_remove_instrument(identifier) # instantiate instrument init_kwargs = instr_cfg.get('init', {}) # somebody might have a empty init section in the config init_kwargs = {} if init_kwargs is None else init_kwargs if 'address' in instr_cfg: init_kwargs['address'] = instr_cfg['address'] if 'port' in instr_cfg: init_kwargs['port'] = instr_cfg['port'] # make explicitly passed arguments overide the ones from the config # file. # We are mutating the dict below # so make a copy to ensure that any changes # does not leek into the station config object # specifically we may be passing non pickleable # instrument instances via kwargs instr_kwargs = deepcopy(init_kwargs) instr_kwargs.update(kwargs) name = instr_kwargs.pop('name', identifier) module = importlib.import_module(instr_cfg['driver']) instr_class = getattr(module, instr_cfg['type']) instr = instr_class(name, **instr_kwargs) # local function to refactor common code from defining new parameter # and setting existing one def resolve_parameter_identifier(instrument: InstrumentBase, identifier: str) -> Parameter: parts = identifier.split('.') try: for level in parts[:-1]: instrument = checked_getattr(instrument, level, InstrumentBase) except TypeError: raise RuntimeError( f'Cannot resolve `{level}` in {identifier} to an ' f'instrument/channel for base instrument ' f'{instrument!r}.') try: return checked_getattr(instrument, parts[-1], Parameter) except TypeError: raise RuntimeError( f'Cannot resolve parameter identifier `{identifier}` to ' f'a parameter on instrument {instrument!r}.') def setup_parameter_from_dict(instr: Instrument, name: str, options: Dict[str, Any]): parameter = resolve_parameter_identifier(instr, name) for attr, val in options.items(): if attr in PARAMETER_ATTRIBUTES: # set the attributes of the parameter, that map 1 to 1 setattr(parameter, attr, val) # extra attributes that need parsing elif attr == 'limits': lower, upper = [float(x) for x in val.split(',')] parameter.vals = validators.Numbers(lower, upper) elif attr == 'monitor' and val is True: self._monitor_parameters.append(parameter) elif attr == 'alias': setattr(instr, val, parameter) elif attr == 'initial_value': # skip value attribute so that it gets set last # when everything else has been set up pass else: log.warning(f'Attribute {attr} not recognized when ' f'instatiating parameter \"{parameter.name}\"') if 'initial_value' in options: parameter.set(options['initial_value']) def add_parameter_from_dict(instr: Instrument, name: str, options: Dict[str, Any]): # keep the original dictionray intact for snapshot options = copy(options) if 'source' in options: instr.add_parameter( name, DelegateParameter, source=resolve_parameter_identifier(instr, options['source'])) options.pop('source') else: instr.add_parameter(name, Parameter) setup_parameter_from_dict(instr, name, options) def update_monitor(): if ((self.use_monitor is None and get_config_use_monitor()) or self.use_monitor): # restart Monitor Monitor(*self._monitor_parameters) for name, options in instr_cfg.get('parameters', {}).items(): setup_parameter_from_dict(instr, name, options) for name, options in instr_cfg.get('add_parameters', {}).items(): add_parameter_from_dict(instr, name, options) self.add_component(instr) update_monitor() return instr
def make_circuit(self, **kw): amplitude = kw.get('amplitude', self.amplitude) off_resonance_amplitude = kw.pop('off_resonance_amplitude', self.off_resonance_amplitude) T_amplitude = kw.get('T_amplitude', self.T_amplitude) frequency_shift = kw.pop('frequency_shift', self.frequency_shift) phase_1 = kw.pop('phase_1', self.phase_1) phase_2 = kw.pop('phase_2', self.phase_2) # qubit_name = kw.pop('qubit', self.qubit) qubit_1 = Instrument.find_instrument('qubit_1') qubit_2 = Instrument.find_instrument('qubit_2') length = kw.get('duration_time', self.length) max_length = kw.pop('max_duration', self.max_length) third_tone = kw.pop('third_tone', self.third_tone) # self.add_single_qubit_gate(name='Rabi_Oscillation', qubit = qubit_2, amplitude = amplitude, # length = 250e-9, frequency_shift = 0) self.add_Z(name='Z1_Q1', qubit=qubit_1, degree=phase_1) self.add_Z(name='Z1_Q2', qubit=qubit_2, degree=phase_2) self.add_X( name='X1_Q1', qubit=qubit_1, #refgate = 'Rabi_Oscillation', amplitude=amplitude, length=length, frequency_shift=frequency_shift) self.add_X(name='X1_Q2', qubit=qubit_2, refgate='X1_Q1', refpoint='start', amplitude=amplitude, length=length, frequency_shift=frequency_shift) refgate = 'X1_Q1' if length > 0 else None self.add_single_qubit_gate(name='off_resonance_pulse', qubit=qubit_1, refgate=refgate, refpoint='end', amplitude=off_resonance_amplitude, length=max_length - length, frequency_shift=-30e6) if third_tone: self.add_Y(name='X2_Q2', qubit=qubit_2, refgate='X1_Q1', refpoint='start', amplitude=0.4, length=length, frequency_shift=0) # self.add_CPhase(name = 'CP_Q12', control_qubit = qubit_1, target_qubit = qubit_2, # refgate = 'X1_Q2', refpoint = 'start', waiting_time = -100e-9, # amplitude_control = 0, amplitude_target = T_amplitude, length = length+150e-9) return self
def make_circuit(self, **kw): waiting_time = kw.pop('waiting_time', self.waiting_time) amplitude = kw.get('amplitude', self.amplitude) frequency_shift = kw.pop('frequency_shift', self.frequency_shift) off_resonance_amplitude = kw.pop('off_resonance_amplitude', self.off_resonance_amplitude) # qubit_name = kw.pop('qubit', self.qubit) qubit_1 = Instrument.find_instrument('qubit_1') qubit_2 = Instrument.find_instrument('qubit_2') length = kw.get('duration_time', self.length) detune_q1 = kw.pop('detune_q1', self.detune_q1) self.add_X(name='X1_Q1', qubit=qubit_1, amplitude=amplitude, length=length, frequency_shift=frequency_shift) self.add_X(name='X1_Q2', qubit=qubit_2, refgate='X1_Q1', refpoint='start', amplitude=amplitude, length=length, frequency_shift=frequency_shift) self.add_single_qubit_gate(name='off_resonance_1', refgate='X1_Q1', qubit=qubit_1, amplitude=off_resonance_amplitude, length=waiting_time / 2, frequency_shift=-30e6) self.add_single_qubit_gate(name='decouple_Q1', refgate='off_resonance_1', qubit=qubit_1, amplitude=1, length=qubit_1.Pi_pulse_length, frequency_shift=0) self.add_single_qubit_gate(name='decouple_Q2', refgate='decouple_Q1', refpoint='start', qubit=qubit_2, amplitude=1, length=qubit_2.Pi_pulse_length, frequency_shift=0) self.add_single_qubit_gate(name='off_resonance_2', refgate='decouple_Q1', qubit=qubit_1, amplitude=off_resonance_amplitude, length=waiting_time / 2, frequency_shift=-30e6) self.add_X(name='X2_Q1', refgate='off_resonance_2', qubit=qubit_1, waiting_time=0, amplitude=amplitude, length=length, frequency_shift=frequency_shift) self.add_X(name='X2_Q2', refgate='X2_Q1', refpoint='start', qubit=qubit_2, waiting_time=0, amplitude=amplitude, length=length, frequency_shift=frequency_shift) return self
def make_circuit(self, **kw): phase = kw.pop('phase', self.phase) detuning_time = kw.pop('detuning_time', self.detuning_time) detuning_amplitude = kw.get('detuning_amplitude', self.detuning_amplitude) detuning_amplitude2 = kw.get('detuning_amplitude2', self.detuning_amplitude2) detuning_amplitude3 = kw.pop('detuning_amplitude3', self.detuning_amplitude3) detuning_amplitude4 = kw.pop('detuning_amplitude4', self.detuning_amplitude4) ledge_amplitude1 = kw.pop('ledge_amplitude1', self.ledge_amplitude1) ledge_amplitude2 = kw.pop('ledge_amplitude2', self.ledge_amplitude2) ramp_time = kw.pop('ramp_time', self.ramp_time) # detuning_amplitude = 30*0.5*0.032 # detuning_amplitude2 = 30*0.5*0.0 # detuning_amplitude3 = detuning_amplitude + 30*0.5*0.080 # detuning_amplitude4 = 30*0.5*-0.02 Pi_amplitude = kw.get('Pi_amplitude', self.Pi_amplitude) frequency_shift = kw.pop('frequency_shift', self.frequency_shift) off_resonance_amplitude = kw.pop('off_resonance_amplitude', self.off_resonance_amplitude) control_qubit = kw.pop('control_qubit', self.control_qubit) target_qubit = 'qubit_1' if control_qubit == 'qubit_2' else 'qubit_2' C = int(control_qubit[-1]) - 1 T = int(target_qubit[-1]) - 1 qubit_1 = Instrument.find_instrument('qubit_1') qubit_2 = Instrument.find_instrument('qubit_2') self.qubits[0] = qubit_1 self.qubits[1] = qubit_2 te = 100e-9 ledge_t = ramp_time # off_resonance_amplitude = 1.2 self.add_single_qubit_gate(name='X_Pi_Q2', qubit=self.qubits[C], amplitude=Pi_amplitude, length=self.qubits[0].Pi_pulse_length, frequency_shift=0) if control_qubit == 'qubit_2': self.add_single_qubit_gate(name='off_resonance1_Q1', refgate='X_Pi_Q2', refpoint='start', qubit=self.qubits[T], amplitude=off_resonance_amplitude, length=self.qubits[0].Pi_pulse_length, frequency_shift=frequency_shift - 30e6) self.add_X( name='X1_Q2', refgate='X_Pi_Q2', qubit=self.qubits[T], amplitude=1, length=self.qubits[1].halfPi_pulse_length, frequency_shift=frequency_shift, ) if target_qubit == 'qubit_2': self.add_X( name='off_resonance2_Q2', refgate='X1_Q2', refpoint='start', qubit=self.qubits[C], amplitude=off_resonance_amplitude, length=self.qubits[1].halfPi_pulse_length + 30e-9, frequency_shift=frequency_shift - 30e6, ) self.add_CPhase( name='wait1', refgate='X1_Q2', #''XPi_Q1', control_qubit=self.qubits[0], target_qubit=self.qubits[1], amplitude_control=0, amplitude_target=0, length=te) self.add_Ramp(name='CP1_ledge1', refgate='wait1', control_qubit=self.qubits[0], target_qubit=self.qubits[1], amplitude_control=detuning_amplitude, amplitude_target=detuning_amplitude2, ramp='up', length=ledge_t) self.add_CPhase(name='CP1_Q12', refgate='CP1_ledge1', control_qubit=self.qubits[0], target_qubit=self.qubits[1], amplitude_control=detuning_amplitude, amplitude_target=detuning_amplitude2, length=detuning_time / 2) self.add_Ramp(name='CP1_ledge2', refgate='CP1_Q12', control_qubit=self.qubits[0], target_qubit=self.qubits[1], amplitude_control=detuning_amplitude, amplitude_target=detuning_amplitude2, ramp='down', length=ledge_t) # self.add_CPhase(name='wait2', refgate='CP1_ledge2', control_qubit=self.qubits[0], target_qubit=self.qubits[1], amplitude_control=0, amplitude_target=0, length=te) ''' ''' # if control_qubit == 'qubit_2': self.add_single_qubit_gate(name='XPi0_decouple', refgate='wait2', qubit=self.qubits[0], amplitude=1, length=self.qubits[0].Pi_pulse_length, frequency_shift=0) # elif control_qubit == 'qubit_1': self.add_single_qubit_gate(name='XPi_decouple', refgate='XPi0_decouple', refpoint='start', qubit=self.qubits[1], amplitude=1, length=self.qubits[1].Pi_pulse_length, frequency_shift=0) # self.add_single_qubit_gate(name='off_resonance_pi_Q1', refgate = 'XPi_decouple', refpoint = 'start', # qubit = self.qubits[1], amplitude = 0, # length = self.qubits[1].halfPi_pulse_length, frequency_shift = 0) ''' ''' self.add_CPhase(name='wait3', refgate='XPi_decouple', control_qubit=self.qubits[0], target_qubit=self.qubits[1], amplitude_control=0, amplitude_target=0, length=te) self.add_Ramp(name='CP2_ledge1', refgate='wait3', control_qubit=self.qubits[0], target_qubit=self.qubits[1], amplitude_control=detuning_amplitude, amplitude_target=detuning_amplitude2, ramp='up', length=ledge_t) self.add_CPhase(name='CP2_Q12', refgate='CP2_ledge1', control_qubit=self.qubits[0], target_qubit=self.qubits[1], amplitude_control=detuning_amplitude, amplitude_target=detuning_amplitude2, length=detuning_time / 2) self.add_Ramp(name='CP2_ledge2', refgate='CP2_Q12', control_qubit=self.qubits[0], target_qubit=self.qubits[1], amplitude_control=detuning_amplitude, amplitude_target=detuning_amplitude2, ramp='down', length=ledge_t) # self.add_CPhase(name='wait4', refgate='CP2_ledge2', control_qubit=self.qubits[0], target_qubit=self.qubits[1], amplitude_control=0, amplitude_target=0, length=te) ''' ''' if control_qubit == 'qubit_2': self.add_Z(name='Z2_Q2', qubit=self.qubits[0], degree=phase) self.add_X( name='X2_Q2', refgate='wait4', qubit=self.qubits[0], amplitude=1, length=self.qubits[0].halfPi_pulse_length, ) # frequency_shift = frequency_shift,) elif target_qubit == 'qubit_2': self.add_Z(name='Z2_Q2', qubit=self.qubits[1], degree=phase) self.add_X( name='X2_Q2', refgate='wait4', qubit=self.qubits[1], amplitude=1, length=self.qubits[0].halfPi_pulse_length, ) # frequency_shift = frequency_shift,) self.add_single_qubit_gate( name='off_resonance2_Q1', refgate='X2_Q2', refpoint='start', qubit=self.qubits[0], amplitude=off_resonance_amplitude, length=self.qubits[0].halfPi_pulse_length + 30e-9, frequency_shift=frequency_shift - 30e6) return self
try: MC_demo = measurement_control.MeasurementControl('QInfinity_MC', live_plot_enabled=True, verbose=True) datadir = os.path.abspath( os.path.join(os.path.dirname(pq.__file__), os.pardir, 'demonstrator_execute_data')) MC_demo.datadir(datadir) st = qc.station.Station() MC_demo.station = st st.add_component(MC_demo) except KeyError: MC_demo = Instrument.find_instrument('QInfinity_MC') config_fn = 'D:\\GitHubRepos\\PycQED_py3\\pycqed\\measurement\\openql_experiments\\output\\cfg_CCL_QI.json' gcfg_qi.generate_config(filename=config_fn, mw_pulse_duration=20, ro_duration=5000, flux_pulse_duration=40, init_duration=300000) # worker = CCLightWorker(name='Starmon', nr_qubits=2, # is_simulator=False, openql_config_path=config_fn) worker = CCLightWorker(name='Octoqubit', nr_qubits=2, is_simulator=False, openql_config_path=config_fn)
def load_instrument(self, identifier: str, **kwargs) -> Instrument: """ Creates an instrument driver as described by the loaded config file. Args: identifier: the identfying string that is looked up in the yaml configuration file, which identifies the instrument to be added **kwargs: additional keyword arguments that get passed on to the __init__-method of the instrument to be added. """ # load file self.load_file(self.filename) # load from config if identifier not in self._instrument_config.keys(): raise RuntimeError('Instrument {} not found in config.' .format(identifier)) instr_cfg = self._instrument_config[identifier] # config is not parsed for errors. On errors qcodes should be able to # to report them # check if instrument is already defined and close connection if instr_cfg.get('enable_forced_reconnect', enable_forced_reconnect): # save close instrument and remove from monitor list with suppress(KeyError): instr = Instrument.find_instrument(identifier) # remove parameters related to this instrument from the monitor list self.monitor_parameters = {k:v for k,v in self.monitor_parameters.items() if v.root_instrument is not instr} instr.close() # remove instrument from station snapshot self.station.components.pop(instr.name) # instantiate instrument module = importlib.import_module(instr_cfg['driver']) instr_class = getattr(module, instr_cfg['type']) init_kwargs = instr_cfg.get('init',{}) # somebody might have a empty init section in the config init_kwargs = {} if init_kwargs is None else init_kwargs if 'address' in instr_cfg: init_kwargs['address'] = instr_cfg['address'] if 'port' in instr_cfg: init_kwargs['port'] = instr_cfg['port'] # make explicitly passed arguments overide the ones from the config file # the intuitive line: # We are mutating the dict below # so make a copy to ensure that any changes # does not leek into the station config object # specifically we may be passing non pickleable # instrument instances via kwargs instr_kwargs = deepcopy(init_kwargs) instr_kwargs.update(kwargs) instr = instr_class(name=identifier, **instr_kwargs) # setup # local function to refactor common code from defining new parameter # and setting existing one def setup_parameter_from_dict(parameter, options_dict): for attr, val in options_dict.items(): if attr in self.PARAMETER_ATTRIBUTES: # set the attributes of the parameter, that map 1 to 1 setattr(parameter, attr, val) # extra attributes that need parsing elif attr == 'limits': lower, upper = [float(x) for x in val.split(',')] parameter.vals = validators.Numbers(lower, upper) elif attr == 'monitor' and val is True: self.monitor_parameters[id(parameter)] = parameter elif attr == 'alias': setattr(instr, val, parameter) elif attr == 'initial_value': # skip value attribute so that it gets set last # when everything else has been set up pass else: log.warning(f'Attribute {attr} no recognized when' f' instatiating parameter \"{parameter.name}\"') if 'initial_value' in options_dict: parameter.set(options_dict['initial_value']) # setup existing parameters for name, options in instr_cfg.get('parameters', {}).items(): # get the parameter object from its name: p = instr for level in name.split('.'): p = getattr(p, level) setup_parameter_from_dict(p, options) # setup new parameters for name, options in instr_cfg.get('add_parameters', {}).items(): # allow only top level paremeters for now # pop source only temporarily source = options.pop('source', False) if source: source_p = instr for level in source.split('.'): source_p = getattr(source_p, level) instr.add_parameter(name, DelegateParameter, source=source_p) else: instr.add_parameter(name, Parameter) p = getattr(instr, name) setup_parameter_from_dict(p, options) # restore source options['source'] = source # add the instrument to the station self.station.add_component(instr) # restart Monitor Monitor(*self.monitor_parameters.values()) return instr
from pycqed.measurement import sweep_functions as swf from tess.TessConnect import TessConnection import logging default_execute_options = {} tc = TessConnection() tc.connect("execute_Starmon") default_simulate_options = { "num_avg": 10000, "iterations": 1 } try: MC = Instrument.find_instrument('MC') st = MC.station new_station = False except KeyError: st = qc.station.Station() new_station = True """ Create the station for which the Instruments can connect to. A virtual representation of the physical setup. In our case, the CCL. Since we're calling the station, """ try: MC_demo = measurement_control.MeasurementControl( 'Demonstrator_MC', live_plot_enabled=True, verbose=True) datadir = os.path.abspath(os.path.join(
def load_instrument(self, identifier: str, revive_instance: bool = False, **kwargs) -> Instrument: """ Creates an :class:`~.Instrument` instance as described by the loaded configuration file. Args: identifier: The identfying string that is looked up in the yaml configuration file, which identifies the instrument to be added. revive_instance: If ``True``, try to return an instrument with the specified name instead of closing it and creating a new one. **kwargs: Additional keyword arguments that get passed on to the ``__init__``-method of the instrument to be added. """ # try to revive the instrument if revive_instance and Instrument.exist(identifier): return Instrument.find_instrument(identifier) # load file # try to reload file on every call. This makes script execution a # little slower but makes the overall workflow more convenient. self.load_config_file(self.config_file) # load from config if identifier not in self._instrument_config.keys(): raise RuntimeError(f'Instrument {identifier} not found in ' 'instrument config file') instr_cfg = self._instrument_config[identifier] # TODO: add validation of config for better verbose errors: # check if instrument is already defined and close connection if instr_cfg.get('enable_forced_reconnect', get_config_enable_forced_reconnect()): with suppress(KeyError): self.close_and_remove_instrument(identifier) # instantiate instrument init_kwargs = instr_cfg.get('init', {}) # somebody might have a empty init section in the config init_kwargs = {} if init_kwargs is None else init_kwargs if 'address' in instr_cfg: init_kwargs['address'] = instr_cfg['address'] if 'port' in instr_cfg: init_kwargs['port'] = instr_cfg['port'] # make explicitly passed arguments overide the ones from the config # file. # We are mutating the dict below # so make a copy to ensure that any changes # does not leek into the station config object # specifically we may be passing non pickleable # instrument instances via kwargs instr_kwargs = deepcopy(init_kwargs) instr_kwargs.update(kwargs) name = instr_kwargs.pop('name', identifier) if 'driver' in instr_cfg: issue_deprecation_warning( 'use of the "driver"-keyword in the station ' 'configuration file', alternative='the "type"-keyword instead, prepending the ' 'driver value' ' to it') module_name = instr_cfg['driver'] instr_class_name = instr_cfg['type'] else: module_name = '.'.join(instr_cfg['type'].split('.')[:-1]) instr_class_name = instr_cfg['type'].split('.')[-1] module = importlib.import_module(module_name) instr_class = getattr(module, instr_class_name) instr = instr_class(name, **instr_kwargs) def resolve_instrument_identifier( instrument: ChannelOrInstrumentBase, identifier: str) -> ChannelOrInstrumentBase: """ Get the instrument, channel or channel_list described by a nested string. E.g: 'dac.ch1' will return the instance of ch1. """ try: for level in identifier.split('.'): instrument = checked_getattr(instrument, level, (InstrumentBase, ChannelList)) except TypeError: raise RuntimeError( f'Cannot resolve `{level}` in {identifier} to an ' f'instrument/channel for base instrument ' f'{instrument!r}.') return instrument def resolve_parameter_identifier(instrument: ChannelOrInstrumentBase, identifier: str) -> _BaseParameter: parts = identifier.split('.') if len(parts) > 1: instrument = resolve_instrument_identifier( instrument, '.'.join(parts[:-1])) try: return checked_getattr(instrument, parts[-1], _BaseParameter) except TypeError: raise RuntimeError( f'Cannot resolve parameter identifier `{identifier}` to ' f'a parameter on instrument {instrument!r}.') def setup_parameter_from_dict(parameter: _BaseParameter, options: Dict[str, Any]) -> None: for attr, val in options.items(): if attr in PARAMETER_ATTRIBUTES: # set the attributes of the parameter, that map 1 to 1 setattr(parameter, attr, val) # extra attributes that need parsing elif attr == 'limits': if isinstance(val, str): issue_deprecation_warning( ('use of a comma separated string for the limits ' 'keyword'), alternative='an array like "[lower_lim, upper_lim]"' ) lower, upper = [float(x) for x in val.split(',')] else: lower, upper = val parameter.vals = validators.Numbers(lower, upper) elif attr == 'monitor' and val is True: self._monitor_parameters.append(parameter) elif attr == 'alias': setattr(parameter.instrument, val, parameter) elif attr == 'initial_value': # skip value attribute so that it gets set last # when everything else has been set up pass else: log.warning(f'Attribute {attr} not recognized when ' f'instatiating parameter \"{parameter.name}\"') if 'initial_value' in options: parameter.set(options['initial_value']) def add_parameter_from_dict(instr: InstrumentBase, name: str, options: Dict[str, Any]) -> None: # keep the original dictionray intact for snapshot options = copy(options) param_type: type = _BaseParameter kwargs = {} if 'source' in options: param_type = DelegateParameter kwargs['source'] = resolve_parameter_identifier( instr.root_instrument, options['source']) options.pop('source') instr.add_parameter(name, param_type, **kwargs) setup_parameter_from_dict(instr.parameters[name], options) def update_monitor(): if ((self.use_monitor is None and get_config_use_monitor()) or self.use_monitor): # restart Monitor Monitor(*self._monitor_parameters) for name, options in instr_cfg.get('parameters', {}).items(): parameter = resolve_parameter_identifier(instr, name) setup_parameter_from_dict(parameter, options) for name, options in instr_cfg.get('add_parameters', {}).items(): parts = name.split('.') local_instr = (instr if len(parts) < 2 else resolve_instrument_identifier( instr, '.'.join(parts[:-1]))) add_parameter_from_dict(local_instr, parts[-1], options) self.add_component(instr) update_monitor() return instr
def make_circuit(self, **kw): qubit_name = kw.pop('qubit', self.qubit) qubit_1 = Instrument.find_instrument('qubit_1') qubit_2 = Instrument.find_instrument('qubit_2') self.sequence_number = int( kw.pop('sequence_number', self.sequence_number)) self.clifford_number = int( kw.pop('clifford_number', self.clifford_number)) self.detuning_time = kw.pop('detuning_time', self.detuning_time) self.phase_1 = kw.pop('phase_1', self.phase_1) self.phase_2 = kw.pop('phase_2', self.phase_2) self.Pi_amplitude = kw.pop('Pi_amplitude', self.Pi_amplitude) clifford_gates = clifford_sets[self.sequence_number][ self.clifford_number] print(clifford_gates) name = 'prepare_state' if self.Pi_amplitude == 0: length_1 = 10e-9 else: length_1 = qubit_2.Pi_pulse_length self.add_single_qubit_gate( name=name, qubit=qubit_2, amplitude=self.Pi_amplitude, length=length_1, ) self.add_single_qubit_gate(name=name + 'X2', refgate=name, refpoint='start', qubit=qubit_1, amplitude=self.Pi_amplitude, length=length_1) # self.add_single_qubit_gate(name = 'off_resonance1', refgate = name, refpoint = 'start', # qubit = qubit_1, amplitude = 1.2, # length = qubit_1.Pi_pulse_length, frequency_shift = -30e6) for i in range(len(clifford_gates)): print('go to next clifford : ', i) for j in range(len(clifford_gates[i])): gate = clifford_gates[i][j] refgate = name name = 'C%d%d' % ((i + 1), (j + 1)) + gate amplitude = 1 if gate == 'CZ': self.add_CPhase(name=name + '1', refgate=refgate, waiting_time=10e-9, control_qubit=self.qubits[0], target_qubit=self.qubits[1], amplitude_control=30 * 0.5 * -0.0256, amplitude_target=30 * 0.5 * 0.04, length=self.detuning_time) self.add_Z(name='Z1_Q1', qubit=self.qubits[0], degree=self.phase_1) self.add_Z(name='Z1_Q2', qubit=self.qubits[1], degree=self.phase_2) self.add_CPhase(name=name + '2', refgate=name + '1', control_qubit=self.qubits[0], target_qubit=self.qubits[1], amplitude_control=0, amplitude_target=0, length=10e-9) name = name + '2' elif gate.startswith('Clifford') or gate.startswith('S1'): # group = 'Clifford' if gate.startswith('Cli') else 'S1' clas = Clifford_gates if gate.startswith( 'Cli') else S1_gates for w in range(len(group)): if group[w] == '_': c1 = w if group[w] == '/': c2 = w cli_1 = group[c1 + 1:c2] cli_2 = group[c2 + 1:] total_duration = [0, 0] for qu in [1, 2]: cli = cli_1 if qu == 1 else cli_2 qubit = qubit_1 if qu == 1 else qubit_2 for operation in Clifford_gates[cli_1]: if operation.startswith('X'): axis = [1, 0, 0] elif operation.startswith('mX'): axis = [-1, 0, 0] elif operation.startswith('Y'): axis = [0, 1, 0] else: axis = [0, -1, 0] length = qubit_1.Pi_pulse_length if gate.endswith( 'p') else qubit_1.halfPi_pulse_length total_duration[qu - 1] += length self.add_single_qubit_gate( name=name + 'Q' + str(qu) + '_', refgate=refgate, qubit=qubit, axis=axis, amplitude=amplitude, length=length, ) name = 'Q1' if total_duration[0] < total_duration[1]: off_resonance_duration = total_duration[ 1] - total_duration[0] self.add_single_qubit_gate(name='off_resonance2' + name, refgate=name, qubit=qubit_1, amplitude=1.15, length=length, frequency_shift=-30e6)
def __init__(self): """ 1. setup the VNA as an instrument (if it's not already setup) 2. specify experimental parameters 3. specify paths of the target files: database file and a new folder with raw (txt, png) files """ self.vna_name = "VNA_Anritsu" self.vna_class = Anritsu_MS46522B # this is a qcodes VisaInstrument (interface between visa and qcodes) self.vna_address = "TCPIP0::169.254.235.118::5001::SOCKET" # "TCPIP0::169.254.81.17::5001::SOCKET" # "TCPIP0::169.254.235.118::5001::SOCKET" # "TCPIP0::maip-franck::hislip0,4880::INSTR" # (# 'VNA', 'TCPIP0::169.254.235.118::5001::SOCKET', # 50e6, 20e9, -30, 30, 2 # ) # -- check if instrument 'VNA' already exists. If not, create it if Instrument.exist(self.vna_name, self.vna_class): # an instrument is created by qcodes in a global context, # from which it can be retrieved manually using find_instrument self.vna = Instrument.find_instrument(self.vna_name, self.vna_class) else: if self.vna_class == Anritsu_MS46522B: self.vna = self.vna_class(self.vna_name, self.vna_address, 50e6, 20e9, -30, 30, 2) else: exit(1) # -- name the experiment -> automatic file names self.exp_name = 'Anritsu_Something' # name used by qcodes self.cooldown_date = '20-09-21' self.sample_name = 'sample_not_important' self.numberofpoints=2001 #number of measurement points self.vnapower=13 #applied power self.start_frequency=3.4e9 #3.387015e9#6.608e9-3.5e6 #start frequency of sweep self.stop_frequency=7.4e9 #3.387065e9#6.611e9 +3.5e6 #stop frequency of sweep self.frequency_span=self.stop_frequency-self.start_frequency self.center_frequency=(self.stop_frequency-self.start_frequency)/2. + self.start_frequency #just used for power sweep self.measuredtrace='S21' #spectral density measured between port 1 and 2 self.ifbandwidth=100 #IF Bandwidth, must be in (10,30,50,70,100,300,500,700,1000,3000,5000,7000,10000)Hz self.powersweepstart=-30 #start for power sweep self.powersweepstop=20 #stop for powersweep self.powersweepnum=6 #number of power sweeps (perhaps +/-1) MUST BE AN EVEN NUMBER AT LEAST 6 # # -- set experiment parameters (global constants, used in different measurement functions) # self.numberofpoints = 50 # 2001 # number of measurement points # self.vnapower = -10 # applied power # self.start_frequency = 300e3 # 3.7e9 #3.387015e9 #6.608e9-3.5e6 # start frequency of sweep # self.stop_frequency = 13.5e9 # 5.7e9 #3.387065e9 #6.611e9 +3.5e6 # stop frequency of sweep # self.frequency_span = self.stop_frequency - self.start_frequency # self.center_frequency = (self.stop_frequency - self.start_frequency)/2. + self.start_frequency # just used for power sweep # self.measuredtrace='S21' # spectral density measured between port 1 and 2 # self.ifbandwidth=10 # IF Bandwidth, must be in (10,30,50,70,100,300,500,700,1000,3000,5000,7000,10000)Hz # self.powersweepstart=-30 # start for power sweep # self.powersweepstop=13 # stop for powersweep # self.powersweepnum=3 # number of power sweeps (perhaps +/-1) MUST BE AN EVEN NUMBER AT LEAST 6 # # groupdelayref=0.0000000225 # # vna.groupdelay.set(groupdelayref)#resets to 0 instead of working -> rounding to 0 # # print(vna.groupdelay.get()) self.create_database_experiment_and_folders()
def XY_rotation(self, degree = 90, length = None, waiting_time = 0, refgate = None, refpoint = 'end', refqubit = None): # global phase # IQ_Modulation = self.frequency if length is not None: pulse_length = length else: pulse_length = self.halfPi_pulse_length if degree == 90 else degree*self.Pi_pulse_length/180 pulse_amp = self.amplitude pulse_delay = Instrument.find_instrument(self.qubit).pulse_delay if self.qubit == 'qubit_2' and refqubit == 'qubit_2': pulse_delay = 0 ## voltage pulse is not used here voltage_pulse = SquarePulse(channel = self.channel_VP, name = '%s_voltage_pulse'%self.name, amplitude = 0, length = 0)#pulse_length + waiting_time) PM_pulse = SquarePulse(channel = self.channel_PM, name = '%s_PM_pulse'%self.name, amplitude = 2, length = pulse_length+self.PM_before+self.PM_after) if self.frequency_shift == 0: microwave_pulse_I = SquarePulse(channel = self.channel_I, name = '%s_microwave_pulse_I'%self.name, amplitude = pulse_amp*np.cos(-self.refphase + self.axis_angle), length = pulse_length) microwave_pulse_Q = SquarePulse(channel = self.channel_Q, name = '%s_microwave_pulse_Q'%self.name, amplitude = pulse_amp*np.sin(-self.refphase + self.axis_angle), length = pulse_length) elif self.frequency_shift != 0: ##here frequency and phase is not yet ready!!!!!!!!!!! phase = self.IQ_phase-self.refphase + self.axis_angle freq = self.frequency_shift microwave_pulse_I = CosPulse(channel = self.channel_I, name = '%s_microwave_pulse_I'%self.name, frequency = freq, amplitude = pulse_amp, length = pulse_length, phase = phase) microwave_pulse_Q = CosPulse(channel = self.channel_Q, name = '%s_microwave_pulse_Q'%self.name, frequency = freq, amplitude = pulse_amp, length = pulse_length, phase = phase-90) ''' adiabatic sweep for test ''' if type(self.frequency_shift) is list : phase = self.IQ_phase-self.refphase + self.axis_angle freq = self.frequency_shift start_freq = self.frequency_shift[0] end_freq = self.frequency_shift[1] microwave_pulse_I = AdiabaticCosPulse(channel = self.channel_I, name = '%s_microwave_pulse_I'%self.name, start_frequency = start_freq, end_frequency = end_freq, amplitude = pulse_amp, length = pulse_length, phase = phase) microwave_pulse_Q = AdiabaticCosPulse(channel = self.channel_Q, name = '%s_microwave_pulse_Q'%self.name, start_frequency = start_freq, end_frequency = end_freq, amplitude = pulse_amp, length = pulse_length, phase = phase-90) ''' ''' self.pulses[0] = { 'pulse': voltage_pulse, 'pulse_name': voltage_pulse.name, 'refpulse': None if refgate == None else refgate[0]['pulse_name'], 'refpoint': refpoint, 'waiting': 0 } self.pulses[1] = { 'pulse': microwave_pulse_I, 'pulse_name': microwave_pulse_I.name, 'refpulse': None if refgate == None else refgate[-2]['pulse_name'], ## name of the refpulse 'refpoint': refpoint, 'waiting': waiting_time + pulse_delay } self.pulses[2] = { 'pulse': microwave_pulse_Q, 'pulse_name': microwave_pulse_Q.name, 'refpulse': '%s_microwave_pulse_I'%self.name, 'refpoint': 'start', 'waiting': 0 } ## here you just construct a dictionary which contains all the information of pulses you use self.pulses[3] = { 'pulse': PM_pulse, 'pulse_name': PM_pulse.name, 'refpulse': '%s_microwave_pulse_I'%self.name, 'refpoint': 'start', 'waiting': -self.PM_before } return True
def __init__(self): """ 1. setup the VNA as an instrument (if it's not already setup) 2. specify experimental parameters 3. specify paths of the target files: database file and a new folder with raw (txt, png) files """ self.vna_name = 'VNA' self.vna_class = Anritsu_MS46522B # this is a qcodes VisaInstrument (interface between visa and qcodes) # Anritsu_MS46522B("VNA2", "TCPIP0::169.254.235.118::5001::SOCKET", 50e6, 20e9, -30, 30, 2) # -- check if instrument 'VNA' already exists. If not, create it if Instrument.exist(self.vna_name, self.vna_class): # an instrument is created by qcodes in a global context, # from which it can be retrieved manually using find_instrument self.vna = Instrument.find_instrument(self.vna_name, self.vna_class) else: self.vna = self.vna_class(self.vna_name, 'TCPIP0::169.254.235.118::5001::SOCKET', 50e6, 20e9, -30, 30, 2) # -- name the experiment -> automatic file names self.exp_name = 'Warm_VNA_Noise' # name used by qcodes self.cooldown_date = '20-09-18' self.sample_name = 'no_sample' # -- set experiment parameters (global constants, used in different measurement functions) self.numberofpoints = 20 # 2001 # number of measurement points self.vnapower = -10 # applied power self.start_frequency = 3.7e9 #3.387015e9 #6.608e9-3.5e6 # start frequency of sweep self.stop_frequency = 5.7e9 #3.387065e9 #6.611e9 +3.5e6 # stop frequency of sweep self.frequency_span = self.stop_frequency - self.start_frequency self.center_frequency = (self.stop_frequency - self.start_frequency)/2. + self.start_frequency # just used for power sweep self.measuredtrace='S21' # spectral density measured between port 1 and 2 self.ifbandwidth=10 # IF Bandwidth, must be in (10,30,50,70,100,300,500,700,1000,3000,5000,7000,10000)Hz self.powersweepstart=-30 # start for power sweep self.powersweepstop=20 # stop for powersweep self.powersweepnum=6 # number of power sweeps (perhaps +/-1) MUST BE AN EVEN NUMBER AT LEAST 6 # groupdelayref=0.0000000225 # vna.groupdelay.set(groupdelayref)#resets to 0 instead of working -> rounding to 0 # print(vna.groupdelay.get()) # -- set the path where the raw data should be saved to (pngs, txts) self.raw_path = ('C:\\Users\\Desktop\\tests' + '\\' + self.cooldown_date + '_' + self.sample_name + '\\' 'raw') # set the .db path qc.config["core"]["db_location"] = ( os.path.join('C:\\Users\\Desktop\\tests', 'test.db')) # store a qcodesrc file with the loaded .db path to the measurements folder qc.config.save_config( os.path.join("C:\\Users\\Desktop\\tests", ".qcodesrc")) # -- check if in the standard folder -see qcodes config file- an experiment with exp_name already exists # if not, create a new folder at path # if so, just print the last exp. ID and go on try: # qcodes interface of loading an experiment: # -- tries to connect to a database (specificed in config data structure) and searches for the exp_name self.exp = load_experiment_by_name(self.exp_name, sample=self.sample_name) print('Experiment loaded. Last ID no: ', self.exp.last_counter) # keep track of the experiment number except ValueError: print("Experiment name ", self.exp_name, " with sample name ", self.sample_name, " not found in ", qc.config["core"]["db_location"]) print('Starting new experiment.') self.exp = new_experiment(self.exp_name, self.sample_name) os.makedirs(self.raw_path, exist_ok=True) # ---- always create a new folder for each day of taking measurements self.raw_path_with_date = os.path.join(self.raw_path, date.today().strftime("%y-%m-%d")) if not os.path.isdir(self.raw_path_with_date): os.makedirs(self.raw_path_with_date, exist_ok=True) # force-create the directory
def make_circuit(self, **kw): qubit_name = kw.pop('qubit', self.qubit) qubit_1 = Instrument.find_instrument('qubit_1') qubit_2 = Instrument.find_instrument('qubit_2') self.sequence_number = int( kw.pop('sequence_number', self.sequence_number)) self.clifford_number = int( kw.pop('clifford_number', self.clifford_number)) self.detuning_time = kw.pop('detuning_time', self.detuning_time) self.phase_1 = kw.pop('phase_1', self.phase_1) self.phase_2 = kw.pop('phase_2', self.phase_2) self.Pi_amplitude = kw.pop('Pi_amplitude', self.Pi_amplitude) clifford_gates = clifford_sets[self.sequence_number][ self.clifford_number] print(clifford_gates) name = 'prepare_state' if self.Pi_amplitude == 0: length_1 = 5e-9 else: length_1 = qubit_2.Pi_pulse_length self.add_single_qubit_gate( name=name, qubit=qubit_2, amplitude=self.Pi_amplitude, length=length_1, ) self.add_single_qubit_gate(name=name + 'X2', refgate=name, refpoint='start', qubit=qubit_1, amplitude=self.Pi_amplitude, length=length_1) # self.add_single_qubit_gate(name = 'off_resonance1', refgate = name, refpoint = 'start', # qubit = qubit_1, amplitude = 1.2, # length = qubit_1.Pi_pulse_length, frequency_shift = -30e6) for i in range(len(clifford_gates)): print('go to next clifford : ', i) for j in range(len(clifford_gates[i])): gate = clifford_gates[i][j] if gate == 'I': continue refgate = name name = 'C%d%d' % ((i + 1), (j + 1)) + gate amplitude = 1 if 'X' in gate or 'Y' in gate: if gate.startswith('X'): axis = [1, 0, 0] elif gate.startswith('mX'): axis = [-1, 0, 0] elif gate.startswith('Y'): axis = [0, 1, 0] else: axis = [0, -1, 0] length = qubit_1.Pi_pulse_length if gate.endswith( 'p') else qubit_1.halfPi_pulse_length # refgate = None if i+j == 0 else name self.add_single_qubit_gate( name=name, refgate=refgate, qubit=qubit_1, axis=axis, amplitude=amplitude, length=length, ) self.add_single_qubit_gate( name=name + 'Q2', refgate=refgate, qubit=qubit_2, axis=axis, amplitude=amplitude, length=length, ) # # self.add_single_qubit_gate(name = 'off_resonance2'+name, refgate = name, # qubit = qubit_1, amplitude = 1.2, # length = length, frequency_shift = -30e6) # name = name +'Q2' elif gate == 'CZ': self.add_CPhase(name=name + '1', refgate=refgate, waiting_time=10e-9, control_qubit=self.qubits[0], target_qubit=self.qubits[1], amplitude_control=30 * 0.5 * -0.0267, amplitude_target=30 * 0.5 * 0.02, length=self.detuning_time) self.add_Z(name='Z1_Q1', qubit=self.qubits[0], degree=self.phase_1) self.add_Z(name='Z1_Q2', qubit=self.qubits[1], degree=self.phase_2) self.add_CPhase(name=name + '2', refgate=name + '1', control_qubit=self.qubits[0], target_qubit=self.qubits[1], amplitude_control=0, amplitude_target=0, length=10e-9) name = name + '2' elif gate == 'iSWAP_1': self.add_single_qubit_gate( name=name, refgate=refgate, qubit=qubit_1, axis=[0, 1, 0], amplitude=amplitude, length=qubit_1.halfPi_pulse_length, ) self.add_single_qubit_gate( name=name + 'Q2_1', refgate=name, refpoint='start', qubit=qubit_2, axis=[-1, 0, 0], amplitude=amplitude, length=qubit_2.halfPi_pulse_length, ) elif gate.startswith('iSWAP'): if gate.endswith('S0'): self.add_single_qubit_gate( name=name, refgate=refgate, qubit=qubit_1, axis=[0, 1, 0], amplitude=amplitude, length=qubit_1.halfPi_pulse_length, ) self.add_single_qubit_gate( name=name + 'Q2_1', refgate=name, refpoint='start', qubit=qubit_2, axis=[1, 0, 0], amplitude=amplitude, length=qubit_2.halfPi_pulse_length, ) elif gate.endswith('S1'): self.add_single_qubit_gate( name=name + 'Q1_1', refgate=refgate, qubit=qubit_1, axis=[0, 1, 0], amplitude=amplitude, length=qubit_1.Pi_pulse_length, ) self.add_single_qubit_gate( name=name + 'Q1_2', refgate=name + 'Q1_1', qubit=qubit_1, axis=[1, 0, 0], amplitude=amplitude, length=qubit_1.halfPi_pulse_length, ) self.add_single_qubit_gate( name=name + 'Q2_1', refgate=name + 'Q1_1', refpoint='start', qubit=qubit_2, axis=[1, 0, 0], amplitude=amplitude, length=qubit_2.halfPi_pulse_length, ) self.add_single_qubit_gate( name=name + 'Q2_2', refgate=name + 'Q2_1', qubit=qubit_2, axis=[0, 1, 0], amplitude=amplitude, length=qubit_2.halfPi_pulse_length, ) self.add_single_qubit_gate( name=name + 'Q2_3', refgate=name + 'Q2_2', qubit=qubit_2, axis=[1, 0, 0], amplitude=amplitude, length=qubit_2.halfPi_pulse_length, ) name = name + 'Q1_2' elif gate.endswith('S2'): self.add_single_qubit_gate( name=name + 'Q1_1', refgate=refgate, qubit=qubit_1, axis=[-1, 0, 0], amplitude=amplitude, length=qubit_1.halfPi_pulse_length, ) self.add_single_qubit_gate( name=name + 'Q1_2', refgate=name + 'Q1_1', qubit=qubit_1, axis=[0, -1, 0], amplitude=amplitude, length=qubit_1.halfPi_pulse_length, ) self.add_single_qubit_gate( name=name + 'Q1_3', refgate=name + 'Q1_2', qubit=qubit_1, axis=[1, 0, 0], amplitude=amplitude, length=qubit_1.halfPi_pulse_length, ) self.add_single_qubit_gate( name=name + 'Q2_1', refgate=name + 'Q1_1', refpoint='start', qubit=qubit_2, axis=[0, -1, 0], amplitude=amplitude, length=qubit_2.halfPi_pulse_length, ) name = name + 'Q1_3' else: raise NameError('Gate name not correct') elif gate.startswith('CNOT'): if gate.endswith('S0'): self.add_single_qubit_gate( name=name, refgate=refgate, qubit=qubit_1, axis=[0, 1, 0], amplitude=amplitude, length=qubit_1.halfPi_pulse_length, ) elif gate.endswith('S1'): self.add_single_qubit_gate( name=name + 'Q1_1', refgate=refgate, qubit=qubit_1, axis=[0, 1, 0], amplitude=amplitude, length=qubit_1.Pi_pulse_length, ) self.add_single_qubit_gate( name=name + 'Q1_2', refgate=name + 'Q1_1', qubit=qubit_1, axis=[1, 0, 0], amplitude=amplitude, length=qubit_1.halfPi_pulse_length, ) self.add_single_qubit_gate( name=name + 'Q2_1', refgate=name + 'Q1_1', refpoint='start', qubit=qubit_2, axis=[0, 1, 0], amplitude=amplitude, length=qubit_2.halfPi_pulse_length, ) self.add_single_qubit_gate( name=name + 'Q2_2', refgate=name + 'Q2_1', qubit=qubit_2, axis=[1, 0, 0], amplitude=amplitude, length=qubit_2.halfPi_pulse_length, ) name = name + 'Q1_2' elif gate.endswith('S2'): self.add_single_qubit_gate( name=name + 'Q1_1', refgate=refgate, qubit=qubit_1, axis=[-1, 0, 0], amplitude=amplitude, length=qubit_1.halfPi_pulse_length, ) self.add_single_qubit_gate( name=name + 'Q1_2', refgate=name + 'Q1_1', qubit=qubit_1, axis=[0, -1, 0], amplitude=amplitude, length=qubit_1.halfPi_pulse_length, ) self.add_single_qubit_gate( name=name + 'Q1_3', refgate=name + 'Q1_2', qubit=qubit_1, axis=[1, 0, 0], amplitude=amplitude, length=qubit_1.halfPi_pulse_length, ) self.add_single_qubit_gate( name=name + 'Q2_1', refgate=name + 'Q1_1', refpoint='start', qubit=qubit_2, axis=[-1, 0, 0], amplitude=amplitude, length=qubit_2.halfPi_pulse_length, ) self.add_single_qubit_gate( name=name + 'Q2_2', refgate=name + 'Q2_1', qubit=qubit_2, axis=[0, -1, 0], amplitude=amplitude, length=qubit_2.halfPi_pulse_length, ) name = name + 'Q1_3' else: raise NameError('Gate name not correct') elif gate == 'SWAP_1': self.add_single_qubit_gate( name=name, refgate=refgate, qubit=qubit_1, axis=[0, 1, 0], amplitude=amplitude, length=qubit_1.halfPi_pulse_length, ) self.add_single_qubit_gate( name=name + 'Q2_1', refgate=name, refpoint='start', qubit=qubit_2, axis=[0, -1, 0], amplitude=amplitude, length=qubit_2.halfPi_pulse_length, ) elif gate == 'SWAP_2': self.add_single_qubit_gate( name=name, refgate=refgate, qubit=qubit_1, axis=[0, -1, 0], amplitude=amplitude, length=qubit_1.halfPi_pulse_length, ) self.add_single_qubit_gate( name=name + 'Q2_1', refgate=name, refpoint='start', qubit=qubit_2, axis=[0, 1, 0], amplitude=amplitude, length=qubit_2.halfPi_pulse_length, ) elif gate == 'SWAP_3': self.add_single_qubit_gate( name=name, refgate=refgate, qubit=qubit_1, axis=[0, 1, 0], amplitude=amplitude, length=qubit_1.halfPi_pulse_length, ) else: raise NameError('Gate name not correct') print('clifford_gates finished') return self