Skip to content

Commit 0849652

Browse files
author
Simon Humpohl
committed
Make variable names more verbose and remove comments
1 parent a07a154 commit 0849652

File tree

1 file changed

+17
-19
lines changed

1 file changed

+17
-19
lines changed

qupulse/utils/__init__.py

Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -152,22 +152,20 @@ def to_next_multiple(sample_rate: ExpressionLike, quantum: int,
152152
#double negative for ceil division.
153153
return lambda duration: -(-(duration*sample_rate)//quantum) * (quantum/sample_rate)
154154
else:
155-
qI = sp.Integer(quantum)
156-
k = qI / sample_rate # factor to go from #quanta -> duration
157-
mqI = sp.Integer(min_quanta)
158-
159-
def _build_sym(d):
160-
u = d*sample_rate/qI # "duration in quanta" (real)
161-
ce = sp.ceiling(u) # number of quanta after rounding up
162-
163-
# Enforce: 0 if d <= 0; else at least mqI quanta.
164-
# max(mqI, ceil(u)) <=> mqI if u <= mqI, else ceil(u)
165-
# do not evaluate right now because parameters could still be variable,
166-
# then it's just overhead.
167-
return sp.Piecewise(
168-
(0, sp.Le(d, 0)),
169-
(k*mqI, sp.Le(u, mqI)),
170-
(k*ce, True)
171-
, evaluate=False)
172-
173-
return lambda duration: ExpressionScalar(_build_sym(duration))
155+
# work with sympy
156+
sample_rate = sample_rate.sympified_expression
157+
duration_per_quantum = sp.Integer(quantum) / sample_rate
158+
minimal_duration = duration_per_quantum * min_quanta
159+
160+
def build_next_multiple(duration: ExpressionLike) -> ExpressionScalar:
161+
duration = sp.sympify(duration)
162+
rounded_up_duration = sp.ceiling(duration / duration_per_quantum) * duration_per_quantum
163+
164+
next_multiple_sp = sp.Piecewise(
165+
(0, sp.Le(duration, 0)),
166+
(minimal_duration, sp.Le(duration, minimal_duration)),
167+
(rounded_up_duration, True)
168+
)
169+
return ExpressionScalar(next_multiple_sp)
170+
171+
return build_next_multiple

0 commit comments

Comments
 (0)