Learn R Programming

qsimulatR

A simple quantum computer simulator in R.

Installation

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

Download the source code, e.g. with

git clone https://github.com/HISKP-LQCD/qsimulatR.git

and go into the newly created directory qsimulatR. Execute:

./install

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("qsimulatR.zip", repos=NULL, type="source")

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

library(qsimulatR)

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

git pull
./install

Usage

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:

library(qsimulatR)

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

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

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

# draw the resulting circuit
plot(z)

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

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

Copy Link

Version

Install

install.packages('qsimulatR')

Monthly Downloads

191

Version

1.1.1

License

GPL-3

Issues

Pull Requests

Stars

Forks

Maintainer

Carsten Urbach

Last Published

October 16th, 2023

Functions in qsimulatR (1.1.1)

*,ccqgate,qstate-method

times-ccqgate-qstate
*,sqgate,qstate-method

times-sqgate-qstate
noise

A noise gate
phase_estimation

phase_estimation
export2qiskit

export2qiskit
*,swapgate,qstate-method

times-swapgate-qstate
normalise

normalise
*,ccnotgate,qstate-method

times-ccnotgate-qstate
genStateNumber

genStateNumber
genComputationalBasis

genComputationalBasis
truth.table

Method truth.table
cnotgate

The CNOT gate
plot,qstate,missing-method

plot-qstate
*,cnotgate,qstate-method

times-cnotgate-qstate
genNoise

genNoise
*,cnqgate,qstate-method

times-cnqgate-qstate
summary.measurement

Summarize a quantum measurement
swapgate

The SWAP gate
ccnotgate

The CCNOT gate
is.bitset

is.bitset
Z

The Z gate
*,complex,qstate-method

times-number-qstate
sqgate

A single qubit gate
measure

Method measure
*,cqgate,qstate-method

times-cqgate-qstate
qstate

The qstate class
*,cswapgate,qstate-method

times-cswapgate-qstate
hist.measurement

Plot the histogram of a quantum measurement
qft

qft
genStateString

genStateString
qsimulatR

The qsimulatR Package
*,matrix,qstate-method

times-matrix-qstate
Id

The identity gate
Ri

The Ri gate
Rz

The Rz gate
CNOT

The CNOT gate
CSWAP

The CSWAP or Fredkin gate
Ry

The Ry gate
S

The S gate
CCNOT

The CCNOT or toffoli gate
Rx

The Rx gate
H

The Hadarmard gate
X

The X gate
cnqgate

n-fold controlled single qubit gate
Y

The Y gate
cqft

cqft
SWAP

The SWAP gate
Tgate

The Tgate gate
ccqgate

A twice controlled single qubit gate
cqgate

A controlled single qubit gate
cswapgate

The CSWAP gate