Qcodes_contrib_drivers icon indicating copy to clipboard operation
Qcodes_contrib_drivers copied to clipboard

zhinst update makes HF2LI qcodes driver not working

Open edumur opened this issue 2 years ago • 1 comments

Dear all,

I am not sure if I should post that here or on the zhinst repo.

The code to reproduce the error:

from Qcodes_contrib_drivers.qcodes_contrib_drivers.drivers.ZurichInstruments.HF2LI import HF2LI

hf2li = HF2LI(...)
hf2li.sigouts.sigouts0.range()

The error:

ValueError                                Traceback (most recent call last)
Input In [8], in <cell line: 1>()
----> 1 hf2li.sigouts.sigouts0.range()

File ~\Miniconda3\envs\python38\lib\site-packages\zhinst\qcodes\qcodes_adaptions.py:208, in ZIParameter.__call__(self, *args, **kwargs)
    206 if len(args) == 0:
    207     if self.gettable:
--> 208         return self.get(**kwargs)
    209     else:
    210         raise NotImplementedError(
    211             "no get cmd found in" + f" Parameter {self.name}"
    212         )

File ~\Miniconda3\envs\python38\lib\site-packages\qcodes\instrument\parameter.py:661, in _BaseParameter._wrap_get.<locals>.get_wrapper(*args, **kwargs)
    659 except Exception as e:
    660     e.args = e.args + (f'getting {self}',)
--> 661     raise e

File ~\Miniconda3\envs\python38\lib\site-packages\qcodes\instrument\parameter.py:648, in _BaseParameter._wrap_get.<locals>.get_wrapper(*args, **kwargs)
    643     raise NotImplementedError(
    644         f"Trying to get an abstract parameter: {self.full_name}"
    645     )
    646 try:
    647     # There might be cases where a .get also has args/kwargs
--> 648     raw_value = get_function(*args, **kwargs)
    650     value = self._from_raw_value_to_value(raw_value)
    652     if self._validate_on_get:

File ~\Miniconda3\envs\python38\lib\site-packages\zhinst\toolkit\nodetree\node.py:503, in Node._get(self, deep, enum, parse, **kwargs)
    501     else:
    502         value = self._get_cached(**kwargs)
--> 503     value = self._parse_get_value(value, enum=enum, parse=parse)
    504     return (timestamp, value) if deep else value
    505 if readable is None and (
    506     self.node_info.contains_wildcards or self.node_info.is_partial
    507 ):

File ~\Miniconda3\envs\python38\lib\site-packages\zhinst\toolkit\nodetree\node.py:455, in Node._parse_get_value(self, value, enum, parse)
    443 """Parse the raw value from the data server.
    444 
    445 Args:
   (...)
    452     Parsed value
    453 """
    454 if enum and isinstance(value, int):
--> 455     enum_info = self.node_info.options.get(value, None)
    456     value = (
    457         getattr(self.node_info.enum, enum_info.enum)
    458         if enum_info and enum_info.enum
    459         else value
    460     )
    461 if parse:

File ~\Miniconda3\envs\python38\lib\site-packages\zhinst\toolkit\nodetree\node.py:227, in NodeInfo.options(self)
    225 for key, value in self._info.get("Options", {}).items():
    226     node_options = re.findall(r'("(.+?)"[,:]+)? ?(.*)', value)
--> 227     option_map[int(key)] = self._option_info(
    228         node_options[0][1], node_options[0][2]
    229     )
    230 return option_map

ValueError: ("invalid literal for int() with base 10: '0.01'", 'getting zi_baseinstrument_dev***_sigouts0_range')

I guess someone has to update the qcodes driver to the new zhinst dict.

edumur avatar Jul 04 '22 09:07 edumur

Could you check what version of zhinst-qcodes and zhinst-toolkit you have installed in your environment? if it's 0.3.*, then it's likely that you're facing the consequences of this refactor https://docs.zhinst.com/zhinst-qcodes/en/latest/refactoring/index.html .

The solution for this HF2LI driver in qcodes_ms_drivers could be the following:

  • implement a version check upon import of zhinst-qcodes (the 0.3 reports __version__ correctly, while the 0.2.* versions did not even have it), and throw an error or warning to the user suggesting to downgrade to zhinst-qcodes 0.2.* to keep this driver working
  • [my recommendation] update the driver to work with 0.3, and still implement the version check that asks the user to update to the 0.3 version of zhinst-qcodes.

the version check could be smth like:

from packaging import version

def is_zi_version_0_3_or_higher() -> bool:
    try:
        zhinst_qcodes_version = zhinst.qcodes.__version__
    except (ImportError, ModuleNotFoundError):
        zhinst_qcodes_version = "0.0"
    return version.parse(zhinst_qcodes_version) >= version.parse("0.3")

astafan8 avatar Jul 04 '22 12:07 astafan8