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

Significant performance improvement in Tektronix5014 driver #2910

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
17 changes: 11 additions & 6 deletions qcodes/instrument_drivers/tektronix/AWG5014.py
Expand Up @@ -876,7 +876,12 @@ def _pack_record(
record_data = value.encode('ASCII')
else:
assert isinstance(value, (abc.Sequence, np.ndarray))
record_data = struct.pack('<' + dtype, *value)
if dtype[-1] == 'H' and isinstance(value, np.ndarray):
# numpy conversion is fast
record_data = value.astype('<u2').tobytes()
else:
# argument unpacking is slow
record_data = struct.pack('<' + dtype, *value)

# the zero byte at the end the record name is the "(Include NULL.)"
record_name = name.encode('ASCII') + b'\x00'
Expand Down Expand Up @@ -1683,11 +1688,11 @@ def _pack_waveform(
raise TypeError('Marker 2 contains invalid values.' +
' Only 0 and 1 are allowed')

wflen = len(wf)
packed_wf = np.zeros(wflen, dtype=np.uint16)
packed_wf += np.uint16(np.round(wf * 8191) + 8191 +
np.round(16384 * m1) +
np.round(32768 * m2))
# Note: we use np.trunc here rather than np.round
# as it is an order of magnitude faster
packed_wf = np.trunc(16384 * m1 + 32768 * m2
+ wf * 8191 + 8191.5).astype(np.uint16)
astafan8 marked this conversation as resolved.
Show resolved Hide resolved

if len(np.where(packed_wf == -1)[0]) > 0:
print(np.where(packed_wf == -1))
return packed_wf
Expand Down