Skip to content

Commit

Permalink
Merge pull request #5712 from jenshnielsen/deprecate_non_visa_ami_driver
Browse files Browse the repository at this point in the history
mark non visa AMI driver as deprecated.
  • Loading branch information
jenshnielsen authored Feb 5, 2024
2 parents be34422 + 45d0f6b commit dd89f7c
Show file tree
Hide file tree
Showing 5 changed files with 116 additions and 59 deletions.
2 changes: 2 additions & 0 deletions docs/changes/newsfragments/5712.breaking
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
The AMI drivers in ``qcodes.instrument_drivers.american_magnetics.AMI430`` and their submodules has been deprecated. Use the ``AMIModel430`` and
``AMIModel4303D`` drivers from ``qcodes.instrument_drivers.american_magnetics`` instead.
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,7 @@ ignore = [
"src/qcodes/instrument_drivers/Harvard/Decadac.py",
]
reportMissingTypeStubs = true
reportDeprecated = true
stubPath = "typings/stubs"
# we would like to move this to at least standard
# eventually. From 1.1.339 onwards standard is the default
Expand Down
12 changes: 10 additions & 2 deletions src/qcodes/instrument/ip_to_visa.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,14 @@
from importlib.resources import as_file, files
from typing import Any

from typing_extensions import deprecated

import qcodes.validators as vals
from qcodes.instrument_drivers.american_magnetics.AMI430 import AMI430
from qcodes.instrument_drivers.american_magnetics.AMI430 import (
AMI430, # pyright: ignore[reportDeprecated]
)
from qcodes.logger import get_instrument_logger
from qcodes.utils import strip_attrs
from qcodes.utils import QCoDeSDeprecationWarning, strip_attrs

from .instrument import Instrument
from .ip import IPInstrument
Expand Down Expand Up @@ -115,5 +119,9 @@ def close(self) -> None:
self.remove_instance(self)


@deprecated(
"The IP version of AMI430 is deprecated and this helper is therefor also deprecated",
category=QCoDeSDeprecationWarning,
)
class AMI430_VISA(AMI430, IPToVisa): # type: ignore[misc]
pass
23 changes: 23 additions & 0 deletions src/qcodes/instrument_drivers/american_magnetics/AMI430.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# pyright: reportDeprecated=none
# This deprecated code calls it self triggering deprecation warnings
from __future__ import annotations

import collections.abc
Expand All @@ -12,6 +14,7 @@
from typing import Any, Callable, ClassVar, TypeVar, cast

import numpy as np
from typing_extensions import deprecated

from qcodes.instrument import Instrument, InstrumentChannel, IPInstrument
from qcodes.math_utils import FieldVector
Expand All @@ -26,14 +29,26 @@
T = TypeVar('T')


@deprecated(
"qcodes.instrument_drivers.american_magnetics.AMI430 module is deprecated use AMI430Exception from qcodes.instrument_drivers.american_magnetics",
category=QCoDeSDeprecationWarning,
)
class AMI430Exception(Exception):
pass


@deprecated(
"qcodes.instrument_drivers.american_magnetics.AMI430 module is deprecated use AMI430Warning from qcodes.instrument_drivers.american_magnetics",
category=QCoDeSDeprecationWarning,
)
class AMI430Warning(UserWarning):
pass


@deprecated(
"qcodes.instrument_drivers.american_magnetics.AMI430 module is deprecated use AMI430SwitchHeater from qcodes.instrument_drivers.american_magnetics",
category=QCoDeSDeprecationWarning,
)
class AMI430SwitchHeater(InstrumentChannel):
class _Decorators:
@classmethod
Expand Down Expand Up @@ -120,6 +135,10 @@ def check_state(self) -> bool:
return bool(int(self.ask("PS?").strip()))


@deprecated(
"qcodes.instrument_drivers.american_magnetics.AMI430 module is deprecated use AMIModel430 from qcodes.instrument_drivers.american_magnetics",
category=QCoDeSDeprecationWarning,
)
class AMI430(IPInstrument):
"""
Driver for the American Magnetics Model 430 magnet power supply programmer.
Expand Down Expand Up @@ -475,6 +494,10 @@ def _update_units(
self.coil_constant()


@deprecated(
"qcodes.instrument_drivers.american_magnetics.AMI430 module is deprecated use AMIModel4303D from qcodes.instrument_drivers.american_magnetics",
category=QCoDeSDeprecationWarning,
)
class AMI430_3D(Instrument):
def __init__(
self,
Expand Down
137 changes: 80 additions & 57 deletions tests/drivers/test_ami430.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# pyright: reportDeprecated=none
# This deprecated code calls it self triggering deprecation warnings
import io
import logging
import re
Expand All @@ -13,19 +15,27 @@
from pytest import FixtureRequest, LogCaptureFixture

from qcodes.instrument import Instrument
from qcodes.instrument.ip_to_visa import AMI430_VISA
from qcodes.instrument_drivers.american_magnetics.AMI430 import (
AMI430,
AMI430_3D,
AMI430Warning,
)
from qcodes.math_utils import FieldVector
from qcodes.utils import QCoDeSDeprecationWarning
from qcodes.utils.types import (
numpy_concrete_ints,
numpy_floats,
numpy_non_concrete_ints_instantiable,
)

with warnings.catch_warnings():
warnings.simplefilter("ignore", category=QCoDeSDeprecationWarning)

from qcodes.instrument.ip_to_visa import (
AMI430_VISA,
)


_time_resolution = time.get_clock_info('time').resolution

# If any of the field limit functions are satisfied we are in the safe zone.
Expand All @@ -44,27 +54,28 @@ def magnet_axes_instances():
Start three mock instruments representing current drivers for the x, y,
and z directions.
"""
mag_x = AMI430_VISA(
"x",
address="GPIB::1::INSTR",
pyvisa_sim_file="AMI430.yaml",
terminator="\n",
port=1,
)
mag_y = AMI430_VISA(
"y",
address="GPIB::2::INSTR",
pyvisa_sim_file="AMI430.yaml",
terminator="\n",
port=1,
)
mag_z = AMI430_VISA(
"z",
address="GPIB::3::INSTR",
pyvisa_sim_file="AMI430.yaml",
terminator="\n",
port=1,
)
with pytest.warns(expected_warning=QCoDeSDeprecationWarning):
mag_x = AMI430_VISA(
"x",
address="GPIB::1::INSTR",
pyvisa_sim_file="AMI430.yaml",
terminator="\n",
port=1,
)
mag_y = AMI430_VISA(
"y",
address="GPIB::2::INSTR",
pyvisa_sim_file="AMI430.yaml",
terminator="\n",
port=1,
)
mag_z = AMI430_VISA(
"z",
address="GPIB::3::INSTR",
pyvisa_sim_file="AMI430.yaml",
terminator="\n",
port=1,
)

yield mag_x, mag_y, mag_z

Expand All @@ -80,8 +91,8 @@ def _make_current_driver(magnet_axes_instances):
representing current drivers for the x, y, and z directions.
"""
mag_x, mag_y, mag_z = magnet_axes_instances

driver = AMI430_3D("AMI430_3D", mag_x, mag_y, mag_z, field_limit)
with pytest.warns(expected_warning=QCoDeSDeprecationWarning):
driver = AMI430_3D("AMI430_3D", mag_x, mag_y, mag_z, field_limit)

yield driver

Expand All @@ -90,13 +101,14 @@ def _make_current_driver(magnet_axes_instances):

@pytest.fixture(scope="function", name="ami430")
def _make_ami430():
mag = AMI430_VISA(
"ami430",
address="GPIB::1::INSTR",
pyvisa_sim_file="AMI430.yaml",
terminator="\n",
port=1,
)
with pytest.warns(expected_warning=QCoDeSDeprecationWarning):
mag = AMI430_VISA(
"ami430",
address="GPIB::1::INSTR",
pyvisa_sim_file="AMI430.yaml",
terminator="\n",
port=1,
)
yield mag
mag.close()

Expand Down Expand Up @@ -144,7 +156,8 @@ def test_instantiation_from_names(
mag_x, mag_y, mag_z = magnet_axes_instances
request.addfinalizer(AMI430_3D.close_all)

driver = AMI430_3D("AMI430_3D", mag_x.name, mag_y.name, mag_z.name, field_limit)
with pytest.warns(expected_warning=QCoDeSDeprecationWarning):
driver = AMI430_3D("AMI430_3D", mag_x.name, mag_y.name, mag_z.name, field_limit)

assert driver._instrument_x is mag_x
assert driver._instrument_y is mag_y
Expand All @@ -155,17 +168,22 @@ def test_instantiation_from_name_of_nonexistent_ami_instrument(
magnet_axes_instances, request: FixtureRequest
) -> None:
mag_x, mag_y, mag_z = magnet_axes_instances

request.addfinalizer(AMI430_3D.close_all)

non_existent_instrument = mag_y.name + "foo"

with pytest.raises(
KeyError,
match=f"with name {non_existent_instrument} does not exist"
):
AMI430_3D(
"AMI430_3D", mag_x.name, non_existent_instrument, mag_z.name, field_limit
)
with pytest.warns(expected_warning=QCoDeSDeprecationWarning):
with pytest.raises(
KeyError, match=f"with name {non_existent_instrument} does not exist"
):
AMI430_3D(
"AMI430_3D",
mag_x.name,
non_existent_instrument,
mag_z.name,
field_limit,
)


def test_instantiation_from_name_of_existing_non_ami_instrument(
Expand All @@ -176,19 +194,22 @@ def test_instantiation_from_name_of_existing_non_ami_instrument(

non_ami_existing_instrument = Instrument("foo")

with pytest.raises(
with pytest.warns(expected_warning=QCoDeSDeprecationWarning):
with pytest.raises(
TypeError,
match=re.escape(
f"Instrument {non_ami_existing_instrument.name} is "
f"{type(non_ami_existing_instrument)} but {AMI430} "
f"was requested"
),
):
AMI430_3D(
"AMI430_3D",
mag_x.name,
non_ami_existing_instrument.name,
mag_z.name,
field_limit,
)
):
AMI430_3D(
"AMI430_3D",
mag_x.name, non_ami_existing_instrument.name, mag_z.name,
field_limit
)


def test_instantiation_from_badly_typed_argument(
Expand All @@ -199,16 +220,17 @@ def test_instantiation_from_badly_typed_argument(

badly_typed_instrument_z_argument = 123

with pytest.raises(
with pytest.warns(expected_warning=QCoDeSDeprecationWarning):
with pytest.raises(
ValueError, match="instrument_z argument is neither of those"
):
AMI430_3D(
"AMI430_3D",
mag_x.name,
mag_y,
badly_typed_instrument_z_argument, # type: ignore[arg-type]
field_limit
)
):
AMI430_3D(
"AMI430_3D",
mag_x.name,
mag_y,
badly_typed_instrument_z_argument, # type: ignore[arg-type]
field_limit,
)


@given(set_target=random_coordinates["cartesian"])
Expand Down Expand Up @@ -1000,7 +1022,7 @@ def test_current_and_field_params_interlink__permutations_of_tests(ami430) -> No
with warnings.catch_warnings():
# this is to avoid AMI430Warning about "maximum ramp rate", which
# may show up but is not relevant to this test
warnings.simplefilter('ignore', category=AMI430Warning)
warnings.simplefilter("ignore", category=AMI430Warning)

test_current_and_field_params_interlink_at_init(ami430)

Expand Down Expand Up @@ -1080,7 +1102,8 @@ def test_numeric_field_limit(
magnet_axes_instances, field_limit, request: FixtureRequest
) -> None:
mag_x, mag_y, mag_z = magnet_axes_instances
ami = AMI430_3D("AMI430_3D", mag_x, mag_y, mag_z, field_limit)
with pytest.warns(expected_warning=QCoDeSDeprecationWarning):
ami = AMI430_3D("AMI430_3D", mag_x, mag_y, mag_z, field_limit)
request.addfinalizer(ami.close)

assert isinstance(ami._field_limit, float)
Expand Down

0 comments on commit dd89f7c

Please sign in to comment.