def _has_compute_uncompute_tag(self, cmd): """ Return True if command cmd has a compute/uncompute tag. Args: cmd (Command object): a command object. """ for t in cmd.tags: if t in [UncomputeTag(), ComputeTag()]: return True return False
def test_control_engine_has_compute_tag(): eng = MainEngine(backend=DummyEngine(), engine_list=[DummyEngine()]) qubit = eng.allocate_qubit() test_cmd0 = Command(eng, H, (qubit,)) test_cmd1 = Command(eng, H, (qubit,)) test_cmd2 = Command(eng, H, (qubit,)) test_cmd0.tags = [DirtyQubitTag(), ComputeTag(), DirtyQubitTag()] test_cmd1.tags = [DirtyQubitTag(), UncomputeTag(), DirtyQubitTag()] test_cmd2.tags = [DirtyQubitTag()] assert _control._has_compute_uncompute_tag(test_cmd0) assert _control._has_compute_uncompute_tag(test_cmd1) assert not _control._has_compute_uncompute_tag(test_cmd2)