How to use the pennylane.expval 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 / qnode_new / test_qnode_base.py View on Github external
def circuit(x):
        qml.RX(x, wires=[0])
        qml.CNOT(wires=[0, 1])
        qml.RY(0.4, wires=[0])
        qml.RZ(-0.2, wires=[1])
        return qml.expval(qml.PauliX(0)), qml.expval(qml.PauliZ(1))
github XanaduAI / pennylane / tests / qnodes / test_qnode_qubit.py View on Github external
def circuit(x):
            qml.RX(x, wires=[1])
            return qml.expval(qml.PauliZ(0))
github XanaduAI / pennylane / tests / interfaces / test_interfaces_autograd.py View on Github external
def classifier_circuit(in_data, x):
            qml.RX(in_data, wires=[0])
            qml.CNOT(wires=[0, 1])
            qml.RY(-1.6, wires=[0])
            qml.RY(in_data, wires=[1])
            qml.CNOT(wires=[1, 0])
            qml.RX(x, wires=[0])
            qml.CNOT(wires=[0, 1])
            return qml.expval(qml.PauliZ(0))
github XanaduAI / pennylane / tests / qnodes / test_qnode_base.py View on Github external
def circuit(x):
            qml.RX(0.5, wires=[0])
            return qml.expval(qml.PauliZ(0))
github XanaduAI / pennylane / tests / test_templates.py View on Github external
def circuit(*inp):
            template(*inp, **hyperp)
            return qml.expval(qml.Identity(0))
github XanaduAI / pennylane / tests / qnodes / test_qnode_base.py View on Github external
def circuit(x):
            qml.RX(x, wires=[0])
            ex = qml.expval(qml.PauliZ(wires=1))
            qml.RY(0.5, wires=[0])
            return qml.expval(qml.PauliZ(wires=0))
github rigetti / pennylane-forest / tests / test_gradients.py View on Github external
def func(x, y):
        """Reference QNode"""
        qml.BasisState(in_state, wires=list(range(w)))
        qml.RY(x, wires=0)
        qml.RX(y, wires=1)
        qml.CNOT(wires=[0, 1])
        return qml.expval(qml.PauliZ(1))
github XanaduAI / pennylane / tests / test_templates_subroutines.py View on Github external
def circuit_tria(varphi):
            Interferometer(theta, phi, varphi, mesh='triangular', beamsplitter='clements', wires=wires)
            return [qml.expval(qml.NumberOperator(w)) for w in wires]
github XanaduAI / qml / demonstrations / tutorial_state_preparation.py View on Github external
def circuit(params, A=None):

    # repeatedly apply each layer in the circuit
    for j in range(nr_layers):
        layer(params, j)

    # returns the expectation of the input matrix A on the first qubit
    return qml.expval(qml.Hermitian(A, wires=0))
github XanaduAI / qml / demonstrations / tutorial_vqls.py View on Github external
# Controlled Z operator at position j. If j = -1, apply the identity.
    if j != -1:
        qml.CZ(wires=[ancilla_idx, j])

    # Unitary U_b associated to the problem vector |b>.
    U_b()

    # Controlled application of Adjoint(A_lp).
    # In this specific example Adjoint(A_lp) = A_lp.
    CA(lp)

    # Second Hadamard gate applied to the ancillary qubit.
    qml.Hadamard(wires=ancilla_idx)

    # Expectation value of Z for the ancillary qubit.
    return qml.expval(qml.PauliZ(wires=ancilla_idx))

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

87 / 100
Full package analysis