Repository navigation
Run Python 3.15 CI with lazy QCoDeS imports + Move and Deprecate modules that overlap classes #8600
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
Open
Jens Hedegaard Nielsen (jenshnielsen)
wants to merge
6
commits into
microsoft:main
Choose a base branch
from
jenshnielsen:lazy_import_test
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
ca8ccf7
Run Python 3.15 CI with lazy QCoDeS imports
jenshnielsen fe6f4e8
Move modules shadowed by package attributes to private modules
jenshnielsen 720d374
Fix do2d_retrace and export it from qcodes.dataset
jenshnielsen cad2794
Export SR560VoltageParameter and keep other SRS parameter classes pri…
jenshnielsen aa846d3
Prefix SR830 parameter classes with the instrument name
jenshnielsen 06604d7
Clarify that names not exported from parent packages are private
jenshnielsen File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| """Limit globally enabled lazy imports to imports involving QCoDeS.""" | ||
|
|
||
| # ruff: noqa: INP001 | ||
|
|
||
| import sys | ||
|
|
||
|
|
||
| def qcodes_import_filter( | ||
| importing: str | None, imported: str, fromlist: tuple[str, ...] | None | ||
| ) -> bool: | ||
| return imported.startswith("qcodes") or ( | ||
| importing is not None and importing.startswith("qcodes") | ||
| ) | ||
|
|
||
|
|
||
| sys.set_lazy_imports_filter(qcodes_import_filter) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| To support Python 3.15 lazy imports, modules whose names collide with objects exported | ||
| from their parent package have been moved to private modules. This affects | ||
| ``qcodes.dataset.dond`` and its submodules, ``qcodes.utils.full_class``, the Stanford Research | ||
| driver modules (e.g. ``qcodes.instrument_drivers.stanford_research.SR830``) and the Basel | ||
| driver modules (e.g. ``qcodes.instrument_drivers.basel.BaselSP983``). The old module paths | ||
| remain available as deprecated aliases that emit a ``QCoDeSDeprecationWarning`` and will be | ||
| removed in a future release. Import the objects from the parent package instead, e.g. | ||
| ``from qcodes.instrument_drivers.stanford_research import SR830`` or | ||
| ``from qcodes.dataset import dond``. | ||
|
|
||
| Any other names that were importable from these modules but are not exported from the parent | ||
| package are now considered private. This includes the type aliases such as ``ParamMeasT`` and | ||
| ``ActionsT``, as well as ``DondKWargs``, ``ParameterGroup``, ``ParameterSetEvent`` and | ||
| ``catch_interrupts`` from ``qcodes.dataset.dond``. They remain importable from the deprecated | ||
| module aliases until those are removed. If you rely on one of these names, please open an issue | ||
| at https://github.com/microsoft/Qcodes/issues so that we can consider making it public. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| ``VoltageParameter`` from the SR560 driver has been renamed to ``SR560VoltageParameter`` and is now | ||
| exported from ``qcodes.instrument_drivers.stanford_research``. The parameter classes | ||
| ``ChannelBuffer``, ``ChannelTrace`` and ``GeneratedSetPoints`` of the SR830 driver have been | ||
| renamed to ``SR830ChannelBuffer``, ``SR830ChannelTrace`` and ``SR830GeneratedSetPoints``. These | ||
| and ``SR86xBufferReadout`` of the SR86x drivers are only created by the drivers themselves and are | ||
| now private. The old names remain available from the deprecated ``SR560``, ``SR830`` and ``SR86x`` | ||
| module aliases until those are removed. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| ``do2d_retrace`` is now exported from ``qcodes.dataset``. It has also been fixed: previously it | ||
| failed because the setpoints of the outer sweep were not added to the datasets. Parameters | ||
| given as ``additional_setpoints`` are now registered in the datasets, and ``exit_actions`` are | ||
| called once at the end of the measurement rather than after every step of the outer sweep. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,154 @@ | ||
| from __future__ import annotations | ||
|
|
||
| import logging | ||
| from typing import TYPE_CHECKING | ||
|
|
||
| from opentelemetry import trace | ||
|
|
||
| from qcodes import config | ||
| from qcodes.dataset._dond.sweeps import LinSweep | ||
| from qcodes.dataset.measurement_extensions import ( | ||
| DataSetDefinition, | ||
| LinSweeper, | ||
| datasaver_builder, | ||
| dond_into, | ||
| ) | ||
|
|
||
| LOG = logging.getLogger(__name__) | ||
| TRACER = trace.get_tracer(__name__) | ||
|
|
||
|
|
||
| if TYPE_CHECKING: | ||
| from collections.abc import Sequence | ||
|
|
||
| from qcodes.dataset._dond.do_nd_utils import ActionsT | ||
| from qcodes.dataset.data_set_protocol import DataSetProtocol | ||
| from qcodes.dataset.experiment_container import Experiment | ||
| from qcodes.parameters import ParameterBase | ||
|
|
||
|
|
||
| @TRACER.start_as_current_span("qcodes.dataset.do2d") | ||
| def do2d_retrace( | ||
| param_set1: ParameterBase, | ||
| start1: float, | ||
| stop1: float, | ||
| num_points1: int, | ||
| delay1: float, | ||
| param_set2: ParameterBase, | ||
| start2: float, | ||
| stop2: float, | ||
| num_points2: int, | ||
| delay2: float, | ||
| *param_meas: ParameterBase, | ||
| enter_actions: ActionsT = (), | ||
| exit_actions: ActionsT = (), | ||
| before_inner_actions: ActionsT = (), | ||
| after_inner_actions: ActionsT = (), | ||
| measurement_name: str = "", | ||
| exp: Experiment | None = None, | ||
| additional_setpoints: Sequence[ParameterBase] = (), | ||
| show_progress: bool | None = None, | ||
| ) -> tuple[DataSetProtocol, DataSetProtocol]: | ||
| """ | ||
| Perform a 1D scan of ``param_set1`` from ``start1`` to ``stop1`` in | ||
| ``num_points1`` and ``param_set2`` from ``start2`` to ``stop2`` in | ||
| ``num_points2`` measuring param_meas at each step. | ||
|
|
||
| Args: | ||
| param_set1: The QCoDeS parameter to sweep over in the outer loop | ||
| start1: Starting point of sweep in outer loop | ||
| stop1: End point of sweep in the outer loop | ||
| num_points1: Number of points to measure in the outer loop | ||
| delay1: Delay after setting parameter in the outer loop | ||
| param_set2: The QCoDeS parameter to sweep over in the inner loop | ||
| start2: Starting point of sweep in inner loop | ||
| stop2: End point of sweep in the inner loop | ||
| num_points2: Number of points to measure in the inner loop | ||
| delay2: Delay after setting parameter before measurement is performed | ||
| param_meas: Parameter(s) to measure at each step or functions that | ||
| will be called at each step. The function should take no arguments. | ||
| The parameters and functions are called in the order they are | ||
| supplied. | ||
| enter_actions: A list of functions taking no arguments that will be | ||
| called before the measurements start | ||
| exit_actions: A list of functions taking no arguments that will be | ||
| called after the measurements ends | ||
| before_inner_actions: Actions executed before each run of the inner loop | ||
| after_inner_actions: Actions executed after each run of the inner loop | ||
| measurement_name: Name of the measurement. This will be passed down to | ||
| the dataset produced by the measurement. If not given, a default | ||
| value of 'results' is used for the dataset. | ||
| exp: The experiment to use for this measurement. | ||
| additional_setpoints: A list of setpoint parameters to be registered in | ||
| the measurement but not scanned. | ||
| show_progress: should a progress bar be displayed during the | ||
| measurement. If None the setting will be read from ``qcodesrc.json`` | ||
|
|
||
| Returns: | ||
| The QCoDeS dataset. | ||
|
|
||
| """ | ||
|
|
||
| if show_progress is None: | ||
| show_progress = config.dataset.dond_show_progress | ||
|
|
||
| independent = [param_set1, param_set2, *additional_setpoints] | ||
| # the outer parameter is set by the LinSweeper below rather than swept by | ||
| # dond_into so it is recorded as an additional setpoint of the inner sweeps | ||
| inner_additional_setpoints = (param_set1, *additional_setpoints) | ||
|
|
||
| dataset_definition = [ | ||
| DataSetDefinition( | ||
| name=measurement_name, | ||
| independent=independent, | ||
| dependent=param_meas, | ||
| experiment=exp, | ||
| ), | ||
| DataSetDefinition( | ||
| name=f"retrace {measurement_name}", | ||
| independent=independent, | ||
| dependent=param_meas, | ||
| experiment=exp, | ||
| ), | ||
| ] | ||
|
|
||
| with datasaver_builder(dataset_definition) as datasavers: | ||
| for action in enter_actions: | ||
| action() | ||
| for _ in LinSweeper(param_set1, start1, stop1, num_points1, delay1): | ||
| sweep_up = LinSweep( | ||
| param_set2, | ||
| start2, | ||
| stop2, | ||
| num_points2, | ||
| delay2, | ||
| post_actions=after_inner_actions, | ||
| ) | ||
| sweep_down = LinSweep( | ||
| param_set2, | ||
| stop2, | ||
| start2, | ||
| num_points2, | ||
| delay2, | ||
| post_actions=after_inner_actions, | ||
| ) | ||
| for action in before_inner_actions: | ||
| action() | ||
| dond_into( | ||
| datasavers[0], | ||
| sweep_up, | ||
| *param_meas, | ||
| additional_setpoints=inner_additional_setpoints, | ||
| ) | ||
| for action in before_inner_actions: | ||
| action() | ||
| dond_into( | ||
| datasavers[1], | ||
| sweep_down, | ||
| *param_meas, | ||
| additional_setpoints=inner_additional_setpoints, | ||
| ) | ||
| for action in exit_actions: | ||
| action() | ||
| datasets = (datasavers[0].dataset, datasavers[1].dataset) | ||
| return datasets | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,50 @@ | ||
| from __future__ import annotations | ||
|
|
||
| import logging | ||
| from typing import TYPE_CHECKING, cast | ||
|
|
||
| from opentelemetry import trace | ||
|
|
||
| from .do_nd import DondKWargs, dond | ||
|
|
||
| if TYPE_CHECKING: | ||
| from typing import Unpack | ||
|
|
||
| from .do_nd_utils import ( | ||
| AxesTupleListWithDataSet, | ||
| ParamMeasT, | ||
| ) | ||
|
|
||
| LOG = logging.getLogger(__name__) | ||
| TRACER = trace.get_tracer(__name__) | ||
|
|
||
|
|
||
| @TRACER.start_as_current_span("qcodes.dataset.do0d") | ||
| def do0d( | ||
| *param_meas: ParamMeasT, **kwargs: Unpack[DondKWargs] | ||
| ) -> AxesTupleListWithDataSet: | ||
| """ | ||
| Perform a measurement of a single parameter. This is probably most | ||
| useful for a ParameterWithSetpoints that already returns an array of data points. | ||
|
|
||
| Args: | ||
| *param_meas: Parameter(s) to measure at each step or functions that | ||
| will be called at each step. The function should take no arguments. | ||
| The parameters and functions are called in the order they are | ||
| supplied. | ||
| **kwargs: kwargs are the same as for :func:`dond` and forwarded directly to :func:`dond`. | ||
|
|
||
| Returns: | ||
| The QCoDeS dataset. | ||
|
|
||
| """ | ||
|
|
||
| kwargs.setdefault("log_info", "Using 'qcodes.dataset.do0d'") | ||
|
|
||
| # since we only support entering parameters | ||
| # as a simple list or args we are sure to always | ||
| # get back a AxesTupleListWithDataSet and cast is safe | ||
| return cast( | ||
| "AxesTupleListWithDataSet", | ||
| dond(*param_meas, **kwargs, squeeze=True), | ||
| ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,71 @@ | ||
| from __future__ import annotations | ||
|
|
||
| import logging | ||
| from typing import TYPE_CHECKING, cast | ||
|
|
||
| from opentelemetry import trace | ||
|
|
||
| from .do_nd import DondKWargs, dond | ||
| from .sweeps import LinSweep | ||
|
|
||
| if TYPE_CHECKING: | ||
| from typing import Unpack | ||
|
|
||
| from qcodes.dataset._dond.do_nd_utils import ( | ||
| AxesTupleListWithDataSet, | ||
| ParamMeasT, | ||
| ) | ||
| from qcodes.parameters import ParameterBase | ||
|
|
||
| LOG = logging.getLogger(__name__) | ||
| TRACER = trace.get_tracer(__name__) | ||
|
|
||
|
|
||
| @TRACER.start_as_current_span("qcodes.dataset.do1d") | ||
| def do1d( | ||
| param_set: ParameterBase, | ||
| start: float, | ||
| stop: float, | ||
| num_points: int, | ||
| delay: float, | ||
| *param_meas: ParamMeasT, | ||
| **kwargs: Unpack[DondKWargs], | ||
| ) -> AxesTupleListWithDataSet: | ||
| """ | ||
| Perform a 1D scan of ``param_set`` from ``start`` to ``stop`` in | ||
| ``num_points`` measuring param_meas at each step. In case param_meas is | ||
| an ArrayParameter this is effectively a 2d scan. | ||
|
|
||
| Args: | ||
| param_set: The QCoDeS parameter to sweep over | ||
| start: Starting point of sweep | ||
| stop: End point of sweep | ||
| num_points: Number of points in sweep | ||
| delay: Delay after setting parameter before measurement is performed | ||
| *param_meas: Parameter(s) to measure at each step or functions that | ||
| will be called at each step. The function should take no arguments. | ||
| The parameters and functions are called in the order they are | ||
| supplied. | ||
| **kwargs: kwargs are the same as for :func:`dond` and forwarded directly to :func:`dond`. | ||
|
|
||
| Returns: | ||
| The QCoDeS dataset. | ||
|
|
||
| """ | ||
| kwargs.setdefault("log_info", "Using 'qcodes.dataset.do1d'") | ||
|
|
||
| return cast( | ||
| "AxesTupleListWithDataSet", | ||
| dond( | ||
| LinSweep( | ||
| param=param_set, | ||
| start=start, | ||
| stop=stop, | ||
| delay=delay, | ||
| num_points=num_points, | ||
| ), | ||
| *param_meas, | ||
| **kwargs, | ||
| squeeze=True, | ||
| ), | ||
| ) |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if this dod2_retrace is something that we want to deprecate instead. The code is not working on main . It was never documented etc.