package qcaml

  1. Overview
  2. Docs
Experimental OCaml library for quantum computing simulation

Install

dune-project
 Dependency

Authors

Maintainers

Sources

v0.1.7.tar.gz
md5=d7eb2f035e630f64250607f08bf1aa51
sha512=7b4e637016793f5ef3370e39f021a50cd9cda24a31a125d1bcbb45bb214140b0b4f4038bea41d3b0361f54f642439cde845f055afe9a67435049d4672df3dbf6

doc/README.html

QCaml logo

A lightweight OCaml library to experiment with quantum states, gates and measurements. For learning quantum computing concepts and visualizing qubit states on the Bloch sphere.

License OCaml GitHub Actions Workflow Status GitHub Release

Presentation

QCaml for Quantum (O)Caml is an experimental library for simulating quantum algorithms. This library is currently under development. Among the MVP's features are qubit declaration, application of classical gates (X,Y,Z,H), measurement, and visualization.Extended gate set (Phase and rotation gates)

Installation

Prerequisites

You need the opam package manager to install the OCaml build tools.

$ sudo apt install opam   # debian/ubuntu
$ opam init
$ opam switch create 5.2.0
$ eval $(opam env)
$ opam install dune odoc alcotest bisect_ppx raylib

Install from OPAM (recommended)

QCaml is now available on the official OPAM repository, so you can install it directly:

$ opam install qcaml

Develop locally

If you want to work on QCaml locally (for development, testing, or contributing), you can still clone and build the repository manually.

The following will clone the repository, build QCaml and install it into your opam.

$ git clone https://github.com/elias-utf8/qcaml.git
$ cd qcaml/
$ make
$ opam install .

Quick start

Try this simple example by running dune exec examples/bloch_sphere.exe to visualize a qubit |0> state on the Bloch sphere:

(* examples/bloch_sphere.ml *)
open Quantum

let () =
  let q = Qubit.zero () in
  Visualization.plot_bloch q ();
  Measurement.measure q;
  Printf.printf "%s\n" (Qubit.print () q);
Bloch Sphere

Architecture

graph TB
    subgraph Core
        A[QCaml]
    end
    
    subgraph Foundation
        B[Complex Module]
        B1[Operations: mul, add, sub, mod, arg, conj]
        B2[Constants: zero, one, minus_one]
        B --> B1
        B --> B2
    end
    
    subgraph States
        C[Qubit Module]
        C1[Init: zero, one, plus, minus]
        C2[Access: get_alpha, get_beta, print]
        C --> C1
        C --> C2
    end
    
    subgraph Operations
        D[Gate Module]
        D1[Pauli: X, Y, Z]
        D2[Hadamard: H]
        D3[Phase: S, T]
        D --> D1
        D --> D2
        D --> D3
    end
    
    subgraph Measure
        E[Measurement]
        E1[Computational basis & collapse]
        E --> E1
    end
    
    subgraph Visual
        F[Bloch Sphere]
        F1[Raylib rendering]
        F --> F1
    end
    
    A --> B
    A --> C
    A --> D
    A --> E
    A --> F    
    C --> B
    D --> C
    E --> C
    F --> C
    
    style A fill:#ec6813,stroke:#333,stroke-width:3px,color:#fff
    style B fill:#3c60b1,stroke:#333,color:#fff
    style C fill:#3c60b1,stroke:#333,color:#fff
    style D fill:#3c60b1,stroke:#333,color:#fff
    style E fill:#3c60b1,stroke:#333,color:#fff
    style F fill:#3c60b1,stroke:#333,color:#fff

Features

Feature Status Description
Qubit Initialization ✓ Completed Single and multi-qubit state initialization with arbitrary amplitudes
Basic Quantum Gates ✓ Completed Implementation of fundamental gates (Hadamard, Pauli-X/Y/Z)
Quantum Measurements ✓ Completed Computational basis measurements with probability calculations
Bloch sphere visualization ✓ Completed Visualization of qubit states on the Bloch sphere
Advanced Gates ✓ Completed Extended gate set (Phase and rotation gates)
Multi-Qubit Operations In progress.. Implementation of n-qubit systems with qubit register
Simulator ○ Planned (I will never have time) Export circuits to standard formats (QASM, diagram generation)

Documentation

API Reference: Generated documentation at _build/default/_doc/_html/index.html (after running dune build @doc) or see online documentation )

Resources

Quantum Computing Course – Math and Theory for Beginners : https://youtu.be/tsbCSkvHhMo?si=XTbz10_b1v1aAS-3