From 50f3976c94462652bdfbf88fb19ffb4ffbd6a5a0 Mon Sep 17 00:00:00 2001 From: Samantha Ho Date: Tue, 8 Oct 2024 14:22:02 -0700 Subject: [PATCH] Lightly modify snapshot example notebook --- .../DataSet/Working with snapshots.ipynb | 472 ++++++++++++++++-- 1 file changed, 434 insertions(+), 38 deletions(-) diff --git a/docs/examples/DataSet/Working with snapshots.ipynb b/docs/examples/DataSet/Working with snapshots.ipynb index ac5f67c7de9..8ea736c4990 100644 --- a/docs/examples/DataSet/Working with snapshots.ipynb +++ b/docs/examples/DataSet/Working with snapshots.ipynb @@ -79,9 +79,27 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 2, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'__class__': 'qcodes.parameters.parameter.Parameter',\n", + " 'full_name': 'p',\n", + " 'inter_delay': 0,\n", + " 'label': 'Parameter P',\n", + " 'name': 'p',\n", + " 'post_delay': 0,\n", + " 'raw_value': 123,\n", + " 'ts': '2024-10-08 14:04:12',\n", + " 'unit': 'kg',\n", + " 'validators': [],\n", + " 'value': 123}\n" + ] + } + ], "source": [ "p = Parameter(\"p\", label=\"Parameter P\", unit=\"kg\", set_cmd=None, get_cmd=None)\n", "p.set(123)\n", @@ -100,9 +118,17 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 3, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Value of Parameter P was 123 (when it was snapshotted).\n" + ] + } + ], "source": [ "print(\n", " f\"Value of {snapshot_of_p['label']} was {snapshot_of_p['value']} (when it was snapshotted).\"\n", @@ -125,9 +151,25 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 4, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'__class__': 'qcodes.parameters.parameter.Parameter',\n", + " 'full_name': 'q',\n", + " 'inter_delay': 0,\n", + " 'label': 'Parameter Q',\n", + " 'name': 'q',\n", + " 'post_delay': 0,\n", + " 'ts': None,\n", + " 'unit': 'A',\n", + " 'validators': []}\n" + ] + } + ], "source": [ "q = Parameter(\n", " \"q\", label=\"Parameter Q\", unit=\"A\", snapshot_value=False, set_cmd=None, get_cmd=None\n", @@ -161,9 +203,90 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 6, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{ '__class__': 'qcodes.instrument_drivers.mock_instruments.DummyInstrument',\n", + " 'functions': {},\n", + " 'label': 'instr',\n", + " 'name': 'instr',\n", + " 'parameters': { 'IDN': { '__class__': 'qcodes.parameters.parameter.Parameter',\n", + " 'full_name': 'instr_IDN',\n", + " 'instrument': 'qcodes.instrument_drivers.mock_instruments.DummyInstrument',\n", + " 'instrument_name': 'instr',\n", + " 'inter_delay': 0,\n", + " 'label': 'IDN',\n", + " 'name': 'IDN',\n", + " 'post_delay': 0,\n", + " 'raw_value': None,\n", + " 'ts': None,\n", + " 'unit': '',\n", + " 'validators': [''],\n", + " 'vals': '',\n", + " 'value': None},\n", + " 'fixed_parameter': { '__class__': 'qcodes.parameters.parameter.Parameter',\n", + " 'full_name': 'instr_fixed_parameter',\n", + " 'instrument': 'qcodes.instrument_drivers.mock_instruments.DummyInstrument',\n", + " 'instrument_name': 'instr',\n", + " 'inter_delay': 0,\n", + " 'label': 'fixed_parameter',\n", + " 'name': 'fixed_parameter',\n", + " 'post_delay': 0,\n", + " 'raw_value': 5,\n", + " 'ts': '2024-10-08 14:04:12',\n", + " 'unit': '',\n", + " 'validators': [],\n", + " 'value': 5},\n", + " 'gain': { '__class__': 'qcodes.parameters.parameter.Parameter',\n", + " 'full_name': 'instr_gain',\n", + " 'instrument': 'qcodes.instrument_drivers.mock_instruments.DummyInstrument',\n", + " 'instrument_name': 'instr',\n", + " 'inter_delay': 0,\n", + " 'label': 'Gate gain',\n", + " 'name': 'gain',\n", + " 'post_delay': 0,\n", + " 'raw_value': 11,\n", + " 'ts': '2024-10-08 14:04:12',\n", + " 'unit': 'V',\n", + " 'validators': [''],\n", + " 'vals': '',\n", + " 'value': 11},\n", + " 'input': { '__class__': 'qcodes.parameters.parameter.Parameter',\n", + " 'full_name': 'instr_input',\n", + " 'instrument': 'qcodes.instrument_drivers.mock_instruments.DummyInstrument',\n", + " 'instrument_name': 'instr',\n", + " 'inter_delay': 0,\n", + " 'label': 'Gate input',\n", + " 'name': 'input',\n", + " 'post_delay': 0,\n", + " 'raw_value': 0,\n", + " 'ts': '2024-10-08 14:04:12',\n", + " 'unit': 'V',\n", + " 'validators': [''],\n", + " 'vals': '',\n", + " 'value': 0},\n", + " 'output': { '__class__': 'qcodes.parameters.parameter.Parameter',\n", + " 'full_name': 'instr_output',\n", + " 'instrument': 'qcodes.instrument_drivers.mock_instruments.DummyInstrument',\n", + " 'instrument_name': 'instr',\n", + " 'inter_delay': 0,\n", + " 'label': 'Gate output',\n", + " 'name': 'output',\n", + " 'post_delay': 0,\n", + " 'raw_value': 0,\n", + " 'ts': '2024-10-08 14:04:12',\n", + " 'unit': 'V',\n", + " 'validators': [''],\n", + " 'vals': '',\n", + " 'value': 0}},\n", + " 'submodules': {}}\n" + ] + } + ], "source": [ "snapshot_of_instr = instr.snapshot()\n", "\n", @@ -192,9 +315,20 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 7, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'instr'" + ] + }, + "execution_count": 7, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "station = Station()\n", "\n", @@ -207,9 +341,119 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 8, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'components': {},\n", + " 'config': None,\n", + " 'instruments': {'instr': {'__class__': 'qcodes.instrument_drivers.mock_instruments.DummyInstrument',\n", + " 'functions': {},\n", + " 'label': 'instr',\n", + " 'name': 'instr',\n", + " 'parameters': {'IDN': {'__class__': 'qcodes.parameters.parameter.Parameter',\n", + " 'full_name': 'instr_IDN',\n", + " 'instrument': 'qcodes.instrument_drivers.mock_instruments.DummyInstrument',\n", + " 'instrument_name': 'instr',\n", + " 'inter_delay': 0,\n", + " 'label': 'IDN',\n", + " 'name': 'IDN',\n", + " 'post_delay': 0,\n", + " 'raw_value': {'firmware': 'NA',\n", + " 'model': '\",\n", + " 'serial': 'NA',\n", + " 'vendor': 'QCoDeS'},\n", + " 'ts': '2024-10-08 14:04:12',\n", + " 'unit': '',\n", + " 'validators': [''],\n", + " 'vals': '',\n", + " 'value': {'firmware': 'NA',\n", + " 'model': '\",\n", + " 'serial': 'NA',\n", + " 'vendor': 'QCoDeS'}},\n", + " 'fixed_parameter': {'__class__': 'qcodes.parameters.parameter.Parameter',\n", + " 'full_name': 'instr_fixed_parameter',\n", + " 'instrument': 'qcodes.instrument_drivers.mock_instruments.DummyInstrument',\n", + " 'instrument_name': 'instr',\n", + " 'inter_delay': 0,\n", + " 'label': 'fixed_parameter',\n", + " 'name': 'fixed_parameter',\n", + " 'post_delay': 0,\n", + " 'raw_value': 5,\n", + " 'ts': '2024-10-08 '\n", + " '14:04:12',\n", + " 'unit': '',\n", + " 'validators': [],\n", + " 'value': 5},\n", + " 'gain': {'__class__': 'qcodes.parameters.parameter.Parameter',\n", + " 'full_name': 'instr_gain',\n", + " 'instrument': 'qcodes.instrument_drivers.mock_instruments.DummyInstrument',\n", + " 'instrument_name': 'instr',\n", + " 'inter_delay': 0,\n", + " 'label': 'Gate gain',\n", + " 'name': 'gain',\n", + " 'post_delay': 0,\n", + " 'raw_value': 11,\n", + " 'ts': '2024-10-08 14:04:12',\n", + " 'unit': 'V',\n", + " 'validators': [''],\n", + " 'vals': '',\n", + " 'value': 11},\n", + " 'input': {'__class__': 'qcodes.parameters.parameter.Parameter',\n", + " 'full_name': 'instr_input',\n", + " 'instrument': 'qcodes.instrument_drivers.mock_instruments.DummyInstrument',\n", + " 'instrument_name': 'instr',\n", + " 'inter_delay': 0,\n", + " 'label': 'Gate input',\n", + " 'name': 'input',\n", + " 'post_delay': 0,\n", + " 'raw_value': 0,\n", + " 'ts': '2024-10-08 14:04:12',\n", + " 'unit': 'V',\n", + " 'validators': [''],\n", + " 'vals': '',\n", + " 'value': 0},\n", + " 'output': {'__class__': 'qcodes.parameters.parameter.Parameter',\n", + " 'full_name': 'instr_output',\n", + " 'instrument': 'qcodes.instrument_drivers.mock_instruments.DummyInstrument',\n", + " 'instrument_name': 'instr',\n", + " 'inter_delay': 0,\n", + " 'label': 'Gate output',\n", + " 'name': 'output',\n", + " 'post_delay': 0,\n", + " 'raw_value': 0,\n", + " 'ts': '2024-10-08 '\n", + " '14:04:12',\n", + " 'unit': 'V',\n", + " 'validators': [''],\n", + " 'vals': '',\n", + " 'value': 0}},\n", + " 'submodules': {}}},\n", + " 'parameters': {'p': {'__class__': 'qcodes.parameters.parameter.Parameter',\n", + " 'full_name': 'p',\n", + " 'inter_delay': 0,\n", + " 'label': 'Parameter P',\n", + " 'name': 'p',\n", + " 'post_delay': 0,\n", + " 'raw_value': 456,\n", + " 'ts': '2024-10-08 14:04:12',\n", + " 'unit': 'kg',\n", + " 'validators': [],\n", + " 'value': 456}}}\n" + ] + } + ], "source": [ "snapshot_of_station = station.snapshot()\n", "\n", @@ -220,13 +464,15 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "## Saving snapshot next to the measurement data\n", + "## Saving snapshots next to the measurement data\n", "\n", "With the power of the station object, it is now possible to conveniently associate the snapshot information with the measured data.\n", "\n", "In order to do so, a station needs to be created, and then that station needs to be provided to the `Measurement` object. If no station is explicitly provided, the `Measurement` object will use the default station, `Station.default` (refer to `Measurement` and `Station` objects docstrings for more information). At the moment the new measurement run is started, a snapshot of the whole station will be taken, and added next to the measured data.\n", "\n", - "Note that the snapshot gets stored in a JSON format (an automatic convertion from python dictionary to JSON takes place). This is done in order to ensure that the snapshot can be read in environments other than python. JSON is an extemely popular data format, and all platforms/environments/languages/frameworks have means to read JSON-formatted data." + "The measured dataset also automatically snapshots the parameters involved in the measurement and stores it alongside the station snapshot.\n", + "\n", + "Note that these snapshots get stored in a JSON format (an automatic convertion from python dictionary to JSON takes place). This is done in order to ensure that the snapshot can be read in environments other than python. JSON is an extemely popular data format, and all platforms/environments/languages/frameworks have means to read JSON-formatted data." ] }, { @@ -251,9 +497,20 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 10, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "" + ] + }, + "execution_count": 10, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "measurement = Measurement(experiment, station)\n", "\n", @@ -292,7 +549,7 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "Now we have a dataset that contains data from the measurement run. It also contains the snapshot.\n", + "Now we have a dataset that contains data from the measurement run. It also contains the station and parameters snapshots.\n", "\n", "In order to access the snapshot, use the `DataSet`'s properties called `snapshot` and `snapshot_raw`. As their docstrings declare, the former returns the snapshot of the run as a python dictionary, while the latter returns it as JSON string (in other words, in exactly the same format as it is stored in the experiments database)." ] @@ -344,14 +601,160 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "Finally, let's pretty-print the snapshot. Notice that the values of the `input` and `output` parameters of the `instr` instrument have `0`s as values, and not `111` and `222` that were set during the measurement run." + "Finally, let's pretty-print the snapshot. Notice that the values of the `input` and `output` parameters of the `instr` instrument have `0`s as values, and not `111` and `222` that were set during the measurement run.\n", + "\n", + "Also note that the `station` top-level-key contains the station snapshot, while the `parameters` top-level-key contains a snapshot of all the measurement parameters." ] }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 16, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'parameters': {'input': {'__class__': 'qcodes.parameters.parameter.Parameter',\n", + " 'full_name': 'instr_input',\n", + " 'instrument': 'qcodes.instrument_drivers.mock_instruments.DummyInstrument',\n", + " 'instrument_name': 'instr',\n", + " 'inter_delay': 0,\n", + " 'label': 'Gate input',\n", + " 'name': 'input',\n", + " 'post_delay': 0,\n", + " 'raw_value': 0,\n", + " 'ts': '2024-10-08 14:04:12',\n", + " 'unit': 'V',\n", + " 'validators': [''],\n", + " 'vals': '',\n", + " 'value': 0},\n", + " 'output': {'__class__': 'qcodes.parameters.parameter.Parameter',\n", + " 'full_name': 'instr_output',\n", + " 'instrument': 'qcodes.instrument_drivers.mock_instruments.DummyInstrument',\n", + " 'instrument_name': 'instr',\n", + " 'inter_delay': 0,\n", + " 'label': 'Gate output',\n", + " 'name': 'output',\n", + " 'post_delay': 0,\n", + " 'raw_value': 0,\n", + " 'ts': '2024-10-08 14:04:12',\n", + " 'unit': 'V',\n", + " 'validators': [''],\n", + " 'vals': '',\n", + " 'value': 0}},\n", + " 'station': {'components': {},\n", + " 'config': None,\n", + " 'instruments': {'instr': {'__class__': 'qcodes.instrument_drivers.mock_instruments.DummyInstrument',\n", + " 'functions': {},\n", + " 'label': 'instr',\n", + " 'name': 'instr',\n", + " 'parameters': {'IDN': {'__class__': 'qcodes.parameters.parameter.Parameter',\n", + " 'full_name': 'instr_IDN',\n", + " 'instrument': 'qcodes.instrument_drivers.mock_instruments.DummyInstrument',\n", + " 'instrument_name': 'instr',\n", + " 'inter_delay': 0,\n", + " 'label': 'IDN',\n", + " 'name': 'IDN',\n", + " 'post_delay': 0,\n", + " 'raw_value': {'firmware': 'NA',\n", + " 'model': '\",\n", + " 'serial': 'NA',\n", + " 'vendor': 'QCoDeS'},\n", + " 'ts': '2024-10-08 '\n", + " '14:04:12',\n", + " 'unit': '',\n", + " 'validators': [''],\n", + " 'vals': '',\n", + " 'value': {'firmware': 'NA',\n", + " 'model': '\",\n", + " 'serial': 'NA',\n", + " 'vendor': 'QCoDeS'}},\n", + " 'fixed_parameter': {'__class__': 'qcodes.parameters.parameter.Parameter',\n", + " 'full_name': 'instr_fixed_parameter',\n", + " 'instrument': 'qcodes.instrument_drivers.mock_instruments.DummyInstrument',\n", + " 'instrument_name': 'instr',\n", + " 'inter_delay': 0,\n", + " 'label': 'fixed_parameter',\n", + " 'name': 'fixed_parameter',\n", + " 'post_delay': 0,\n", + " 'raw_value': 5,\n", + " 'ts': '2024-10-08 '\n", + " '14:04:12',\n", + " 'unit': '',\n", + " 'validators': [],\n", + " 'value': 5},\n", + " 'gain': {'__class__': 'qcodes.parameters.parameter.Parameter',\n", + " 'full_name': 'instr_gain',\n", + " 'instrument': 'qcodes.instrument_drivers.mock_instruments.DummyInstrument',\n", + " 'instrument_name': 'instr',\n", + " 'inter_delay': 0,\n", + " 'label': 'Gate '\n", + " 'gain',\n", + " 'name': 'gain',\n", + " 'post_delay': 0,\n", + " 'raw_value': 11,\n", + " 'ts': '2024-10-08 '\n", + " '14:04:12',\n", + " 'unit': 'V',\n", + " 'validators': [''],\n", + " 'vals': '',\n", + " 'value': 11},\n", + " 'input': {'__class__': 'qcodes.parameters.parameter.Parameter',\n", + " 'full_name': 'instr_input',\n", + " 'instrument': 'qcodes.instrument_drivers.mock_instruments.DummyInstrument',\n", + " 'instrument_name': 'instr',\n", + " 'inter_delay': 0,\n", + " 'label': 'Gate '\n", + " 'input',\n", + " 'name': 'input',\n", + " 'post_delay': 0,\n", + " 'raw_value': 0,\n", + " 'ts': '2024-10-08 '\n", + " '14:04:12',\n", + " 'unit': 'V',\n", + " 'validators': [''],\n", + " 'vals': '',\n", + " 'value': 0},\n", + " 'output': {'__class__': 'qcodes.parameters.parameter.Parameter',\n", + " 'full_name': 'instr_output',\n", + " 'instrument': 'qcodes.instrument_drivers.mock_instruments.DummyInstrument',\n", + " 'instrument_name': 'instr',\n", + " 'inter_delay': 0,\n", + " 'label': 'Gate '\n", + " 'output',\n", + " 'name': 'output',\n", + " 'post_delay': 0,\n", + " 'raw_value': 0,\n", + " 'ts': '2024-10-08 '\n", + " '14:04:12',\n", + " 'unit': 'V',\n", + " 'validators': [''],\n", + " 'vals': '',\n", + " 'value': 0}},\n", + " 'submodules': {}}},\n", + " 'parameters': {'p': {'__class__': 'qcodes.parameters.parameter.Parameter',\n", + " 'full_name': 'p',\n", + " 'inter_delay': 0,\n", + " 'label': 'Parameter P',\n", + " 'name': 'p',\n", + " 'post_delay': 0,\n", + " 'raw_value': 456,\n", + " 'ts': '2024-10-08 14:04:12',\n", + " 'unit': 'kg',\n", + " 'validators': [],\n", + " 'value': 456}}}}\n" + ] + } + ], "source": [ "pprint(snapshot_of_run)" ] @@ -360,7 +763,7 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "Note that the snapshot that we have just loaded from the dataset is almost the same as the snapshot that we directly obtained from the station above. The only difference is that the snapshot loaded from the dataset has a top-level `station` field. If you do not trust me, have a look at the following `assert` statement for the proof." + "Note that the snapshot that we have just loaded from the dataset is almost the same as the snapshot that we directly obtained from the station above. One difference is that the snapshot loaded from the dataset has a top-level `station` field. It also has a top-level `parameters` field. If you do not trust me, have a look at the following `assert` statement for the proof." ] }, { @@ -372,13 +775,6 @@ "assert snapshot_of_station == snapshot_of_run[\"station\"]" ] }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## Comparing how two DataSets were taken" - ] - }, { "cell_type": "markdown", "metadata": {}, @@ -424,7 +820,7 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "The `diff_param_values` function tells us about the parameters that changed betw" + "The `diff_param_values` function tells us about the parameters that changed between the two snapshots" ] }, { @@ -433,7 +829,7 @@ "metadata": {}, "outputs": [], "source": [ - "from qcodes.utils.metadata import diff_param_values" + "from qcodes.utils import diff_param_values" ] }, {