def __init__(self, name, address, gpib_slot, **kw): super().__init__(address=address) Instrument.__init__(self, name, **kw) self.connect() self.select(gpib_slot) self.write('*DCL') # device clear self.write('FLSH') # flush port buffers self.write('SRST') # SIM reset (causes 100 ms delay) time.sleep(0.5) #Build up the available module outputs on all slots... #TODO: Is this a bit draconian (e.g. slots could be shared across experiments)? Usually they make the actual module the arching object while #it's being treated as if it were a single voltage-source entity... Also, there are LP/HP SIM-Rack filters that can be tuned from the PC... #Anyway, food for thought... self.modules = self._find_modules() self._source_outputs = {} for ch_ind in self.modules: self._write_module(ch_ind, 'TERM LF') leName = f'CH{ch_ind}' cur_module = SIM928_ChannelModule(self, ch_ind, leName) self.add_submodule( leName, cur_module) #Name is christened inside the channel object... self._source_outputs[ch_ind] = cur_module super().connect_message()
def __init__(self, name, remote_proxy, gpib_slots, slot_names=None, **kw): # super().__init__(address=address, type='rs232') self._proxy = remote_proxy Instrument.__init__(self, name, **kw) self.gpib_slots = gpib_slots if slot_names is None: self.slot_names = {} else: self.slot_names = slot_names self.module_nr = {} for i in self.slot_names: if self.slot_names[i] in self.module_nr: raise ValueError('Duplicate names in slot_names') self.module_nr[self.slot_names[i]] = i self.write('*DCL') # device clear self.write('FLSH') # flush port buffers self.write('SRST') # SIM reset (causes 100 ms delay) time.sleep(0.5) self.modules = self.find_modules() for i in self.modules: self.write_module(i, 'TERM LF') module_name = self.slot_names.get(i, i) self.add_parameter('volt_{}'.format(module_name), unit='V', label="Output voltage of module " "{}".format(module_name), vals=vals.Numbers(-20, 20), get_cmd=partial(self.get_voltage, i), set_cmd=partial(self.set_voltage, i), inter_delay=0.05, step=0.0025)
def _discover_from_instrument(cls, parent: Instrument, **kwargs) -> List[Dict[Any, Any]]: """ New channels need `name` and `channel` keyword arguments. """ channels_str = parent.channel_catalog() channels_to_skip = kwargs.get("channels_to_skip", []) # Note that # `channels_to_skip` is an optional kwarg for loading from instrument. # We test this by giving this keyword during the initialization of the # AutoLoadableChannelList. kwarg_list = [] for channel_str in channels_str.split(","): if channel_str in channels_to_skip: continue channel = int(channel_str) greeting = parent.ask(f":INST:CHN{channel}:GRT") new_kwargs = { "name": f"channel{channel}", "channel": channel, "greeting": greeting } kwarg_list.append(new_kwargs) return kwarg_list
def __init__( self, name: str, transport: Transport, num_ccio: int = 9, ccio_slots_driving_vsm: List[ int] = None # NB: default can not be '[]' because that is a mutable default argument ) -> None: super().__init__(name, transport) # calls QuTechCC_core Instrument.__init__(self, name) # calls Instrument # user constants self._num_ccio = num_ccio # the number of CCIO modules used if ccio_slots_driving_vsm is None: self._ccio_slots_driving_vsm = [] else: self._ccio_slots_driving_vsm = ccio_slots_driving_vsm # the slot numbers of the CCIO driving the VSM # fixed constants self._Q1REG_DIO_DELAY = 63 # the register used in OpenQL generated programs to set DIO delay self._NUM_VSM_CH = 32 # the number of VSM channels used per CCIO connector self._CCIO_MAX_VSM_DELAY = 48 self._add_parameters(self._num_ccio) self._add_compatibility_parameters(self._num_ccio)
def setup(): Instrument.close_all() Instrument('AWG520') AWG_interface = AWG520Interface('AWG520') Chip('chip', channels=['ch1', 'ch2']) chip_interface = ChipInterface('chip') trigger_instrument = Chip('triggerer', channels=['ch1', 'ch2']) trigger_interface = MockInterface('triggerer') layout = Layout(instrument_interfaces=[ AWG_interface, chip_interface, trigger_interface ]) layout.load_connections(connections_dicts=[ { "output_arg": "AWG520.ch1", "input_arg": "chip.ch1" }, { "output_arg": "AWG520.ch2", "input_arg": "chip.ch2" }, { "output_arg": "triggerer.ch1", "input_arg": "AWG520.trig_in", "trigger": True }, ]) return { 'AWG_interface': AWG_interface, 'chip_interface': chip_interface, 'trigger_interface': trigger_interface, 'layout': layout }
def _make_empty_instrument(): instr = Instrument(name="dci") try: yield instr finally: instr.close()
def assert_on_reconnect(*, use_user_cfg: Optional[bool], use_instr_cfg: Optional[bool], expect_failure: bool) -> None: qcodes.config["station"]\ ['enable_forced_reconnect'] = use_user_cfg st = station_from_config_str(get_instrument_config(use_instr_cfg)) st.load_instrument('mock') if expect_failure: with pytest.raises(KeyError) as excinfo: st.load_instrument('mock') assert ("Another instrument has the name: mock" in str(excinfo.value)) else: st.load_instrument('mock') Instrument.close_all()
def instrument_factory(instrument_class: type, name: str, *args, **kwargs) -> Type[Instrument]: """ Find an instrument with the given name of a given class, or create one if it is not found. If an instrument is found, a connection message is printed, as if the instrument has just been instantiated. Note: this function similar to pytopo.create_inst(). Args: instrument_class Class of the instrument to find or create name Name of the instrument to find or create Returns: The found or created instrument """ try: instrument = Instrument.find_instrument( name, instrument_class=instrument_class) instrument.connect_message() # prints the message except KeyError as exception: if any(str_ in str(exception) for str_ in [name, 'has been removed']): instrument = instrument_class(name, *args, **kwargs) else: raise exception return instrument
def _singleInstrumentParametersToJson(instrument: Instrument, get: bool = False, addPrefix: str = '', includeMeta: List[str] = [], excludeParameters: List[str] = [], simpleFormat: bool = True) -> Dict: """Create a dictionary that holds the parameters of an instrument.""" if "IDN" not in excludeParameters: excludeParameters.append("IDN") ret = {} snap = instrument.snapshot(update=get) for name, param in instrument.parameters.items(): if name not in excludeParameters: if len(includeMeta) == 0 and simpleFormat: ret[addPrefix + name] = snap['parameters'][name].get('value', None) else: ret[addPrefix + name] = dict() for k, v in snap['parameters'][name].items(): if k in (['value'] + includeMeta): ret[addPrefix + name][k] = v else: logger.debug(f"excluded: {addPrefix + name}") for name, submod in instrument.submodules.items(): ret.update(_singleInstrumentParametersToJson( submod, get=get, addPrefix=f"{addPrefix + name}.", simpleFormat=simpleFormat, includeMeta=includeMeta)) return ret
def connect_device(self, device, classtype, name, address, args=[], kwargs={}): new_dev = None if name in Instrument.instances(): self.show_error( "Error", f'Instrument name is already in use. Try again with a new name.' ) return None try: if device == 'Dummy' or device == 'Test': new_dev = classtype(name) else: new_dev = classtype(name, address, *args, **kwargs) if len(kwargs.keys()) > 0: self.device_init[name] = kwargs except Exception as e: self.show_error( "Error", f'Couldn\'t connect to the instrument. Check address and try again.', e) print(e, file=sys.stderr) if hasattr(new_dev, 'close'): new_dev.close() new_dev = None return new_dev
def test_close_all_registered_instruments(): names = [f'some_name_{i}' for i in range(10)] instrs = [Instrument(name=name) for name in names] st = Station(*instrs) for name in names: assert name in Instrument._all_instruments st.close_all_registered_instruments() for name in names: assert name not in Instrument._all_instruments
def test_load_all_instruments_only_types(example_station): all_dummy_instruments = {"mock_dac", "mock_dac2"} loaded_instruments = example_station.load_all_instruments( only_types=("DummyInstrument", )) assert set(loaded_instruments) == all_dummy_instruments for instrument in all_dummy_instruments: assert instrument in example_station.components assert Instrument.exist(instrument) other_instruments = (set(example_station.config["instruments"].keys()) - all_dummy_instruments) for instrument in other_instruments: assert instrument not in example_station.components assert not Instrument.exist(instrument)
def test_load_all_instruments_only_names(example_station): instruments_to_load = {"lakeshore", "mock_dac"} loaded_instruments = example_station.load_all_instruments( only_names=instruments_to_load) assert set(loaded_instruments) == instruments_to_load for instrument in loaded_instruments: assert instrument in example_station.components assert Instrument.exist(instrument) other_instruments = (set(example_station.config["instruments"].keys()) - instruments_to_load) for instrument in other_instruments: assert instrument not in example_station.components assert not Instrument.exist(instrument)
def test_load_all_instruments_no_args(example_station): all_instruments_in_config = {"lakeshore", "mock_dac", "mock_dac2"} loaded_instruments = example_station.load_all_instruments() assert set(loaded_instruments) == all_instruments_in_config for instrument in all_instruments_in_config: assert instrument in example_station.components assert Instrument.exist(instrument)
def f_to_parallelize_new(arglist): # cluster wants a list as an argument. # Below the various list items are assigned to their own variable fitted_stepresponse_ty = arglist['fitted_stepresponse_ty'] fluxlutman_args = arglist['fluxlutman_args'] # see function return_instrument_args in czf noise_parameters_CZ_args = arglist['noise_parameters_CZ_args'] # see function return_instrument_args in czf number = arglist['number'] adaptive_pars = arglist['adaptive_pars'] try: MC = Instrument.find_instrument('MC'+'{}'.format(number)) except KeyError: MC = mc.MeasurementControl('MC'+'{}'.format(number), live_plot_enabled=False) from qcodes import station station = station.Station() station.add_component(MC) MC.station =station fluxlutman = flm.AWG8_Flux_LutMan('fluxlutman'+'{}'.format(number)) station.add_component(fluxlutman) noise_parameters_CZ = npCZ.NoiseParametersCZ('noise_parameters_CZ'+'{}'.format(number)) station.add_component(noise_parameters_CZ) fluxlutman, noise_parameters_CZ = czf.return_instrument_from_arglist(fluxlutman,fluxlutman_args,noise_parameters_CZ,noise_parameters_CZ_args) d=ramsey_experiment(fluxlutman=fluxlutman, noise_parameters_CZ=noise_parameters_CZ, fitted_stepresponse_ty=fitted_stepresponse_ty) MC.set_sweep_functions([fluxlutman.cz_length]) MC.set_detector_function(d) MC.set_sweep_points(np.arange(0, adaptive_pars['max_time'], adaptive_pars['time_step'])) exp_metadata = {'detuning': noise_parameters_CZ.detuning(), 'sigma_q1': noise_parameters_CZ.sigma_q1(), 'sigma_q0': noise_parameters_CZ.sigma_q0()} if noise_parameters_CZ.cluster(): dat = MC.run('1D ramsey_new_cluster sigma_q1 {:.0f}, sigma_q0 {:.0f}, detuning {:.0f}'.format(noise_parameters_CZ.sigma_q1()*1e6, noise_parameters_CZ.sigma_q0()*1e6, noise_parameters_CZ.detuning()/1e6), mode='1D',exp_metadata=exp_metadata) else: if adaptive_pars['long_name']: dat = MC.run('1D ramsey_new sigma_q1 {:.0f}, sigma_q0 {:.0f}, detuning {:.0f}'.format(noise_parameters_CZ.sigma_q1()*1e6, noise_parameters_CZ.sigma_q0()*1e6, noise_parameters_CZ.detuning()/1e6), mode='1D',exp_metadata=exp_metadata) else: dat = MC.run('1D ramsey_new', mode='1D',exp_metadata=exp_metadata) fluxlutman.close() noise_parameters_CZ.close() MC.close()
def QWG_pulse_prepare(operation_name, **kwargs): QWG_name = kwargs.pop('QWG_name') codeword = kwargs.pop('codeword') channels = kwargs.pop('channels') QWG = Instrument.find_instrument(QWG_name) pulse_func = getattr(wf, kwargs['pulse_type']) waveform = pulse_func(kwargs) for i, ch in enumerate(channels): wf_name = operation_name + str(ch) QWG.createWaveformReal(wf_name, waveform[i], [], []) QWG.set(codeword, ch, wf_name)
def QWG_pulse_prepare(operation_name, **kwargs): QWG_name = kwargs.pop('QWG_name') codeword = kwargs.pop('codeword') channels = kwargs.pop('channels') QWG = Instrument.find_instrument(QWG_name) pulse_func = getattr(wf, kwargs['pulse_type']) waveform = pulse_func(kwargs) for i, ch in enumerate(channels): wf_name = operation_name+str(ch) QWG.createWaveformReal(wf_name, waveform[i], [], []) QWG.set(codeword, ch, wf_name)
def _make_dci_with_list(): for i in range(10): pass dci = Instrument(name="dciwl") channels = ChannelList(dci, "ListElem", DummyChannel, snapshotable=False) for chan_name in ("A", "B", "C", "D", "E", "F"): channel = DummyChannel(dci, f"Chan{chan_name}", chan_name) channels.append(channel) dci.add_submodule(chan_name, channel) dci.add_submodule("channels", channels) try: yield dci finally: dci.close()
def _get_new_instance_kwargs(cls, parent: Instrument = None, **kwargs) -> dict: """ Find the smallest channel number not yet occupied. An optional keyword `greeting` is extracted from the kwargs. The default is "Hello" """ channels_str = parent.channel_catalog() existing_channels = [int(i) for i in channels_str.split(",")] new_channel = 1 while new_channel in existing_channels: new_channel += 1 new_kwargs = { "name": f"channel{new_channel}", "channel": new_channel, "greeting": kwargs.get("greeting", "Hello") } return new_kwargs
def __init__(self, name, acquisition_parameter=None, discriminant=None, silent=True, **kwargs): SettingsClass.__init__(self) MultiParameter.__init__(self, name, snapshot_value=False, **kwargs) if self.layout is None: try: MeasurementParameter.layout = Instrument.find_instrument( 'layout') except KeyError: logger.warning(f'No layout found for {self}') self.discriminant = discriminant self.silent = silent self.acquisition_parameter = acquisition_parameter self._meta_attrs.extend(['acquisition_parameter_name'])
# -*- coding: utf-8 -*- #%% Imports import os from qcodes import Instrument from instrumentserver.client import Client from instrumentserver.serialize import saveParamsToFile from instrumentserver.client import ProxyInstrument #%% Create all my instruments Instrument.close_all() ins_cli = Client() dummy_vna = ins_cli.create_instrument( 'instrumentserver.testing.dummy_instruments.rf.ResonatorResponse', 'dummy_vna') dummy_multichan = ins_cli.create_instrument( 'instrumentserver.testing.dummy_instruments.generic.DummyInstrumentWithSubmodule', 'dummy_multichan', ) pm = ins_cli.create_instrument( 'instrumentserver.params.ParameterManager', 'pm', ) #%% save the state saveParamsToFile([pm], os.path.abspath('./parameters.json')) #%% load pm settings from file
def f_to_parallelize_new(arglist): # cluster wants a list as an argument. # Below the various list items are assigned to their own variable fitted_stepresponse_ty = arglist['fitted_stepresponse_ty'] fluxlutman_args = arglist[ 'fluxlutman_args'] # see function return_instrument_args in czf noise_parameters_CZ_args = arglist[ 'noise_parameters_CZ_args'] # see function return_instrument_args in czf number = arglist['number'] adaptive_pars = arglist['adaptive_pars'] try: MC = Instrument.find_instrument('MC' + '{}'.format(number)) except KeyError: MC = mc.MeasurementControl('MC' + '{}'.format(number), live_plot_enabled=False) from qcodes import station station = station.Station() station.add_component(MC) MC.station = station fluxlutman = flm.AWG8_Flux_LutMan('fluxlutman' + '{}'.format(number)) station.add_component(fluxlutman) noise_parameters_CZ = npCZ.NoiseParametersCZ('noise_parameters_CZ' + '{}'.format(number)) station.add_component(noise_parameters_CZ) fluxlutman, noise_parameters_CZ = czf.return_instrument_from_arglist( fluxlutman, fluxlutman_args, noise_parameters_CZ, noise_parameters_CZ_args) d = CZ_trajectory_superoperator( fluxlutman=fluxlutman, noise_parameters_CZ=noise_parameters_CZ, fitted_stepresponse_ty=fitted_stepresponse_ty, qois=adaptive_pars.get('qois', 'all')) MC.set_detector_function(d) exp_metadata = { 'double sided': fluxlutman.czd_double_sided(), 'length': fluxlutman.cz_length(), 'distortions': noise_parameters_CZ.distortions(), 'T2_scaling': noise_parameters_CZ.T2_scaling(), 'sigma_q1': noise_parameters_CZ.sigma_q1(), 'sigma_q0': noise_parameters_CZ.sigma_q0() } if adaptive_pars['mode'] == 'adaptive': MC.set_sweep_functions([fluxlutman.cz_theta_f, fluxlutman.cz_lambda_2]) if adaptive_pars['uniform']: loss_per_triangle = adaptive.learner.learner2D.uniform_loss else: loss_per_triangle = None MC.set_adaptive_function_parameters({ 'adaptive_function': adaptive.Learner2D, 'loss_per_triangle': loss_per_triangle, 'goal': lambda l: l.npoints > adaptive_pars['n_points'], 'bounds': [(adaptive_pars['theta_f_min'], adaptive_pars['theta_f_max']), (adaptive_pars['lambda2_min'], adaptive_pars['lambda2_max'])] }) if noise_parameters_CZ.cluster(): dat = MC.run( '2D simulation_new_cluster2 double sided {} - length {:.1f} - distortions {} - waiting {:.2f} - T2_scaling {:.2f} - sigma_q1 {:.0f}, sigma_q0 {:.0f}' .format(fluxlutman.czd_double_sided(), fluxlutman.cz_length() * 1e9, noise_parameters_CZ.distortions(), noise_parameters_CZ.waiting_at_sweetspot(), noise_parameters_CZ.T2_scaling(), noise_parameters_CZ.sigma_q1() * 1e6, noise_parameters_CZ.sigma_q0() * 1e6), mode='adaptive', exp_metadata=exp_metadata) else: if adaptive_pars['long_name']: dat = MC.run( '2D simulation_new_2 double sided {} - length {:.1f} - distortions {} - T2_scaling {:.1f} - sigma_q1 {:.0f}, sigma_q0 {:.0f}' .format(fluxlutman.czd_double_sided(), fluxlutman.cz_length() * 1e9, noise_parameters_CZ.distortions(), noise_parameters_CZ.T2_scaling(), noise_parameters_CZ.sigma_q1() * 1e6, noise_parameters_CZ.sigma_q0() * 1e6), mode='adaptive', exp_metadata=exp_metadata) else: dat = MC.run('2D simulation_new_2', exp_metadata=exp_metadata, mode='adaptive') elif adaptive_pars['mode'] == '1D': MC.set_sweep_functions([fluxlutman.cz_theta_f]) MC.set_sweep_points( np.linspace(adaptive_pars['theta_f_min'], adaptive_pars['theta_f_max'], adaptive_pars['n_points'])) if noise_parameters_CZ.cluster(): dat = MC.run( '1D simulation_new_cluster2 double sided {} - length {:.1f} - distortions {} - T2_scaling {:.1f} - sigma_q1 {:.0f}, sigma_q0 {:.0f}' .format(fluxlutman.czd_double_sided(), fluxlutman.cz_length() * 1e9, noise_parameters_CZ.distortions(), noise_parameters_CZ.T2_scaling(), noise_parameters_CZ.sigma_q1() * 1e6, noise_parameters_CZ.sigma_q0() * 1e6), mode='1D', exp_metadata=exp_metadata) else: if adaptive_pars['long_name']: dat = MC.run( '1D simulation_new_2 double sided {} - length {:.1f} - distortions {} - T2_scaling {:.1f} - sigma_q1 {:.0f}, sigma_q0 {:.0f}' .format(fluxlutman.czd_double_sided(), fluxlutman.cz_length() * 1e9, noise_parameters_CZ.distortions(), noise_parameters_CZ.T2_scaling(), noise_parameters_CZ.sigma_q1() * 1e6, noise_parameters_CZ.sigma_q0() * 1e6), mode='1D', exp_metadata=exp_metadata) else: dat = MC.run('1D simulation_new_2', exp_metadata=exp_metadata, mode='1D') if adaptive_pars['mode'] == 'cma_optimizer': MC.set_sweep_functions([fluxlutman.cz_theta_f, fluxlutman.cz_lambda_2]) if adaptive_pars['uniform']: loss_per_triangle = adaptive.learner.learner2D.uniform_loss else: loss_per_triangle = None MC.set_adaptive_function_parameters({ 'adaptive_function': cma.fmin, 'x0': adaptive_pars['x0'], 'sigma0': adaptive_pars['sigma0'], # options for the CMA algorithm can be found using # "cma.CMAOptions()" 'options': { 'maxfevals': adaptive_pars['n_points'], # maximum function cals # Scaling for individual sigma's 'cma_stds': [5, 6, 3], 'ftarget': 0.005 }, # Target function value }) if noise_parameters_CZ.cluster(): dat = MC.run( '2D simulation_new_cluster2 double sided {} - length {:.1f} - waiting {:.2f} - T2_scaling {:.2f} - sigma_q1 {:.0f}, sigma_q0 {:.0f}' .format(fluxlutman.czd_double_sided(), fluxlutman.cz_length() * 1e9, noise_parameters_CZ.waiting_at_sweetspot(), noise_parameters_CZ.T2_scaling(), noise_parameters_CZ.sigma_q1() * 1e6, noise_parameters_CZ.sigma_q0() * 1e6), mode='adaptive', exp_metadata=exp_metadata) else: if adaptive_pars['long_name']: dat = MC.run( '2D simulation_new_2 double sided {} - length {:.1f} - distortions {} - T2_scaling {:.1f} - sigma_q1 {:.0f}, sigma_q0 {:.0f}' .format(fluxlutman.czd_double_sided(), fluxlutman.cz_length() * 1e9, noise_parameters_CZ.distortions(), noise_parameters_CZ.T2_scaling(), noise_parameters_CZ.sigma_q1() * 1e6, noise_parameters_CZ.sigma_q0() * 1e6), mode='adaptive', exp_metadata=exp_metadata) else: dat = MC.run('2D simulation_new_2', exp_metadata=exp_metadata, mode='adaptive') fluxlutman.close() noise_parameters_CZ.close() MC.close()
def f_to_parallelize_new(arglist): # cluster wants a list as an argument. # Below the various list items are assigned to their own variable fitted_stepresponse_ty = arglist['fitted_stepresponse_ty'] fluxlutman_args = arglist[ 'fluxlutman_args'] # see function return_instrument_args in czf noise_parameters_CZ_args = arglist[ 'noise_parameters_CZ_args'] # see function return_instrument_args in czf number = arglist['number'] adaptive_pars = arglist['adaptive_pars'] try: MC = Instrument.find_instrument('MC' + '{}'.format(number)) except KeyError: MC = mc.MeasurementControl('MC' + '{}'.format(number), live_plot_enabled=False) from qcodes import station station = station.Station() station.add_component(MC) MC.station = station fluxlutman = flm.AWG8_Flux_LutMan('fluxlutman' + '{}'.format(number)) station.add_component(fluxlutman) noise_parameters_CZ = npCZ.NoiseParametersCZ('noise_parameters_CZ' + '{}'.format(number)) station.add_component(noise_parameters_CZ) fluxlutman, noise_parameters_CZ = czf.return_instrument_from_arglist( fluxlutman, fluxlutman_args, noise_parameters_CZ, noise_parameters_CZ_args) d = CZ_trajectory_superoperator( fluxlutman=fluxlutman, noise_parameters_CZ=noise_parameters_CZ, fitted_stepresponse_ty=fitted_stepresponse_ty, qois=adaptive_pars.get('qois', 'all')) MC.set_detector_function(d) exp_metadata = { 'double sided': fluxlutman.czd_double_sided(), 'length': fluxlutman.cz_length(), 'distortions': noise_parameters_CZ.distortions(), 'T2_scaling': noise_parameters_CZ.T2_scaling(), 'sigma_q1': noise_parameters_CZ.sigma_q1(), 'sigma_q0': noise_parameters_CZ.sigma_q0() } if adaptive_pars['mode'] == 'adaptive': MC.set_sweep_functions([fluxlutman.cz_theta_f, fluxlutman.cz_lambda_2]) if adaptive_pars['uniform']: loss_per_triangle = adaptive.learner.learner2D.uniform_loss else: loss_per_triangle = None MC.set_adaptive_function_parameters({ 'adaptive_function': adaptive.Learner2D, 'loss_per_triangle': loss_per_triangle, 'goal': lambda l: l.npoints > adaptive_pars['n_points'], 'bounds': [(adaptive_pars['theta_f_min'], adaptive_pars['theta_f_max']), (adaptive_pars['lambda2_min'], adaptive_pars['lambda2_max'])] }) if noise_parameters_CZ.cluster(): dat = MC.run( '2D simulation_new_cluster2 double sided {} - length {:.0f} - distortions {} - T2_scaling {:.1f} - sigma_q1 {:.0f}, sigma_q0 {:.0f}' .format(fluxlutman.czd_double_sided(), fluxlutman.cz_length() * 1e9, noise_parameters_CZ.distortions(), noise_parameters_CZ.T2_scaling(), noise_parameters_CZ.sigma_q1() * 1e6, noise_parameters_CZ.sigma_q0() * 1e6), mode='adaptive', exp_metadata=exp_metadata) else: if adaptive_pars['long_name']: dat = MC.run( '2D simulation_new_2 double sided {} - length {:.0f} - distortions {} - T2_scaling {:.1f} - sigma_q1 {:.0f}, sigma_q0 {:.0f}' .format(fluxlutman.czd_double_sided(), fluxlutman.cz_length() * 1e9, noise_parameters_CZ.distortions(), noise_parameters_CZ.T2_scaling(), noise_parameters_CZ.sigma_q1() * 1e6, noise_parameters_CZ.sigma_q0() * 1e6), mode='adaptive', exp_metadata=exp_metadata) else: dat = MC.run('2D simulation_new_2', exp_metadata=exp_metadata, mode='adaptive') elif adaptive_pars['mode'] == '1D': MC.set_sweep_functions([fluxlutman.cz_theta_f]) MC.set_sweep_points( np.linspace(adaptive_pars['theta_f_min'], adaptive_pars['theta_f_max'], adaptive_pars['n_points'])) if noise_parameters_CZ.cluster(): dat = MC.run( '1D simulation_new_cluster2 double sided {} - length {:.0f} - distortions {} - T2_scaling {:.1f} - sigma_q1 {:.0f}, sigma_q0 {:.0f}' .format(fluxlutman.czd_double_sided(), fluxlutman.cz_length() * 1e9, noise_parameters_CZ.distortions(), noise_parameters_CZ.T2_scaling(), noise_parameters_CZ.sigma_q1() * 1e6, noise_parameters_CZ.sigma_q0() * 1e6), mode='1D', exp_metadata=exp_metadata) else: if adaptive_pars['long_name']: dat = MC.run( '1D simulation_new_2 double sided {} - length {:.0f} - distortions {} - T2_scaling {:.1f} - sigma_q1 {:.0f}, sigma_q0 {:.0f}' .format(fluxlutman.czd_double_sided(), fluxlutman.cz_length() * 1e9, noise_parameters_CZ.distortions(), noise_parameters_CZ.T2_scaling(), noise_parameters_CZ.sigma_q1() * 1e6, noise_parameters_CZ.sigma_q0() * 1e6), mode='1D', exp_metadata=exp_metadata) else: dat = MC.run('1D simulation_new_2', exp_metadata=exp_metadata, mode='1D') elif adaptive_pars['mode'] == 'spectral_tomo': MC.set_sweep_functions([noise_parameters_CZ.T1_q0]) MC.set_sweep_points( np.logspace(adaptive_pars['theta_f_min'], adaptive_pars['theta_f_max'], adaptive_pars['n_points'])) if noise_parameters_CZ.cluster(): dat = MC.run( '1D sim_spectral_tomo double sided {} - length {:.0f} - distortions {} - T2_scaling {:.1f} - sigma_q1 {:.0f}, sigma_q0 {:.0f}' .format(fluxlutman.czd_double_sided(), fluxlutman.cz_length() * 1e9, noise_parameters_CZ.distortions(), noise_parameters_CZ.T2_scaling(), noise_parameters_CZ.sigma_q1() * 1e6, noise_parameters_CZ.sigma_q0() * 1e6), mode='1D', exp_metadata=exp_metadata) else: if adaptive_pars['long_name']: dat = MC.run( '1D sim_spectral_tomo double sided {} - length {:.0f} - distortions {} - T2_scaling {:.1f} - sigma_q1 {:.0f}, sigma_q0 {:.0f}' .format(fluxlutman.czd_double_sided(), fluxlutman.cz_length() * 1e9, noise_parameters_CZ.distortions(), noise_parameters_CZ.T2_scaling(), noise_parameters_CZ.sigma_q1() * 1e6, noise_parameters_CZ.sigma_q0() * 1e6), mode='1D', exp_metadata=exp_metadata) else: dat = MC.run('1D sim_spectral_tomo', exp_metadata=exp_metadata, mode='1D') elif adaptive_pars['mode'] == 'spectral_tomo_nonmarkovian': MC.set_sweep_functions([noise_parameters_CZ.repetitions]) MC.set_sweep_points(np.arange(0, adaptive_pars['n_points'], 1)) if noise_parameters_CZ.cluster(): dat = MC.run( '1D sim_spectral_tomo_nonmarkovian double sided {} - length {:.0f} - distortions {} - T2_scaling {:.1f} - sigma_q1 {:.0f}, sigma_q0 {:.0f}' .format(fluxlutman.czd_double_sided(), fluxlutman.cz_length() * 1e9, noise_parameters_CZ.distortions(), noise_parameters_CZ.T2_scaling(), noise_parameters_CZ.sigma_q1() * 1e6, noise_parameters_CZ.sigma_q0() * 1e6), mode='1D', exp_metadata=exp_metadata) else: if adaptive_pars['long_name']: dat = MC.run( '1D sim_spectral_tomo_nonmarkovian double sided {} - length {:.0f} - distortions {} - T2_scaling {:.1f} - sigma_q1 {:.0f}, sigma_q0 {:.0f}' .format(fluxlutman.czd_double_sided(), fluxlutman.cz_length() * 1e9, noise_parameters_CZ.distortions(), noise_parameters_CZ.T2_scaling(), noise_parameters_CZ.sigma_q1() * 1e6, noise_parameters_CZ.sigma_q0() * 1e6), mode='1D', exp_metadata=exp_metadata) else: dat = MC.run('1D sim_spectral_tomo_nonmarkovian', exp_metadata=exp_metadata, mode='1D') elif adaptive_pars['mode'] == 'time_series': MC.set_sweep_functions( [noise_parameters_CZ.detuning] ) # random sweep function never used in this file. Put it just because I need to put one MC.set_sweep_points(np.array([-1])) if noise_parameters_CZ.cluster(): dat = MC.run( '1D time_series_cluster double sided {} - length {:.0f} - sigma_q0 {:.0f}' .format(fluxlutman.czd_double_sided(), fluxlutman.cz_length() * 1e9, noise_parameters_CZ.sigma_q0() * 1e6), mode='1D', exp_metadata=exp_metadata) else: if adaptive_pars['long_name']: dat = MC.run( '1D time_series double sided {} - length {:.0f} - sigma_q0 {:.0f}' .format(fluxlutman.czd_double_sided(), fluxlutman.cz_length() * 1e9, noise_parameters_CZ.sigma_q0() * 1e6), mode='1D', exp_metadata=exp_metadata) else: dat = MC.run('1D time_series', exp_metadata=exp_metadata, mode='1D') fluxlutman.close() noise_parameters_CZ.close() MC.close()
def f_to_parallelize_v2(arglist): # cluster wants a list as an argument. # Below the various list items are assigned to their own variable fitted_stepresponse_ty = arglist["fitted_stepresponse_ty"] fluxlutman_args = arglist[ "fluxlutman_args"] # see function return_instrument_args in czf_v2 fluxlutman_static_args = arglist[ "fluxlutman_static_args"] # see function return_instrument_args in czf_v2 sim_control_CZ_args = arglist[ "sim_control_CZ_args"] # see function return_instrument_args in czf_v2 number = arglist["number"] adaptive_pars = arglist["adaptive_pars"] additional_pars = arglist["additional_pars"] live_plot_enabled = arglist["live_plot_enabled"] exp_metadata = arglist["exp_metadata"] #which_gate = arglist["which_gate"] try: MC = Instrument.find_instrument("MC" + "{}".format(number)) except KeyError: MC = mc.MeasurementControl("MC" + "{}".format(number), live_plot_enabled=live_plot_enabled) from qcodes import station station = station.Station() station.add_component(MC) MC.station = station fluxlutman = flm.HDAWG_Flux_LutMan("fluxlutman" + "{}".format(number)) station.add_component(fluxlutman) fluxlutman_static = flm.HDAWG_Flux_LutMan("fluxlutman_static" + "{}".format(number)) station.add_component(fluxlutman_static) sim_control_CZ = scCZ_v2.SimControlCZ_v2("sim_control_CZ" + "{}".format(number)) station.add_component(sim_control_CZ) fluxlutman = czf_v2.return_instrument_from_arglist_v2( fluxlutman, fluxlutman_args) fluxlutman_static = czf_v2.return_instrument_from_arglist_v2( fluxlutman_static, fluxlutman_static_args) sim_control_CZ = czf_v2.return_instrument_from_arglist_v2( sim_control_CZ, sim_control_CZ_args) sim_control_CZ.set_cost_func() which_gate = sim_control_CZ.which_gate() d = CZ_trajectory_superoperator( fluxlutman=fluxlutman, fluxlutman_static=fluxlutman_static, sim_control_CZ=sim_control_CZ, fitted_stepresponse_ty=fitted_stepresponse_ty, qois=additional_pars['qois'], ) MC.set_detector_function(d) if exp_metadata["mode"] == "adaptive": MC.set_sweep_functions([ getattr(fluxlutman, "vcz_amp_sq_{}".format(which_gate)), getattr(fluxlutman, "vcz_amp_fine_{}".format(which_gate)), ]) MC.set_adaptive_function_parameters(adaptive_pars) if sim_control_CZ.cluster(): dat = MC.run( additional_pars["label"] + "_cluster", mode="adaptive", exp_metadata=exp_metadata, ) else: if additional_pars["long_name"]: dat = MC.run( additional_pars["label"], mode="adaptive", exp_metadata=exp_metadata, ) else: dat = MC.run( "2D_simulations_v2", mode="adaptive", exp_metadata=exp_metadata, ) elif exp_metadata["mode"] == "contour_scan": from pycqed.analysis_v2.tools import contours2d as c2d from pycqed.measurement import sweep_functions as swf timestamp = sim_control_CZ.timestamp_for_contour() coha_for_contour = ma2.Conditional_Oscillation_Heatmap_Analysis( t_start=timestamp, t_stop=timestamp, close_figs=True, extract_only=False, plt_orig_pnts=True, plt_contour_L1=False, plt_contour_phase=True, plt_optimal_values=True, plt_optimal_values_max=1, find_local_optimals=True, plt_clusters=False, cluster_from_interp=False, clims={ "Cost func": [0., 100], "missing fraction": [0, 30], "offset difference": [0, 30] }, target_cond_phase=180, phase_thr=15, L1_thr=5, clustering_thr=0.15, gen_optima_hulls=True, hull_L1_thr=10, hull_phase_thr=20, plt_optimal_hulls=True, save_cond_phase_contours=[180], ) c_180 = coha_for_contour.proc_data_dict["quantities_of_interest"][ "cond_phase_contours"]["180"]["0"] hull = coha_for_contour.proc_data_dict["quantities_of_interest"][ "hull_vertices"]["0"] c_180_in_hull = c2d.pnts_in_hull(pnts=c_180, hull=hull) if c_180_in_hull[0][0] > c_180_in_hull[-1][0]: c_180_in_hull = np.flip(c_180_in_hull, axis=0) swf_2d_contour = swf.SweepAlong2DContour( getattr(fluxlutman, "vcz_amp_sq_{}".format(which_gate)), getattr(fluxlutman, "vcz_amp_fine_{}".format(which_gate)), c_180_in_hull) MC.set_sweep_function(swf_2d_contour) MC.set_sweep_points(np.linspace(0, 1, 40)) if sim_control_CZ.cluster(): dat = MC.run( additional_pars["label"] + "_cluster", mode="1D", exp_metadata=exp_metadata, ) else: if additional_pars["long_name"]: dat = MC.run( additional_pars["label"], mode="1D", exp_metadata=exp_metadata, ) else: dat = MC.run( "contour_scan", mode="1D", exp_metadata=exp_metadata, ) elif exp_metadata["mode"] == "fluxbias_scan": MC.set_sweep_function(getattr(sim_control_CZ, "fluxbias_mean")) MC.set_sweep_points(np.arange(-3000e-6, 3001e-6, 50e-6)) if sim_control_CZ.cluster(): dat = MC.run( additional_pars["label"] + "_cluster", mode="1D", exp_metadata=exp_metadata, ) else: if additional_pars["long_name"]: dat = MC.run( additional_pars["label"], mode="1D", exp_metadata=exp_metadata, ) else: dat = MC.run( "contour_scan", mode="1D", exp_metadata=exp_metadata, ) elif exp_metadata["mode"] == "fluxbias_scan_q1": MC.set_sweep_function(getattr(sim_control_CZ, "fluxbias_mean_q1")) MC.set_sweep_points(np.arange(20000e-6, 30001e-6, 10000e-6)) if sim_control_CZ.cluster(): dat = MC.run( additional_pars["label"] + "_cluster", mode="1D", exp_metadata=exp_metadata, ) else: if additional_pars["long_name"]: dat = MC.run( additional_pars["label"], mode="1D", exp_metadata=exp_metadata, ) else: dat = MC.run( "contour_scan", mode="1D", exp_metadata=exp_metadata, ) fluxlutman.close() fluxlutman_static.close() sim_control_CZ.close() MC.close()
def close_all_instruments(): """Makes sure that after startup and teardown all instruments are closed""" Instrument.close_all() yield Instrument.close_all()
def f_to_parallelize_v2(arglist): # cluster wants a list as an argument. # Below the various list items are assigned to their own variable fitted_stepresponse_ty = arglist["fitted_stepresponse_ty"] fluxlutman_args = arglist[ "fluxlutman_args"] # see function return_instrument_args in czf_v2 fluxlutman_static_args = arglist[ "fluxlutman_static_args"] # see function return_instrument_args in czf_v2 sim_control_CZ_args = arglist[ "sim_control_CZ_args"] # see function return_instrument_args in czf_v2 number = arglist["number"] additional_pars = arglist["additional_pars"] live_plot_enabled = arglist["live_plot_enabled"] exp_metadata = arglist["exp_metadata"] #which_gate = arglist["which_gate"] try: MC = Instrument.find_instrument("MC" + "{}".format(number)) except KeyError: MC = mc.MeasurementControl("MC" + "{}".format(number), live_plot_enabled=live_plot_enabled) from qcodes import station station = station.Station() station.add_component(MC) MC.station = station fluxlutman = flm.HDAWG_Flux_LutMan("fluxlutman" + "{}".format(number)) station.add_component(fluxlutman) fluxlutman_static = flm.HDAWG_Flux_LutMan("fluxlutman_static" + "{}".format(number)) station.add_component(fluxlutman_static) sim_control_CZ = scCZ_v2.SimControlCZ_v2("sim_control_CZ" + "{}".format(number)) station.add_component(sim_control_CZ) fluxlutman = czf_v2.return_instrument_from_arglist_v2( fluxlutman, fluxlutman_args) fluxlutman_static = czf_v2.return_instrument_from_arglist_v2( fluxlutman_static, fluxlutman_static_args) sim_control_CZ = czf_v2.return_instrument_from_arglist_v2( sim_control_CZ, sim_control_CZ_args) sim_control_CZ.set_cost_func() which_gate = sim_control_CZ.which_gate() d = Ramsey_experiment( fluxlutman=fluxlutman, fluxlutman_static=fluxlutman_static, sim_control_CZ=sim_control_CZ, fitted_stepresponse_ty=fitted_stepresponse_ty, qois="all", ) MC.set_detector_function(d) if additional_pars["mode"] == "1D_ramsey": MC.set_sweep_functions([sim_control_CZ.scanning_time]) MC.set_sweep_points( np.arange(0, additional_pars['max_time'], additional_pars['time_step'])) if sim_control_CZ.cluster(): dat = MC.run( "1D ramsey_v2_cluster double sided {} - sigma_q0 {:.0f} - detuning {:.0f}" .format(sim_control_CZ.get("czd_double_sided"), sim_control_CZ.sigma_q0() * 1e6, sim_control_CZ.detuning() / 1e6), mode="1D", exp_metadata=exp_metadata, ) else: if additional_pars["long_name"]: dat = MC.run( "1D ramsey_v2 double sided {} - sigma_q0 {:.0f} - detuning {:.0f}" .format(sim_control_CZ.get("czd_double_sided"), sim_control_CZ.sigma_q0() * 1e6, sim_control_CZ.detuning() / 1e6), mode="1D", exp_metadata=exp_metadata, ) else: dat = MC.run("1D ramsey_v2", exp_metadata=exp_metadata, mode="1D") fluxlutman.close() fluxlutman_static.close() sim_control_CZ.close() MC.close()