How to use the pennylane.PauliY function in PennyLane

To help you get started, we’ve selected a few PennyLane examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github XanaduAI / pennylane / tests / beta / test_tensornet_tf.py View on Github external
def circuit(x):
            qml.RX(x, wires=0)
            return qml.expval(qml.PauliY(0))
github XanaduAI / pennylane / tests / interfaces / test_interfaces_autograd.py View on Github external
def circuit(x, y, z):
            qml.CNOT(wires=[0, 1])
            return qml.expval(qml.PauliZ(0)), qml.expval(qml.PauliY(1))
github XanaduAI / pennylane / tests / test_operation.py View on Github external
def test_construct(self):
        """Test construction of a tensor product"""
        X = qml.PauliX(0)
        Y = qml.PauliY(2)
        T = Tensor(X, Y)
        assert T.obs == [X, Y]

        T = Tensor(T, Y)
        assert T.obs == [X, Y, Y]

        with pytest.raises(ValueError, match="Can only perform tensor products between observables"):
            Tensor(T, qml.CNOT(wires=[0, 1]))
github XanaduAI / pennylane-cirq / tests / test_cirq_device.py View on Github external
            (qml.PauliY(wires=[0]).inv(), [cirq.Y ** -1]),
            (qml.PauliZ(wires=[0]).inv(), [cirq.Z ** -1]),
            (qml.Hadamard(wires=[0]), [cirq.H]),
            (qml.Hadamard(wires=[0]).inv(), [cirq.H ** -1]),
            (qml.S(wires=[0]), [cirq.S]),
            (qml.S(wires=[0]).inv(), [cirq.S ** -1]),
            (qml.PhaseShift(1.4, wires=[0]), [cirq.ZPowGate(exponent=1.4 / np.pi)]),
            (qml.PhaseShift(-1.2, wires=[0]), [cirq.ZPowGate(exponent=-1.2 / np.pi)]),
            (qml.PhaseShift(2, wires=[0]), [cirq.ZPowGate(exponent=2 / np.pi)]),
            (
                qml.PhaseShift(1.4, wires=[0]).inv(),
                [cirq.ZPowGate(exponent=-1.4 / np.pi)],
            ),
            (
                qml.PhaseShift(-1.2, wires=[0]).inv(),
                [cirq.ZPowGate(exponent=1.2 / np.pi)],
            ),
github XanaduAI / pennylane / tests / test_device.py View on Github external
def test_parameters_available_at_pre_measure(self, mock_device, monkeypatch):
        """Tests that the parameter mapping is available when pre_measure is called and that accessing
           Device.parameters raises no error"""

        p0 = 0.54
        p1 = -0.32

        queue = [
            qml.RX(p0, wires=0),
            qml.PauliY(wires=1),
            qml.Rot(0.432, 0.123, p1, wires=2),
        ]

        parameters = {0: (0, 0), 1: (2, 3)}

        observables = [
            qml.expval(qml.PauliZ(0)),
            qml.var(qml.PauliZ(1)),
            qml.sample(qml.PauliZ(2)),
        ]

        p_mapping = {}

        with monkeypatch.context() as m:
            m.setattr(Device, "pre_measure", lambda self: p_mapping.update(self.parameters))
            mock_device.execute(queue, observables, parameters=parameters)
github XanaduAI / pennylane-cirq / tests / test_expval.py View on Github external
def test_pauliy_expectation(self, device, shots, tol):
        """Test that PauliY expectation value is correct"""
        theta = 0.432
        phi = 0.123

        dev = device(2)
        O = qml.PauliY

        with mimic_execution_for_expval(dev):
            dev.apply(
                [qml.RX(theta, wires=[0]), qml.RX(phi, wires=[1]), qml.CNOT(wires=[0, 1]),],
                rotations=O(wires=[0], do_queue=False).diagonalizing_gates()
                + O(wires=[1], do_queue=False).diagonalizing_gates(),
            )

        dev._obs_queue = [O(wires=[0], do_queue=False), O(wires=[1], do_queue=False)]

        res = np.array(
            [dev.expval(O(wires=[0], do_queue=False)), dev.expval(O(wires=[1], do_queue=False)),]
        )
        assert np.allclose(res, np.array([0, -(np.cos(theta)) * np.sin(phi)]), **tol)
github XanaduAI / pennylane / tests / test_operation.py View on Github external
def test_eigvals(self):
        """Test that the correct eigenvalues are returned for the Tensor"""
        X = qml.PauliX(0)
        Y = qml.PauliY(2)
        t = Tensor(X, Y)
        assert np.array_equal(t.eigvals, np.kron(qml.PauliX.eigvals, qml.PauliY.eigvals))
github XanaduAI / pennylane / tests / test_qnode.py View on Github external
def layer3_diag(x, y, z, h, g, f):
            non_parametrized_layer(a, b, c)
            qml.RX(x, wires=0)
            qml.RY(y, wires=1)
            qml.RZ(z, wires=2)
            non_parametrized_layer(a, b, c)
            return qml.var(qml.PauliZ(2)), qml.var(qml.PauliY(1))

PennyLane

PennyLane is a cross-platform Python library for quantum computing, quantum machine learning, and quantum chemistry. Train a quantum computer the same way as a neural network.

Apache-2.0
Latest version published 1 month ago

Package Health Score

84 / 100
Full package analysis