1. Install DrRacket
  2. Download source
  3. Open Dr.Racket and Run "quantum-simulator.scm"
  4. Testing - run "example-tesing.scm". Many useful constructs can be found here Specific algorithms - run "example-specific.scm" which contains implementations of Grover and Deutsch-Jozsa and quantum-fourier-transform. Instruction for testing are in the file itself.

This tutorial covers basic aspects of how QuiCkS implements basic aspects quantum computation.

Handling Registers

A register is implemented as a complete binary tree whose leaves are complex-valued numbers implemented as coeff and the internal nodes as registers themselves. To understand the mapping between leaves and pure states, consider the path taken to reach leaf. Each time left child is chosen append 0 to state else append 1, till you reach the leaf Initializing Registers

A quantum register (also known as a qregister) is the quantum mechanical analogue of a classical processor register. If it has n-bits it will have 2n states each with its own coefficient. Effectively the system is a linear superposition of these pure states. In general in a quantum algorithm a register always starts with all coefficients 0 except for 1 state.

  • To generate a register with one particular state having coefficient 1, use form-reg.
  • Or else to start with a specific set of coefficients usepump. The input is a list of complex numbers indexed by the binary number representing the pure state Indexing starts from 0. So if the index is 5 and there are 3 qubits then it represents the coefficient of |101>
  • To start with a uniform register use 1-register followed by normalise

Direct Manipulation of Registers

Sometimes a function which is easy to implement directly can be cumbersome to simulate using set of quantum gates. So we've extracted a few important register manipulation functions which allow such changes to be made directly without having to use gates. Note however that reversibility which comes along with quantum gates is compromised.

  • To get the resulting register after applying a function over the coefficient of a particular state try use
  • To change the original register by applying a function over the coefficient of a particular state (set! in scheme parlance) try mutate
  • To apply a function over all states use over-all
  • Sometimes we might have two registers of same size and desire a statewise operation to combine both. For this purpose use state-wise

Probability Spying and Display

These are a set of functions to help you out, if you want to know the value of coefficients without disturbing the states (in the quantum sense)

  • To get the imaginary coefficient, use get-coeff
  • For normalizing a register use normalise
  • To get the probability, use prob
  • To get the total probability (which in general should be 1) , use prob-sum
  • For displaying contents in a quantum syntax use display-reg
  • For creating a list out of the coefficients, indexed by the binary number represented by its pure state try flatten-reg

Also checkout the quantum syntax for registers.

Quantum Operations


  1. Dot product - Essentially a dot-product of vectors of their coefficients, it is generally written in the form of bra-ket notation
  2. Tensor product - Essentially a cross-product of vectors of their coefficients.


Gates are applied over a set of qubits in a register. There is a variety of pre-built gates

  1. Single Qubit gates - Hadamard, Pauli-X, Pauli-Y, Pauli-Z
  2. Single Qubut Phase shift - phase-shift function takes in a single parameter which is the phase shift angle
  3. Two Qubit Gates - CNOT and swap
  4. Three Qubit Gates - Toffoli and fredkin
  5. Control Gates - Gates with control qubits can be built with Control facility that has been implemented

If the register has as many qubits as required by the gate, it can be directly applied. However if the register has more qubits, use the on function to specify which qubits you want the gate to act on.

Matrix Operator Correspondence

Any quantum system is a superposition of some pure states and can hence be expressed as a vector of the corresponding coefficient. Hence we can express all operators as matrices acting on these vectors

  1. Transformation - Gates and matrices are rendered interconvertible by convert-to-matrix and matrix-to-gate
  2. Only a gate can be applied over a quantum register and matrices can act on vector so apply-matrix has been provided which allows a matrix to be applied directly on the register
  3. Many matrix manipulation functions have also been provided



  1. measure! A probabilistic measurement on the quantum state leading to its collapse entirely to its pure state
  2. partial-measure! A probabilitic measurement on particular qubits of a given register and the system collapses to a superposition of states where those particular qubits are get fixed

Normal Usage

Open Dr.Racket and Run "quantum-simulator-gui.scm"

Debug Mode