Skip to content

Commit 56dd10b

Browse files
authored
Merge pull request #8009 from jenshnielsen/ami_snapshot_fix
Ami snapshot fix
2 parents fa47380 + 1e95d68 commit 56dd10b

File tree

3 files changed

+59
-3
lines changed

3 files changed

+59
-3
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
The ``AMI430SwitchHeater`` snapshot now skips updating heater-specific parameters
2+
(``state``, ``in_persistent_mode``, ``current``, ``heat_time``, ``cool_time``) when
3+
the switch heater is not enabled. This prevents VISA query failures on real hardware
4+
when the heater is not installed.

src/qcodes/instrument_drivers/american_magnetics/AMI430_visa.py

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
from collections.abc import Callable, Iterable, Sequence
77
from contextlib import ExitStack
88
from functools import partial
9-
from typing import TYPE_CHECKING, ClassVar, Concatenate, TypeVar, cast
9+
from typing import TYPE_CHECKING, Any, ClassVar, Concatenate, TypeVar, cast
1010

1111
import numpy as np
1212
from pyvisa import VisaIOError
@@ -152,6 +152,32 @@ def _check_state(self) -> bool:
152152
return False
153153
return bool(int(self.ask("PS?").strip()))
154154

155+
def snapshot_base(
156+
self,
157+
update: bool | None = False,
158+
params_to_skip_update: Sequence[str] | None = None,
159+
) -> dict[str, Any]:
160+
if params_to_skip_update is None:
161+
params_to_skip_update = []
162+
163+
if update is True:
164+
enabled = self.enabled.get()
165+
else:
166+
enabled = self.enabled.cache.get()
167+
if not enabled:
168+
heater_params = [
169+
"state",
170+
"in_persistent_mode",
171+
"current",
172+
"heat_time",
173+
"cool_time",
174+
]
175+
params_to_skip_update = list(params_to_skip_update) + heater_params
176+
177+
return super().snapshot_base(
178+
update=update, params_to_skip_update=params_to_skip_update
179+
)
180+
155181

156182
class AMIModel430(VisaInstrument):
157183
_SHORT_UNITS: ClassVar[dict[str, str]] = {

tests/drivers/test_ami430_visa.py

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1445,10 +1445,36 @@ def test_switch_heater_enabled(ami430: AMIModel430, caplog: LogCaptureFixture) -
14451445
# make sure that getting snapshot with heater disabled works without warning
14461446
caplog.clear()
14471447
with caplog.at_level(logging.WARNING, logger=ami430.log.name):
1448-
ami430.snapshot(update=True)
1448+
snap = ami430.snapshot(update=True)
14491449
assert len(caplog.records) == 0
1450+
1451+
# When heater is disabled, heater-specific parameters should not be updated
1452+
heater_snap = snap["submodules"]["switch_heater"]["parameters"]
1453+
for param_name in (
1454+
"state",
1455+
"in_persistent_mode",
1456+
"current",
1457+
"heat_time",
1458+
"cool_time",
1459+
):
1460+
assert heater_snap[param_name]["ts"] is None, (
1461+
f"Parameter {param_name} should not have been updated when heater is disabled"
1462+
)
1463+
1464+
# When heater is enabled, snapshot should update all parameters
14501465
ami430.switch_heater.enabled(True)
1451-
assert ami430.switch_heater.enabled() is True
1466+
snap_enabled = ami430.snapshot(update=True)
1467+
heater_snap_enabled = snap_enabled["submodules"]["switch_heater"]["parameters"]
1468+
for param_name in (
1469+
"state",
1470+
"in_persistent_mode",
1471+
"current",
1472+
"heat_time",
1473+
"cool_time",
1474+
):
1475+
assert heater_snap_enabled[param_name]["ts"] is not None, (
1476+
f"Parameter {param_name} should have been updated when heater is enabled"
1477+
)
14521478
ami430.switch_heater.enabled(False)
14531479
assert ami430.switch_heater.enabled() is False
14541480

0 commit comments

Comments
 (0)