Skip to content

About

No description, website, or topics provided.

Resources

Stars

1 star

Watchers

0 watching

Forks

Latest commit

 

History

3 Commits

Folders and files

Repository files navigation

⚛️ PennyLane — Quantum Machine Learning

PennyLane Python scikit-learn License

A hands-on introduction to Quantum Computing and Quantum Machine Learning using PennyLane — from building your first quantum circuit to training a Variational Quantum Classifier (VQC) on real data.


📁 Project Structure

PennyLane/
│
├── simple_circuit.py     # Bell state: Hadamard + CNOT entanglement
├── param_circuit.py      # Parameterized rotations + expectation values
├── vqc_train.py          # Variational Quantum Classifier on make_moons dataset
├── .gitignore
└── README.md

🚀 STEP 1 — Set Up a Virtual Environment

Create a fresh virtual environment to keep your dependencies isolated:

python -m venv qml-env

Activate it:

Platform Command
🪟 Windows qml-env\Scripts\activate
🍎 Mac/Linux source qml-env/bin/activate

You should now see (qml-env) at the start of your terminal prompt.


📦 STEP 2 — Install Dependencies

With the virtual environment active, install the required packages:

pip install pennylane
pip install matplotlib
pip install scikit-learn

💡 All at once (optional):

pip install pennylane matplotlib scikit-learn

✅ STEP 3 — Verify Installation

Test that PennyLane installed correctly:

python -c "import pennylane as qml; print(qml.__version__)"

If a version number prints (e.g., 0.38.0) → you're all set! ⚡


▶️ STEP 4 — Run the Scripts

🔵 1. simple_circuit.py — Bell State Circuit

Creates a 2-qubit Bell state using a Hadamard gate and a CNOT gate — the classic quantum entanglement circuit.

python simple_circuit.py

What it does:

  • Applies H (Hadamard) to qubit 0 → puts it in superposition
  • Applies CNOT with qubit 0 as control, qubit 1 as target → entangles them
  • Returns the full quantum state vector

Expected output:

[0.70710678+0.j 0.        +0.j 0.        +0.j 0.70710678+0.j]

🟣 2. param_circuit.py — Parameterized Quantum Circuit

Demonstrates a parameterized circuit using rotation gates with a trainable angle θ.

python param_circuit.py

What it does:

  • Applies RX(θ) to qubit 0 and RY(θ) to qubit 1
  • Entangles them with CNOT
  • Measures the expectation value of the Pauli-Z operator on qubit 0

Expected output:

Expectation value: 0.7071067811865476

🟡 3. vqc_train.py — Variational Quantum Classifier (VQC)

Trains a Variational Quantum Classifier on the make_moons dataset from scikit-learn — a real quantum machine learning example!

python vqc_train.py

What it does:

  • Loads the make_moons dataset (100 samples, non-linearly separable)
  • Encodes classical data into quantum states via RX / RY rotations
  • Adds trainable weight layers (RX, RY + CNOT)
  • Optimizes using quantum gradient descent (PennyLane's GradientDescentOptimizer)
  • Runs for 50 training steps and reports loss every 10 steps

Expected output:

Step 0,  Loss: 0.9523...
Step 10, Loss: 0.7841...
Step 20, Loss: 0.6102...
Step 30, Loss: 0.4987...
Step 40, Loss: 0.4213...
Final weights: [...]

The loss decreases across steps, showing the quantum model is learning! 🧠


🧠 Concepts Covered

Concept Script
Quantum gates (H, CNOT, RX, RY) simple_circuit.py, param_circuit.py
Quantum entanglement (Bell state) simple_circuit.py
Parameterized quantum circuits param_circuit.py
Expectation values (Pauli-Z) param_circuit.py
Data encoding into qubit rotations vqc_train.py
Quantum gradient descent vqc_train.py
Variational Quantum Classifier vqc_train.py

🔧 Requirements

Package Purpose
pennylane Quantum circuit simulation & ML
scikit-learn make_moons dataset generation
matplotlib (Optional) Plotting
numpy Numerical operations (bundled with PennyLane)

📚 Resources


🤝 Contributing

Pull requests are welcome! For major changes, please open an issue first.


📄 License

This project is licensed under the MIT License.


Made with ❤️ and ⚛️ quantum magic

About

No description, website, or topics provided.

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages