How to use the pennylane.PauliX 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 / test_templates.py View on Github external
def circuit(**inp):
            # Split inputs again
            ks = [int(k) for k in inp.keys()]
            vs = inp.values()
            inp = [x for _, x in sorted(zip(ks, vs))]
            inp1 = inp[:n]
            inp2 = inp[n:]
            # Circuit
            templ1(*inp1, **hyperparameters1)
            templ2(*inp2, **hyperparameters2)
            qml.PauliX(wires=1)
            return [qml.expval(qml.Identity(0)), qml.expval(qml.PauliX(1))]
github XanaduAI / pennylane / tests / test_qnode.py View on Github external
def circuit(x):
            qml.PauliX(wires=0)
            qml.CRY(x, wires=[0, 1])
            return qml.expval(qml.PauliZ(0))
github XanaduAI / pennylane / tests / qnodes / test_qnode_metric_tensor.py View on Github external
def circuit(a, b, c):
            qml.RX(a, wires=0)
            qml.RY(b, wires=0)
            qml.CNOT(wires=[0, 1])
            qml.PhaseShift(c, wires=1)
            return qml.expval(qml.PauliX(0)), qml.expval(qml.PauliX(1))
github XanaduAI / pennylane / tests / test_tf.py View on Github external
def circuit(dummy1, array, dummy2):
            qml.RY(0.5 * array[0,1], wires=0)
            qml.RY(-0.5 * array[1,1], wires=0)
            return qml.expval(qml.PauliX(0)),  # note the comma, returns a 1-vector
github XanaduAI / pennylane / tests / test_operation.py View on Github external
def circuit(x):
            qml.RZ(x, wires=[1]).inv()
            qml.RZ(x, wires=[1]).inv().inv()
            return qml.expval(qml.PauliX(0)), qml.expval(qml.PauliZ(1))
github XanaduAI / pennylane / tests / test_torch.py View on Github external
def circuit(dummy1, array, dummy2):
            qml.RY(0.5 * array[0,1], wires=0)
            qml.RY(-0.5 * array[1,1], wires=0)
            return qml.expval(qml.PauliX(0))  # returns a scalar
github XanaduAI / pennylane-cirq / tests / test_simulator_device.py View on Github external
def test_state_non_analytic(self, simulator_device_2_wires):
        """Test that the state is None if in non-analytic mode."""
        simulator_device_2_wires.reset()
        simulator_device_2_wires.apply([qml.PauliX(0), qml.PauliX(1)])

        assert simulator_device_2_wires.state is None
github rigetti / pennylane-forest / tests / test_qvm.py View on Github external
def test_paulix_expectation(self, shots, qvm, compiler):
        """Test that PauliX expectation value is correct"""
        theta = 0.432
        phi = 0.123

        dev = plf.QVMDevice(device="2q-qvm", shots=shots)
        dev.apply("RY", wires=[0], par=[theta])
        dev.apply("RY", wires=[1], par=[phi])
        dev.apply("CNOT", wires=[0, 1], par=[])

        O = qml.PauliX
        name = "PauliX"

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

        res = np.array([dev.expval(name, [0], []), dev.expval(name, [1], [])])
        # below are the analytic expectation values for this circuit
        self.assertAllAlmostEqual(
            res, np.array([np.sin(theta) * np.sin(phi), np.sin(phi)]), delta=3 / np.sqrt(shots)
        )
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_device.py View on Github external
def test_obs_queue_is_filled_during_execution(self, monkeypatch, mock_device_with_paulis_and_methods):
        """Tests that the operations are properly applied and queued"""
        observables = [
            qml.expval(qml.PauliX(0)),
            qml.var(qml.PauliY(1)),
            qml.sample(qml.PauliZ(2)),
        ]

        # capture the arguments passed to dev methods
        expval_args = []
        var_args = []
        sample_args = []
        with monkeypatch.context() as m:
            m.setattr(Device, 'expval', lambda self, *args: expval_args.extend(args))
            m.setattr(Device, 'var', lambda self, *args: var_args.extend(args))
            m.setattr(Device, 'sample', lambda self, *args: sample_args.extend(args))
            mock_device_with_paulis_and_methods.execute([], observables)

        assert expval_args == ["PauliX", [0], []]
        assert var_args == ["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 17 days ago

Package Health Score

87 / 100
Full package analysis