Skip to content

Commit

Permalink
Drop empty loops
Browse files Browse the repository at this point in the history
  • Loading branch information
terrorfisch committed Jun 18, 2018
1 parent f1f723a commit 45f789d
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions qctoolkit/hardware/program.py
Expand Up @@ -4,6 +4,7 @@
from copy import deepcopy
from enum import Enum
from fractions import Fraction
import warnings

import numpy as np

Expand Down Expand Up @@ -261,6 +262,21 @@ def flatten_and_balance(self, depth: int) -> None:
else:
i += 1

def remove_empty_loops(self):
new_children = []
for child in self:
if child.is_leaf():
if child.waveform is None:
if child._measurements:
warnings.warn("Dropping measurement since there is no waveform attached")
else:
new_children.append(child)
else:
child.remove_empty_loops()
new_children.append(child)
self[:] = new_children


class ChannelSplit(Exception):
def __init__(self, channel_sets):
self.channel_sets = channel_sets
Expand Down Expand Up @@ -332,6 +348,8 @@ def repeat_measurements(child_loop, rep_count):
iterable = itertools.chain((loop,), iterable)
except StopIteration:
pass
for program in self.programs.values():
program.remove_empty_loops()

@property
def programs(self) -> Dict[FrozenSet[ChannelID], Loop]:
Expand Down

0 comments on commit 45f789d

Please sign in to comment.