How to use the pennylane.CNOT 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_utils.py View on Github external
def circuit(a, b, c):
            qml.RX(a, wires=0)
            qml.RY(b, wires=1)

            with pu.OperationRecorder() as recorder:
                ops = [
                    qml.PauliY(0),
                    qml.PauliY(1),
                    qml.RZ(c, wires=0),
                    qml.RZ(c, wires=1),
                    qml.CNOT(wires=[0, 1]),
                ]

            assert str(recorder) == expected_output
            assert recorder.queue == ops

            return qml.expval(qml.PauliZ(0)), qml.expval(qml.PauliZ(1))
github XanaduAI / pennylane / tests / qnodes / test_qnode_jacobian.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_vqe.py View on Github external
def custom_fixed_ansatz(*params, wires=None):
    """Custom fixed ansatz"""
    qml.RX(0.5, wires=0)
    qml.RX(-1.2, wires=1)
    qml.Hadamard(wires=0)
    qml.CNOT(wires=[0, 1])
    qml.Hadamard(wires=1)
    qml.CNOT(wires=[0, 1])
github XanaduAI / pennylane / tests / interfaces / test_interfaces_autograd.py View on Github external
def ansatz(x, y, z):
            qml.QubitStateVector(np.array([1, 0, 1, 1]) / np.sqrt(3), wires=[0, 1])
            qml.Rot(x, y, z, wires=0)
            qml.CNOT(wires=[0, 1])
            return qml.expval(qml.PauliZ(0))
github XanaduAI / pennylane / tests / test_tf.py View on Github external
def ansatz(x, y, z):
            qml.QubitStateVector(np.array([1, 0, 1, 1])/np.sqrt(3), wires=[0, 1])
            qml.Rot(x, y, z, wires=0)
            qml.CNOT(wires=[0, 1])
            return qml.expval(qml.PauliZ(0)), qml.expval(qml.PauliY(1))
github XanaduAI / pennylane / tests / test_device.py View on Github external
def test_supports_observable_exception(self, mock_device):
        """check that device.supports_observable raises proper errors
           if the argument is of the wrong type"""

        with pytest.raises(
                ValueError,
                match="The given observable must either be a pennylane.Observable class or a string.",
        ):
            mock_device.supports_observable(3)

        operation = qml.CNOT

        with pytest.raises(
                ValueError,
                match="The given observable must either be a pennylane.Observable class or a string.",
        ):
            mock_device.supports_observable(operation)
github XanaduAI / qml / demonstrations / tutorial_advanced_usage.py View on Github external
def circuit(param, fixed=None):
    qml.RX(fixed, wires=0)
    qml.RX(param, wires=1)
    qml.CNOT(wires=[0, 1])
    return qml.expval(qml.PauliZ(0)), qml.expval(qml.PauliZ(1))
github XanaduAI / qml / demonstrations / tutorial_state_preparation.py View on Github external
def layer(params, j):
    for i in range(nr_qubits):
        qml.RX(params[i, j, 0], wires=i)
        qml.RY(params[i, j, 1], wires=i)
        qml.RZ(params[i, j, 2], wires=i)

    qml.CNOT(wires=[0, 1])
    qml.CNOT(wires=[0, 2])
    qml.CNOT(wires=[1, 2])
github Roger-luo / quantum-benchmarks / pennylane / benchmarks.py View on Github external
def test_CX(benchmark, nqubits):
    benchmark.group = "CNOT"
    gate_test = GateTest(nqubits, qml.CNOT, [0, 1])
    benchmark(gate_test)
github XanaduAI / qml / demonstrations / tutorial_coherent_vqls.py View on Github external
def CA_all():
    """Controlled application of all the unitary components A_l of the problem matrix A."""
    # Controlled-A_1
    qml.CNOT(wires=[ancilla_idx, 0])
    qml.CZ(wires=[ancilla_idx, 1])

    # Controlled-A2
    qml.CNOT(wires=[ancilla_idx + 1, 0])

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 15 days ago

Package Health Score

87 / 100
Full package analysis