qcodes.station

Station objects - collect all the equipment you use to do an experiment.

Functions:

Exceptions:

ValidationWarning

Replacement for jsonschema.error.ValidationError as warning.

Classes:

StationConfig

Station(*components[, config_file, ...])

A representation of the entire physical setup.

qcodes.station.get_config_enable_forced_reconnect() bool[source]
qcodes.station.get_config_default_folder() str | None[source]
qcodes.station.get_config_default_file() str | None[source]
qcodes.station.get_config_use_monitor() str | None[source]
exception qcodes.station.ValidationWarning[source]

Bases: Warning

Replacement for jsonschema.error.ValidationError as warning.

Methods:

add_note

Exception.add_note(note) -- add a note to the exception

with_traceback

Exception.with_traceback(tb) -- set self.__traceback__ to tb and return self.

Attributes:

add_note()

Exception.add_note(note) – add a note to the exception

args
with_traceback()

Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.

class qcodes.station.StationConfig[source]

Bases: dict[Any, Any]

Methods:

snapshot([update])

clear()

copy()

fromkeys([value])

Create a new dictionary with keys from iterable and values set to value.

get(key[, default])

Return the value for key if key is in the dictionary, else default.

items()

keys()

pop(k[,d])

If the key is not found, return the default if given; otherwise, raise a KeyError.

popitem()

Remove and return a (key, value) pair as a 2-tuple.

setdefault(key[, default])

Insert key with a value of default if key is not in the dictionary.

update([E, ]**F)

If E is present and has a .keys() method, then does: for k in E: D[k] = E[k] If E is present and lacks a .keys() method, then does: for k, v in E: D[k] = v In either case, this is followed by: for k in F: D[k] = F[k]

values()

snapshot(update: bool = True) StationConfig[source]
clear() None.  Remove all items from D.
copy() a shallow copy of D
fromkeys(value=None, /)

Create a new dictionary with keys from iterable and values set to value.

get(key, default=None, /)

Return the value for key if key is in the dictionary, else default.

items() a set-like object providing a view on D's items
keys() a set-like object providing a view on D's keys
pop(k[, d]) v, remove specified key and return the corresponding value.

If the key is not found, return the default if given; otherwise, raise a KeyError.

popitem()

Remove and return a (key, value) pair as a 2-tuple.

Pairs are returned in LIFO (last-in, first-out) order. Raises KeyError if the dict is empty.

setdefault(key, default=None, /)

Insert key with a value of default if key is not in the dictionary.

Return the value for key if key is in the dictionary, else default.

update([E, ]**F) None.  Update D from dict/iterable E and F.

If E is present and has a .keys() method, then does: for k in E: D[k] = E[k] If E is present and lacks a .keys() method, then does: for k, v in E: D[k] = v In either case, this is followed by: for k in F: D[k] = F[k]

values() an object providing a view on D's values
class qcodes.station.Station(*components: MetadatableWithName, config_file: str | Sequence[str] | None = None, use_monitor: bool | None = None, default: bool = True, update_snapshot: bool = True, **kwargs: Any)[source]

Bases: Metadatable, DelegateAttributes

A representation of the entire physical setup.

Lists all the connected Components and the current default measurement (a list of actions).

Parameters:
  • *components – components to add immediately to the Station. Can be added later via self.add_component.

  • config_file

    Path to YAML files to load the station config from.

    • If only one yaml file needed to be loaded, it should be passed as a string, e.g., ‘~/station.yaml’

    • If more than one yaml file needed, they should be supplied as a sequence of strings, e.g. [‘~/station1.yaml’, ‘~/station2.yaml’]

  • use_monitor – Should the QCoDeS monitor be activated for this station.

  • default – Is this station the default?

  • update_snapshot – Immediately update the snapshot of each component as it is added to the Station.

Attributes:

default

Class attribute to store the default station.

delegate_attr_dicts

A list of names (strings) of dictionaries which are (or will be) attributes of self, whose keys should be treated as attributes of self.

config

A user dict representing the YAML file that the station was loaded from

delegate_attr_objects

A list of names (strings) of objects which are (or will be) attributes of self, whose attributes should be passed through to self.

omit_delegate_attrs

A list of attribute names (strings) to not delegate to any other dictionary or object.

Methods:

snapshot_base([update, params_to_skip_update])

State of the station as a JSON-compatible dictionary (everything that the custom JSON encoder class NumpyJSONEncoder supports).

add_component(component[, name, update_snapshot])

Record one component as part of this Station.

remove_component(name)

Remove a component with a given name from this Station.

get_component(full_name)

Get a (sub)component with a given name from this Station.

__getitem__(key)

Shortcut to components dictionary.

close_all_registered_instruments()

Closes all instruments that are registered to this Station object by calling the base.Instrument.close()-method on each one.

load_config_file([filename])

Loads a configuration from a YAML file.

load_config_files(*filenames)

Loads configuration from multiple YAML files after merging them into one.

load_config(config)

Loads a configuration from a supplied string or file/stream handle.

close_and_remove_instrument(instrument)

Safely close instrument and remove from station and monitor list.

load_metadata(metadata)

Load metadata into this classes metadata dictionary.

snapshot([update])

Decorate a snapshot dictionary with metadata.

load_instrument(identifier[, ...])

Creates an Instrument instance as described by the loaded configuration file.

load_all_instruments()

Load all instruments specified in the loaded YAML station configuration.

default: Station | None = None

Class attribute to store the default station.

delegate_attr_dicts: ClassVar[list[str]] = ['components']

A list of names (strings) of dictionaries which are (or will be) attributes of self, whose keys should be treated as attributes of self.

config: StationConfig | None = None

A user dict representing the YAML file that the station was loaded from

components: dict[str, MetadatableWithName]
snapshot_base(update: bool | None = True, params_to_skip_update: Sequence[str] | None = None) dict[Any, Any][source]

State of the station as a JSON-compatible dictionary (everything that the custom JSON encoder class NumpyJSONEncoder supports).

Note: If the station contains an instrument that has already been closed, not only will it not be snapshotted, it will also be removed from the station during the execution of this function.

Parameters:
  • update – If True, update the state by querying the all the children: f.ex. instruments, parameters, components, etc. If None only update if the state is known to be invalid. If False, just use the latest values in memory and never update the state.

  • params_to_skip_update – Not used.

Returns:

Base snapshot.

Return type:

dict

add_component(component: MetadatableWithName, name: str | None = None, update_snapshot: bool = True) str[source]

Record one component as part of this Station.

Parameters:
  • component – Components to add to the Station.

  • name – Name of the component.

  • update_snapshot – Immediately update the snapshot of each component as it is added to the Station.

Returns:

The name assigned this component, which may have been changed

to make it unique among previously added components.

Return type:

str

remove_component(name: str) MetadatableWithName | None[source]

Remove a component with a given name from this Station.

Parameters:

name – Name of the component.

Returns:

The component that has been removed (this behavior is the same as for Python dictionaries).

Raises:

KeyError – If a component with the given name is not part of this station.

get_component(full_name: str) MetadatableWithName[source]

Get a (sub)component with a given name from this Station. The name may be of a component that is a sub-component of another component, e.g. a parameter on an instrument, an instrument module or an top-level instrument.

Parameters:

full_name – Name of the component.

Returns:

The component with the given name.

Raises:

KeyError – If a component with the given name is not part of this station.

__getitem__(key: str) Metadatable[source]

Shortcut to components dictionary.

close_all_registered_instruments() None[source]

Closes all instruments that are registered to this Station object by calling the base.Instrument.close()-method on each one. The instruments will be removed from the station and from the QCoDeS monitor.

load_config_file(filename: str | None = None) None[source]

Loads a configuration from a YAML file. If filename is not specified the default file name from the qcodes configuration will be used.

Loading of a configuration will update the snapshot of the station and make the instruments described in the config file available for instantiation with the load_instrument() method.

Additionally the shortcut methods load_<instrument_name> will be updated.

load_config_files(*filenames: str) None[source]

Loads configuration from multiple YAML files after merging them into one. If filenames are not specified the default file name from the qcodes configuration will be used.

Loading of configuration will update the snapshot of the station and make the instruments described in the config files available for instantiation with the load_instrument() method.

Additionally the shortcut methods load_<instrument_name> will be updated.

load_config(config: str | IO) None[source]

Loads a configuration from a supplied string or file/stream handle. The string or file/stream is expected to be YAML formatted

Loading of a configuration will update the snapshot of the station and make the instruments described in the config file available for instantiation with the load_instrument() method.

Additionally the shortcut methods load_<instrument_name> will be updated.

close_and_remove_instrument(instrument: Instrument | str) None[source]

Safely close instrument and remove from station and monitor list.

delegate_attr_objects: ClassVar[list[str]] = []

A list of names (strings) of objects which are (or will be) attributes of self, whose attributes should be passed through to self.

load_metadata(metadata: Mapping[str, Any]) None

Load metadata into this classes metadata dictionary.

Parameters:

metadata – Metadata to load.

omit_delegate_attrs: ClassVar[list[str]] = []

A list of attribute names (strings) to not delegate to any other dictionary or object.

snapshot(update: bool | None = False) dict[str, Any]

Decorate a snapshot dictionary with metadata. DO NOT override this method if you want metadata in the snapshot instead, override snapshot_base().

Parameters:

update – Passed to snapshot_base.

Returns:

Base snapshot.

metadata: dict[str, Any]
load_instrument(identifier: str, revive_instance: bool = False, update_snapshot: bool = True, **kwargs: Any) Instrument[source]

Creates an Instrument instance as described by the loaded configuration file.

Parameters:
  • identifier – The identifying 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.

  • update_snapshot – Immediately update the snapshot of the instrument as it is added to the Station.

  • **kwargs – Additional keyword arguments that get passed on to the __init__-method of the instrument to be added.

load_all_instruments(only_names: None, only_types: Iterable[str]) tuple[str, ...][source]
load_all_instruments(only_names: Iterable[str], only_types: None) tuple[str, ...]
load_all_instruments(only_names: None, only_types: None) tuple[str, ...]
load_all_instruments(only_names: Iterable[str], only_types: Iterable[str]) NoReturn

Load all instruments specified in the loaded YAML station configuration.

Optionally, the instruments to be loaded can be filtered by their names or types, use only_names and only_types arguments for that. It is an error to supply both only_names and only_types.

Parameters:
  • only_names – List of instrument names to load from the config. If left as None, then all instruments are loaded.

  • only_types – List of instrument types e.g. the class names of the instruments to load. If left as None, then all instruments are loaded.

Returns:

The names of the loaded instruments

qcodes.station.update_config_schema(additional_instrument_modules: list[ModuleType] | None = None) None[source]

Update the json schema file ‘station.schema.json’.

Parameters:

additional_instrument_modules – python modules that contain qcodes.instrument.base.InstrumentBase definitions (and subclasses thereof) to be included as values for instrument definition in the station definition yaml files.