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 register_name to register parameters by in datasets #5381

Merged
merged 23 commits into from
Oct 6, 2023
Merged
Show file tree
Hide file tree
Changes from 15 commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
d30f70c
Initial implementation
samantha-ho Sep 19, 2023
6f64db9
Fix formatting issues
samantha-ho Sep 20, 2023
431ae5a
Updating other places where name/full_name were assumed
samantha-ho Sep 20, 2023
61160b1
Add integration tests
samantha-ho Sep 21, 2023
acfe156
Add docstring
samantha-ho Oct 5, 2023
1c9f482
Rename test parameters
samantha-ho Oct 5, 2023
ddce884
Add str_or_register to public API
samantha-ho Oct 5, 2023
7b080c2
Expand Tests and add str_or_register_name to `unregister`
samantha-ho Oct 5, 2023
6b2c8b0
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Oct 5, 2023
39a5fee
Add example notebook
samantha-ho Oct 5, 2023
f12a200
Add Changelog file
samantha-ho Oct 5, 2023
e06c11c
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Oct 5, 2023
13d02c9
Merge branch 'master' into samanthaho/register_names
samantha-ho Oct 5, 2023
60cb958
Fix pre-commit errors
samantha-ho Oct 5, 2023
db6462f
Expand error message to refer to register_name
samantha-ho Oct 5, 2023
5320c0b
Keep str_or_register_name `private`
samantha-ho Oct 6, 2023
6ecbcda
Apply docstring suggestions from code review
samantha-ho Oct 6, 2023
98f3388
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Oct 6, 2023
88aa0dc
Remove missed reference to str_or_register_name in _init__ all
samantha-ho Oct 6, 2023
ea36aef
Merge branch 'samanthaho/register_names' of https://github.com/samant…
samantha-ho Oct 6, 2023
bbbdc3c
Reformat for Darker
samantha-ho Oct 6, 2023
c703b81
More Reformatting for Darker
samantha-ho Oct 6, 2023
862d3ea
Darkening
samantha-ho Oct 6, 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
2 changes: 2 additions & 0 deletions docs/changes/newsfragments/5381.new
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Add a register_name keyword to the ParameterBase constructor. If supplied, this value
will be used to register parameters in datasets instead of the default full_name.
samantha-ho marked this conversation as resolved.
Show resolved Hide resolved
173 changes: 173 additions & 0 deletions docs/examples/DataSet/Using_register_name.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,173 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Using the `register_name` kwarg to select how a parameter is saved to a dataset\n",
"\n",
"This example notebook shows how to use the `register_name` keyword argument to control the name used to save a parameter to a dataset\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Setup\n",
"\n",
"### Module Imports\n"
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {},
"outputs": [],
"source": [
"from functools import partial\n",
"from pprint import pprint\n",
"\n",
"import numpy as np\n",
"\n",
"import qcodes as qc\n",
"from qcodes.dataset import do0d, do1d\n",
"from qcodes.parameters import ManualParameter, Parameter, ParameterWithSetpoints\n",
"from qcodes.validators import Arrays"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Database and Experiment creation"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
"qc.initialise_or_create_database_at(\"experiments.db\")\n",
"qc.load_or_create_experiment(\"register_name\")"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Creating a Parameter with a `register_name`\n",
"\n",
"It is simple to create a parameter with a `register_name`. Simply provide the keyword and the desired name to the parameter initialization. "
]
},
{
"cell_type": "code",
"execution_count": 8,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Starting experimental run with id: 5. Using 'qcodes.dataset.do1d'\n",
"[ParamSpec('renamed_indep_param', 'numeric', 'indep_param', '', inferred_from=[], depends_on=[]),\n",
" ParamSpec('renamed_dep_param', 'numeric', 'dep_param', '', inferred_from=[], depends_on=['renamed_indep_param'])]\n"
]
}
],
"source": [
"indep_param = ManualParameter(\"indep_param\", initial_value=1, register_name=\"renamed_indep_param\")\n",
"dep_param = ManualParameter(\"dep_param\", initial_value= 2, register_name=\"renamed_dep_param\")\n",
"\n",
"ds, _,_ = do1d(indep_param, 0, 1, 101, 0, dep_param)\n",
"pprint(ds.get_parameters())"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Note that the dataset's ParamSpecs have replaced the usual parameter name with the register name.\n",
"\n",
"Why is this useful?\n",
"---\n",
"Imagine that you have a parameter that is defined as part of a complex instrument. The parameter's full_name may be something like:\n",
"\n",
"`instrument_submodule1_submodule2_param_full_name`\n",
"\n",
"But you only really care about `param_full_name`. The `register_name` allows the user to define the string saved to the dataset decoupling the structure in the instrument.\n",
"\n",
"## ParameterWithSetpoints\n",
"\n",
"`register_name` also works with the ParameterWithSetpoints"
]
},
{
"cell_type": "code",
"execution_count": 9,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Starting experimental run with id: 6. Using 'qcodes.dataset.do0d'\n",
"[ParamSpec('renamed_setpoints', 'array', 'setpoints_param', '', inferred_from=[], depends_on=[]),\n",
" ParamSpec('renamed_meas_param', 'array', 'meas_param', '', inferred_from=[], depends_on=['renamed_setpoints'])]\n"
]
}
],
"source": [
"setpoints_param = Parameter(\n",
" name=\"setpoints_param\",\n",
" get_cmd=partial(np.linspace, 0, 1, 101),\n",
" vals=Arrays(shape=(101,)),\n",
" register_name=\"renamed_setpoints\",\n",
")\n",
"meas_param = ParameterWithSetpoints(\n",
" \"meas_param\",\n",
" setpoints=(setpoints_param,),\n",
" get_cmd=partial(np.linspace, 0, -1, 101),\n",
" vals=Arrays(\n",
" shape=(101,),\n",
" valid_types=[np.integer, np.floating, np.complexfloating],\n",
" ),\n",
" register_name=\"renamed_meas_param\",\n",
")\n",
"\n",
"ds, _, _ = do0d(meas_param)\n",
"pprint(ds.get_parameters())"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Note: `register_name` does not currently work with `MultiParameter` or `ArrayParameter`"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "py311",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.11.4"
},
"orig_nbformat": 4
},
"nbformat": 4,
"nbformat_minor": 2
}
3 changes: 2 additions & 1 deletion qcodes/dataset/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
datasaver_builder,
dond_into,
)
from .measurements import Measurement
from .measurements import Measurement, str_or_register_name
samantha-ho marked this conversation as resolved.
Show resolved Hide resolved
from .plotting import plot_by_id, plot_dataset
from .sqlite.connection import ConnectionPlus
from .sqlite.database import (
Expand Down Expand Up @@ -112,4 +112,5 @@
"plot_dataset",
"reset_default_experiment_id",
"rundescriber_from_json",
"str_or_register_name"
]