Esempio n. 1
0
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)
Esempio n. 2
0
def test_tagremover():
    backend = DummyEngine(save_commands=True)
    tag_remover = _tagremover.TagRemover([type("")])
    eng = MainEngine(backend=backend, engine_list=[tag_remover])
    # Create a command_list and check if "NewTag" is removed
    qubit = eng.allocate_qubit()
    cmd0 = Command(eng, H, (qubit, ))
    cmd0.tags = ["NewTag"]
    cmd1 = Command(eng, H, (qubit, ))
    cmd1.tags = [1, 2, "NewTag", 3]
    cmd_list = [cmd0, cmd1, cmd0]
    assert len(backend.received_commands) == 1  # AllocateQubitGate
    tag_remover.receive(cmd_list)
    assert len(backend.received_commands) == 4
    assert backend.received_commands[1].tags == []
    assert backend.received_commands[2].tags == [1, 2, 3]
Esempio n. 3
0
def test_auto_replacer_adds_tags(test_gate_filter):
    # Test that AutoReplacer puts back the tags
    backend = DummyEngine(save_commands=True)
    eng = MainEngine(backend=backend,
                     engine_list=[_replacer.AutoReplacer(), test_gate_filter])
    assert len(decompositions[TestGate.__class__.__name__]) == 2
    assert len(backend.received_commands) == 0
    qb = eng.allocate_qubit()
    cmd = Command(eng, TestGate, (qb, ))
    cmd.tags = ["AddedTag"]
    eng.send([cmd])
    eng.flush()
    assert len(backend.received_commands) == 3
    assert backend.received_commands[1].gate == X
    assert len(backend.received_commands[1].tags) == 1
    assert backend.received_commands[1].tags[0] == "AddedTag"