Skip to content

Commit

Permalink
Merge branch 'main' into samanthaho/delegate_inherits_settable_gettable
Browse files Browse the repository at this point in the history
  • Loading branch information
jenshnielsen authored Nov 22, 2024
2 parents e33435f + 44cd451 commit d60d310
Show file tree
Hide file tree
Showing 9 changed files with 51 additions and 10 deletions.
1 change: 1 addition & 0 deletions docs/changes/newsfragments/6643.improved
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Improves the DataSetDefinition class to allow users to specify metadata to be added to the resulting dataset
5 changes: 5 additions & 0 deletions docs/changes/newsfragments/6647.breaking
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
QCoDeS no longer attempts to automatically disable Sypders User module reloader (UMR).
The code was no longer working correctly with the latest version of Spyder and is not
maintainable since Spyder does not have a public api to disable UMR. If you use
QCoDeS from an editable install it is strongly recommended to disable UMR for QCoDeS.
See :ref:`gettingstarted` for more details.
11 changes: 11 additions & 0 deletions docs/start/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,17 @@ or jupyter lab:
jupyter lab
.. note::

Note that Spyder ships with functionality to automatically reload modules that are installed
editable. This functionality called
`User Module Reloader <https://docs.spyder-ide.org/current/panes/ipythonconsole.html#reload-changed-modules>`__
is known to not work well with QCoDeS. If you install QCoDeS editable (with -e flag)
we strongly recommend users to exclude QCoDeS from UMR. QCoDeS used to attempt to automatically
disable this feature. However, as `Spyder does not provide a public API for doing this <https://github.com/spyder-ide/spyder/issues/2451>`__
this relied on a private API in Spyder and broke with the last Spyder release.
If at some point this becomes possible to do with a public API QCoDeS may again disable this automatically.

For other options from the terminal you can activate the QCoDeS in that terminal
then start any other application, such as *IPython* or
just plain old *Python*.
Expand Down
4 changes: 2 additions & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ dask==2024.11.2
# via
# qcodes (pyproject.toml)
# qcodes
debugpy==1.8.8
debugpy==1.8.9
# via ipykernel
decorator==5.1.1
# via ipython
Expand Down Expand Up @@ -422,7 +422,7 @@ toolz==1.0.0
# via
# dask
# partd
tornado==6.4.1
tornado==6.4.2
# via
# qcodes (pyproject.toml)
# ipykernel
Expand Down
6 changes: 0 additions & 6 deletions src/qcodes/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
import qcodes.configuration as qcconfig
from qcodes.logger.logger import conditionally_start_all_logging
from qcodes.utils import QCoDeSDeprecationWarning
from qcodes.utils.spyder_utils import add_to_spyder_UMR_excludelist

__version__ = qcodes._version.__version__

Expand All @@ -25,11 +24,6 @@

conditionally_start_all_logging()

# we dont want spyder to reload qcodes as this will overwrite the default station
# instrument list and running monitor
add_to_spyder_UMR_excludelist("qcodes")


import atexit

import qcodes.validators
Expand Down
8 changes: 8 additions & 0 deletions src/qcodes/dataset/measurement_extensions.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ class DataSetDefinition:
experiment: Experiment | None = None
"""An optional argument specifying which Experiment this dataset should be
written to"""
metadata: dict[str, Any] | None = None
"""An optional dictionary of metadata that will be added to the dataset
generated by this definition"""


def setup_measurement_instances(
Expand Down Expand Up @@ -107,6 +110,11 @@ def datasaver_builder(
stack.enter_context(measurement.run(parent_span=datasaver_builder_span))
for measurement in measurement_instances
]
for i, datasaver in enumerate(datasavers):
ds_def = dataset_definitions[i]
if ds_def.metadata is not None:
for key, value in ds_def.metadata.items():
datasaver.dataset.add_metadata(tag=key, metadata=value)
yield datasavers


Expand Down
4 changes: 3 additions & 1 deletion src/qcodes/utils/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@
from .json_utils import NumpyJSONEncoder
from .partial_utils import partial_with_docstring
from .path_helpers import QCODES_USER_PATH_ENV, get_qcodes_path, get_qcodes_user_path
from .spyder_utils import add_to_spyder_UMR_excludelist
from .spyder_utils import (
add_to_spyder_UMR_excludelist, # pyright: ignore[reportDeprecated]
)


# on longer in used but left for backwards compatibility until
Expand Down
8 changes: 8 additions & 0 deletions src/qcodes/utils/spyder_utils.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,17 @@
import logging
import os

from typing_extensions import deprecated

from qcodes.utils.deprecate import QCoDeSDeprecationWarning

_LOG = logging.getLogger(__name__)


@deprecated(
"Known to not work with latest Spyder and unused in QCoDeS",
category=QCoDeSDeprecationWarning,
)
def add_to_spyder_UMR_excludelist(modulename: str) -> None:
"""
Spyder tries to reload any user module. This does not work well for
Expand Down
14 changes: 13 additions & 1 deletion tests/dataset/test_measurement_extensions.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,17 @@ def default_database_and_experiment_(tmp_path):
def test_context(default_params, default_database_and_experiment):
_ = default_database_and_experiment
set1, set2, set3, meas1, meas2, meas3 = default_params
metadata_dict = { # Nesting dictionaries does NOT work here
"test_metadata": "test_meta_value_1",
"test_metadata_2": "test_meta_value_2",
}
dataset_definition = [
DataSetDefinition(name="dataset_1", independent=[set1], dependent=[meas1]),
DataSetDefinition(
name="dataset_1",
independent=[set1],
dependent=[meas1],
metadata=metadata_dict,
),
DataSetDefinition(
name="dataset_2", independent=[set1, set2, set3], dependent=[meas2, meas3]
),
Expand Down Expand Up @@ -133,6 +142,8 @@ def test_context(default_params, default_database_and_experiment):
},
data_vars=(meas1.name,),
)
assert datasets[0].metadata == metadata_dict

assert_dataset_as_expected(
datasets[1],
dims_dict={
Expand All @@ -142,6 +153,7 @@ def test_context(default_params, default_database_and_experiment):
},
data_vars=(meas2.name, meas3.name),
)
assert datasets[1].metadata == {}


def test_dond_into(default_params, default_database_and_experiment):
Expand Down

0 comments on commit d60d310

Please sign in to comment.