Skip to content

Interactive 3D Quantum Coin Flip & Bloch Sphere Explorer. Visualize superposition, measurement, and qubit states directly in your browser. โš›๏ธ๐Ÿช™

License

Notifications You must be signed in to change notification settings

Muhib-Mehdi/quantum-coin-flip

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

7 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

โš›๏ธ Quantum Whirl

Interactive Quantum Coinflip & Bloch Sphere Explorer

HTML5 CSS3 JavaScript Three.js License: MIT


Explore the Qubit ยท View Demo ยท Report Bug


๐Ÿ“‘ Table of Contents


๐Ÿ”ฎ Overview

Quantum Whirl is an interactive educational tool designed to visualize and simulate single-qubit quantum mechanics. Unlike standard educational tools that rely on static diagrams, Quantum Whirl provides a real-time, interactive Bloch Sphere and a Quantum Coin Flip experiment that demonstrates superposition, probability amplitudes, and measurement collapse.

Why Choose Quantum Whirl?

Feature ๐Ÿช™ Standard Coin Flip Sim โš›๏ธ Quantum Whirl
State Representation Binary (H or T) Continuous Bloch Sphere
Probability Fixed 50/50 Adjustable Amplitudes (ฮฑ, ฮฒ)
3D Visualization None Interactive Three.js Sphere
Math Transparency Hidden Real-time Calculation Steps
Quantum Concepts N/A Superposition, Phase, Fidelity

โœจ Features

๐Ÿงช Quantum Simulation

  • Superposition: Visualize states where the qubit exists in both |0โŸฉ and |1โŸฉ simultaneously.
  • Measurement Collapse: Watch the state collapse to a basis state upon measurement (coin flip).
  • Quantum Noise: Simulate environmental effects like decoherence and entanglement.

๐ŸงŠ 3D Visualization

  • Interactive Bloch Sphere: Rotate and zoom to explore the qubit state vector in 3D space.
  • Dynamic State Vector: Real-time updates to the vector position based on ฮธ (theta) and ฯ† (phi) parameters.
  • Visual Guides: Equatorial and meridian rings for precise state tracking.

๐ŸŽ›๏ธ Interactive UI

  • Real-time Parameters: Adjust probabilities and angles using intuitive sliders.
  • Step-by-Step Math: computation panel showing the exact math behind every quantum operation.
  • Immersive Design: Particle background, custom cursor trails, and neon aesthetics.

๐Ÿš€ Installation

Prerequisites

Software Version Description
Node.js 14.x+ Required for the dev server (optional if just opening HTML)
Web Browser Modern Chrome, Firefox, Edge, or Safari with WebGL support

Quick Start

  1. Clone the Repository

    git clone https://github.com/muhib-mehdi/quantum-coin-flip.git
    cd quantum-coin-flip
  2. Install Dependencies (Optional) If you want to use the included lightweight server:

    npm install
  3. Run the Application

    npm start

    Or simply open index.html in your browser.


๐ŸŽฎ Usage

Workflow

graph LR
    A[Start] --> B[Explore Page]
    B --> C{Action}
    C -->|Adjust Sliders| D[Update Quantum State]
    C -->|Click Coin| E[Measure Qubit]
    D --> F[Bloch Sphere Updates]
    E --> G[Collapse Wavefunction]
    G --> H["Show Result |0โŸฉ or |1โŸฉ"]
Loading
  1. Enter the Lab: Click "Explore" on the landing page.
  2. Define State: Use the Quantum Parameters panel on the right to set your qubit's state (e.g., set Alpha to 0.5 for a 25% chance of Heads).
  3. Visual Check: Verify the state on the Bloch Sphere at the bottom right.
  4. Experiment: Click the Quantum Coin to perform a measurement.
  5. Analyze: Watch the Computation Display to see how probability + noise determined the outcome.

๐Ÿ—๏ธ Architecture

The application is built with a separation of concerns between the Physics engine, the Visualization layer, and the User Interface.

graph TD
    subgraph UI [User Interface]
        HTML[index.html]
        CSS[styles.css]
        Script[script.js]
    end

    subgraph Logic [Quantum Core]
        QState[QuantumState Class]
        Math[Probabilities & Phase]
    end

    subgraph Vis [Visualization]
        Three[Three.js Renderer]
        Sphere[Bloch Sphere Mesh]
    end

    HTML -->|User Input| Script
    Script -->|Update Params| QState
    QState -->|State Vector| Sphere
    Sphere -->|Render| HTML
    QState -->|Measurement Result| Script
Loading

Key Components

  • quantum.js: Contains the QuantumState class which handles all physics calculations (amplitudes, probabilities, noise simulation).
  • script.js: Manages UI interactions, custom cursor effects, and the particle background system.
  • Three.js: Used within quantum.js (and inline scripts) to render the 3D Bloch Sphere.

โš™๏ธ Configuration

Expand the sections below to understand the adjustable parameters.

๐Ÿ“ Geometric Parameters (Bloch Sphere)
  • ฮธ (Theta): The polar angle (0 to 180ยฐ). Determines the probability of |0โŸฉ vs |1โŸฉ.
    • 0ยฐ = |0โŸฉ (Heads)
    • 180ยฐ = |1โŸฉ (Tails)
    • 90ยฐ = Superposition
  • ฯ† (Phi): The azimuthal angle (0 to 360ยฐ). Represents the phase of the qubit.
  • Phase (ฮด): Additional global phase factor.
๐Ÿ“‰ Environmental Factors
  • Entanglement Factor: Simulates noise from entanglement with an environment, adding randomness to the probability distribution.
  • Decoherence Rate (ฮณ): Simulates the loss of quantum coherence over time, pushing the state towards a classical mix.
  • Fidelity: Represents the quality of the quantum gate/operation.

๐Ÿ”ฌ Advanced Features

Math Behind the Magic

The simulation calculates the probability of measuring state $|0\rangle$ using the Born rule, adjusted for environmental noise:

$$ P(|0\rangle) = |\alpha|^2 \times F + \epsilon_{noise} - \gamma_{decoherence} $$

Where:

  • $\alpha = \cos(\theta/2)$
  • $\beta = e^{i\phi}\sin(\theta/2)$
  • $F$ is the Fidelity factor.

Keyboard Shortcuts

Key Action
Space Flip Coin (Measure)
R Reset Parameters
Esc Return to Menu

๐Ÿ“ธ Screenshots

Quantum Whirl Interface

The Quantum Whirl Interface showing the Coin (left), Parameters (center), and Bloch Sphere (bottom right).


๐Ÿค Contributing

Contributions are what make the open-source community such an amazing place to learn, inspire, and create. Any contributions you make are greatly appreciated.

  1. Fork the Project
  2. Create your Feature Branch (git checkout -b feature/AmazingFeature)
  3. Commit your Changes (git commit -m 'Add some AmazingFeature')
  4. Push to the Branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

๐Ÿ“œ License & Contact

License: MIT

Mehdi Hasan

LinkedIn GitHub

About

Interactive 3D Quantum Coin Flip & Bloch Sphere Explorer. Visualize superposition, measurement, and qubit states directly in your browser. โš›๏ธ๐Ÿช™

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published