Skip to main content

A package for compiling quantum circuit code from Cirq, Qiskit, and PennyLane to OpenQASM 3.0.

Project description

Quantum Unified Simulator (QCanvas)

A comprehensive quantum computing platform that provides unified simulation, circuit conversion, and visualization capabilities across multiple quantum frameworks using a hybrid Next.js and FastAPI architecture.

๐Ÿš€ Overview

QCanvas is a modern, web-based quantum computing platform that bridges the gap between different quantum computing frameworks. It provides a unified interface for simulating quantum circuits, converting between different quantum programming languages, and visualizing quantum states and operations.

Key Features

  • Multi-Framework Support: Convert circuits between Cirq, Qiskit, and PennyLane
  • Hybrid CPUโ€“QPU Model: QCanvas orchestrates; QSim executes (simulator-first, pluggable QPU later)
  • Real-Time Simulation: Execute quantum circuits with statevector, density matrix, or stabilizer backends
  • OpenQASM 3.0 (Rosetta Stone): Universal intermediate representation across frameworks
  • Smart Conversion Engine: AST-based parsing, intelligent gate mapping, built-in validation, instant analytics
  • Interactive Visualization: Circuit rendering, histograms, and results analysis
  • Shared TypeScript Types: Type safety across frontend and backend services
  • Extensible Architecture: Plugin-based system for adding new frameworks

๐Ÿ—๏ธ Architecture

QCanvas/
โ”œโ”€โ”€ frontend/             # Next.js-based web interface
โ”‚   โ”œโ”€โ”€ app/              # App Router pages and layouts
โ”‚   โ”œโ”€โ”€ components/       # Reusable UI components
โ”‚   โ”œโ”€โ”€ lib/              # Utility functions and state management
โ”‚   โ””โ”€โ”€ public/           # Static assets (images, icons)
โ”‚
โ”œโ”€โ”€ backend/              # FastAPI REST API and WebSocket server
โ”‚   โ”œโ”€โ”€ app/              # Main application logic
โ”‚   โ”‚   โ”œโ”€โ”€ api/          # API routes and endpoints
โ”‚   โ”‚   โ”œโ”€โ”€ models/       # Database models and Pydantic schemas
โ”‚   โ”‚   โ””โ”€โ”€ services/     # Business logic services
โ”‚   โ””โ”€โ”€ alembic/          # Database migration scripts
โ”‚
โ”œโ”€โ”€ quantum_converters/   # Framework conversion modules
โ”‚   โ”œโ”€โ”€ qiskit/           # Qiskit to OpenQASM converters
โ”‚   โ”œโ”€โ”€ cirq/             # Cirq to OpenQASM converters
โ”‚   โ””โ”€โ”€ pennylane/        # PennyLane to OpenQASM converters
โ”‚
โ”œโ”€โ”€ quantum_simulator/    # Quantum simulation engine
โ”‚   โ”œโ”€โ”€ backends/         # Simulation backends (statevector, density matrix)
โ”‚   โ””โ”€โ”€ core/             # Core simulation logic
โ”‚
โ”œโ”€โ”€ examples/             # Sample circuits and tutorials
โ”‚
โ”œโ”€โ”€ docs/                 # Project documentation
โ”‚
โ”œโ”€โ”€ tests/                # Comprehensive test suite
โ”‚
โ””โ”€โ”€ scripts/              # Helper scripts for setup and maintenance

Core Components

  1. QCanvas (Compilation/Orchestration): AST parsing, QASM generation, validation, hybrid scheduling
  2. QSim (Execution): High-performance simulation backends and result aggregation
  3. Next.js Frontend: UI components, routing, and simple operations
  4. FastAPI Backend: API, WebSockets, and heavy computations
  5. Shared TypeScript Types: Type safety across frontend and backend

๐Ÿ› ๏ธ Installation

Prerequisites

  • Python 3.9+
  • Node.js 18+ (for Next.js)
  • Docker Engine with Compose V2 (docker compose CLI)
  • Git

Docker and Docker Compose

The repo includes docker-compose.yml for PostgreSQL, Redis, QCanvas FastAPI backend, Cirq-RAG-Code-Assistant (Cirq AI / Bedrock), and optionally SonarQube (metrics profile).

The Next.js frontend is not in Compose; run it locally with npm run dev in frontend/ (see below).

Service overview

Service Container name Host port Notes
PostgreSQL qcanvas_postgres 5433 โ†’ 5432 Database for QCanvas
Redis qcanvas_redis 6379 Caching
Cirq AI qcanvas_cirq_agent 8001 โ†’ 8000 Bedrock/RAG; internal URL http://cirq_agent:8000
QCanvas API qcanvas_backend 8000 Sets CIRQ_AGENT_URL=http://cirq_agent:8000
SonarQube qcanvas_sonarqube 9000 Only with --profile metrics

Each container can use port 8000 internally without conflict; they are isolated. Only host ports must be unique (8000 vs 8001).

Environment file (project root)

Create a .env in the repository root (Compose loads it automatically). Minimum for the database:

POSTGRES_USER=postgres
POSTGRES_PASSWORD=postgres
POSTGRES_DB=qcanvas_db

For Cirq AI inside Docker, add the same variables you use for Bedrock (see Cirq-RAG-Code-Assistant/.env.example):

AWS_ACCESS_KEY_ID=...
AWS_SECRET_ACCESS_KEY=...
AWS_DEFAULT_REGION=us-east-1
BEDROCK_INFERENCE_PROFILE_ARN_DESIGNER=...
BEDROCK_INFERENCE_PROFILE_ARN_OPTIMIZER=...
BEDROCK_INFERENCE_PROFILE_ARN_VALIDATOR=...
BEDROCK_INFERENCE_PROFILE_ARN_EDUCATIONAL=...

Put AWS keys in Cirq-RAG-Code-Assistant/.env when using Docker: that file is bind-mounted into the cirq_agent container as /app/.env. The Compose file does not set AWS_ACCESS_KEY_ID / AWS_SECRET_ACCESS_KEY to empty defaults anymoreโ€”empty values used to block python-dotenv from applying the mounted file.

Commands (run from the repo root)

Build images and start the default stack (postgres, redis, cirq_agent, backend):

docker compose up -d --build

Start or restart without rebuilding images:

docker compose up -d

Include SonarQube (metrics profile):

docker compose --profile metrics up -d --build

Rebuild only specific services (e.g. after changing a Dockerfile):

docker compose build cirq_agent backend
docker compose up -d

Force a clean rebuild (slower; use when dependencies change):

docker compose build --no-cache cirq_agent backend
docker compose up -d

View running services:

docker compose ps

Follow logs (all services or one):

docker compose logs -f
docker compose logs -f backend
docker compose logs -f cirq_agent

Stop containers (keeps named volumes such as database data):

docker compose stop

Stop and remove containers (keeps volumes unless you add -v):

docker compose down

Stop and remove containers and volumes (โš ๏ธ deletes Postgres/Redis/SonarQube data):

docker compose down -v

Run a one-off command in the backend container (example: open a shell):

docker compose exec backend bash

After Docker is up

Run database migrations against the Dockerized Postgres (from host, with venv and PYTHONPATH set, or exec into backend):

# Example from host (Windows PowerShell); adjust path and venv
$env:PYTHONPATH = "D:\path\to\QCanvas\backend"
$env:DATABASE_URL = "postgresql://postgres:postgres@127.0.0.1:5433/qcanvas_db"
python -m alembic -c backend/alembic.ini upgrade head

Then start the frontend:

cd frontend
npm install
npm run dev

Open http://localhost:3000

Windows Setup (Recommended for Development)

1. Clone Repository

git clone https://github.com/Umer-Farooq-CS/QCanvas.git
cd QCanvas

2. Create Virtual Environment

python -m venv qcanvas_env
.\qcanvas_env\Scripts\activate

3. Install Dependencies

pip install -r requirements.txt

4. Start Docker Services

Use Docker Compose as described in Docker and Docker Compose (e.g. docker compose up -d --build). For SonarQube, add --profile metrics.

5. Set Up Database Schema

# From repo root; set path to your clone
$env:PYTHONPATH = "D:\path\to\QCanvas\backend"
# If Postgres is the Docker Compose service (mapped to host 5433):
$env:DATABASE_URL = "postgresql://postgres:postgres@127.0.0.1:5433/qcanvas_db"

python -m alembic -c backend/alembic.ini upgrade head

6. Create Admin User (Optional)

python backend/create_user.py

Follow prompts to create an admin account.

7. Create Demo Account (Optional)

python backend/create_demo_account.py

This creates a demo account (demo@qcanvas.dev / demo123) for testing. Demo data is cleared on logout.

8. Verify Database

python backend/verify_database.py

๐Ÿ“š For detailed information about database architecture, security (CIA principles), and troubleshooting, see docs/db_setup.md

9. Start Backend Server

If you already use Docker Compose for the API, skip this step (backend is on http://localhost:8000).

$env:PYTHONPATH="d:\path\to\QCanvas\backend"
python backend/start.py

Backend will run on http://localhost:8000

  • API Docs: http://localhost:8000/docs
  • Health Check: http://localhost:8000/api/health

Cirq AI assistant (optional): The IDE can proxy to Cirq-RAG-Code-Assistant. Run the Cirq service on port 8001 (QCanvas already uses 8000). Set CIRQ_AGENT_URL in the QCanvas backend environment (defaults to http://127.0.0.1:8001). The frontend calls {QCanvas API}/api/cirq-agent/api/v1/.... For local UI-only testing without the QCanvas API proxy, set NEXT_PUBLIC_CIRQ_USE_NEXT_REWRITE=true and optionally CIRQ_REWRITE_TARGET (Next.js rewrites /cirq-api/* to the Cirq server).

10. Start Frontend (New Terminal)

cd frontend
npm install
npm run dev

Frontend will run on http://localhost:3000

Linux Quick Setup (Recommended)

For a fresh Linux machine, you can install all requirements and start QCanvas using the provided scripts:

  1. Clone the repository

    git clone https://github.com/Umer-Farooq-CS/QCanvas.git
    cd QCanvas
    
  2. Run firstโ€‘time setup

    # Installs system packages, creates venv, installs backend + frontend deps
    bash setup.sh
    
  3. Configure environment

    cp environment.env.example environment.env
    # Edit environment.env with your configuration
    
  4. Start/stop QCanvas in the background

    # Start Next.js frontend and FastAPI backend in background
    ./run.sh start
    
    # Stop all QCanvas services (kills node/next/uvicorn and clears PID files)
    ./run.sh stop
    
    • Background logs are written to logs/frontend.log and logs/backend.log.
    • PID files frontend.pid and backend.pid are used to avoid doubleโ€‘starting services.

๐Ÿ“ก API Usage

Conversion API

Endpoint: POST /api/converter/convert

Convert quantum circuit code from a specific framework to OpenQASM 3.0.

{
  "source_code": "from qiskit import QuantumCircuit\nqc = QuantumCircuit(2)\nqc.h(0)\nqc.cx(0, 1)",
  "source_framework": "qiskit",
  "conversion_type": "classic"
}

Response:

{
    "success": true,
    "qasm_code": "OPENQASM 3.0;...",
    "framework": "qiskit",
    "conversion_stats": { ... }
}

Simulation API (QSim)

Endpoint: POST /api/simulator/execute

Execute OpenQASM 3.0 code using the QSim engine with various backends.

{
  "qasm_code": "OPENQASM 3.0; include \"stdgates.inc\"; qubit[2] q; bit[2] c; h q[0]; cx q[0], q[1]; c = measure q;",
  "backend": "cirq",  // Options: "cirq", "qiskit", "pennylane"
  "shots": 1024
}

Response:

{
    "success": true,
    "counts": { "00": 512, "11": 512 },
    "metadata": { ... }
}

๐Ÿ”ง Configuration

Environment Variables

  • DATABASE_URL: PostgreSQL connection string
  • REDIS_URL: Redis connection string for caching
  • SECRET_KEY: Application secret key
  • DEBUG: Enable debug mode (True/False)
  • ALLOWED_HOSTS: Comma-separated list of allowed hosts
  • NEXT_PUBLIC_API_URL / NEXT_PUBLIC_API_BASE: Frontend API endpoint for Next.js
  • CIRQ_AGENT_URL: QCanvas backend proxy target for Cirq AI (Compose sets http://cirq_agent:8000 inside Docker; locally often http://127.0.0.1:8001)

๐Ÿงช Testing

Run Tests

# Run all tests
pytest

# Run specific test categories
pytest tests/unit/
pytest tests/integration/
pytest tests/e2e/

# Run frontend tests
cd frontend
npm test

# Run with coverage
pytest --cov=quantum_converters --cov=quantum_simulator --cov=backend

๐Ÿ“š Documentation

๐Ÿค Contributing

We welcome contributions! Please see our Contributing Guide for details.

๐Ÿ“„ License

This project is licensed under the Open Quantum Workbench Proprietary License. See the LICENSE file for details.

๐Ÿ‘ฅ Teams

QCanvas Team

  • Umer Farooq
  • Hussan Waseem Syed
  • Muhammad Irtaza Khan

QSim Team

  • Aneeq Ahmed Malik
  • Abeer Noor
  • Abdullah Mehmood

Supervisors

  • Dr. Imran Ashraf (Project Supervisor)
  • Dr. Muhammad Nouman Noor (Co-Supervisor)

Built under Open Quantum Workbench: A FAST University Initiative

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

qcanvas_sdk-1.0.3.tar.gz (107.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

qcanvas_sdk-1.0.3-py3-none-any.whl (119.1 kB view details)

Uploaded Python 3

File details

Details for the file qcanvas_sdk-1.0.3.tar.gz.

File metadata

  • Download URL: qcanvas_sdk-1.0.3.tar.gz
  • Upload date:
  • Size: 107.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.5

File hashes

Hashes for qcanvas_sdk-1.0.3.tar.gz
Algorithm Hash digest
SHA256 117f1cbd53acad107abf768879f80f8d63e6550a0bed270fffec0cb5800806a4
MD5 8197f7814e50260aaa705d2dff9177ee
BLAKE2b-256 7410087fcaf53f2b5132c0d02875840c0e627ddb91f4070850f1957fa56f2ed2

See more details on using hashes here.

File details

Details for the file qcanvas_sdk-1.0.3-py3-none-any.whl.

File metadata

  • Download URL: qcanvas_sdk-1.0.3-py3-none-any.whl
  • Upload date:
  • Size: 119.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.5

File hashes

Hashes for qcanvas_sdk-1.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 8e9b771fb303f7148f46f8476e0e42e58e53d830cb2b4eeeff0cba863478f165
MD5 67d5c83d3a8844c4d87f4c590a832ac2
BLAKE2b-256 cedd5b74909a89d1a04eb9ccafda2af7d75cf1391439cdcffeacdeeb02b65d51

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page