Skip to content

QMeshPy/distributed-quantum

Repository files navigation

Distributed Quantum Services

Quantum operations as discoverable peer-to-peer network services - orchestrated over py-libp2p, analyzed with Qiskit

Python FastAPI Next.js Qiskit License: MIT Last Commit Hits


What This Is

A research platform with two connected tracks:

Demo Video

Watch the demo here

Track 1 - Distributed Quantum Orchestration. A coordinator node (FastAPI + py-libp2p) discovers worker nodes via GossipSub pubsub, compiles OpenQASM circuits into distributed execution plans, routes fragments to workers over libp2p streams, and assembles full quantum results using Qiskit statevector simulation. A Next.js operator console gives real-time visibility into the peer network, job lifecycle, and quantum analysis output.

Track 2 - QAOA Portfolio Optimization. The same infrastructure drives a QAOA-based portfolio optimizer that runs rigorous empirical comparisons against classical baselines (Simulated Annealing) to characterize exactly where, and why, quantum computing gains a scaling advantage.


Platform Architecture

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                    Next.js Operator Console                      β”‚
β”‚   /dashboard  Β·  /runs  Β·  /runs/new  Β·  /finance               β”‚
β”‚   3D peer graph Β· circuit builder Β· quantum analysis Β· QAOA      β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                           β”‚ BFF proxy (REST polling)
                           β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                   FastAPI Coordinator                            β”‚
β”‚                                                                  β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”‚
β”‚  β”‚ Circuit Jobs β”‚  β”‚   Finance    β”‚  β”‚  Enrollment &        β”‚  β”‚
β”‚  β”‚   Service    β”‚  β”‚  (QAOA)      β”‚  β”‚  Discovery           β”‚  β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β”‚
β”‚                                                                  β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”   β”‚
β”‚  β”‚              py-libp2p Runtime (Trio)                    β”‚   β”‚
β”‚  β”‚   Ed25519 host Β· GossipSub pubsub Β· Stream RPC           β”‚   β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                              β”‚ libp2p streams
           β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
           β–Ό                  β–Ό                  β–Ό
   β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
   β”‚  Worker Peer  β”‚  β”‚  Worker Peer  β”‚  β”‚  Worker Peer  β”‚
   β”‚  hadamard/cnotβ”‚  β”‚  qft/teleport β”‚  β”‚  programmable β”‚
   β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Persistence:  Postgres (event-sourced)  Β·  MongoDB (projections)  Β·  JSONL (peer log)

Key Research Finding

97% of quantum runtime is classical COBYLA parameter search β€” not the quantum circuit.

Quantum runtime breakdown:
  Parameter search (COBYLA):  β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ  97%
  Circuit execution:          β–ˆ                                       2%
  Overhead:                   β–Œ                                       1%

Implication (Amdahl's Law): adding more quantum nodes yields at most 1.03Γ— speedup. Quantum advantage comes from scaling behavior, not raw speed:

Portfolio Size Classical (SA) Quantum (QAOA) Winner
10 assets 20 ms 1,500 ms Classical 75Γ— faster
20 assets 600 ms 1,700 ms Classical 2.8Γ— faster
40 assets 6,000 ms 1,900 ms Quantum 3.2Γ— faster
60 assets 20,000 ms 2,100 ms Quantum 9.5Γ— faster

Quick Start

Prerequisites

  • Python 3.11+ with uv
  • Node.js 20+ with npm
  • Docker (for full-stack deployment)

Run the Backend

cd backend
make install     # uv sync --extra dev
make run         # FastAPI on http://localhost:8081

Swagger docs at http://localhost:8081/docs. To restart with a clean runtime state: make run-clean.

Run the Frontend

cd frontend
npm install
npm run dev      # Next.js on http://localhost:3000

Create frontend/.env.local:

QUANTUM_BACKEND_URL=http://localhost:8081
NEXT_PUBLIC_TRIAL_DISABLED=true

Full Stack with Docker

cp .env.example .env   # fill in Neon Postgres + Atlas MongoDB credentials
docker compose up --build

Frontend β†’ localhost:3000 Β· Backend API β†’ localhost:8081 Β· Swagger β†’ localhost:8081/docs


Documentation

Apple-style navigation β€” pick your goal, go directly there. No guessing needed.

πŸŽ“ I'm a researcher or academic

β†’ Start here: docs/research/RESEARCH_PAPER_DRAFT.md

~15,000 words Β· 9 sections Β· publication-ready draft. All experiments, benchmarks, and findings from bottleneck analysis through scaling characterization.

Then read:


πŸ”§ I'm a developer contributing to the platform

β†’ Start here: CONTEXT.md

Deep contributor context β€” package layout, critical caveats (Trio/asyncio bridge, auth model, embedded dev swarm), and entry points for every type of change.

Then read:

  • docs/ARCHITECTURE.md β€” full system architecture: control/execution/data planes, every component, state machines, Mermaid diagrams
  • docs/design.md β€” design rationale, cost model, failure model, protocol contracts
  • docs/requirements.md β€” FR-001–FR-014 with implementation status

πŸ–₯️ I want to understand the operator console (frontend)

β†’ Start here: frontend/DESIGN.md

The Clay design system β€” oklch colors, component patterns, shadcn/ui conventions used throughout the UI.

Then read:

  • docs/ARCHITECTURE.md Β§Frontend β€” BFF proxy pattern, Zustand stores, polling hooks
  • /runs/new β€” visual circuit builder with drag-and-drop gate palette + OpenQASM editor
  • /runs/[id] β€” full quantum analysis: Bloch spheres, fragment DAG, entanglement entropy, density matrices

πŸ“Š I want to replicate or extend the benchmarks

β†’ Start here: docs/technical/IMPLEMENTATION_NOTES.md

Complete technical timeline from initial 600Γ— slowdown through three optimization phases to the final scaling result.

Then read:


πŸš€ I want to deploy the platform

β†’ Start here: DEPLOYMENT-MANUAL.md

Full production runbook: frontend on Vercel, backend on AWS Lightsail, Neon Postgres, MongoDB Atlas, Caddy HTTPS. ~$40/month all-in.

Then read:


πŸ’° I want to understand the finance/quantum use case

β†’ Start here: docs/FINANCIAL_MODELING_FOUNDATIONS.md

What "financial modeling" actually means, Track A (corporate finance) vs Track B (quantum-finance optimization), and why portfolio optimization maps naturally to QAOA.

Then read:


πŸ—ΊοΈ I want the long-term product vision

β†’ Start here: docs/FUTURE_ROADMAP.md

Five-milestone evolution: SDK platform β†’ open node network β†’ autonomous research engine β†’ torrent-native service swarm β†’ self-healing distributed organism.

Then read:


⚑ I'm new and want the fastest possible orientation

β†’ docs/START_HERE.md β€” the full documentation navigator in one page


Research: Optimization Phases

Phase Approach Result
Baseline Default COBYLA (150 iters Γ— 12 starts) 10,000 ms Β· 77% parameter search
Phase 1 βœ… Reduced iterations + parameter caching 1,400 ms Β· 97% parameter search β€” Amdahl limit hit
Phase 2 ❌ Parameter-shift gradients + L-BFGS-B 2–3Γ— slower β€” 8Γ— evaluation overhead dominated
Phase 3 βœ… Focus on scaling N, not speed Quantum wins at N β‰₯ 40 assets

Full paper: docs/research/RESEARCH_PAPER_DRAFT.md Β· Failure analysis: docs/technical/GRADIENT_OPTIMIZATION_POSTMORTEM.md


Future Roadmap

Milestone Theme
M1 Production SDK & Platform
M2 Bring Your Own Node Network
M3 Autonomous Research & Drug Discovery Platform
M4 Torrent-Native Service Network
M5 Hydra Self-Healing Network

Details: docs/FUTURE_ROADMAP.md


Contributing

  1. Fork and create a feature branch.
  2. Read CONTEXT.md first β€” the Trio/asyncio bridge and event-sourced persistence have constraints that aren't obvious.
  3. make lint && make test must pass in backend/ before submitting.
  4. npm run build must succeed in frontend/ (no TypeScript errors).
  5. Surgical changes only β€” match existing style, don't refactor adjacent code.

Citation

@article{bhoir2026quantum,
  title={Quantum Portfolio Optimization: Bottleneck Analysis and Scaling Studies},
  author={Bhoir, Soham and Gupta, Manusheel},
  journal={[Pending submission]},
  year={2026},
  note={QAOA bottleneck profiling, Amdahl's Law analysis, and quantum advantage
        characterization for financial portfolio optimization using distributed
        py-libp2p infrastructure}
}

Acknowledgments

  • Qiskit (IBM) β€” quantum computing framework
  • py-libp2p β€” peer-to-peer networking
  • FastAPI β€” async Python API framework
  • shadcn/ui β€” UI component library
  • Yahoo Finance / Prof. Aswath Damodaran (NYU Stern) β€” market data

docs/START_HERE.md Β· Research Paper Β· Architecture Β· Deployment

Built with quantum circuits, debugged with patience, documented with care.

About

Autonomous research lab with distributed quantum infrastructure for computational chemistry, molecular simulation, quantum finance, and scientific discovery - powered by libp2p and IPFS for peer-to-peer collaboration.

Topics

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages