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

Move hdawg driver out of main repo to allow version split #811

Merged
merged 8 commits into from
Mar 14, 2024
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
1 change: 1 addition & 0 deletions changes.d/779.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Move HDAWG driver to qupulse-hdawg-legacy to disentangle driver version from qupulse version. The new HDAWG driver will be published under qupulse-hdawg.
1,498 changes: 0 additions & 1,498 deletions qupulse/_program/seqc.py

This file was deleted.

1,221 changes: 15 additions & 1,206 deletions qupulse/hardware/awgs/zihdawg.py

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion qupulse/hardware/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def traced(obj):
njit = lambda x: x

try:
import zhinst
import zhinst.utils
except ImportError: # pragma: no cover
zhinst = None

Expand Down
90 changes: 90 additions & 0 deletions qupulse/utils/performance.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,4 +81,94 @@ def time_windows_to_samples(begins: np.ndarray, lengths: np.ndarray,
is_monotonic = _is_monotonic_numba


@njit
def _average_windows_numba(time: np.ndarray, values: np.ndarray,
begins: np.ndarray, ends: np.ndarray) -> np.ndarray:
n_samples, = time.shape
n_windows, = begins.shape

assert len(begins) == len(ends)
assert values.shape[0] == n_samples

result = np.zeros(begins.shape + values.shape[1:], dtype=float)
count = np.zeros(n_windows, dtype=np.uint64)

start = 0
for i in range(n_samples):
t = time[i]
v = values[i, ...]

while start < n_windows and ends[start] <= t:
n = count[start]
if n == 0:
result[start] = np.nan
else:
result[start] /= n
start += 1

idx = start
while idx < n_windows and begins[idx] <= t:
result[idx] += v
count[idx] += 1
idx += 1

for idx in range(start, n_windows):
n = count[idx]
if n == 0:
result[idx] = np.nan
else:
result[idx] /= count[idx]

return result


def _average_windows_numpy(time: np.ndarray, values: np.ndarray,
begins: np.ndarray, ends: np.ndarray) -> np.ndarray:
start = np.searchsorted(time, begins)
end = np.searchsorted(time, ends)

val_shape = values.shape[1:]

count = end - start
val_mask = result_mask = start < end

result = np.zeros(begins.shape + val_shape, dtype=float)
while np.any(val_mask):
result[val_mask, ...] += values[start[val_mask], ...]
start[val_mask] += 1
val_mask = start < end

result[~result_mask, ...] = np.nan
if result.ndim == 1:
result[result_mask, ...] /= count[result_mask]
else:
result[result_mask, ...] /= count[result_mask, None]

return result


def average_windows(time: np.ndarray, values: np.ndarray, begins: np.ndarray, ends: np.ndarray):
"""This function calculates the average over all windows that are defined by begins and ends.
The function assumes that the given time array is monotonically increasing and might produce
nonsensical results if not.

Args:
time: Time associated with the values of shape (n_samples,)
values: Values to average of shape (n_samples,) or (n_samples, n_channels)
begins: Beginning time stamps of the windows of shape (n_windows,)
ends: Ending time stamps of the windows of shape (n_windows,)

Returns:
Averaged values for each window of shape (n_windows,) or (n_windows, n_channels).
Windows without samples are NaN.
"""
n_samples, = time.shape
n_windows, = begins.shape

assert n_windows == len(ends)
assert values.shape[0] == n_samples

if numba is None:
return _average_windows_numpy(time, values, begins, ends)
else:
return _average_windows_numba(time, values, begins, ends)
3 changes: 2 additions & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ plotting = matplotlib
tabor-instruments =
tabor_control>=0.1.1
zurich-instruments =
zhinst<=20.7.2701;python_version<'3.9'
qupulse-hdawg-legacy;python_version<'3.9'
qupulse-hdawg;python_version>='3.9'
Faster-fractions = gmpy2
tektronix = tek_awg>=0.2.1
autologging = autologging
Expand Down
Loading
Loading