Exemplo n.º 1
0
    def test_error_basis_state_format(self, basis_state, wires):
        """Tests that the correct error messages is raised when
        the basis state contains numbers different from 0 and 1."""

        with pytest.raises(ValueError,
                           match="Basis state must only (contain|consist)"):
            qml.BasisStatePreparation(basis_state, wires)
Exemplo n.º 2
0
    def test_error_num_qubits(self, basis_state, wires):
        """Tests that the correct error message is raised when the number
        of qubits does not match the number of wires."""

        with pytest.raises(ValueError,
                           match="Basis state must be of (shape|length)"):
            qml.BasisStatePreparation(basis_state, wires)
Exemplo n.º 3
0
    def test_correct_pl_gates(self, basis_state, wires, target_wires):
        """Tests queue for simple cases."""

        op = qml.BasisStatePreparation(basis_state, wires)
        queue = op.expand().operations

        for id, gate in enumerate(queue):
            assert gate.name == "PauliX"
            assert gate.wires.tolist() == [target_wires[id]]
Exemplo n.º 4
0
 def circuit2():
     qml.BasisStatePreparation(basis_state, wires=["z", "a", "k"])
     return qml.expval(qml.Identity("z"))
Exemplo n.º 5
0
 def circuit():
     qml.BasisStatePreparation(basis_state, wires=range(3))
     return qml.expval(qml.Identity(0))
Exemplo n.º 6
0
        def circuit():
            qml.BasisStatePreparation(basis_state, wires)

            # Pauli Z gates identify the basis state
            return qml.expval(qml.PauliZ(0)), qml.expval(
                qml.PauliZ(1)), qml.expval(qml.PauliZ(2))
Exemplo n.º 7
0
 def test_id(self):
     """Tests that the id attribute can be set."""
     template = qml.BasisStatePreparation(np.array([0, 1]),
                                          wires=[0, 1],
                                          id="a")
     assert template.id == "a"
Exemplo n.º 8
0
 def circuit(basis_state):
     qml.BasisStatePreparation(basis_state, wires=range(2))
     return qml.expval(qml.PauliZ(0))