Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add datasaver_builder and dond_core #5294

Merged
merged 45 commits into from
Aug 11, 2023
Merged
Show file tree
Hide file tree
Changes from 42 commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
c483f0f
Add prototype complex_measurements notebook to examples
samantha-ho Jan 23, 2023
741cdcd
WIP Commit
samantha-ho Jul 24, 2023
c32b9fd
Add hacky tests
samantha-ho Jul 24, 2023
ee81588
Add copy/paste of ipynb tests
samantha-ho Jul 24, 2023
19b6281
Make tests minimally functional
samantha-ho Jul 24, 2023
52b381a
Rename to measurement_extensions
samantha-ho Jul 25, 2023
ea38b35
Make _Sweeper an iterable
samantha-ho Jul 25, 2023
26273fa
Change dond arg parse to explicilty reject groups and TogetherSweeps
samantha-ho Jul 26, 2023
d0a17d4
Rename CMC to datasaver_builder
samantha-ho Jul 27, 2023
24ff587
Make catch_interrupts not private
samantha-ho Jul 28, 2023
7f0ccde
Fixing broken imports from renaming _catch_interrupts
samantha-ho Jul 28, 2023
609c764
Merge branch 'QCoDeS:master' into samanthaho/complex_context
samantha-ho Jul 31, 2023
0a3edb5
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jul 31, 2023
485986e
Add Changelog file
samantha-ho Jul 31, 2023
6424654
Merge branch 'samanthaho/complex_context' of https://github.com/saman…
samantha-ho Jul 31, 2023
8a275de
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jul 31, 2023
1b7dbde
Add docstrings
samantha-ho Aug 3, 2023
afc3e7f
Fix typing and pyright issues
samantha-ho Aug 4, 2023
351dd0a
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Aug 4, 2023
c2c8c4c
Fix more mypy errors
samantha-ho Aug 4, 2023
f15d300
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Aug 4, 2023
2c8d986
Merge branch 'master' into samanthaho/complex_context
samantha-ho Aug 4, 2023
35291ec
Clean up unused imports and variables
samantha-ho Aug 4, 2023
ac00a4d
Add dataset assertions
samantha-ho Aug 4, 2023
9461ccf
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Aug 4, 2023
7a36cdf
Fix Codacy Issues
samantha-ho Aug 5, 2023
6b4ffb0
Revise example notebook
samantha-ho Aug 7, 2023
495f403
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Aug 7, 2023
131a6b1
Fix bug in example notebook imports
samantha-ho Aug 7, 2023
6c39db0
Merge branch 'samanthaho/complex_context' of https://github.com/saman…
samantha-ho Aug 8, 2023
baf23af
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Aug 8, 2023
d7b1c76
Fix DataSetDefinition docstrings
samantha-ho Aug 8, 2023
c28cb2c
Merge branch 'master' into samanthaho/complex_context
samantha-ho Aug 8, 2023
7418c92
Fix codeblock docstring error
samantha-ho Aug 8, 2023
ada18c0
Rename dond_core to dond_into
samantha-ho Aug 9, 2023
a0f8a44
Rename changelog file from .improved to .new
samantha-ho Aug 9, 2023
c1edf0f
Fix typo
samantha-ho Aug 9, 2023
76afe25
Add new Experiment behavior, as suggested
samantha-ho Aug 10, 2023
27af53c
Update example to use new Experiment feature
samantha-ho Aug 10, 2023
712541d
Reformat docstrings to be less than 88 characters
samantha-ho Aug 10, 2023
cf4bfd5
Remove Try..Except from datasaver_builder
samantha-ho Aug 10, 2023
043fc18
Merge branch 'master' into samanthaho/complex_context
samantha-ho Aug 10, 2023
56b3267
Indent section hierarchy of example notebook
samantha-ho Aug 11, 2023
eed8297
Merge branch 'samanthaho/complex_context' of https://github.com/saman…
samantha-ho Aug 11, 2023
4ae56f1
Merge branch 'master' into samanthaho/complex_context
samantha-ho Aug 11, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions docs/changes/newsfragments/5294.new
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
New features: datasaver_builder and dond_into are intermediate measurement extensions designed to fill a gap between
the low-level Measurement object and the high-level doNd functions. They allow convenient specification of parameter
dependencies for registration and doNd-like syntax while also allowing direct access to the underlying datasaver objects.
1 change: 1 addition & 0 deletions docs/examples/DataSet/Accessing-data-in-DataSet.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -18113,6 +18113,7 @@
" standalones = all_independents.difference(used_independents)\n",
" return tuple(ps for ps in paramspecs if ps.name in standalones)\n",
"\n",
"\n",
"all_parameters = dataset.get_parameters()\n",
"standalone_parameters = get_standalone_parameters(all_parameters)\n",
"standalone_parameters"
Expand Down
1 change: 0 additions & 1 deletion docs/examples/DataSet/Cache/write_for_caching.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,6 @@
" datasaver.flush_data_to_database(block=True)\n",
" time.sleep(0.1)\n",
"\n",
" \n",
" dataset = datasaver.dataset # convenient to have for plotting"
]
},
Expand Down
426 changes: 426 additions & 0 deletions docs/examples/DataSet/Datasaver_Builder.ipynb
samantha-ho marked this conversation as resolved.
Show resolved Hide resolved

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions docs/examples/DataSet/Offline Plotting Tutorial.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -649,18 +649,22 @@
"tvals = np.linspace(-500, 1500, 25)\n",
"\n",
"# define two small forbidden range functions\n",
"\n",
"\n",
"def no_x(xv):\n",
" if xv > 0 and xv < 3:\n",
" return True\n",
" else:\n",
" return False\n",
" \n",
"\n",
"def no_t(tv):\n",
" if tv > 0 and tv < 450:\n",
" return True\n",
" else:\n",
" return False\n",
"\n",
"\n",
"with meas.run() as datasaver:\n",
" for xv in xvals:\n",
" for tv in tvals:\n",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,6 @@
" datasaver.add_result((fridge_config, configuration),\n",
" (voltage, np.random.rand()))\n",
"\n",
"\n",
" datasaver.add_result((fridge_config, 'open'),\n",
" (voltage, np.random.rand()))\n",
" \n",
Expand Down Expand Up @@ -554,6 +553,7 @@
" return 'Possible'\n",
" return 'Good'\n",
"\n",
"\n",
"with meas.run() as datasaver:\n",
" \n",
" for bias_v in np.linspace(0, 3, 100):\n",
Expand Down Expand Up @@ -644,6 +644,7 @@
" return 'Possible'\n",
" return 'Good'\n",
"\n",
"\n",
"with meas.run() as datasaver:\n",
" \n",
" for bias_v in 3*(np.random.rand(100)):\n",
Expand Down Expand Up @@ -724,6 +725,7 @@
"\n",
"# a function to simulate the usefulness of a region\n",
"\n",
"\n",
"def get_usefulness(x, y):\n",
" x_num = samples.index(x)*4/len(samples)\n",
" val = np.sin(x_num)*np.sin(y)\n",
Expand All @@ -735,6 +737,7 @@
" return 'Possible'\n",
" return 'Good'\n",
"\n",
"\n",
"with meas.run() as datasaver:\n",
" \n",
" for samp in samples:\n",
Expand Down Expand Up @@ -810,6 +813,7 @@
"\n",
"# a function to simulate the usefulness of a region\n",
"\n",
"\n",
"def get_usefulness(x, y):\n",
" x_num = samples.index(x)*4/len(samples)\n",
" val = np.sin(x_num)*np.sin(y)\n",
Expand All @@ -821,6 +825,7 @@
" return 'Possible'\n",
" return 'Good'\n",
"\n",
"\n",
"with meas.run() as datasaver:\n",
" \n",
" for samp in samples:\n",
Expand Down
4 changes: 4 additions & 0 deletions docs/examples/DataSet/Paramtypes explained.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@
"source": [
"# some array-like data types\n",
"\n",
"\n",
"class Spectrum(ArrayParameter):\n",
" \n",
" def __init__(self, name, instrument):\n",
Expand Down Expand Up @@ -150,13 +151,16 @@
" setpoint_names=('Frequency0', 'Frequency1',\n",
" 'Frequency2'),\n",
" setpoint_units=('Hz', 'Other Hz', \"Third Hz\"))\n",
"\n",
" def get_raw(self):\n",
" a = self.npts[0]\n",
" b = self.npts[1]\n",
" c = self.npts[2]\n",
" return np.reshape(np.arange(a*b*c), (a, b, c))\n",
" \n",
"# a string-valued parameter\n",
"\n",
"\n",
"def dac1_too_high():\n",
" return 'Too high' if dac.ch1() > 5 else 'OK'"
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,12 +116,15 @@
"source": [
"# now make some silly set-up and tear-down actions\n",
"\n",
"\n",
"def veryfirst():\n",
" print('Starting the measurement')\n",
"\n",
"\n",
"def numbertwo(inst1, inst2):\n",
" print(f'Doing stuff with the following two instruments: {inst1}, {inst2}')\n",
" \n",
"\n",
"def thelast():\n",
" print('End of experiment')"
]
Expand Down Expand Up @@ -3317,6 +3320,7 @@
" dac.ch2(xk[1])\n",
" return dmm.v2.get()\n",
"\n",
"\n",
"noise = 0.0005\n",
"x0 = [np.random.rand(), np.random.rand()]\n",
"\n",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -917,14 +917,18 @@
],
"source": [
"# set-up and tear-down actions\n",
"\n",
"\n",
"def setup():\n",
" key.ch1.output('ON')\n",
"\n",
"\n",
"def teardown():\n",
" key.ch1.output('OFF')\n",
"\n",
"# simple frequency sweep\n",
"\n",
"\n",
"meas = Measurement()\n",
"meas.register_parameter(key.ch1.frequency)\n",
"meas.register_parameter(sr830.R, setpoints=(key.ch1.frequency,))\n",
Expand Down Expand Up @@ -2636,6 +2640,8 @@
"outputs": [],
"source": [
"# Prepare the scope\n",
"\n",
"\n",
"def scope_setup():\n",
" mso.ch1.input('DC50')\n",
"\n",
Expand Down Expand Up @@ -2665,6 +2671,7 @@
" \n",
" mso.write('run')\n",
"\n",
"\n",
"def keysight_setup():\n",
" # Prepare the Keysight\n",
" key.ch2.function_type('TRI')\n",
Expand All @@ -2673,6 +2680,7 @@
" key.ch2.burst_state('OFF')\n",
" key.ch2.output('ON')\n",
" \n",
"\n",
"def keysight_teardown():\n",
" key.ch2.output('OFF')"
]
Expand Down
1 change: 1 addition & 0 deletions docs/examples/DataSet/Saving_data_in_the_background.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@
"def gaussian(x, mu, sig):\n",
" return np.exp(-np.power(x - mu, 2.) / (2 * np.power(sig, 2.)))\n",
"\n",
"\n",
"def get_response():\n",
" \"\"\"\n",
" Simulated slow instrument response\n",
Expand Down
1 change: 1 addition & 0 deletions docs/examples/Parameters/Legacy_Parameters.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
" self._val += 6\n",
" return out\n",
"\n",
"\n",
"array_counter = ArrayCounter()\n",
"\n",
"# simple get\n",
Expand Down
2 changes: 2 additions & 0 deletions docs/examples/Parameters/MultiParameter.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
" scale_val = self._scale_param()\n",
" return (scale_val, scale_val / 2)\n",
"\n",
"\n",
"scale = ManualParameter('scale', initial_value=2)\n",
"iq = SingleIQPair(scale_param=scale)\n",
"\n",
Expand Down Expand Up @@ -93,6 +94,7 @@
" scale_val = self._scale_param()\n",
" return (self._indices * scale_val, self._indices * scale_val / 2)\n",
"\n",
"\n",
"iq_array = IQArray(scale_param=scale)\n",
"\n",
"# simple get\n",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@
" A parameter that generates a setpoint array from start, stop and num points\n",
" parameters.\n",
" \"\"\"\n",
"\n",
" def __init__(self, startparam, stopparam, numpointsparam, *args, **kwargs):\n",
" super().__init__(*args, **kwargs)\n",
" self._startparam = startparam\n",
Expand All @@ -101,7 +102,6 @@
" self._numpointsparam())\n",
"\n",
"\n",
" \n",
"class DummyArray(ParameterWithSetpoints):\n",
" \n",
" def get_raw(self):\n",
Expand All @@ -115,7 +115,6 @@
" \n",
" super().__init__(name, **kwargs)\n",
" \n",
"\n",
" self.add_parameter('sweep_start',\n",
" source=None,\n",
" parameter_class=DelegateParameter)\n",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@
" A parameter that generates a setpoint array from start, stop and num points\n",
" parameters.\n",
" \"\"\"\n",
"\n",
" def __init__(self, startparam, stopparam, numpointsparam, *args, **kwargs):\n",
" super().__init__(*args, **kwargs)\n",
" self._startparam = startparam\n",
Expand All @@ -102,6 +103,7 @@
" return np.linspace(self._startparam(), self._stopparam(),\n",
" self._numpointsparam())\n",
"\n",
"\n",
"class DummyArray(ParameterWithSetpoints):\n",
" \n",
" def get_raw(self):\n",
Expand All @@ -115,7 +117,6 @@
" \n",
" super().__init__(name, **kwargs)\n",
" \n",
"\n",
" self.add_parameter('f_start',\n",
" initial_value=0,\n",
" unit='Hz',\n",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,8 @@
"source": [
"n_avgs = 10\n",
"vna.number_of_averages(n_avgs)\n",
"\n",
"\n",
"def run_sweeper():\n",
" vna.run_N_times(n_avgs)"
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@
" \"\"\"\n",
" return np.sqrt(x**2 + y**2 + z**2) <= 1\n",
"\n",
"\n",
"# assign the limit function (this can also be done at init)\n",
"mips.set_new_field_limits(spherical_limit)"
]
Expand Down
10 changes: 10 additions & 0 deletions qcodes/dataset/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,12 @@
from .export_config import get_data_export_path
from .guid_helpers import guids_from_dbs, guids_from_dir, guids_from_list_str
from .legacy_import import import_dat_file
from .measurement_extensions import (
DataSetDefinition,
LinSweeper,
datasaver_builder,
dond_into,
)
from .measurements import Measurement
from .plotting import plot_by_id, plot_dataset
from .sqlite.connection import ConnectionPlus
Expand Down Expand Up @@ -71,10 +77,13 @@
"TogetherSweep",
"call_params_threaded",
"connect",
"datasaver_builder",
"DataSetDefinition",
"do0d",
"do1d",
"do2d",
"dond",
"dond_into",
"experiments",
"extract_runs_into_db",
"get_data_export_path",
Expand All @@ -87,6 +96,7 @@
"initialise_database",
"initialise_or_create_database_at",
"initialised_database_at",
"LinSweeper",
"load_by_counter",
"load_by_guid",
"load_by_id",
Expand Down
4 changes: 2 additions & 2 deletions qcodes/dataset/dond/do_1d.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@
from qcodes.dataset.descriptions.detect_shapes import detect_shape_of_measurement
from qcodes.dataset.dond.do_nd_utils import (
BreakConditionInterrupt,
_catch_interrupts,
_handle_plotting,
_register_actions,
_register_parameters,
_set_write_period,
catch_interrupts,
)
from qcodes.dataset.experiment_container import Experiment
from qcodes.dataset.measurements import Measurement
Expand Down Expand Up @@ -146,7 +146,7 @@ def do1d(
# do1D enforces a simple relationship between measured parameters
# and set parameters. For anything more complicated this should be
# reimplemented from scratch
with _catch_interrupts() as interrupted, meas.run() as datasaver, param_meas_caller as call_param_meas:
with catch_interrupts() as interrupted, meas.run() as datasaver, param_meas_caller as call_param_meas:
dataset = datasaver.dataset
additional_setpoints_data = process_params_meas(additional_setpoints)
setpoints = np.linspace(start, stop, num_points)
Expand Down
5 changes: 3 additions & 2 deletions qcodes/dataset/dond/do_2d.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@
from qcodes.dataset.descriptions.detect_shapes import detect_shape_of_measurement
from qcodes.dataset.dond.do_nd_utils import (
BreakConditionInterrupt,
_catch_interrupts,
_handle_plotting,
_register_actions,
_register_parameters,
_set_write_period,
catch_interrupts,
)
from qcodes.dataset.experiment_container import Experiment
from qcodes.dataset.measurements import Measurement
Expand All @@ -39,6 +39,7 @@
ParamMeasT,
)


def do2d(
param_set1: ParameterBase,
start1: float,
Expand Down Expand Up @@ -166,7 +167,7 @@
else SequentialParamsCaller(*param_meas)
)

with _catch_interrupts() as interrupted, meas.run() as datasaver, param_meas_caller as call_param_meas:
with catch_interrupts() as interrupted, meas.run() as datasaver, param_meas_caller as call_param_meas:

Check notice on line 170 in qcodes/dataset/dond/do_2d.py

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

qcodes/dataset/dond/do_2d.py#L170

Line too long (106/88)
dataset = datasaver.dataset
additional_setpoints_data = process_params_meas(additional_setpoints)
setpoints1 = np.linspace(start1, stop1, num_points1)
Expand Down