A simple quantum computer simulator in R.


Install the programming language R if you have not done so yet.

Download the source code, e.g. with

git clone

and go into the newly created directory qsimulatR. Execute:


You might have to install additional packages. Just use install.packages() for any packages recommended in a possible error message.

The install script might not work under Windows. To circumvent this, you can download the source package from github. Then

install.packages("", repos=NULL, type="source")

The library qsimulatR is now available in your R installation and can be loaded with:


Check for updates regularly. Do so by going into the directory qsimulatR and executing

git pull


A detailed usage description can be found in qsimulatR.pdf. We provide many useful examples in the R Markdown format in vignettes.

Your first very simple program with qsimulatR might look like this:


# generate a quantum state with 2 qubits, initialised to |00>
x = qstate(nbits=2)
# display the state

# apply the Hadamard gate to the first (right) qubit
y = H(1) * x

# apply a controlled NOT
z = CNOT(c(1,2)) * y

# draw the resulting circuit

# project onto a single compute basis state
res = measure(z)
# draw the circuit

# perform the measurement many times and plot the outcome
dist = measure(z, rep=1000)

Try the qsimulatR package in your browser

Any scripts or data that you put into this service are public.

qsimulatR documentation built on Sept. 9, 2022, 5:05 p.m.