mjolnir.measurements.handler#

Stateful control of optical measurements.

Todo

  • quantify-core might be suitable to replace this.

Notes

DAC trigger output:

# Route external trigger 1 to internal trigger 1
dac.write('OUTP:TRIG1:SOUR INT1')
# Width 1 ms
dac.write('OUTP:TRIG1:WIDT 1e-3')
# Fire internal trigger 1 (triggers external trigger 1)
dac.write('TINT:SIGN: 1')

Classes

CcdMeasurementHandler(station[, ...])

Handler for measurements using the CCD.

DefaultMeasurementHandler(station[, ...])

The default measurement handler, which does nothing on the side.

LaserCcdMeasurementHandler(station[, ...])

Handler for measurements with Laser+CCD.

MeasurementHandler(station[, sample_name, ...])

Abstract base class for specifying measurement protocols.

TimeTaggerMeasurementHandler(station[, ...])

Handler for measurements using the APDs and Time Tagger.

class mjolnir.measurements.handler.CcdMeasurementHandler(station, sample_name=None, experiment='optics', measure_leakage=True, critical_leakage=1e-07, measurement_nplc=1, measurement_count=1, database_location='~/experiments.db', single_track_settings=<factory>)[source]#

Bases: DefaultMeasurementHandler

Handler for measurements using the CCD.

Parameters:
add_before_run(sweeps, measures)[source]#

Default actions to run before starting the measurement.

Parameters:
Return type:

tuple[tuple[Callable[[…], Any], Sequence[Any]], …]

add_default_measures(sweeps, measures)[source]#

Add default parameters to measure to the set measures.

sweeps.leak_measures is kept separate to be able to act conditioned on their value.

Parameters:
Return type:

MeasureSet

abstractmethod assert_background_acquired()[source]#

This method needs to be run after all parameters (possibly in parameter contexts) are set. Hence, it cannot be included in run_assertions().

property ccd: AndorIDus4xx#
cya()[source]#

Disables CCD cooler and white light.

Return type:

bool

get_custom_metadata(sweeps, measures)[source]#

Extract custom metadata to be saved with the measurement.

Parameters:
Return type:

dict[str, dict[str, str]]

get_default_parameter_contexts(sweeps, measures)[source]#

Default parameter values for each measurement.

Return type:

dict[ParameterBase, Any]

initialize(**initialization_settings)[source]#

Initialize instruments for the measurement.

initialize_ccd_buffered_acquisition(n_pts, exposure_time=1.0, preamp_gain=1.0, horizontal_shift_speed=0.1, vertical_shift_speed=None, delay=0.0, **_)[source]#

Set the CCD up for buffered acquisition. Unused.

Parameters:
Return type:

float

initialize_ccd_single_acquisition(exposure_time=1.0, preamp_gain=1.0, horizontal_shift_speed=0.1, vertical_shift_speed=None, read_mode='single track', acquisition_mode='accumulate', number_accumulations=2, number_kinetics=1, accumulation_cycle_time=0.0, kinetic_cycle_time=0.0, **_)[source]#

Set the CCD up for acquisition of a single buffer.

Parameters:
  • exposure_time (float)

  • preamp_gain (float)

  • horizontal_shift_speed (float)

  • vertical_shift_speed (float | None)

  • read_mode (str)

  • acquisition_mode (Literal['single scan', 'accumulate'])

  • number_accumulations (int)

  • number_kinetics (int)

  • accumulation_cycle_time (float)

  • kinetic_cycle_time (float)

single_track_settings: dict[int, tuple[int, int]]#

Settings for single-track acquisition mode of the CCD.

property type: str#

An identifier for the type of measurement this class executes.

class mjolnir.measurements.handler.DefaultMeasurementHandler(station, sample_name=None, experiment='optics', measure_leakage=True, critical_leakage=1e-07, measurement_nplc=1, measurement_count=1, database_location='~/experiments.db')[source]#

Bases: MeasurementHandler

The default measurement handler, which does nothing on the side.

Parameters:
  • station (Station)

  • sample_name (str | None)

  • experiment (Experiment | str)

  • measure_leakage (bool)

  • critical_leakage (float)

  • measurement_nplc (int)

  • measurement_count (int)

  • database_location (str)

add_after_run(sweeps, measures)[source]#

Default actions to run after finishing the measurement.

Parameters:
Return type:

tuple[tuple[Callable[[…], Any], Sequence[Any]], …]

add_before_run(sweeps, measures)[source]#

Default actions to run before starting the measurement.

Parameters:
Return type:

tuple[tuple[Callable[[…], Any], Sequence[Any]], …]

add_default_measures(sweeps, measures)[source]#

Add default parameters to measure to the set measures.

sweeps.leak_measures is kept separate to be able to act conditioned on their value.

Parameters:
Return type:

MeasureSet

add_default_sweeps(sweeps, measures, **default_sweeps_kwargs)[source]#

Add default sweep to the list sweeps.

Parameters:
Return type:

SweepList

get_custom_metadata(sweeps, measures)[source]#

Extract custom metadata to be saved with the measurement.

Parameters:
Return type:

dict[str, Any]

get_default_parameter_contexts(sweeps, measures)[source]#

Default parameter values for each measurement.

Parameters:
Return type:

dict[ParameterBase, Any]

initialize(**initialization_settings)[source]#

Initialize instruments for the measurement.

run_assertions(sweeps, measures)[source]#

Assert conditions necessary for the measurement.

Parameters:
property type: str#

An identifier for the type of measurement this class executes.

class mjolnir.measurements.handler.LaserCcdMeasurementHandler(station, sample_name=None, experiment='optics', measure_leakage=True, critical_leakage=1e-07, measurement_nplc=1, measurement_count=1, database_location='~/experiments.db', single_track_settings=<factory>)[source]#

Bases: CcdMeasurementHandler

Handler for measurements with Laser+CCD.

Parameters:
add_before_run(sweeps, measures)[source]#

Default actions to run before starting the measurement.

Parameters:
Return type:

tuple[tuple[Callable[[…], Any], Sequence[Any]], …]

add_default_measures(sweeps, measures)[source]#

Add default parameters to measure to the set measures.

sweeps.leak_measures is kept separate to be able to act conditioned on their value.

Parameters:
Return type:

MeasureSet

assert_background_acquired()[source]#

This method needs to be run after all parameters (possibly in parameter contexts) are set. Hence, it cannot be included in run_assertions().

cya()[source]#

Disables CCD cooler.

Return type:

bool

get_default_parameter_contexts(sweeps, measures)[source]#

Default parameter values for each measurement.

Parameters:
Return type:

dict[ParameterBase, Any]

run_assertions(sweeps, measures)[source]#

Assert conditions necessary for the measurement.

Parameters:
property type: str#

An identifier for the type of measurement this class executes.

class mjolnir.measurements.handler.MeasurementHandler(station, sample_name=None, experiment='optics', measure_leakage=True, critical_leakage=1e-07, measurement_nplc=1, measurement_count=1, database_location='~/experiments.db')[source]#

Bases: ABC

Abstract base class for specifying measurement protocols.

Subclasses override methods of this class which get run at different points during measure() and loop(). See those methods for documentation on when they are run and what they should do.

Parameters:
  • station (qcodes.station.Station) – The station hosting the logical instruments that control the experiment

  • sample_name (str | None) – A string identifier for the sample. Defaults to the name of a TrapSample that is a member of station, if any.

  • experiment (qcodes.dataset.experiment_container.Experiment | str) – A qcodes experiment. Defaults to “optics”.

  • measure_leakage (bool) – Automatically measure the leakage current if a QDAC channel is swept.

  • critical_leakage (float) – Current (in Ampere) that determines a critical leakage threshold above which sweeps are aborted.

  • measurement_nplc (int) – The number of power line cycles (PLC) to average currents over.

  • measurement_count (int) – The number of current samples taken.

  • database_location (str) – The location of the database. Defaults to the qcodes default.

abstractmethod add_after_run(sweeps, measures)[source]#

Default actions to run after finishing the measurement.

Parameters:
Return type:

tuple[tuple[Callable[[…], Any], Sequence[Any]], …]

abstractmethod add_before_run(sweeps, measures)[source]#

Default actions to run before starting the measurement.

Parameters:
Return type:

tuple[tuple[Callable[[…], Any], Sequence[Any]], …]

abstractmethod add_default_measures(sweeps, measures)[source]#

Add default parameters to measure to the set measures.

sweeps.leak_measures is kept separate to be able to act conditioned on their value.

Parameters:
Return type:

MeasureSet

abstractmethod add_default_sweeps(sweeps, measures, **default_sweeps_kwargs)[source]#

Add default sweep to the list sweeps.

Parameters:
Return type:

SweepList

critical_leakage: float = 1e-07#
cya()[source]#

Teardown actions to perform when measure(cya=True).

Return type:

bool

database_location: str = '~/experiments.db'#
experiment: Experiment | str = 'optics'#
abstractmethod get_custom_metadata(sweeps, measures)[source]#

Extract custom metadata to be saved with the measurement.

Parameters:
Return type:

dict[str, Any]

abstractmethod get_default_parameter_contexts(sweeps, measures)[source]#

Default parameter values for each measurement.

Parameters:
Return type:

dict[ParameterBase, Any]

get_leakage_measures(sweeps)[source]#

Qdac channel leakage measures conditional on the flag.

Parameters:

sweeps (SweepList)

Return type:

MeasureSet

get_leakage_parameter_contexts(sweeps)[source]#

Parses the SweepList to find QDAC-II current parameters.

Parameters:

sweeps (SweepList)

Return type:

dict[ParameterBase, int]

abstractmethod initialize(**initialization_settings)[source]#

Initialize instruments for the measurement.

leakage_limit_exceeded(params)[source]#

Measures leakage on the QDAC channels underlying params and tests if the critical limit is exceeded.

Returns the boolean and the list of leakage currents.

Return type:

tuple[bool, list[float]]

loop(datasaver, params_caller_context, sweeps, measures, *, i=0, show_progress=True)[source]#

The main measurement loop.

This function recurses into sweeps, measures measures at the lowest recursion level (the innermost loop), and saves the results into datasaver.

Sweeps can specify initialization procedures as well, see sweeps.

Measures can specify a live-plotting procedure that is passed current measurement data at every point, see measures.

Parameters:
measure(sweeps=None, measures=None, *, add_before_run=(), add_after_run=(), parameter_contexts=None, return_to_start=True, preallocate_results=True, cya=False, live_plot=True, show_progress=True, threaded_acquisition=True, write_in_background=True, metadata=None, default_sweeps_kwargs=None, loop_kwargs=None, initialize_plotting_kwargs=None, **initialization_settings)[source]#

The measurement entrypoint.

This function takes care of all measurement set-up, tear-down, as well as running the actual measurement loop.

Parameters:
  • sweeps (SweepList | SweepProtocol | None) – A SweepList defining the nD sweep to execute, or a single sweep implementing the SweepProtocol. If None, only whatever the subclass implementation of add_default_sweeps() adds is used.

  • measures (MeasureSet | Measure | ParameterBase | None) – A MeasureSet defining the parameters to measure at each point of the sweep, or a single ParameterBase or Measure to get. If None, only whatever the subclass implementation of add_default_measures() adds is used.

  • add_before_run (Sequence[tuple[Callable[[...], Any], Sequence[Any]]]) – A sequence of two-tuples (callable, args) to run before the measurement is started.

  • add_after_run (Sequence[tuple[Callable[[...], Any], Sequence[Any]]]) – A sequence of two-tuples (callable, args) to run before the measurement is started.

  • parameter_contexts (dict[ParameterBase, Any] | None) – A mapping of Parameter to values that the parameters should be set to for the duration of the measurement.

  • return_to_start (bool) – Set parameters to their value before the measurement after it is done.

  • preallocate_results (bool) – Preallocate measurement results in the database. Should normally only be set to a different value by subclasses.

  • cya (bool) – Run cya() after finishing the measurement.

  • live_plot (bool) – Run the plot_callback hooks each time a data point is taken. Individual measures can be excluded by setting their live_plot attribute to False.

  • show_progress (bool) – Show a progress bar for the outermost sweep loop.

  • threaded_acquisition (bool) – Use ThreadPoolParamsCaller to acquire data asynchronously.

  • write_in_background (bool) – Write data to the db in a background thread.

  • metadata (tuple[str, Any] | Any | None) – Runtime metadata either as a tuple (tag, metadata) or just metadata.

  • default_sweeps_kwargs (dict[Any, Any] | None) – Kwargs that are passed on to add_default_sweeps().

  • loop_kwargs (dict[Any, Any] | None) – Kwargs that are passed on to loop().

  • initialize_plotting_kwargs (dict[Any, Any] | None) – Kwargs that are passed on to initialize_plotting().

  • **initialization_settings – Kwargs that are passed on to initialize().

Returns:

The DataSet holding the measurement.

Return type:

dataset

measure_leakage: bool = True#
measurement_count: int = 1#
measurement_nplc: int = 1#
property metadata: dict[str, dict[str, Any]]#

Exports git commit hashes and this class instance.

abstractmethod run_assertions(sweeps, measures)[source]#

Assert conditions necessary for the measurement.

Parameters:
property sample: TrapSample#

The logical instrument representing the current sample.

sample_name: str | None = None#
station: Station#
abstract property type: str#

An identifier for the type of measurement this class executes.

class mjolnir.measurements.handler.TimeTaggerMeasurementHandler(station, sample_name=None, experiment='optics', measure_leakage=True, critical_leakage=1e-07, measurement_nplc=1, measurement_count=1, database_location='~/experiments.db', max_duration=datetime.timedelta(days=1))[source]#

Bases: DefaultMeasurementHandler

Handler for measurements using the APDs and Time Tagger.

Measurements executed with measure() by default get a TimeParameter sweep that simply waits for a given interval for a certain number of times. Laser wavelength and power are automatically recalibrated at each interval.

Parameters:
  • station (Station)

  • sample_name (str | None)

  • experiment (Experiment | str)

  • measure_leakage (bool)

  • critical_leakage (float)

  • measurement_nplc (int)

  • measurement_count (int)

  • database_location (str)

  • max_duration (timedelta)

add_after_run(sweeps, measures)[source]#

Default actions to run after finishing the measurement.

Parameters:
Return type:

tuple[tuple[Callable[[…], Any], Sequence[Any]], …]

add_before_run(sweeps, measures)[source]#

Default actions to run before starting the measurement.

Parameters:
Return type:

tuple[tuple[Callable[[…], Any], Sequence[Any]], …]

add_default_measures(sweeps, measures)[source]#

Add default parameters to measure to the set measures.

sweeps.leak_measures is kept separate to be able to act conditioned on their value.

Parameters:
Return type:

MeasureSet

add_default_sweeps(sweeps, measures, update_interval, parameter_contexts)[source]#

Add default sweep to the list sweeps.

Parameters:
Return type:

SweepList

static clear_tagger_measurements(measures)[source]#

Clear all TimeTagger measurements.

Parameters:

measures (MeasureSet)

get_default_parameter_contexts(sweeps, measures)[source]#

Default parameter values for each measurement.

Parameters:
Return type:

dict[ParameterBase, Any]

loop(datasaver, params_caller_context, sweeps, measures, *, i=0, show_progress=True, add_result_on_update=False)[source]#

Custom measurement loop for Time Tagger measurements.

Measurements can be gracefully terminated by sending a keyboard interrupt.

Parameters:
max_duration: timedelta = datetime.timedelta(days=1)#

The maximum duration the default sweep will run for if not interrupted.

measure(sweeps=None, measures=None, *, add_before_run=(), add_after_run=(), parameter_contexts=None, cya=False, live_plot=True, update_interval=10.0, add_result_on_update=False, show_progress=True, threaded_acquisition=True, write_in_background=True, metadata=None, initialize_plotting_kwargs=None, **initialization_settings)[source]#

The measurement entry point.

For most parameters, see the base method.

Parameters:
Return type:

DataSetProtocol

register_tagger_measurements(measures)[source]#

Register a TimeTagger measurement with the TimeTaggerSynchronizedMeasurements object to synchronize measurements.

Parameters:

measures (MeasureSet)

property tagger: TimeTagger#
property type: str#

An identifier for the type of measurement this class executes.

unregister_tagger_measurements(measures)[source]#

Unregister TimeTagger measurements.

Parameters:

measures (MeasureSet)