Skip to content
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

Add simple demodulator signals to Zi UHFLI #870

Merged
merged 6 commits into from
Nov 15, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
222 changes: 159 additions & 63 deletions docs/examples/driver_examples/Qcodes example with ZI UHF-LI.ipynb

Large diffs are not rendered by default.

52 changes: 44 additions & 8 deletions qcodes/instrument_drivers/ZI/ZIUHFLI.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import logging
import numpy as np
from functools import partial
from typing import Union
try:
import zhinst.utils
except ImportError:
Expand Down Expand Up @@ -548,15 +549,13 @@ class ZIUHFLI(Instrument):
* Add zoom-FFT
"""

def __init__(self, name, device_ID, **kwargs):
def __init__(self, name: str, device_ID: str, **kwargs) -> None:
"""
Create an instance of the instrument.

Args:
name (str): The internal QCoDeS name of the instrument
device_ID (str): The device name as listed in the web server.
api_level (int): Compatibility mode of the API interface. Must be 5
for the UHF.
"""

super().__init__(name, **kwargs)
Expand Down Expand Up @@ -711,6 +710,26 @@ def __init__(self, name, device_ID, **kwargs):
vals=vals.Enum(*list(dmtrigs.keys()))
)

self.add_parameter('demod{}_sample'.format(demod),
label='Demod sample',
get_cmd=partial(self._getter, 'demods',
demod - 1, 2, 'sample'),
snapshot_value=False
)

for demod_param in ['x', 'y', 'R', 'phi']:
if demod_param in ('x', 'y', 'R'):
unit = 'V'
else:
unit = 'deg'
self.add_parameter('demod{}_{}'.format(demod, demod_param),
label='Demod {} {}'.format(demod, demod_param),
get_cmd=partial(self._get_demod_sample,
demod - 1, demod_param),
snapshot_value=False,
unit=unit
)

########################################
# SIGNAL INPUTS

Expand Down Expand Up @@ -1440,7 +1459,8 @@ def _setter(self, module, number, mode, setting, value):
if mode == 1:
self.daq.setDouble(setstr, value)

def _getter(self, module, number, mode, setting):
def _getter(self, module: str, number: int,
mode: int, setting: str) -> Union[float, int, str, dict]:
"""
General get function for generic parameters. Note that some parameters
use more specialised setter/getters.
Expand All @@ -1453,22 +1473,38 @@ def _getter(self, module, number, mode, setting):
we want to know the value of.
number (int): Module's index
mode (int): Indicating whether we are asking for an int or double.
0: Int, 1: double.
0: Int, 1: double, 2: Sample
setting (str): The module's setting to set.
returns:
inquered value

"""

querystr = '/{}/{}/{}/{}'.format(self.device, module, number, setting)
log.debug("getting %s", querystr)
if mode == 0:
value = self.daq.getInt(querystr)
if mode == 1:
elif mode == 1:
value = self.daq.getDouble(querystr)

elif mode == 2:
value = self.daq.getSample(querystr)
else:
raise RuntimeError("Invalid mode supplied")
# Weird exception, samplingrate returns a string
return value

def _get_demod_sample(self, number: int, demod_param: str) -> float:
log.debug("getting demod %s param %s", number, demod_param)
mode = 2
module = 'demods'
setting = 'sample'
if demod_param not in ['x', 'y', 'R', 'phi']:
raise RuntimeError("Invalid demodulator parameter")
datadict = self._getter(module, number, mode, setting)
datadict['R'] = np.abs(datadict['x'] + 1j * datadict['y'])
datadict['phi'] = np.angle(datadict['x'] + 1j * datadict['y'], deg=True)
return datadict[demod_param]

def _sigout_setter(self, number, mode, setting, value):
"""
Function to set signal output's settings. A specific setter function is
Expand Down Expand Up @@ -1787,7 +1823,7 @@ def add_signal_to_sweeper(self, demodulator, attribute):
raise ValueError('Can not select attribute:'+
'{}. Only the following attributes are' +
' available: ' +
('{}, '*len(attributes)).format(*attributes))
('{}, '*len(valid_attributes)).format(*valid_attributes))

# internally, we use strings very similar to the ones used by the
# instrument, but with the attribute added, e.g.
Expand Down