Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
repos:
- repo: https://github.com/astral-sh/ruff-pre-commit
# Ruff version.
rev: v0.16.3
rev: v0.16.2
hooks:
- id: ruff-check
types_or: [python, pyi, jupyter, toml]
Expand Down
19 changes: 16 additions & 3 deletions docs/examples/DataSet/Working with snapshots.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,9 @@
"outputs": [],
"source": [
"import json # for converting JSON data into python 'dict'\n",
"from difflib import unified_diff\n",
"from pathlib import Path\n",
"from pprint import pprint # for pretty-printing python variables like 'dict'\n",
"from pprint import pformat, pprint # for pretty-printing python variables like 'dict'\n",
"\n",
"from qcodes.dataset import (\n",
" Measurement,\n",
Expand Down Expand Up @@ -554,6 +555,8 @@
"metadata": {},
"outputs": [],
"source": [
"snapshot_of_station_before_run = station.snapshot()\n",
"\n",
"with measurement.run() as data_saver:\n",
" input_value = 111\n",
" instr.input.set(input_value)\n",
Expand Down Expand Up @@ -793,7 +796,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. 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."
"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 immediately before the run. One difference is that the snapshot loaded from the dataset has a top-level `station` field. It also has a top-level `parameters` field. The following comparison raises an error with a unified diff if the station snapshots do not match."
]
},
{
Expand All @@ -802,7 +805,17 @@
"metadata": {},
"outputs": [],
"source": [
"assert snapshot_of_station == snapshot_of_run[\"station\"]"
"if snapshot_of_station_before_run != snapshot_of_run[\"station\"]:\n",
" snapshot_diff = \"\\n\".join(\n",
" unified_diff(\n",
" pformat(snapshot_of_station_before_run).splitlines(),\n",
" pformat(snapshot_of_run[\"station\"]).splitlines(),\n",
" fromfile=\"snapshot_of_station_before_run\",\n",
" tofile='snapshot_of_run[\"station\"]',\n",
" lineterm=\"\",\n",
" )\n",
" )\n",
" raise RuntimeError(f\"Station snapshots differ:\\n{snapshot_diff}\")"
]
},
{
Expand Down
Loading