Skip to content

Commit

Permalink
Merge pull request #817 from qutech/fix/simple_expression_offset_check
Browse files Browse the repository at this point in the history
Make offset type consistent and add runtime check
  • Loading branch information
terrorfisch committed Apr 4, 2024
2 parents 5c6fd63 + 346e980 commit c9fc1e6
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
5 changes: 4 additions & 1 deletion qupulse/program/__init__.py
Expand Up @@ -31,7 +31,10 @@ class SimpleExpression(Generic[NumVal]):
"""

base: NumVal
offsets: Dict[str, NumVal]
offsets: Mapping[str, NumVal]

def __post_init__(self):
assert isinstance(self.offsets, Mapping)

def value(self, scope: Mapping[str, NumVal]) -> NumVal:
value = self.base
Expand Down
10 changes: 5 additions & 5 deletions qupulse/program/linspace.py
Expand Up @@ -124,7 +124,7 @@ def inner_scope(self, scope: Scope) -> Scope:
process."""
if self._ranges:
name, _ = self._ranges[-1]
return scope.overwrite({name: SimpleExpression(base=0, offsets=[(name, 1)])})
return scope.overwrite({name: SimpleExpression(base=0, offsets={name: 1})})
else:
return scope

Expand All @@ -149,10 +149,10 @@ def hold_voltage(self, duration: HardwareTime, voltages: Mapping[ChannelID, Hard
for rng_name, rng in ranges.items():
start = 0.
step = 0.
for off_name, offset in offsets:
if off_name == rng_name:
start += rng.start * offset
step += rng.step * offset
offset = offsets.get(rng_name, None)
if offset:
start += rng.start * offset
step += rng.step * offset
base += start
incs.append(step)
factors.append(tuple(incs))
Expand Down

0 comments on commit c9fc1e6

Please sign in to comment.