# PennyLane — Quantum Machine Learning Framework > An open-source library for quantum machine learning, quantum chemistry, and quantum computing that supports automatic differentiation across quantum and classical computations. ## Install Save as a script file and run: # PennyLane — Quantum Machine Learning Framework ## Quick Use ```bash pip install pennylane python -c " import pennylane as qml from pennylane import numpy as np dev = qml.device('default.qubit', wires=2) @qml.qnode(dev) def circuit(x): qml.RX(x, wires=0) qml.CNOT(wires=[0, 1]) return qml.expval(qml.PauliZ(0)) print(qml.grad(circuit)(np.array(0.5))) " ``` ## Introduction PennyLane is a Python library for quantum machine learning and quantum computing that bridges quantum circuits with classical ML frameworks. It enables automatic differentiation of quantum computations, allowing researchers to train variational quantum algorithms using gradient-based optimization with PyTorch, TensorFlow, or JAX. ## What PennyLane Does - Defines parameterized quantum circuits as differentiable computational graphs - Computes gradients of quantum circuits using parameter-shift rules and backpropagation - Integrates with PyTorch, TensorFlow, JAX, and NumPy for hybrid quantum-classical workflows - Runs circuits on simulators and real hardware from IBM, Amazon Braket, IonQ, and others - Provides built-in templates for common variational circuits and quantum chemistry methods ## Architecture Overview PennyLane uses QNodes as its core abstraction: a quantum circuit bound to a device that acts as a differentiable function. The autograd engine applies quantum-specific differentiation methods (parameter-shift or backprop). Device plugins connect QNodes to simulators or hardware backends. ## Self-Hosting & Configuration - Install via pip: pip install pennylane (pure Python, no compilation needed) - Add hardware plugins: pip install pennylane-qiskit, pennylane-braket, etc. - Default simulator (default.qubit) works immediately with no setup - Configure devices by specifying backend name, wire count, and shot count - Use pennylane.about() to verify installed plugins and versions ## Key Features - Automatic differentiation of quantum circuits with multiple gradient methods - Hardware-agnostic design supporting 20+ quantum devices and simulators - Native integration with PyTorch, TensorFlow, JAX, and Autograd - Built-in circuit templates for VQE, QAOA, and quantum neural networks - Quantum chemistry module for molecular simulation and ground-state energy estimation ## Comparison with Similar Tools - **Cirq** — Lower-level circuit framework; PennyLane adds autodiff and ML framework integration - **Qiskit** — Broader quantum SDK; PennyLane specializes in differentiable quantum computing - **TensorFlow Quantum** — TF-only; PennyLane supports PyTorch, JAX, and TF equally - **Amazon Braket SDK** — AWS-focused hardware access; PennyLane is backend-agnostic with a plugin system ## FAQ **Q: Can PennyLane run on real quantum hardware?** A: Yes. Through plugins it connects to IBM Quantum, Amazon Braket, IonQ, Rigetti, and other providers. **Q: How does PennyLane compute gradients of quantum circuits?** A: It uses the parameter-shift rule by default. Simulators can also use backpropagation for faster training. **Q: Is PennyLane only for machine learning?** A: No. It supports quantum chemistry (VQE, molecular simulation) and general variational algorithms beyond ML. **Q: What classical ML frameworks does PennyLane integrate with?** A: PyTorch, TensorFlow, JAX, and NumPy/Autograd, allowing hybrid models that mix quantum and classical layers. ## Sources - https://github.com/PennyLaneAI/pennylane - https://pennylane.ai/qml/ --- Source: https://tokrepo.com/en/workflows/asset-09ea01fd Author: Script Depot