Liking cljdoc? Tell your friends :D

QClojure

The QClojure library provides a Clojure interface to quantum computing concepts. It allows us to create and manipulate quantum states, gates, and circuits in a functional programming style. QClojure can also be used to simulate quantum circuits and, by implementing backends, run them on quantum hardware.

The API is in alpha state, I expect the api to change!

Clojars Project cljdoc badge GitHub

Main Features of QClojure

  1. Pure Functional Quantum Circuit Construction

    Build quantum circuits using immutable data structures and functional composition with convenience gate functions (H, X, Y, Z, CNOT, etc.)

  2. Comprehensive Gate Library

    Support for 20+ quantum gates including single-qubit gates (Pauli, Hadamard, phase), controlled gates (CNOT, CZ, CY), rotation gates (RX, RY, RZ), and multi-qubit gates (Toffoli, Fredkin, SWAP)

  3. Quantum Algorithm Implementations

    Built-in implementations of classic quantum algorithms including Deutsch, Bernstein-Vazirani, Simon and Grover's search algorithms

  4. Extensible Backend System

    Protocol-based architecture allowing integration with different quantum simulators and hardware backends

  5. Circuit Transformation & Optimization

    Automatic gate decomposition and circuit transformation to match backend-supported gate sets and topologies

  6. Local Quantum Simulator Backend

    High-performance local simulator with job submission, status tracking, and statistical measurement results with configurable shot counts

  7. OpenQASM Integration

    Bidirectional conversion between quantum circuits and OpenQASM 2/3 formats for interoperability with other quantum computing platforms

  8. Visualization

    Vizualization of quantum states and quantum circuits as ASCII, SVG or HTML.

  9. Comprehensive Testing & Validation

    Extensive test suite with statistical validation of quantum circuit behavior and measurement outcomes

Usage

QClojure is a library to be used in programs or interactive within the REPL.

To use QClojure, add a dependency to your project definition.

This small example shows the creation of a quantum circuit in a functional way, the execution of the circuit on the simulator. It also prints the final state and the measurement outcomes and generates SVG images of the circuit and the final state.

(require '[org.soulspace.qclojure.domain.circuit :as qc])
(require '[org.soulspace.qclojure.application.backend :as qb])
(require '[org.soulspace.qclojure.adapter.backend.simulator :as sim])
(require '[org.soulspace.qclojure.adapter.visualization :as vis])
(require '[org.soulspace.qclojure.adapter.visualization.svg :as svg])

;; Create a Bell state circuit
(def circuit (-> (qc/create-circuit 2 "Bell Circuit" "Creates a Bell state")
                 (qc/h-gate 0)
                 (qc/cnot-gate 0 1)))

;; Run the circuit on the simulator
(def simulator (sim/create-simulator))
(def result (qb/execute-circuit simulator circuit {:shots 1000}))

;; Examine the results
(:final-state result)
(:measurement-results result)

;; Create SVG visualizations for the circuit and the final state
(spit "bell-circuit.svg" (vis/visualize-circuit :svg circuit))
(spit "bell-state.svg" (vis/visualize-quantum-state :svg (:final-state result)))

Visualizations of the Bell Circuit and State

Visualization of the Bell circuit Visualization of the probabilities of the Bell state

Examples

Some examples are provided in the examples folder.

Build

QClojure is currently build with Leiningen.

Compile the code with:

lein compile

Run the test suite with:

lein test

Known Issues

  • Grover algorithm doesn't use the provided backend
  • Error handling on backend failure missing, e.g. timeouts on Shor algorithm
  • missing state initialization on backend

Copyright

© 2025 Ludger Solbach

License

Eclipse Public License 1.0 (EPL1.0)

Can you improve this documentation?Edit on GitHub

cljdoc is a website building & hosting documentation for Clojure/Script libraries

× close