Skip to content

Commit

Permalink
Merge pull request #135 from QDevil/master
Browse files Browse the repository at this point in the history
QDevil QDAC2: Getter functions for Lists and Sweeps
  • Loading branch information
astafan8 authored Jun 7, 2022
2 parents 413a5a8 + 1ce4794 commit 2d23729
Show file tree
Hide file tree
Showing 7 changed files with 94 additions and 22 deletions.
41 changes: 36 additions & 5 deletions qcodes_contrib_drivers/drivers/QDevil/QDAC2.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from typing import Any, NewType, Sequence, List, Dict, Tuple, Optional
from packaging.version import parse

# Version 0.12.1
# Version 0.13.0
#
# Guiding principles for this driver for QDevil QDAC-II
# -----------------------------------------------------
Expand Down Expand Up @@ -144,11 +144,11 @@ def __init__(self, parent: 'QDac2', name: str, external: int):

def floats_to_comma_separated_list(array: Sequence[float]):
rounded = [format(x, 'g') for x in array]
return ', '.join(rounded)
return ','.join(rounded)


def array_to_comma_separated_list(array: str):
return ', '.join(map(str, array))
return ','.join(map(str, array))


def comma_sequence_to_list(sequence: str):
Expand Down Expand Up @@ -367,6 +367,27 @@ def time_s(self) -> float:
"""
return float(self._ask_channel('sour{0}:swe:time?'))

def start_V(self) -> float:
"""
Returns:
float: Starting voltage
"""
return float(self._ask_channel('sour{0}:swe:star?'))

def stop_V(self) -> float:
"""
Returns:
float: Ending voltage
"""
return float(self._ask_channel('sour{0}:swe:stop?'))

def values_V(self) -> Sequence[float]:
"""
Returns:
Sequence[float]: List of voltages
"""
return list(np.linspace(self.start_V(), self.stop_V(), self.points()))


class List_Context(_Dc_Context):

Expand Down Expand Up @@ -430,6 +451,16 @@ def cycles_remaining(self) -> int:
"""
return int(self._ask_channel('sour{0}:list:ncl?'))

def values_V(self) -> Sequence[float]:
"""
Returns:
Sequence[float]: List of voltages
"""
# return comma_sequence_to_list_of_floats(
# self._ask_channel('sour{0}:list:volt?'))
return comma_sequence_to_list_of_floats(
self._ask_channel('sour{0}:list:volt?'))


class _Waveform_Context(_Channel_Context):

Expand Down Expand Up @@ -1500,7 +1531,7 @@ def __init__(self, parent, name: str, size: int):
self._parent = parent
self._size = size
self._name = name
self._parent.write(f'trac:def "{name}", {size}')
self._parent.write(f'trac:def "{name}",{size}')

def __len__(self):
return self.size
Expand Down Expand Up @@ -1532,7 +1563,7 @@ def waveform(self, values: Sequence[float]) -> None:
if len(values) != self.size:
raise ValueError(f'trace length {len(values)} does not match '
f'allocated length {self.size}')
self._parent.write_floats(f'trac:data "{self.name}", ', values)
self._parent.write_floats(f'trac:data "{self.name}",', values)


class Sweep_2D_Context:
Expand Down
10 changes: 8 additions & 2 deletions qcodes_contrib_drivers/sims/QDAC2.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,10 @@ devices:
q: "tint {:d}"
trace_define:
setter:
q: "trac:def \"{:s}\", {:d}"
q: "trac:def \"{:s}\",{:d}"
trace_data:
setter:
q: "trac:data \"{:s}\", {:s}"
q: "trac:data \"{:s}\",{:s}"

channels:
trigger:
Expand Down Expand Up @@ -367,8 +367,14 @@ devices:
setter:
q: "sour{ch_id}:list:dwel {}"
list_voltages:
default: "0"
setter:
q: "sour{ch_id}:list:volt {}"
getter:
q: "sour{ch_id}:list:volt?"
r: "-0.123,0,1.234"
specs:
type: str
list_append:
setter:
q: "sour{ch_id}:list:volt:app {}"
Expand Down
4 changes: 2 additions & 2 deletions qcodes_contrib_drivers/tests/QDevil/test_sim_qdac2_awg.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def test_trace_define(qdac): # noqa
# -----------------------------------------------------------------------
trace = qdac.allocate_trace(name, length)
# -----------------------------------------------------------------------
assert qdac.get_recorded_scpi_commands() == [f'trac:def "{name}", {length}']
assert qdac.get_recorded_scpi_commands() == [f'trac:def "{name}",{length}']
assert trace.name == name
assert trace.size == length
assert len(trace) == length
Expand Down Expand Up @@ -60,7 +60,7 @@ def test_trace_data(qdac): # noqa
trace.waveform(numpy.linspace(0, 1, 6))
# -----------------------------------------------------------------------
assert qdac.get_recorded_scpi_commands() == [
f'trac:data "{name}", 0, 0.2, 0.4, 0.6, 0.8, 1']
f'trac:data "{name}",0,0.2,0.4,0.6,0.8,1']


def test_trace_data_length_mismatch(qdac): # noqa
Expand Down
4 changes: 2 additions & 2 deletions qcodes_contrib_drivers/tests/QDevil/test_sim_qdac2_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ def test_floats_to_list_empty():


def test_floats_to_list_direct():
assert floats_to_comma_separated_list([1, 2]) == '1, 2'
assert floats_to_comma_separated_list([1, 2]) == '1,2'


def test_floats_to_list_rounding():
unrounded = numpy.linspace(0, 1, 11)
assert floats_to_comma_separated_list(unrounded) == \
'0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1'
'0,0.1,0.2,0.3,0.4,0.5,0.6,0.7,0.8,0.9,1'
19 changes: 15 additions & 4 deletions qcodes_contrib_drivers/tests/QDevil/test_sim_qdac2_source_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def test_list_explicit(qdac): # noqa
assert qdac.get_recorded_scpi_commands() == [
'sour1:dc:trig:sour hold',
'sour1:volt:mode list',
'sour1:list:volt -1, 0, 1',
'sour1:list:volt -1,0,1',
'sour1:list:tmod step',
'sour1:list:dwel 1e-06',
'sour1:list:dir down',
Expand All @@ -34,7 +34,7 @@ def test_list_implicit(qdac): # noqa
assert qdac.get_recorded_scpi_commands() == [
'sour1:dc:trig:sour hold',
'sour1:volt:mode list',
'sour1:list:volt 1, 2, 3, 4',
'sour1:list:volt 1,2,3,4',
'sour1:list:tmod auto',
'sour1:list:dwel 0.001',
'sour1:list:dir up',
Expand Down Expand Up @@ -73,7 +73,7 @@ def test_list_append(qdac): # noqa
# -----------------------------------------------------------------------
# Cannot sim test: assert points == 6
assert qdac.get_recorded_scpi_commands() == [
'sour1:list:volt:app 5, 6',
'sour1:list:volt:app 5,6',
'sour1:dc:init:cont on',
'sour1:dc:init',
]
Expand Down Expand Up @@ -108,7 +108,7 @@ def test_list_infinite(qdac): # noqa
assert qdac.get_recorded_scpi_commands() == [
'sour1:dc:trig:sour hold',
'sour1:volt:mode list',
'sour1:list:volt 1, 2, 3, 4',
'sour1:list:volt 1,2,3,4',
'sour1:list:tmod auto',
'sour1:list:dwel 0.001',
'sour1:list:dir up',
Expand Down Expand Up @@ -250,6 +250,17 @@ def test_list_trigger_on_external(qdac): # noqa
]


def test_list_get_voltages(qdac): # noqa
qdac.start_recording_scpi()
dc_list = qdac.ch01.dc_list(voltages=[-0.123, 0, 1.234])
# -----------------------------------------------------------------------
voltages = dc_list.values_V()
# -----------------------------------------------------------------------
x = qdac.get_recorded_scpi_commands()
print(x)
assert voltages == [-0.123, 0, 1.234]


# def test_list_internal_trigger(qdac): # noqa
# trigger = qdac.allocate_trigger()
# # -----------------------------------------------------------------------
Expand Down
24 changes: 24 additions & 0 deletions qcodes_contrib_drivers/tests/QDevil/test_sim_qdac2_source_sweep.py
Original file line number Diff line number Diff line change
Expand Up @@ -252,3 +252,27 @@ def test_sweep_trigger_on_external(qdac): # noqa
f'sour1:dc:init:cont on',
'sour1:dc:init'
]


def test_sweep_get_start(qdac): # noqa
dc_sweep = qdac.ch01.dc_sweep(start_V=-1.2345, stop_V=1.2345, points=3)
# -----------------------------------------------------------------------
voltage = dc_sweep.start_V()
# -----------------------------------------------------------------------
assert voltage == -1.2345


def test_sweep_get_stop(qdac): # noqa
dc_sweep = qdac.ch01.dc_sweep(start_V=-1.2345, stop_V=1.2345, points=3)
# -----------------------------------------------------------------------
voltage = dc_sweep.stop_V()
# -----------------------------------------------------------------------
assert voltage == 1.2345


def test_sweep_get_voltages(qdac): # noqa
dc_sweep = qdac.ch01.dc_sweep(start_V=-1.23, stop_V=1.23, points=3)
# -----------------------------------------------------------------------
voltages = dc_sweep.values_V()
# -----------------------------------------------------------------------
assert voltages == [-1.23, 0, 1.23]
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def test_arrangement_sweep(qdac): # noqa
# Sensor 1
'sour1:dc:trig:sour hold',
'sour1:volt:mode list',
'sour1:list:volt 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0',
'sour1:list:volt 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0',
'sour1:list:tmod auto',
'sour1:list:dwel 2e-06',
'sour1:list:dir up',
Expand All @@ -59,7 +59,7 @@ def test_arrangement_sweep(qdac): # noqa
# Plunger 2
'sour2:dc:trig:sour hold',
'sour2:volt:mode list',
'sour2:list:volt -0.2, 0, 0.2, 0.4, 0.6, -0.2, 0, 0.2, 0.4, 0.6, -0.2, 0, 0.2, 0.4, 0.6, -0.2, 0, 0.2, 0.4, 0.6, -0.2, 0, 0.2, 0.4, 0.6',
'sour2:list:volt -0.2,0,0.2,0.4,0.6,-0.2,0,0.2,0.4,0.6,-0.2,0,0.2,0.4,0.6,-0.2,0,0.2,0.4,0.6,-0.2,0,0.2,0.4,0.6',
'sour2:list:tmod auto',
'sour2:list:dwel 2e-06',
'sour2:list:dir up',
Expand All @@ -73,7 +73,7 @@ def test_arrangement_sweep(qdac): # noqa
# Plunger 3
'sour3:dc:trig:sour hold',
'sour3:volt:mode list',
'sour3:list:volt -0.7, -0.7, -0.7, -0.7, -0.7, -0.4875, -0.4875, -0.4875, -0.4875, -0.4875, -0.275, -0.275, -0.275, -0.275, -0.275, -0.0625, -0.0625, -0.0625, -0.0625, -0.0625, 0.15, 0.15, 0.15, 0.15, 0.15',
'sour3:list:volt -0.7,-0.7,-0.7,-0.7,-0.7,-0.4875,-0.4875,-0.4875,-0.4875,-0.4875,-0.275,-0.275,-0.275,-0.275,-0.275,-0.0625,-0.0625,-0.0625,-0.0625,-0.0625,0.15,0.15,0.15,0.15,0.15',
'sour3:list:tmod auto',
'sour3:list:dwel 2e-06',
'sour3:list:dir up',
Expand Down Expand Up @@ -190,7 +190,7 @@ def test_stability_diagram_external(qdac): # noqa
# Sensor 1
'sour3:dc:trig:sour hold',
'sour3:volt:mode list',
'sour3:list:volt 0.089, 0.085, 0.081, 0.077, 0.073, 0.099625, 0.095625, 0.091625, 0.087625, 0.083625, 0.11025, 0.10625, 0.10225, 0.09825, 0.09425, 0.120875, 0.116875, 0.112875, 0.108875, 0.104875, 0.1315, 0.1275, 0.1235, 0.1195, 0.1155',
'sour3:list:volt 0.089,0.085,0.081,0.077,0.073,0.099625,0.095625,0.091625,0.087625,0.083625,0.11025,0.10625,0.10225,0.09825,0.09425,0.120875,0.116875,0.112875,0.108875,0.104875,0.1315,0.1275,0.1235,0.1195,0.1155',
'sour3:list:tmod auto',
'sour3:list:dwel 1e-06',
'sour3:list:dir up',
Expand All @@ -204,7 +204,7 @@ def test_stability_diagram_external(qdac): # noqa
# Plunger 2
'sour6:dc:trig:sour hold',
'sour6:volt:mode list',
'sour6:list:volt -0.046, -0.034, -0.022, -0.01, 0.002, 0.01775, 0.02975, 0.04175, 0.05375, 0.06575, 0.0815, 0.0935, 0.1055, 0.1175, 0.1295, 0.14525, 0.15725, 0.16925, 0.18125, 0.19325, 0.209, 0.221, 0.233, 0.245, 0.257',
'sour6:list:volt -0.046,-0.034,-0.022,-0.01,0.002,0.01775,0.02975,0.04175,0.05375,0.06575,0.0815,0.0935,0.1055,0.1175,0.1295,0.14525,0.15725,0.16925,0.18125,0.19325,0.209,0.221,0.233,0.245,0.257',
'sour6:list:tmod auto',
'sour6:list:dwel 1e-06',
'sour6:list:dir up',
Expand All @@ -218,7 +218,7 @@ def test_stability_diagram_external(qdac): # noqa
# Plunger 3
'sour7:dc:trig:sour hold',
'sour7:volt:mode list',
'sour7:list:volt -0.647, -0.617, -0.587, -0.557, -0.527, -0.4345, -0.4045, -0.3745, -0.3445, -0.3145, -0.222, -0.192, -0.162, -0.132, -0.102, -0.0095, 0.0205, 0.0505, 0.0805, 0.1105, 0.203, 0.233, 0.263, 0.293, 0.323',
'sour7:list:volt -0.647,-0.617,-0.587,-0.557,-0.527,-0.4345,-0.4045,-0.3745,-0.3445,-0.3145,-0.222,-0.192,-0.162,-0.132,-0.102,-0.0095,0.0205,0.0505,0.0805,0.1105,0.203,0.233,0.263,0.293,0.323',
'sour7:list:tmod auto',
'sour7:list:dwel 1e-06',
'sour7:list:dir up',
Expand All @@ -232,7 +232,7 @@ def test_stability_diagram_external(qdac): # noqa
# Plunger 4
'sour8:dc:trig:sour hold',
'sour8:volt:mode list',
'sour8:list:volt -0.48821, -0.27633, -0.06445, 0.14743, 0.35931, -0.371441, -0.159561, 0.0523187, 0.264199, 0.476079, -0.254672, -0.0427925, 0.169088, 0.380968, 0.592847, -0.137904, 0.0739763, 0.285856, 0.497736, 0.709616, -0.021135, 0.190745, 0.402625, 0.614505, 0.826385',
'sour8:list:volt -0.48821,-0.27633,-0.06445,0.14743,0.35931,-0.371441,-0.159561,0.0523187,0.264199,0.476079,-0.254672,-0.0427925,0.169088,0.380968,0.592847,-0.137904,0.0739763,0.285856,0.497736,0.709616,-0.021135,0.190745,0.402625,0.614505,0.826385',
'sour8:list:tmod auto',
'sour8:list:dwel 1e-06',
'sour8:list:dir up',
Expand Down

0 comments on commit 2d23729

Please sign in to comment.