Tutorial 5. Plot monitor#

See also

The complete source code of this tutorial can be found in

Tutorial 5. Plot monitor.ipynb

In this tutorial we dive into the capabilities of the plot monitor. We will create a fictional device and showcase how the plot monitor can be used. Enjoy!

Hide code cell content
import numpy as np
from IPython.core.interactiveshell import InteractiveShell
from qcodes import Instrument, ManualParameter

from quantify_core.data.handling import (
    get_tuids_containing,
    set_datadir,
    default_datadir,
)
from quantify_core.measurement import MeasurementControl
from quantify_core.visualization.pyqt_plotmon import PlotMonitor_pyqt

rng = np.random.default_rng(seed=555555)  # random number generator

# Display any variable or statement on its own line
InteractiveShell.ast_node_interactivity = "all"

Before instantiating any instruments or starting a measurement we change the directory in which the experiments are saved using the set_datadir() [get_datadir()] functions.


⚠️ Warning!

We recommend always setting the directory at the start of the python kernel and stick to a single common data directory for all notebooks/experiments within your measurement setup/PC.

The cell below sets a default data directory (~/quantify-data on Linux/macOS or $env:USERPROFILE\\quantify-data on Windows) for tutorial purposes. Change it to your desired data directory. The utilities to find/search/extract data only work if all the experiment containers are located within the same directory.


set_datadir(default_datadir())
Data will be saved in:
C:\Users\AmirthaVarshinyArumu\quantify-data

QCoDeS drivers for our instruments#

class Device(Instrument):
    """A dummy instrument."""

    def __init__(self, name: str):
        super().__init__(name=name)

        self.add_parameter(name="amp_0", unit="A", parameter_class=ManualParameter)
        self.add_parameter(name="amp_1", unit="A", parameter_class=ManualParameter)
        self.add_parameter(name="offset", unit="A", parameter_class=ManualParameter)

        self.add_parameter(
            name="adc", label="ADC input", unit="V", get_cmd=self._get_dac_value
        )

    def _get_dac_value(self):
        s1 = np.exp(-3 * self.amp_0()) * np.sin(self.amp_0() * 2 * np.pi * 3)
        s2 = np.cos(self.amp_1() * 2 * np.pi * 2)
        return s1 + s2 + rng.uniform(0, 0.2) + self.offset()

Instantiate the instruments#

meas_ctrl = MeasurementControl("meas_ctrl")
plotmon = PlotMonitor_pyqt("PlotMonitor")
meas_ctrl.instr_plotmon(plotmon.name)
device = Device("Device")
QFontDatabase: Cannot find font directory C:/Users/AmirthaVarshinyArumu/miniforge3/lib/site-packages/PyQt5/Qt5/lib/fonts.
Note that Qt no longer ships fonts. Deploy some (from https://dejavu-fonts.github.io/ for example) or switch to fontconfig.
QFontDatabase: Cannot find font directory C:/Users/AmirthaVarshinyArumu/miniforge3/lib/site-packages/PyQt5/Qt5/lib/fonts.
Note that Qt no longer ships fonts. Deploy some (from https://dejavu-fonts.github.io/ for example) or switch to fontconfig.
QFontDatabase: Cannot find font directory C:/Users/AmirthaVarshinyArumu/miniforge3/lib/site-packages/PyQt5/Qt5/lib/fonts.
Note that Qt no longer ships fonts. Deploy some (from https://dejavu-fonts.github.io/ for example) or switch to fontconfig.
QFontDatabase: Cannot find font directory C:/Users/AmirthaVarshinyArumu/miniforge3/lib/site-packages/PyQt5/Qt5/lib/fonts.
Note that Qt no longer ships fonts. Deploy some (from https://dejavu-fonts.github.io/ for example) or switch to fontconfig.
QFontDatabase: Cannot find font directory C:/Users/AmirthaVarshinyArumu/miniforge3/lib/site-packages/PyQt5/Qt5/lib/fonts.
Note that Qt no longer ships fonts. Deploy some (from https://dejavu-fonts.github.io/ for example) or switch to fontconfig.

Overview#

There are 3 parameters in the PlotMonitor_pyqt that control the datasets being displayed.

Two main parameters determine the datasets being displayed: tuids and tuids_extra.

plotmon.tuids()
plotmon.tuids_extra()
[]
[]

The interface is the same for both. The parameters accept a list of tuids or an empty list to reset.

### Example of loading datasets onto the plot
#plotmon.tuids(["20201124-184709-137-8a5112", "20201124-184716-237-918bee"])
#plotmon.tuids_extra(["20201124-184722-988-0463d4", "20201124-184729-618-85970f"])

The difference is that the MeasurementControl uses tuids and overrides them when running measurements.

Note

All the datasets must have matching data variables (settables and gettables).

The third relevant parameter is the tuids_max_num. It accepts an integer that determines the maximum number of datasets that will be stored in tuids when the MeasurementControl is running.

plotmon.tuids_max_num()
3

Note

This parameter has no effect when setting the tuids manually.

Usage examples#

# set initial values to emulate the instrument state
device.amp_0(0.0)
device.amp_1(0.0)
device.offset(0.0)

n_pnts = 50

meas_ctrl.settables(device.amp_0)
meas_ctrl.setpoints(np.linspace(0, 1, n_pnts))
meas_ctrl.gettables(device.adc)
dset = meas_ctrl.run("ADC scan")
Starting iterative measurement...
plotmon.main_QtPlot
QFontDatabase: Cannot find font directory C:/Users/AmirthaVarshinyArumu/miniforge3/lib/site-packages/PyQt5/Qt5/lib/fonts.
Note that Qt no longer ships fonts. Deploy some (from https://dejavu-fonts.github.io/ for example) or switch to fontconfig.
QFontDatabase: Cannot find font directory C:/Users/AmirthaVarshinyArumu/miniforge3/lib/site-packages/PyQt5/Qt5/lib/fonts.
Note that Qt no longer ships fonts. Deploy some (from https://dejavu-fonts.github.io/ for example) or switch to fontconfig.
QFontDatabase: Cannot find font directory C:/Users/AmirthaVarshinyArumu/miniforge3/lib/site-packages/PyQt5/Qt5/lib/fonts.
Note that Qt no longer ships fonts. Deploy some (from https://dejavu-fonts.github.io/ for example) or switch to fontconfig.
QFontDatabase: Cannot find font directory C:/Users/AmirthaVarshinyArumu/miniforge3/lib/site-packages/PyQt5/Qt5/lib/fonts.
Note that Qt no longer ships fonts. Deploy some (from https://dejavu-fonts.github.io/ for example) or switch to fontconfig.
QFontDatabase: Cannot find font directory C:/Users/AmirthaVarshinyArumu/miniforge3/lib/site-packages/PyQt5/Qt5/lib/fonts.
Note that Qt no longer ships fonts. Deploy some (from https://dejavu-fonts.github.io/ for example) or switch to fontconfig.
../_images/e9c38d8674a3c1c3af2e5ef9497e23317c8ee8cf36f2bf2e0e24679386d4262a.png
n_pnts = 20

meas_ctrl.settables(device.amp_0)
meas_ctrl.setpoints(np.linspace(0, 1, n_pnts))
meas_ctrl.gettables(device.adc)
dset = meas_ctrl.run("ADC scan")
Starting iterative measurement...
plotmon.main_QtPlot
../_images/4d1f482517915b8aac92450ee30c1564de59bb84943e19a57a6c22876defc929.png
n_pnts = 30

meas_ctrl.settables(device.amp_0)
meas_ctrl.setpoints(np.linspace(0, 1, n_pnts))
meas_ctrl.gettables(device.adc)
dset = meas_ctrl.run("ADC scan")
Starting iterative measurement...
plotmon.main_QtPlot
../_images/82986bafcbf94719ff7d43051ebb18e2cd0dce512543a77bde9416c15d04c2a5.png

Now the oldest dataset will vanish from the plot:

# Now the oldest dataset will vanish from the plot

n_pnts = 40

meas_ctrl.settables(device.amp_0)
meas_ctrl.setpoints(np.linspace(0, 1, n_pnts))
meas_ctrl.gettables(device.adc)
dset = meas_ctrl.run("ADC scan")
Starting iterative measurement...
plotmon.main_QtPlot
../_images/70dd31eae3a7c92cc3f4d84f96c33857b90f7464fb6eef7c9942add090678a6a.png

We can accumulate more datasets on the plot if we want to:

# We can accumulate more datasets on the plot if we want to
plotmon.tuids_max_num(4)
n_pnts = 40

meas_ctrl.settables(device.amp_0)
meas_ctrl.setpoints(np.linspace(0, 1, n_pnts))
meas_ctrl.gettables(device.adc)
dset = meas_ctrl.run("ADC scan")
Starting iterative measurement...
plotmon.main_QtPlot
../_images/a914f2fd51e9bf89ddca63ce7e11d9c0dc0214f2d5265f3aee5ba940c537401b.png

Or we can disable the accumulation and plot a single dataset:

# Or we can disable the accumulation and plot a single dataset
plotmon.tuids_max_num(1)

plotmon.main_QtPlot
../_images/ba6c58cb8505d3cc175a934d008912e39bf10a510846e61b4b674d2bdeaca469.png

This can also be reset:

# This can also be reset with
plotmon.tuids([])

plotmon.main_QtPlot  # The plotting window will vanish, it is supposed to
../_images/fabf04168e56bbb0f5186f5950510ed6a80473057a98bf96209bf8df36593f5c.png

For now, we will allow two datasets on the plot monitor.

# For now we will allow two datasets on the plot monitor
plotmon.tuids_max_num(2)

Now let’s imagine that something strange is happening with our setup…

# Now let's imagine that something strange is happening with our setup
device.offset(1.5)

n_pnts = 40
meas_ctrl.settables(device.amp_0)
meas_ctrl.setpoints(np.linspace(0, 1, n_pnts))
meas_ctrl.gettables(device.adc)
dset = meas_ctrl.run("ADC scan problem")
Starting iterative measurement...
plotmon.main_QtPlot
../_images/a4ab72f0156d21ebda3aa9bd9487d124f37d6d2fe68329514040535faaa14ebb.png

We would like to compare if the current behavior matches for example what we got a few minutes ago:

# We would like to compare if the current behavior matches for example
# what we got a few minutes ago

reference_tuids = sorted(get_tuids_containing("ADC"))[-3:-1]

plotmon.tuids_extra(reference_tuids)
plotmon.main_QtPlot
../_images/ec7f4353d0b04c0fe9b0381545255488bbc4759e5798761bf8c9fae2e7923dae.png

OK… that cable was not connected in the right place…

device.offset(0.0)  # OK... that cable was not connected in the right place...

# Now let's run again our experiments while we compare it to the previous one in realtime

n_pnts = 30
meas_ctrl.settables(device.amp_0)
meas_ctrl.setpoints(np.linspace(0, 1, n_pnts))
meas_ctrl.gettables(device.adc)
dset = meas_ctrl.run("ADC scan")

n_pnts = 40
meas_ctrl.settables(device.amp_0)
meas_ctrl.setpoints(np.linspace(0, 1, n_pnts))
meas_ctrl.gettables(device.adc)
dset = meas_ctrl.run("ADC scan")
Starting iterative measurement...
Starting iterative measurement...
plotmon.main_QtPlot
../_images/efb3bfe1286ed459a71c525e77916eec10f2bbb494911716cdf7a5b6ddf0f1cd.png

We do not need the reference datasets anymore

# We do not need the reference datasets anymore
plotmon.tuids_extra([])
plotmon.main_QtPlot
../_images/d122ea007a5c10939be7691a2e01a8caf9cd791c39ef1fcefcae1f9409f55dca.png
# Note: both plotmon.tuids_extra and plotmon.tuids can be used
# but keep in mind that meas_ctrl also uses the plotmon.tuids

tuids = get_tuids_containing("problem")[0:1]
tuids
plotmon.tuids(tuids)

n_pnts = 40
meas_ctrl.settables(device.amp_0)
meas_ctrl.setpoints(np.linspace(0, 1, n_pnts))
meas_ctrl.gettables(device.adc)
dset = meas_ctrl.run("ADC scan")

plotmon.main_QtPlot
['20240412-113025-588-ed2dbf']
Starting iterative measurement...
../_images/8a0536c699e2b2319242d34c231cf8a145dd9afa43da9100e78729be4f08c7a6.png

When we have 2D plots only the first dataset from plotmon.tuids or plotmon.tuids_extra will be plotted in the secondary window, in that order of priority.

# When we have 2D plots only the first dataset from plotmon.tuids or
# plotmon.tuids_extra, in that order of priority, will be plotted in the
# secondary window

meas_ctrl.settables([device.amp_0, device.amp_1])
meas_ctrl.setpoints_grid([np.linspace(0, 1, 20), np.linspace(0, 0.5, 15)])
meas_ctrl.gettables(device.adc)
dset = meas_ctrl.run("ADC scan 2D")
reference_tuid_2D = dset.attrs["tuid"]
Starting iterative measurement...
plotmon.main_QtPlot
plotmon.secondary_QtPlot
../_images/c709d78656b6246e9a7a8deb90c345ca41fa7b1abf3b4af750aa764ead427071.png ../_images/1b3a903ccc52db3f1c91afdfbb780576e03b8b3b1f38a2eb2076514f3670127e.png

Note

The secondary window displays the last dataset with a 2D structure, and it remains persistent until replaced by a new dataset with a 2D structure.

Mind that the data on the secondary window does not always display data corresponding to the same dataset as the main window.

We still have the persistence of the previous dataset on the main window:

meas_ctrl.settables([device.amp_0, device.amp_1])
meas_ctrl.setpoints_grid([np.linspace(0, 1, 20), np.linspace(0, 0.5, 15)])
meas_ctrl.gettables(device.adc)
dset = meas_ctrl.run("ADC scan 2D")
Starting iterative measurement...
plotmon.main_QtPlot
plotmon.secondary_QtPlot
../_images/806953f8353a2e959feb9163910bda83bba26ef35bc11701a9602dd5fd244da2.png ../_images/d5b523a920544b2aa6033f1e40a7338201d5b2dcf0ad00e940d5c6cc909913fd.png

We can still have a permanent dataset as a reference in the main window:

device.offset(2.03)
plotmon.tuids_extra([reference_tuid_2D])

meas_ctrl.settables([device.amp_0, device.amp_1])
meas_ctrl.setpoints_grid([np.linspace(0, 1, 20), np.linspace(0, 0.5, 15)])
meas_ctrl.gettables(device.adc)
dset = meas_ctrl.run("ADC scan 2D")
Starting iterative measurement...
plotmon.main_QtPlot
plotmon.secondary_QtPlot
../_images/4cc3730d2d5e9c14589a43e9821cd833c1d02e61e307320be36b9d6d4f70fa50.png ../_images/6c095dd3ffa0d68a458b182eeab01d41bdc9b134b5132529d9edd93b8540a1e0.png

But if we want to see the 2D plot we need to reset plotmon.tuids.

plotmon.tuids([])
plotmon.tuids_extra([reference_tuid_2D])
plotmon.main_QtPlot
plotmon.secondary_QtPlot
../_images/7a406f8010a63831d9279ae1ce99f35e9d9a9d376571620c9c4161aa25005440.png ../_images/1b3a903ccc52db3f1c91afdfbb780576e03b8b3b1f38a2eb2076514f3670127e.png
plotmon.tuids()
[]

Now your life will never be the same again ;)