示例#1
0
def test_insert_then_drop():
    d1 = DummyEngine()
    d2 = DummyEngine()
    d3 = DummyEngine()
    eng = MainEngine(backend=d3, engine_list=[d1])

    assert d1.next_engine is d3
    assert d2.next_engine is None
    assert d3.next_engine is None
    assert d1.main_engine is eng
    assert d2.main_engine is None
    assert d3.main_engine is eng

    insert_engine(d1, d2)
    assert d1.next_engine is d2
    assert d2.next_engine is d3
    assert d3.next_engine is None
    assert d1.main_engine is eng
    assert d2.main_engine is eng
    assert d3.main_engine is eng

    drop_engine_after(d1)
    assert d1.next_engine is d3
    assert d2.next_engine is None
    assert d3.next_engine is None
    assert d1.main_engine is eng
    assert d2.main_engine is None
    assert d3.main_engine is eng
示例#2
0
    def _send_cmd_with_mapped_ids(self, cmd):
        """
        Send this Command using the mapped qubit ids of self.current_mapping.

        If it is a Measurement gate, then it adds a LogicalQubitID tag.

        Args:
            cmd: Command object with logical qubit ids.
        """
        new_cmd = deepcopy(cmd)
        qubits = new_cmd.qubits
        for qureg in qubits:
            for qubit in qureg:
                if qubit.id != -1:
                    qubit.id = self.current_mapping[qubit.id]
        control_qubits = new_cmd.control_qubits
        for qubit in control_qubits:
            qubit.id = self.current_mapping[qubit.id]
        if isinstance(new_cmd.gate, MeasureGate):
            assert len(new_cmd.qubits) == 1 and len(new_cmd.qubits[0]) == 1

            # Add LogicalQubitIDTag to MeasureGate
            def add_logical_id(command, old_tags=deepcopy(cmd.tags)):
                command.tags = (old_tags +
                                [LogicalQubitIDTag(cmd.qubits[0][0].id)])
                return command

            tagger_eng = CommandModifier(add_logical_id)
            insert_engine(self, tagger_eng)
            self.send([new_cmd])
            drop_engine_after(self)
        else:
            self.send([new_cmd])