Documentation
Introduction
Sansqrit is a hybrid quantum-classical visual programming environment. Drag blocks onto a canvas, connect them with wires, run quantum circuits — or write code directly in the Sanskrit DSL.
What is Sansqrit?
Vision
Quantum computing sits behind a wall of notation, prerequisites, and physics. Sansqrit tears that wall down. A drug discovery researcher should be able to run a molecular docking simulation without knowing what a Toffoli gate is. An ML engineer should be able to quantum-enhance their models by dragging a block.
At the same time, the physicist who does know what a Toffoli gate is should have full access to every primitive — and be able to export to IBM Quantum, IonQ, Google Sycamore, or Amazon Braket in one click.
Who Is It For?
Run VQE on molecules. Build Hamiltonians visually. Get energies, orbital analysis, dissociation curves.
Ising models, many-body systems, Lindblad dynamics, topological phases. All as blocks or code.
QSVM, VQC, quantum kernels, quantum transformers. Hybrid classical-quantum pipelines.
Teach Bell states, superposition, entanglement — visually, interactively, with real results.
Architecture
Three Layers
Sansqrit has three layers, each independently useful:
The Rust Engine
The quantum simulator is written in Rust and compiled to WebAssembly. It implements:
- Sparse amplitude storage (
HashMap<u64,Complex64>) with automatic dense fallback at 12% fill - 10-qubit sharding — a 30-qubit register uses 3 shards of 1024 entries instead of 1 billion
- All standard gates: H, X, Y, Z, S, T, Rx, Ry, Rz, CNOT, CZ, SWAP, iSWAP, RZZ, RXX, RYY, MS, Toffoli, Fredkin
- QFT, IQFT, n-controlled-Z, Grover oracle and diffusion
- All 15 bugs from the original JavaScript engine corrected and verified by 12 physics unit tests
The Sanskrit DSL Interpreter
The interpreter is written in JavaScript (~1,064 lines). It parses and executes .sq files and the code editor. Features:
- Variables (
let), mutables (mut), functions (def), loops (for), conditionals (if/elif/else) - F-strings:
f"Energy: {result.energy:.6f} Ha" - List comprehensions:
[x*2 for x in range(10)] - 200+ standard library functions:
mean(),gcd(),fibonacci(),state_fidelity(),fft() - Full quantum API:
qubits(), all gate functions,grover(),vqe(),qaoa()
Quick Start
Installation
# 1. Install Node.js (v18+) from nodejs.org
# 2. Install Rust from rustup.rs
# Clone the repository
git clone https://github.com/your-org/sansqrit.git
cd sansqrit
# Install Node.js dependencies
npm install
# Build Rust → WASM (takes ~60 seconds first time)
bash build.sh
# Generate pre-computed tables
python3 precompute.py
# Run tests (should show 39/39 + 32/32)
npm test
First Run
# Start the server
npm start
# → ✓ Sanskrit Rust/WASM engine loaded — ~15-30x speedup active
# → 📦 528 blocks loaded across 42 categories
# → Server running at http://localhost:3000
Open http://localhost:3000 in Chrome or Firefox.
Core Concepts
Qubits
A qubit is the quantum analog of a classical bit. Unlike a bit (always 0 or 1), a qubit can be in superposition: simultaneously partially 0 and partially 1 until measured.
let q = qubits(4) -- create 4 qubits, all start as |0⟩
-- q[0], q[1], q[2], q[3] are the individual qubit references
-- state vector has 2^4 = 16 complex amplitudes
Gates
Quantum gates are reversible operations on qubits. They are represented as unitary matrices.
H(q[0]) -- Hadamard: creates superposition |0⟩ → (|0⟩+|1⟩)/√2
X(q[1]) -- Pauli-X: bit flip |0⟩ ↔ |1⟩
CNOT(q[0], q[1]) -- Entangle: flip q[1] if q[0]=|1⟩
Rx(q[2], PI/2) -- Rotate qubit 2 around X-axis by π/2
Measurement
Measuring a qubit collapses its superposition to a definite 0 or 1, with probabilities given by the squared amplitudes.
-- Single shot: collapses the state
let bit = measure(q[0]) -- returns 0 or 1
-- Multi-shot: samples the probability distribution (non-destructive)
let r = measure_all(q, shots=1000)
print(r.histogram) -- {"00": 503, "11": 497}
shots=1, the quantum state collapses. With shots>1, the engine samples from the probability distribution without destroying the state — allowing you to get statistics efficiently.