nanotune.tuningstages.base_tasks

nanotune.tuningstages.base_tasks.save_machine_learning_result(run_id: int, ml_result: Dict[str, Any], meta_tag: str = 'nanotune_metadata') None[source]

Saves a classification result such as quality or regime to metadata.

Parameters
  • run_id – QCoDeS data run ID.

  • result_type – Specifies which classification result is being saved. Currently either quality or regime, saved for example as ‘predicted_quality’ or ‘predicted_regime’.

  • result – The classification result.

  • meta_tag – Tag under which metadata is saved. Used in QCoDeS’ dataset.add_metadata method.

nanotune.tuningstages.base_tasks.check_measurement_quality(classifier: Classifier, run_id: int, db_name: Optional[str] = None, db_folder: Optional[str] = None) bool[source]

Applies supplied classifer to determine a measurement’s quality.

Parameters
  • classifier – Pretrained classifier to use for quality prediction.

  • run_id – QCoDeS data run ID.

  • db_name – Name of database where dataset is saved.

  • db_folder – Path to folder containing database db_name.

Returns

bool – Predicted measurement quality.

nanotune.tuningstages.base_tasks.save_extracted_features(fit_class: Type[DataFit], run_id: int, db_name: str, db_folder: Optional[str]) None[source]

Performs a data fit and saves extracted features into metadata of the QCoDeS dataset.

Parameters
  • fit_class

  • run_id – QCoDeS data run ID.

  • db_name – Database name where the dataset in question is located.

  • db_folder – Path to folder containing database db_name.

nanotune.tuningstages.base_tasks.get_extracted_features(fit_class: Type[DataFit], run_id: int, db_name: str, db_folder: Optional[str]) Dict[str, Any][source]

Performs a data fit and returns the extracted features.

Parameters
  • fit_class

  • run_id – QCoDeS data run ID.

  • db_name – Database name where the dataset in question is located.

  • db_folder – Path to folder containing database db_name.

Returns

dict – Extracted features.

nanotune.tuningstages.base_tasks.get_measurement_features(run_id: int, db_name: str, db_folder: Optional[str]) Dict[str, Any][source]

Loads data into a nanotune Dataset and returns features previously saved to metadata.

Parameters
  • run_id – QCoDeS data run ID.

  • db_name – Database name where the dataset in question is located.

  • db_folder – Path to folder containing database db_name.

Returns

Features

Return type

dict

nanotune.tuningstages.base_tasks.set_up_gates_for_measurement(parameters_to_sweep: List[Parameter], setpoints: Sequence[Sequence[float]]) Generator[None, None, None][source]

Context manager setting up gates before a measurement. It ramps them to their first setpoint before deactivating ramping (if supported) and yields a generator. At the end, typically after a measurement, ramping is activated again. If the input parameters do not belong to a nanotune Gate, ramping is not deactivated.

Parameters
  • parameters_to_sweep – Voltage parameters of gates which are to be swept

  • measurement. (in the) –

  • setpoints – Measurement setpoints.

Returns

generator yielding None

nanotune.tuningstages.base_tasks.set_post_delay(parameters: List[Parameter], post_delay: Union[float, List[float]]) None[source]

Set qc.Parameter post delay. Can be used before a measurement to set a waiting time after a voltage has been set to ensure the electron gas settles before taking a measurement point.

Parameters
  • parameters – List of QCoDeS parameters.

  • post_delay – Post delay to set. Single value input if all parameters should have the set post_delay, list of values if they require different values.

nanotune.tuningstages.base_tasks.swap_range_limits_if_needed(current_voltages: Sequence[float], current_valid_ranges: Sequence[Sequence[float]]) Sequence[Sequence[float]][source]

Saw start and end points of a sweep depending on the current voltages set on gates. To save time and avoid unnecessary ramping. Order of current_voltages and current_valid_ranges has to match, i.e. the voltage value and range at a particular index come from the same voltage parameter/gate.

Parameters
  • current_voltages – List of voltages currently set to the voltage parameters/gates of interest.

  • current_valid_ranges – Current voltages ranges to sweep.

Returns

list – Voltage ranges to sweep.

nanotune.tuningstages.base_tasks.compute_linear_setpoints(ranges: Sequence[Sequence[float]], voltage_precision: float) Sequence[Sequence[float]][source]

Computes linear setpoints the number of points we based on a voltage_precision as opposed to a fixed number of points. Useful to ensure a minimum resolution required for ML purposes.

Parameters

ranges – Voltage ranges for all voltage parameters/gates to sweep.

Returns

list – Linearly spaced setpoints.

nanotune.tuningstages.base_tasks.prepare_metadata(device_name: str, normalization_constants: NormalizationConstants, readout_methods: Readout) Dict[str, Any][source]

Sets up a metadata dictionary with fields known prior to a measurement set.

Parameters
  • normalization_constants – Normalization constants

  • readout_methods – Dictionary with readout parameters.

Returns

dict – Metadata dict with fields known prior to a measurement filled in.

nanotune.tuningstages.base_tasks.add_metadata_to_dict(meta_dict: Dict[str, Any], additional_metadata: Dict[str, Any]) Dict[str, Any][source]

Adds metadata to an existing dict. Checks if content is serializible by QCoDeS.

Parameters
  • meta_dict – Existing metadata dictionary.

  • additional_metadata – Additional key-value items to add to existing metadta dictionary.

Returns

dict – New metadata dictionary.

nanotune.tuningstages.base_tasks.save_metadata(run_id: int, meta_dict: Dict[str, Any], meta_tag: str) None[source]

Adds metadata to a QCoDeS dataset.

Parameters
  • meta_dict – Dictionary to be added to metadata of a QCoDeS dataset.

  • meta_tag – Tag under which the metadata will be stored, i.e. the tag used in qc.dataset.add_metadata().

nanotune.tuningstages.base_tasks.get_elapsed_time(start_time: float, end_time: float, format_template: ~string.Template = <string.Template object>) Tuple[float, str][source]

Returns the elapsed time in seconds and as a formatted string ready to be logged/printed.

Parameters
  • start_time – Start time of event which is being timed.

  • end_time – Time at which the timed event finished.

  • format_template – A string Template which needs to contain ‘$hours’, ‘$minutes’ and $’seconds’ as substrings.

Returns
  • float – Elapsed time in seconds.

  • str – Formatted string indicating the elapsed time in hours, minutes and seconds.

nanotune.tuningstages.base_tasks.plot_fit(fit_class: Type[DataFit], run_id: int, db_name: str, db_folder: Optional[str] = None) None[source]

Plots a data fit.

Parameters
  • fit_class – The DataFit subclass to be used.

  • run_id – QCoDeS data run ID.

  • db_name – Database name where the dataset in question is located.

  • db_folder – Path to folder containing database db_name.

nanotune.tuningstages.base_tasks.print_tuningstage_status(tuning_result: TuningResult) None[source]

Prints a tuningstage status on info level of a python logger.

Parameters

tuning_result – TuningResult instance.

nanotune.tuningstages.base_tasks.take_data_add_metadata(parameters_to_sweep: List[Parameter], parameters_to_measure: List[Parameter], setpoints: Sequence[Sequence[float]], pre_measurement_metadata: Dict[str, Any], finish_early_check: Optional[Callable[[Dict[str, float]], bool]] = None, do_at_inner_setpoint: Optional[Callable[[Any], None]] = None, meta_tag: str = 'nanotune_metadata') int[source]

Takes 1D or 2D data and saves relevant metadata to the dataset.

Parameters
  • parameters_to_sweep – List of qc.Parameters to sweep.

  • parameters_to_measure – List of qc.Parameter to read out.

  • setpoints – Voltage setpoints to measure.

  • pre_measurement_metadata – Metadata dictionary to be saved before a measurement starts.

  • finish_early_check – Function to be called to check if a measurement can be stopped early.

  • do_at_inner_setpoint – Function to be called before a new iteration of the inner for-loop resumes. Example: Sweep a gate to a new value if ramping is turned off.

  • stored (Tag under which the metadata will be) – in qc.dataset.add_metadata().

  • used (i.e. the tag) – in qc.dataset.add_metadata().

Returns

int – QCoDeS data run ID.

nanotune.tuningstages.base_tasks.run_stage(stage: str, parameters_to_sweep: Sequence[_BaseParameter], parameters_to_measure: Sequence[_BaseParameter], voltage_ranges: Sequence[Sequence[float]], compute_setpoint_task: Callable[[Sequence[Sequence[float]]], Sequence[Sequence[float]]], measure_task: Callable[[Sequence[_BaseParameter], Sequence[_BaseParameter], Sequence[Sequence[float]]], int], machine_learning_task: Callable[[int], Any], save_machine_learning_result: Callable[[int, Any], None], validate_result: Callable[[Any], bool]) TuningResult[source]

Executes basic tasks of a tuning stage.

It uses the following functions supplied as input: - computes setpoints - perform the actual measurement, i.e. take data - perform a machine learning task, e.g. classification - validate the machine learning result, e.g. check if a good regime was found - collect all information in a TuningResult instance. It does not set back voltages to initial values.

Parameters
  • stage – Name/identifier of the tuning stage.

  • voltage_ranges – List of voltages ranges to sweep.

  • compute_setpoint_task – Function computing setpoints.

  • measure_task – Functions taking data.

  • machine_learning_task – Function performing the required machine learning task.

  • save_machine_learning_result – Function saving machine learning result. E.g. save prediction to metadata of the dataset.

  • validate_result – Function validating the machine learning result/prediction.

Returns

TuningResult – Currently without db_name and db_folder set.

nanotune.tuningstages.base_tasks.iterate_stage(stage: str, parameters_to_sweep: Sequence[_BaseParameter], parameters_to_measure: Sequence[_BaseParameter], current_valid_ranges: Sequence[Sequence[float]], safety_voltage_ranges: Sequence[Sequence[float]], run_stage: Callable[[str, Sequence[_BaseParameter], Sequence[_BaseParameter], Sequence[Sequence[float]], Callable[[Sequence[Sequence[float]]], Sequence[Sequence[float]]], Callable[[Sequence[_BaseParameter], Sequence[_BaseParameter], Sequence[Sequence[float]]], int], Callable[[int], Any], Callable[[int, Any], None], Callable[[Any], bool]], TuningResult], run_stage_tasks: Tuple[Callable[[Sequence[Sequence[float]]], Sequence[Sequence[float]]], Callable[[Sequence[_BaseParameter], Sequence[_BaseParameter], Sequence[Sequence[float]]], int], Callable[[int], Any], Callable[[int, Any], None], Callable[[Any], bool]], conclude_iteration: Callable[[TuningResult, Sequence[Sequence[float]], Sequence[Sequence[float]], int, int], Tuple[bool, Sequence[Sequence[float]], List[str]]], display_result: Callable[[int, TuningResult], None], max_n_iterations: int = 10) TuningResult[source]

Performs several iterations of a run_stage function, a sequence of basic tasks of a tuning stage. If desired, and implemented in conclude_iteration, new voltage ranges to sweep are determined for the iteration. Issues encountered are saved in the TuningStage instance under termination_reasons. It does not set back voltages to initial values.

Parameters
  • stage – Name/indentifier of the tuning stage.

  • current_valid_ranges – List of voltages ranges to sweep.

  • run_stage – Function executing the sequence of steps of a tuning stage.

  • run_stage_tasks – All input functions of run_stage.

  • conclude_iteration – Function checking the outcome of an iteration and possibly adjusting voltage ranges if needed. Returns a list of termination reasons if the current iteration is to be abandoned.

  • display_result – Function to show result of the current iteration.

  • max_n_iterations – Maximum number of iterations to perform abandoning.

Returns

TuningResult – Tuning results of the last iteration, with the dataids field containing QCoDeS run IDs of all datasets measured.

nanotune.tuningstages.base_tasks.conclude_iteration_with_range_update(tuning_result: TuningResult, current_valid_ranges: Sequence[Sequence[float]], safety_voltage_ranges: Sequence[Sequence[float]], get_range_update_directives: Callable[[int, Sequence[Sequence[float]], Sequence[Sequence[float]]], Tuple[List[str], List[str]]], get_new_current_ranges: Callable[[Sequence[Sequence[float]], Sequence[Sequence[float]], List[str]], Sequence[Sequence[float]]], current_iteration: int, max_n_iterations: int) Tuple[bool, Sequence[Sequence[float]], List[str]][source]

Implements a conclude_iteration function for iterate_stage, which determines new voltage ranges if the last measurement was not successful.

Parameters
  • tuning_result – Tuning result of current run_stage iteration.

  • current_valid_ranges – List of the last voltage ranges swep.

  • safety_voltage_ranges – List of safety voltages for each voltage parameter swept.

  • get_range_update_directives – Function to compile a list of directives indicating how voltages need to be changed.

  • get_new_current_ranges – Function applying list of range change directives and returning new voltage ranges.

  • current_iteration – Current iteration number.

  • max_n_iterations – Maximum number of tuning stage runs to perform.

nanotune.tuningstages.base_tasks.get_current_voltages(parameters: Sequence[_BaseParameter]) List[float][source]

Returns the values set to parameters in parameters.

Parameters

parameters – List of QCoDeS parameters, i.e. voltage parameters of gates.

Returns
  • list – Values set the input parameters are at, in the same order as

  • parameters in ``parameters``.

nanotune.tuningstages.base_tasks.set_voltages(parameters: Sequence[_BaseParameter], voltages_to_set: Sequence[float]) None[source]

Set voltages in voltages_to_set to voltage parameters in parameters.

Parameters
  • parameters – List of QCoDeS parameters, i.e. voltage parameters of gates.

  • voltages_to_set – List of voltages, in the same order as parameters in parameters.

nanotune.tuningstages.base_tasks.get_fit_range_update_directives(fit_class: Type[DataFit], run_id: int, db_name: str, db_folder: Optional[str], **kwargs) List[str][source]

Returns voltage range update directives determined from a fit.

Parameters
  • fit_class – Data fit class to use for fitting.

  • run_id – QCoDeS data run ID.

  • db_name – Database name.

  • db_folder – Path to folder where database is saved.

Returns

list – List of strings indicating in which direction voltage ranges of the gates swept need to be changed.