Пример #1
0
    def test_map_wires_exception_mismatch_in_number_of_wires(self, recorder):
        """Tests that the map_wires function raises an exception if there is a mismatch between
        wires."""

        wires = [0, 1, 2]
        qc = QuantumCircuit(1)
        qc_wires = [hash(q) for q in qc.qubits]

        with pytest.raises(
            qml.QuantumFunctionError,
            match="The specified number of wires - {} - does not match "
            "the number of wires the loaded quantum circuit acts on.".format(len(wires)),
        ):
            map_wires(qc_wires, wires)
Пример #2
0
    def test_map_wires(self, recorder):
        """Tests the map_wires function for wires of a quantum circuit."""

        wires = [0]
        qc = QuantumCircuit(1)
        qc_wires = [hash(q) for q in qc.qubits]

        assert map_wires(wires, qc_wires) == {0: hash(qc.qubits[0])}
Пример #3
0
    def test_map_wires(self, recorder):
        """Tests the map_wires function for wires of a quantum circuit."""

        wires = [0]
        qc = QuantumCircuit(1)
        qc_wires = [(q.register.name, q.index) for q in qc.qubits]

        assert map_wires(qc_wires, wires) == {0: ('q', 0)}
Пример #4
0
    def test_map_wires_provided_non_standard_order(self, recorder):
        """Tests the map_wires function for wires of non-standard order."""

        wires = [1, 2, 0]
        qc = QuantumCircuit(3)
        qc_wires = [(q.register.name, q.index) for q in qc.qubits]

        mapped_wires = map_wires(qc_wires, wires)

        assert len(mapped_wires) == len(wires)
        assert set(mapped_wires.keys()) == set(wires)
        for q in qc.qubits:
            assert (q.register.name, q.index) in mapped_wires.values()
        assert mapped_wires[0][1] == 2
        assert mapped_wires[1][1] == 0
        assert mapped_wires[2][1] == 1
Пример #5
0
    def test_map_wires_provided_non_standard_order(self, recorder):
        """Tests the map_wires function for wires of non-standard order."""

        wires = [1, 2, 0]
        qc = QuantumCircuit(3)
        qc_wires = [hash(q) for q in qc.qubits]

        mapped_wires = map_wires(wires, qc_wires)

        for q in qc.qubits:
            assert hash(q) in mapped_wires.values()

        assert len(mapped_wires) == len(wires)
        assert set(mapped_wires.keys()) == set(wires)
        assert mapped_wires[0] == qc_wires[2]
        assert mapped_wires[1] == qc_wires[0]
        assert mapped_wires[2] == qc_wires[1]
Пример #6
0
    def test_map_wires_instantiate_quantum_circuit_with_registers(self, recorder):
        """Tests the map_wires function for wires of a quantum circuit instantiated
        using quantum registers."""

        wires = [0, 1, 2]
        qr1 = QuantumRegister(1)
        qr2 = QuantumRegister(1)
        qr3 = QuantumRegister(1)
        qc = QuantumCircuit(qr1, qr2, qr3)
        qc_wires = [hash(q) for q in qc.qubits]

        mapped_wires = map_wires(wires, qc_wires)

        assert len(mapped_wires) == len(wires)
        assert list(mapped_wires.keys()) == wires
        for q in qc.qubits:
            assert hash(q) in mapped_wires.values()