Title: | Performs Common Linear Algebra Operations Used in Quantum Computing and Implements Quantum Algorithms |
---|---|
Description: | Contains basic structures and operations used frequently in quantum computing. Intended to be a convenient tool to help learn quantum mechanics and algorithms. Can create arbitrarily sized kets and bras and implements quantum gates, inner products, and tensor products. Creates arbitrarily controlled versions of all gates and can simulate complete or partial measurements of kets. Has functionality to convert functions into equivalent quantum gates and model quantum noise. Includes larger applications, such as Steane error correction <DOI:10.1103/physrevlett.77.793>, Quantum Fourier Transform and Shor's algorithm (Shor 1999), Grover's algorithm (1996), Quantum Approximation Optimization Algorithm (QAOA) (Farhi, Goldstone, and Gutmann 2014) <arXiv:1411.4028>, and a variational quantum classifier (Schuld 2018) <arXiv:1804.00633>. Can be used with the gridsynth algorithm <arXiv:1212.6253> to perform decomposition into the Clifford+T set. |
Authors: | Salonik Resch |
Maintainer: | Salonik Resch <[email protected]> |
License: | GPL-3 |
Version: | 3.0.1 |
Built: | 2025-02-23 04:31:03 UTC |
Source: | https://github.com/cran/QuantumOps |
Takes two integers and adds their bits modulus two. The resulting string of bits represents an integer, that value of which is the output.
addmod2(x,a)
addmod2(x,a)
x |
integer |
a |
integer |
Integer resulting from the bit-wise addition of two number modulus 2
addmod2(5,5) addmod2(1,2)
addmod2(5,5) addmod2(1,2)
Finds the adjoint of the input. An input ket will become a bra and input bra will become a ket
adjoint(x)
adjoint(x)
x |
A ket (column vector), bra (row vecor), or gate (matrix) |
The adjoint of x
adjoint(ket(1,5))
adjoint(ket(1,5))
Implements Amplitude Damping noise model on the input quantum state. Formulas taken from <DOI:10.1103/PhysRevA.90.062320>.
AmplitudeDamping(p,Pad)
AmplitudeDamping(p,Pad)
p |
Input quantum state, in density matrix format |
Pad |
The probability of Amplitude Damping. Commonly referred to as gamma in the literature. |
The quantum state, after Amplitude Damping has been applied.
AmplitudeDamping(p=convert_ket2DM(ket(1,0)),Pad=0.01)
AmplitudeDamping(p=convert_ket2DM(ket(1,0)),Pad=0.01)
If no argument is supplied, returns the matrix of BELL gate. If ket given as input, applies a BELL gate to the input ket and returns the resulting ket
BELL(...)
BELL(...)
... |
No argument, or 4 dimensional (2 qubit) ket (column vector) that is input to the gate |
Matix of the BELL gate or ket after a BELL gate is applied
BELL(ket(1,1,1,1)) BELL()
BELL(ket(1,1,1,1)) BELL()
Returns a normalized bra (row vector)
bra(...)
bra(...)
... |
Variable number of numbers representing the amplitudes of the bra |
Row vector containing normalized amplitudes of a bra
bra(1,0,1,2)
bra(1,0,1,2)
Performs the continued fractions algorithm to find a fraction close to input value
CFA(y,epsilon=1e-2)
CFA(y,epsilon=1e-2)
y |
Value that function attempts to find. Typically comes from measurement of Shor's algorithm |
epsilon |
Acceptable error between value and fraction |
Vector containing numerator and denominator of fraction
CFA(285/14)
CFA(285/14)
Takes in a matrix of clauses and determines what percentage of the clauses each possible value satisfies.
checkCases(clauses,colorCode=FALSE)
checkCases(clauses,colorCode=FALSE)
clauses |
Matrix that specifies the clauses. Each row is a clause. Each row must contain the same number of columns as qubits, the bit length of the clauses. 0 and 1 are values which are added to clause, ignored bits should be set to any other value. |
colorCode |
Boolean which specifies if data should be returned as list of colors rather than numerical data |
Array of numbers or string color names
checkCases( rbind(c(1,-1),c(1,1) ) )
checkCases( rbind(c(1,-1),c(1,1) ) )
Creates a matrix representing a controlled gate on a system of qubits. The target and control qubits can be located at arbitrarying positions.
cntrld(gate,n,...)
cntrld(gate,n,...)
gate |
single qubit gate to create controlled version of |
n |
Number of qubits in the ket, including target, control, and all other qubits |
... |
List of qubits. The last qubit in the list is the target. Any others listed before it are control qubits. Can be any number between 1 and n-1 control qubits, where n is the number of qubits in the ket. Qubits are indexed from 0, starting at the most significant qubit |
A matrix representing the operation of a controlled qubit gate on any subset of the input ket
cntrld(X(),2,0,1) cntrld(X(),2,1,0) cntrld(Y(),4,2,3) cntrld(X(),8,0,5)
cntrld(X(),2,0,1) cntrld(X(),2,1,0) cntrld(Y(),4,2,3) cntrld(X(),8,0,5)
Implements a model of coherent noise as used in <DOI:10.1038/s41534-018-0106-y>. It rotates each qubit around the z-axis by the specified amount. If randomRoation is set, it will rotate around the X, Y, or Z axis, which is chosen at random. Randomizing provides interesting side effects but is less representative of quantum noise.
CoherentNoise(p,theta,randomRotation=FALSE)
CoherentNoise(p,theta,randomRotation=FALSE)
p |
Input quantum state in density matrix format |
theta |
Angle of rotation to apply |
randomRotation |
Boolean specifying whether the rotation should be in a semi-random direction |
The quantum state in density matrix format after noise has been applied
CoherentNoise( p= convert_ket2DM(ket(1,1,1,1)),theta=0.06*pi)
CoherentNoise( p= convert_ket2DM(ket(1,1,1,1)),theta=0.06*pi)
Returns a column vector
colv(...)
colv(...)
... |
Variable number of numbers representing the values in the column vector |
Column vector containing input arguments
colv(1,0,1,2)
colv(1,0,1,2)
Generates a matrix (quantum oracle) which will flip the last qubit in a quantum state if the qubits at indices in vectors a and b are the same
compareQuantumState(nQubits,a,b)
compareQuantumState(nQubits,a,b)
nQubits |
Number of qubits in a target ket. Should contain at least enough for states a and b and an additional last qubit. |
a |
Vector of indices of first state to compare in a target ket |
b |
Vector of indices of second state to compare in a target ket |
Matrix of the compareQuantumState oracle
compareQuantumState(5,0:1,2:3)
compareQuantumState(5,0:1,2:3)
Creates a matrix representing a controlled gate on a system of qubits. The target and control qubits can be located at arbitrary positions.
controlled(gate,n,cQubits,tQubit)
controlled(gate,n,cQubits,tQubit)
gate |
single qubit gate to create controlled version of |
n |
Number of qubits in the ket, including target, control, and all other qubits |
cQubits |
Vector of qubit indices. There can be between 1 and n-1 control qubits, where n is the number of qubits in the ket. Qubits are indexed from 0, starting at the most significant qubit |
tQubit |
Index of the target qubit. Qubits are indexed from 0, starting at the most significant qubit |
A matrix representing the operation of a controlled qubit gate on any subset of the input ket
controlled(X(),n=2,cQubits=0,tQubit=1) controlled(X(),n=4,cQubits=c(0,1,2),tQubit=3)
controlled(X(),n=2,cQubits=0,tQubit=1) controlled(X(),n=4,cQubits=c(0,1,2),tQubit=3)
Takes a vector of unsigned bits with MSB first and produces integer value
convert_bin2dec(b)
convert_bin2dec(b)
b |
Vector of bits with most significant bits first |
Integer value of bits
convert_bin2dec( c(1,0,0) )
convert_bin2dec( c(1,0,0) )
Takes an integer and returns an unsigned vector bits representing the same value
convert_dec2bin(x,len=32)
convert_dec2bin(x,len=32)
x |
Integer |
len |
Number of bits to represent integer with. Will crop most significant bits if insufficient length. |
Vector of bits with MSB first
convert_dec2bin(10) convert_dec2bin(10,8)
convert_dec2bin(10) convert_dec2bin(10,8)
Converts a ket (pure) description of quantum state and creates a density matrix representation of the same state. Density matrices can represent both pure and mixed states.
convert_ket2DM(v)
convert_ket2DM(v)
v |
An input ket |
Density matrix representing same state as input ket
convert_ket2DM( ket(1,0) )
convert_ket2DM( ket(1,0) )
If no argument is supplied, returns the matrix of Controlled-X gate. If ket given as input, applies a Controlled-X gate to the input ket and returns the resulting ket
CX(...)
CX(...)
... |
No argument, or 4 dimensional (2 qubit) ket (column vector) that is input to the gate |
Matix of the Controlled-X gate or ket after a Controlled-X gate is applied
CX(ket(1,1,1,1)) CX()
CX(ket(1,1,1,1)) CX()
If no argument is supplied, returns the matrix of Controlled-Y gate. If ket given as input, applies a Controlled-Y gate to the input ket and returns the resulting ket
CY(...)
CY(...)
... |
No argument, or 4 dimensional (2 qubit) ket (column vector) that is input to the gate |
Matix of the Controlled-Y gate or ket after a Controlled-Y gate is applied
CY(ket(1,1,1,1)) CY()
CY(ket(1,1,1,1)) CY()
If no argument is supplied, returns the matrix of Controlled-Z gate. If ket given as input, applies a Controlled-Z gate to the input ket and returns the resulting ket
CZ(...)
CZ(...)
... |
No argument, or 4 dimensional (2 qubit) ket (column vector) that is input to the gate |
Matix of the Controlled-Z gate or ket after a Controlled-Z gate is applied
CZ(ket(1,1,1,1)) CZ()
CZ(ket(1,1,1,1)) CZ()
Uses the gridsynth algorithm Sellinger 2012 <arXiv:1212.6253>, which is available at https://www.mathstat.dal.ca/~selinger/newsynth/, to decompose arbitrary gates to the Clifford+T set. For decomposition of controlled 2-qubit gates, circuits from Amy 2013 <DOI:10.1109/TCAD.2013.2244643> are also used.
DecomposeGate(path,g,TwoQubit=FALSE,n=1,tQubit=0,cQubit=1,prec=10)
DecomposeGate(path,g,TwoQubit=FALSE,n=1,tQubit=0,cQubit=1,prec=10)
path |
String of path to folder containing gridsynth binary (not including gridsynths file name). R must have permission to read and write from this folder, and to execute the binary. |
g |
If a single number, this is the Z-rotation angle to approximate. If a vector of length 3, it is the alpha, beta, and gamma parameters as defined in Schuld 2018 <arXiv:1804.00633>. |
TwoQubit |
Boolean specifying whether this is a single or controlled 2-qubit gate |
n |
The total number of qubits in the system. If TwoQubit is TRUE, the returned circuit will have n+1 qubits due to the requirement of an ancilla qubit. |
tQubit |
The target qubit. If a single qubit gate, the gate is applied to this qubit. If a 2-qubit gate, this is the target qubit. |
cQubit |
Control qubit if a 2-qubit gate. Value does not matter for single qubit gate. |
prec |
The binary precision of the approximation, which is passed to the gridsynth binary. |
List of cycles which approximates the input gate.
## Not run: DecomposeGate(path="./",g=pi/5,TwoQubit=TRUE,n=3,tQubit=0,cQubit=1,prec=3) ## End(Not run)
## Not run: DecomposeGate(path="./",g=pi/5,TwoQubit=TRUE,n=3,tQubit=0,cQubit=1,prec=3) ## End(Not run)
Prints the dirac notation of the input ket
dirac(ket)
dirac(ket)
ket |
Ket (column vector) to print dirac notation of |
String of dirac notation
dirac(ket(1,0,1,0))
dirac(ket(1,0,1,0))
Reports the distance between two vectors/kets
dist(a,b)
dist(a,b)
a |
column vector |
b |
column vector |
Distance between two vectors
dist(ket(1,1,1,1),ket(1,0,0,1))
dist(ket(1,1,1,1),ket(1,0,0,1))
Takes two integers and takes the dot product of their binary representations. Output is the value of the dot product, modulus 2
dotmod2(x,a)
dotmod2(x,a)
x |
integer |
a |
integer |
Binary value resulting from the bit-wise dot product modulus 2
dotmod2(5,5) dotmod2(1,2) dotmod2(0,1)
dotmod2(5,5) dotmod2(1,2) dotmod2(0,1)
Creates a function that raises a number to a power modulus another number. Is a fix for information loss due to extremely large numbers. It takes the modulus for every multiplication
exponentialMod(a,N)
exponentialMod(a,N)
a |
random number that is used as input to Shor's algorithm |
N |
Number that Shor's algorithm is to factor |
A function that takes argument x and returns a^x modulus N
exponentialMod(8,21) exponentialMod(2,15)
exponentialMod(8,21) exponentialMod(2,15)
Opens the MNIST training data and label files (not provided with package) and extracts the images and labels and returns them in a list
extractMNIST(data,labels,s,centercrop=TRUE)
extractMNIST(data,labels,s,centercrop=TRUE)
data |
String of path to file containing MNIST training images |
labels |
String of path to file containing MNIST training labels |
s |
Number of samples and labels to extract from file |
centercrop |
Boolean indicating whether the images should be centercropped to contain only 256 points |
List containing matrix of image data and array of training labels
## Not run: extractMNIST("train-images.idx3-ubyte","train-labels.idx1-ubyte",2) ## End(Not run)
## Not run: extractMNIST("train-images.idx3-ubyte","train-labels.idx1-ubyte",2) ## End(Not run)
Provides the quantum operatios for a full-adder with the specified input and output indices. Uses the circuit developed by Cheng and Tseng <DOI:10.1049/el:20020949>. Uses CNOT and TOFFOLI gates, with the TOFFOLI gates being broken down into H, T, and CNOT gates. The SUM (qu)bit gets places where the b operand (qu)bit is.
FullAdder(n=4,cin=0,a=1,b=2,cout=3)
FullAdder(n=4,cin=0,a=1,b=2,cout=3)
n |
Number of qubits in input quantum state |
cin |
index of the carry in (qu)bit |
a |
Index of the first operand (qu)bit |
b |
Index of the second operand (qu)bit |
cout |
Index where the output carry (qu)bit will be placed |
A list with elements containing the quantum operations (matrices) for the full adder in each cycle.
FullAdder(n=4,cin=0,a=1,b=2,cout=3)
FullAdder(n=4,cin=0,a=1,b=2,cout=3)
Creates quantum gate defined by 4 angles as demonstrated by Barenco (1995). If no argument is supplied, returns the matrix of G gate. If ket given as input, applies an G gate to the input ket and returns the resulting ket
G(a,b,g,p=0,...)
G(a,b,g,p=0,...)
a |
First angle |
b |
second angle |
g |
third angle |
p |
global phase |
... |
No argument, or ket (column vector) that is input to the gate |
Matrix of the G gate or ket after an G gate is applied
G(0,0,0,0,ket(1,0)) G(1,1,1)
G(0,0,0,0,ket(1,0)) G(1,1,1)
Finds the gcd
gcd(x,y)
gcd(x,y)
x |
First argument |
y |
Second argument |
The greated common divisor of x and y
gcd(7,3) gcd(10,4)
gcd(7,3) gcd(10,4)
If integer is input, returns the matrix of Grover Diffusion operation on the integer number of qubits. If ket given as input, applies a Grover Diffusion operation to the input ket and returns the resulting ket
GroverDiffusion(input)
GroverDiffusion(input)
input |
Either integer specifying size of operation (in number of qubits it is applied to) or input ket to apply Grover Diffusion to |
Either the matrix of the Grover Diffusion gate of the specified size or ket after a Grover Diffusion operation is applied
GroverDiffusion(ket(1,1,1,1,1,1,1,1)) GroverDiffusion(3)
GroverDiffusion(ket(1,1,1,1,1,1,1,1)) GroverDiffusion(3)
If integer is input, returns the matrix of GroverOracle operation on the integer number of qubits. If ket given as input, applies a GroverOracle operation to the input ket and returns the resulting ket
GroverOracle(w,input)
GroverOracle(w,input)
w |
Integer specifying the state to search for, between 0 and 2^n-1 where n is the number of qubits |
input |
Either integer specifying size of operation (in number of qubits it is applied to) or input ket to apply GroverOracle to |
Either the matrix of the GroverOracle gate of the specified size or ket after a GroverOracle operation is applied
GroverOracle(0,ket(1,1,1,1,1,1,1,1)) GroverOracle(0,3)
GroverOracle(0,ket(1,1,1,1,1,1,1,1)) GroverOracle(0,3)
Applies Grover's search algorithm to a uniform ket to simulate a quantum search
GroversAlgorithm(n,w,iterations=n,printOutput=FALSE,plotOutput=FALSE,tag="")
GroversAlgorithm(n,w,iterations=n,printOutput=FALSE,plotOutput=FALSE,tag="")
n |
Number of qubits in the problem, not counting the extra ancillary qubit |
w |
Integer specifying the state to search for, between 0 and 2^n-1 where n is the number of qubits |
iterations |
Number of iterations to apply the oracle and diffusion, optimal is approximately n |
printOutput |
Boolean specifying if the measurement probabilities should be printed as search progresses |
plotOutput |
Boolean specifying if the output probabilities should be plotted to a graph |
tag |
String which is attached to output file name if plotOutput is TRUE |
Ket after a Grover search has been applied to it
GroversAlgorithm(7,0,14) GroversAlgorithm(7,0,14,printOutput=TRUE)
GroversAlgorithm(7,0,14) GroversAlgorithm(7,0,14,printOutput=TRUE)
If no argument is supplied, returns the matrix of H gate. If ket given as input, applies an H gate to the input ket and returns the resulting ket
H(...)
H(...)
... |
No argument, or ket (column vector) that is input to the gate |
Matix of the H gate or ket after a Hgate is applied
H(ket(1,0)) H()
H(ket(1,0)) H()
Determines whether an operation (matrix) is hermitian by comparing it to its adjoint
hermitian(m)
hermitian(m)
m |
gate operation (gate) that is to be checked |
boolean indicating whether matrix is hermitian or not
hermitian(matrix(c(0,1,1,0),nrow=2))
hermitian(matrix(c(0,1,1,0),nrow=2))
If no argument is supplied, returns the matrix of I gate. If ket given as input, applies an I gate to the input ket and returns the resulting ket
I(...)
I(...)
... |
No argument, or ket (column vector) that is input to the gate |
Matix of the I gate or ket after an I gate is applied
I(ket(1,0)) I()
I(ket(1,0)) I()
Finds the inner product of two kets, <w|v>. w and v can be the same
inner(w,v)
inner(w,v)
w |
ket (column vector) that is the left side of the innter product, converted to a bra before the dot product |
v |
ket (column vector) that is the right side of the inner product |
Value of the inner product
inner(ket(1,0),ket(1,1))
inner(ket(1,0),ket(1,1))
Returns a ket (column vector) that has the encoded value of the specified integers. Implements what is commonly known as basis encoding. Does not simulate the state creation.
intket(x,n,amplitudes=rep(1,length(x)))
intket(x,n,amplitudes=rep(1,length(x)))
x |
Integer, or vector of integers, specifying the integer encoded state(s) of the ket |
n |
Integer specifying the number of qubits in the ket |
amplitudes |
Integer, or vector of integers, specifying the amplitudes for corresponding basis in x. Must be same length as x. Only relative values matter as the ket will be normalized. Default is for all states to have same amplitude. |
Column vector containing normalized amplitudes of a ket
intket(0,1) intket(3,2) intket(4,3) intket( c(0,1), 4) intket( c(0,2), 4 , c(1,2) )
intket(0,1) intket(3,2) intket(4,3) intket( c(0,1), 4) intket( c(0,2), 4 , c(1,2) )
Returns a normalized ket (column vector)
ket(...)
ket(...)
... |
Variable number of numbers representing the amplitudes of the ket |
Column vector containing normalized amplitudes of a ket
ket(1,0,1,2)
ket(1,0,1,2)
Takes as input a gate and generates the matrix for that gate being applied to multiple qubits by creating a tensor product of the matrix. If a ket is supplied, the matrix will be applied to the ket
many(gate,n,...)
many(gate,n,...)
gate |
Single qubit gate to apply |
n |
Number of qubits that the gate will be applied to |
... |
Either no argument or a ket that the gates will be applied to |
The matrix representing the application of many gates or a ket after the gates have been applied
many(H(),4) many(X(),2,ket(1,0,0,0))
many(H(),4) many(X(),2,ket(1,0,0,0))
Probabilistically measures the input ket. By default measures all qubits, but if a list of integers is supplied it will measure only those qubits. Returns a list containing the state of the ket after measurement along with integer value of the state that was measured. Additionally, returns a vector of the measured binary values, if a list of qubits to measure was specified.
measure(...,l2r=FALSE)
measure(...,l2r=FALSE)
... |
The input ket to measure. Optionally followed by integers specifying which qubits of the ket to measure. Qubits indexed from 0 from right to left |
l2r |
Boolean which specifices if indexing should be performed from left to right. Is FALSE by default to maintain backwards compatibility, however all other functions index from left to right. |
A list with the first item a column vector containing normalized amplitudes of the measured ket and the second item the integer value of the state which was measured. If a list of qubits to measure was specified as an argument, there is a 3rd item in the list which is a vector of the binary measured values.
measure(ket(1,0),l2r=TRUE) measure(ket(1,2,2,1),0,l2r=TRUE) measure(ket(1,2,3,4,5,6,7,8),0,l2r=TRUE) measure(ket(1,2,3,4,5,6,7,8),0,1,l2r=TRUE) measure(ket(1,2,3,4,5,6,7,8),0,1,2,l2r=TRUE)
measure(ket(1,0),l2r=TRUE) measure(ket(1,2,2,1),0,l2r=TRUE) measure(ket(1,2,3,4,5,6,7,8),0,l2r=TRUE) measure(ket(1,2,3,4,5,6,7,8),0,1,l2r=TRUE) measure(ket(1,2,3,4,5,6,7,8),0,1,2,l2r=TRUE)
Returns a matrix containing the specified elements. Values are input column-wise. Used for convenient shorthand creation of matrices
mm(...)
mm(...)
... |
Variable number of numbers representing the values in the matrix |
Matrix containing the values of the inputs
mm(1,0,1,2)
mm(1,0,1,2)
Strings together output from FullAdder function to create multi-(qu)bit addition. It assumes the input operands are laid out as in <DOI:10.1049/el:20020949>. From left to right (top to bottom) the order is C0, a1, b1, C1, a2, b2, C2, .... bn-1, Cn. There must be 3n+1 qubits in order to perform n-(qu)bit addition.
nBitAddition(n)
nBitAddition(n)
n |
Length of input (qu)bit strings. |
A list containing the quantum circuit (each elemented is one cycle of the circuit) performing n-bit addition.
## Not run: nBitAddition(2) ## End(Not run)
## Not run: nBitAddition(2) ## End(Not run)
Finds the norm of input column vector by taking the inner product with itself
norm(v)
norm(v)
v |
kcolumn vector |
Norm of the input column vector
norm(ket(1,0))
norm(ket(1,0))
Applies a quantum operation to a density matrix
opDM(V,G)
opDM(V,G)
V |
Input density matrix |
G |
Quantum operation to apply to density matrix |
A density matrix which has been modofied by the input quantum operation
opDM( V=convert_ket2DM(ket(1,0)) , G=X() )
opDM( V=convert_ket2DM(ket(1,0)) , G=X() )
Applies stochastic Pauli noise to an input quantum state. If only e is set, it is equally distributed to X, Y, and Z error which is an isotropic Pauli noise model. Otherwise, levels can be set seperately for each.
PauliNoise(p,e=ex+ey+ez,ex=e/3,ey=e/3,ez=e/3)
PauliNoise(p,e=ex+ey+ez,ex=e/3,ey=e/3,ez=e/3)
p |
Input quantum state, in density matrix format |
e |
Total amount of noise to apply the state, is the sum of ex, ey, and ez |
ex |
Amount of X noise to apply to the state |
ey |
Amount of Y noise to apply to the state |
ez |
Amount of Z noise to apply to the state |
The quantum state in density matrix format, after Pauli noise has been applied to it
PauliNoise( p=convert_ket2DM(ket(1,0)) , e=0.01 )
PauliNoise( p=convert_ket2DM(ket(1,0)) , e=0.01 )
Generates random Pauli operators (tensor products of random I,X,Y,or Z gates applied to each qubit) that can be applied to register of n qubits. Used with Randomized Compiling, where random Pauli gates are applied to each qubit.
PauliOperators(n,m=4^n,unique=TRUE)
PauliOperators(n,m=4^n,unique=TRUE)
n |
Size of the Pauli operators to generate, should be equal to the number of target qubits |
m |
Number of different Pauli operators to generate |
unique |
Boolean indicating if each Pauli operator generated should be unqiue. Must be false is m > 4^n |
A list of m Pauli operators of size n
PauliOperators( n=2,m=2,unique=FALSE)
PauliOperators( n=2,m=2,unique=FALSE)
Implements Phase Damping noise model on the input quantum state. Formulas taken from <DOI:10.1103/PhysRevA.90.062320>.
PhaseDamping(p,Ppd)
PhaseDamping(p,Ppd)
p |
Input quantum state, in density matrix format |
Ppd |
The probability of phase Damping. |
The quantum state, after Phase Damping has been applied.
PhaseDamping(p=convert_ket2DM(ket(1,0)),Ppd=0.01)
PhaseDamping(p=convert_ket2DM(ket(1,0)),Ppd=0.01)
Plots the probabilities of each of the amplitudes of ket in a barplot
plotprobs(v,color=rep("Blue",length(v)),customLegend=FALSE,lgNm="",lgCl="")
plotprobs(v,color=rep("Blue",length(v)),customLegend=FALSE,lgNm="",lgCl="")
v |
ket that is to be plotted |
color |
Text, possibly an array, specifying the colors of the bars |
customLegend |
Boolean specifying if a custom legend should be inserted |
lgNm |
Vector of legend names |
lgCl |
Vector of legend colors |
A plot
plotprobs(ket(1,0,1,0),color=c("Red","Blue","Red","Blue"))
plotprobs(ket(1,0,1,0),color=c("Red","Blue","Red","Blue"))
Prints a pasted string containing all arguments. Short hand for print(paste(...))
pp(...)
pp(...)
... |
Variable number of inputs to be printed |
Prints string
pp("Value is",1,0,1,2)
pp("Value is",1,0,1,2)
Returns a column vector containing the probabilities of measuring the system in each state
probs(ket)
probs(ket)
ket |
ket (column vector) that is input to the gate |
Column vector containing probabilities
probs(ket(1,1))
probs(ket(1,1))
Implements a clause-based version of Quantum Approximation Optimization Algorithm (Farhi, Goldstone, and Gutmann 2014) <arXiv:1411.4028>. Takes as input a set of clauses and performs Controlled-Phase and Rx gates to perform optimization. See "An Introduction to Quantum Optimization Approximation Algorithm" (Wang and Abdullah 2018) for explanation.
QAOA(clauses,p=1,gamma=pi/p,beta=pi/(2*p),displayProgress=FALSE,byCycle=FALSE)
QAOA(clauses,p=1,gamma=pi/p,beta=pi/(2*p),displayProgress=FALSE,byCycle=FALSE)
clauses |
Matrix that specifies the clauses. Each row is a clause. Each row must contain the same number of columns as qubits, the bit length of the clauses. 0 and 1 are values which are added to clause, ignored bits should be set to any other value. |
p |
Number of iterations that algorithm will run. Each iteration applies U(C,g) and U(B,b) |
gamma |
Angle for U(C,g), currently the same for all iterations. Should be between 0 and 2*pi |
beta |
Angle for U(B,b), currently the same for all iterations. Should be between 0 and pi |
displayProgress |
Boolean which specifies if progress should be shown. If TRUE, a bar plot is continually updated showing the amplitudes |
byCycle |
Boolean which specifies if function should return the circuit. If TRUE, rather than performing the algorithm it will generate and return the equivalent circuit. |
Ket after algorithm is applied
QAOA(rbind(c(0,0),c(0,1)))
QAOA(rbind(c(0,0),c(0,1)))
Runs an example of QAOA
QAOA_example(case=1)
QAOA_example(case=1)
case |
Integer specifying case to demonstrate. Currently only two, 1 (small) and 2 (medium) |
No value
## Not run: QAOA_example(1) QAOA_example(2) ## End(Not run)
## Not run: QAOA_example(1) QAOA_example(2) ## End(Not run)
Takes a connection matrix as input and converts it to a set of clauses, then runs the Quantum Approximation Optimization Algorithm (Farhi, Goldstone, and Gutmann 2014) <arXiv:1411.4028>.
QAOA_maxcut(connectionMatrix,p=1,gamma=pi/p,beta=pi/(2*p),displayProgress=FALSE)
QAOA_maxcut(connectionMatrix,p=1,gamma=pi/p,beta=pi/(2*p),displayProgress=FALSE)
connectionMatrix |
Matrix that specifies the edges between nodes. Rows are source nodes and columns are destination nodes. Value of 0 means no edge, value of 1 means edge. If edge is undirected, an edge should be specified going both directions. |
p |
Number of iterations that algorithm will run. Each iteration applies U(C,g) and U(B,b) |
gamma |
Angle for U(C,g), currently the same for all iterations. Should be between 0 and 2*pi |
beta |
Angle for U(B,b), currently the same for all iterations. Should be between 0 and pi |
displayProgress |
Boolean which specifies if progress should be shown. If TRUE, a bar plot is continually updated showing the amplitudes |
Ket after algorithm is applied
QAOA_maxcut(randomConnectionMatrix(4,2),p=5)
QAOA_maxcut(randomConnectionMatrix(4,2),p=5)
If integer is input, returns the matrix of QFT operation on the integer number of qubits. If ket given as input, applies a QFT operation to the input ket and returns the resulting ket. If byCycle is TRUE, it generated the circuit for the QFT and returns a list of the cycles.
QFT(input,byCycle=FALSE,swaps=TRUE,CliffordT=FALSE,prec=10,path="./")
QFT(input,byCycle=FALSE,swaps=TRUE,CliffordT=FALSE,prec=10,path="./")
input |
Either integer specifying size of operation (in number of qubits it is applied to) or input ket to apply QFT to |
byCycle |
Boolean which specifies whether the circuit should be generated or not. If TRUE, rather than returning the matrix or performing the algorithm, the function will generate and return the equivalent circuit. |
swaps |
Boolean which specifies if the the SWAP gates required at the end of the QFT should be inserted. May not be necessary if qubit reordering is acceptable. Only valid if byCycle is TRUE. |
CliffordT |
Boolean which specifies if the generated circuit should be decomposed into the Clifford+T set. Only valid if byCycle is TRUE. |
prec |
The precision of the decomposition into the Clifford+T set. Only valid if byCycle and CliffordT are both TRUE. |
path |
Path from current working directory to the gridsynth binary. Only used if CliffordT is set to TRUE. The gridsynth binary is not contained in QuantumOps but available from https://www.mathstat.dal.ca/~selinger/newsynth/ |
If the input is an integer, the matrix of the QFT gate of the specified size. If the input is a ket, the ket after a QFT operation is applied. If byCycle is TRUE, a list of the cycles of the algorithm.
QFT(ket(1,0)) QFT(ket(1,0,0,1)) QFT(3)
QFT(ket(1,0)) QFT(ket(1,0,0,1)) QFT(3)
Quantum classifier which was proposed by Maria Schuld (2018). Consists of code blocks which have parallel single qubit quantum gates followed by controlled qubit gates. Takes as input samples and a corresponding list of labels indicating the correct output value of each sample. Will update the parameters of the gates in order to correctly identify the samples.
QuantumClassifier( n=8,B=2,r=c(1,3), data=NULL,labels=NULL,digit=0, eta=1,decay=1,bsc=1,t=20,tag="",pl=TRUE,train=TRUE, validT=FALSE,vdata=NULL,vlabels=NULL, pretrained=FALSE,alpha=NULL,beta=NULL,gamma=NULL,bias=NULL, writeParameters=FALSE,outputPath=NULL )
QuantumClassifier( n=8,B=2,r=c(1,3), data=NULL,labels=NULL,digit=0, eta=1,decay=1,bsc=1,t=20,tag="",pl=TRUE,train=TRUE, validT=FALSE,vdata=NULL,vlabels=NULL, pretrained=FALSE,alpha=NULL,beta=NULL,gamma=NULL,bias=NULL, writeParameters=FALSE,outputPath=NULL )
n |
Number of qubits that this the classifier will use. |
B |
Number of blocks in the circuit. A block consists of n single qubit gates applied to each of the qubits in parallel and then n/(gcd,r) controlled qubit gates to perform a maximal entanglement. r is the specified range of the controlled gates |
r |
Vector containing the range for each block. length(r) should be equal to B. r of 1 means controlled gates are performed on adjacent qubits |
data |
matrix containing input training data. Rows are individual samples. The number of columns should be equal to 2^n |
labels |
Vector containing labels of digits. Length must be the same as the number of rows in data |
digit |
Individual output to identify. The network will attempt to differentiate between inputs that are labelled as digit (in the labels vector) and inputs that are labelled as any other number |
eta |
learning rate for parameter updates |
decay |
Multiplier for learning rate after each training iteration. If set to less than 1, the learning rate decays in time |
bsc |
Scaler for the learning rate of the bias. Setting to a low value will result in other parameters updating faster than the bias |
t |
Number of training iterations to perform. Total runs is equal to this value multiplied by the number of samples provided |
tag |
String to attach to name of output files |
pl |
Boolean indicating whether training output should be plotted |
train |
Boolean specifying if network should trained on training data, only false if passing in pretrained model |
validT |
Boolean specifying if the network should be tested on validation data while being trained |
vdata |
Validation data, necessary if validT is set to true in which case network is tested on this data while being trained. Can be set to same as data. |
vlabels |
Validation labels, necessary if validT is set to true in which case network is tested on vdata while being trained. Can be set to same as labels. |
pretrained |
Boolean specifying if a pretrained model is being passed in. If so, alpha, beta, and gamme will be set to intputs, rather than randomized. |
alpha |
alpha values for gates if pretrained is set to TRUE, should be a vector of length equal to the number of gates in the circuit. |
beta |
beta values for gates if pretrained is set to TRUE, should be a vector of length equal to the number of gates in the circuit. |
gamma |
gamma values for gates if pretrained is set to TRUE, should be a vector of length equal to the number of gates in the circuit. |
bias |
Bias applied to the output of the circuit. |
writeParameters |
Boolean specifying whether function should write the parameters as it trains. Useful when training takes a long time. |
outputPath |
String which specifies path to write output parameters to if writeParameters is TRUE. Must have write priveleges in this directory. The function will create two directories inside outputPath, named 0 and 1, and will alternate output to each folder. This prevents corruption of output if interrupted. |
List containing a list of the 33 gates and the matrix representing the entire circuit of the trained classifier
## Not run: QuantumClassifier(n=8,B=2,r=c(1,3), matrix(sample(256,replace=TRUE),nrow=1), array(1),0,1,1,.001,1,"test") ## End(Not run)
## Not run: QuantumClassifier(n=8,B=2,r=c(1,3), matrix(sample(256,replace=TRUE),nrow=1), array(1),0,1,1,.001,1,"test") ## End(Not run)
Quantum classifier which was proposed by Maria Schuld (2018). Consists of 33 quantum gates with a depth of 19. Takes as input samples with dimensions of 256 and a corresponding list of labels indicating the correct output value of each sample. Will update the parameters of the gates in order to correctly identify one of the digits specified.
QuantumMNIST256Classifier( data=NULL,labels=NULL,digit=0, eta=1,decay=1,bsc=1,t=20,tag="",pl=TRUE,train=TRUE, validT=FALSE,vdata=NULL,vlabels=NULL, pretrained=FALSE,alpha=NULL,beta=NULL,gamma=NULL)
QuantumMNIST256Classifier( data=NULL,labels=NULL,digit=0, eta=1,decay=1,bsc=1,t=20,tag="",pl=TRUE,train=TRUE, validT=FALSE,vdata=NULL,vlabels=NULL, pretrained=FALSE,alpha=NULL,beta=NULL,gamma=NULL)
data |
matrix containing input training data. Rows are individual samples. There must be 256 columns |
labels |
Vector containing labels of digits. Length must be the same as the number of rows in data |
digit |
Individual digit (0-9) to identify |
eta |
learning rate for parameter updates |
decay |
Multiplier for learning rate after each training iteration. If set to less than 1, the learning rate decays in time |
bsc |
Scaler for the learning rate of the bias. Setting to a low value will result in other parameters updating faster than the bias |
t |
Number of training iterations to perform. Total runs is equal to this value multiplied by the number of samples provided |
tag |
String to attach to name of output files |
pl |
Boolean indicating whether training output should be plotted |
train |
Boolean specifying if network should trained on training data, only false if passing in pretrained model |
validT |
Boolean specifying if the network should be tested on validation data while being trained |
vdata |
Validation data, necessary if validT is set to true in which case network is tested on this data while being trained. Can be set to same as data. |
vlabels |
Validation labels, necessary if validT is set to true in which case network is tested on vdata while being trained. Can be set to same as labels. |
pretrained |
Boolean specifying if a pretrained model is being passed in. If so, alpha, beta, and gamme will be set to intputs, rather than randomized. |
alpha |
alpha values for gates if pretrained is set to TRUE, should be a vector of length 33 |
beta |
beta values for gates if pretrained is set to TRUE, should be a vector of length 33 |
gamma |
gamma values for gates if pretrained is set to TRUE, should be a vector of length 33 |
List containing a list of the 33 gates and the matrix representing the entire circuit of the trained classifier
## Not run: QuantumMNIST256Classifier(matrix(sample(256,replace=TRUE),nrow=1),array(1),0,1,1,.001,1,"test") ## End(Not run)
## Not run: QuantumMNIST256Classifier(matrix(sample(256,replace=TRUE),nrow=1),array(1),0,1,1,.001,1,"test") ## End(Not run)
If no second argument is supplied, returns the matrix of an R phase gate of the specified radians. If ket given as second argument, applies the R gate to the input ket and returns the resulting ket. Is equivalent to the more recently added Rz function.
R(theta,...)
R(theta,...)
theta |
Radians to phase rotate the ket |
... |
No argument, or ket (column vector) that is input to the gate |
Matix of the R gate or ket after an R gate is applied
R(pi,ket(1,0)) R(pi)
R(pi,ket(1,0)) R(pi)
Generates a connection matrix for a random undirected graph. Intended for input to QAOA_maxcut.
randomConnectionMatrix(nNodes,nEdges)
randomConnectionMatrix(nNodes,nEdges)
nNodes |
Number of nodes in generated graph |
nEdges |
Number of undirected edges in generated graph |
Connection Matrix specifying the edges of an undirected graph. Rows are source nodes, columns are destination nodes.
randomConnectionMatrix(5,3)
randomConnectionMatrix(5,3)
Implements Randomized Compiling as described by Wallman and Emerson <DOI:10.1103/PhysRevA.94.052325>. Takes as input a list of easy cycles and a list of hard cycles. In this context, a cycle is the application of one operation to a register of qubits. Inserts randomizing Pauli gates after easy cycles, and corrective operations before the next easy cycle. The randomizations are then combined with the easy cycles. The first and last cycles are easy, with all other cycles alternating betweene asy and hard. Hence, the number of easy cycles should be one more than the number of hard cycles. Easy cycles (C) can be left unset, in which case Idle cycles will be inserted to enabled the randomizations.
RandomizeCompile( C=rep( list( repeatTensor(I(),log( dim(G[[1]])[1],base=2))), length(G)+1) ,G,combine=TRUE)
RandomizeCompile( C=rep( list( repeatTensor(I(),log( dim(G[[1]])[1],base=2))), length(G)+1) ,G,combine=TRUE)
C |
List of easy cycles |
G |
List of hard cycles |
combine |
Boolean specifying if the output should be combined into one list or left seperate |
If combine is TRUE, a list of cycles that are now Randomly Compiled. If combine is FALSE, a list of two lists, the first being the Randomly Compiled easy cycles and the second the hard cycles.
RandomizeCompile( G=list( CX(), CX())) RandomizeCompile( G=list( controlled(gate=Z(),n=3,cQubits=0,tQubit=1) , single(gate=H(),n=3,t=1) ))
RandomizeCompile( G=list( CX(), CX())) RandomizeCompile( G=list( controlled(gate=Z(),n=3,cQubits=0,tQubit=1) , single(gate=H(),n=3,t=1) ))
Generates a random ket by selecting random polar coordinates (theta,phi) for each. Approach taken from <DOI:10.1103/PhysRevA.95.062338>.
ranket(n)
ranket(n)
n |
Number of qubits in generated get |
A ket with a randomized state
ranket(4)
ranket(4)
Probabilistically measures the input ket and reduces the size of ket by removing the measured qubits. By default measures all qubits, but if a list of integers is supplied it will measure only those qubits. Returns a list containing the state of the ket after measurement along with integer value of the state that was measured. Additionally, returns a vector of the measured binary value if a list of qubits to measure was specified.
reduceMeasure(...,l2r=FALSE)
reduceMeasure(...,l2r=FALSE)
... |
The input ket to measure. Optionally followed by integers specifying which qubits of the ket to measure. Qubits indexed from 0 from right to left |
l2r |
Boolean which specifices if indexing should be performed from left to right. Is FALSE by default to maintain backwards compatibility, however all other functions index from left to right. |
A list with the first item a column vector containing normalized amplitudes of the measured ket and the second item the integer value of the state which was measured. If a list of qubits to measure was specified as an argument, there is a 3rd item in the list which is a vector of the binary measured
reduceMeasure(ket(1,0),l2r=TRUE) reduceMeasure(ket(1,2,2,1),0,l2r=TRUE) reduceMeasure(ket(1,2,3,4,5,6,7,8),0,l2r=TRUE) reduceMeasure(ket(1,2,3,4,5,6,7,8),0,1,l2r=TRUE) reduceMeasure(ket(1,2,3,4,5,6,7,8),0,1,2,l2r=TRUE)
reduceMeasure(ket(1,0),l2r=TRUE) reduceMeasure(ket(1,2,2,1),0,l2r=TRUE) reduceMeasure(ket(1,2,3,4,5,6,7,8),0,l2r=TRUE) reduceMeasure(ket(1,2,3,4,5,6,7,8),0,1,l2r=TRUE) reduceMeasure(ket(1,2,3,4,5,6,7,8),0,1,2,l2r=TRUE)
Repeatedly tensors the input with itself
repeatTensor(g,n)
repeatTensor(g,n)
g |
Object, typically a gate, that is to be tensored with itself |
n |
Number of times to tensor g with itself |
The input g tensored by itself n times
repeatTensor(X(),2) repeatTensor(X(),2)
repeatTensor(X(),2) repeatTensor(X(),2)
If no second argument is supplied, returns the matrix of an Rx rotation gate of the specified radians. If ket given as second argument, applies the Rx gate to the input ket and returns the resulting ket.
Rx(theta,...)
Rx(theta,...)
theta |
Radians to phase rotate the ket around the x-axis |
... |
No argument, or ket (column vector) that is input to the gate |
Matix of the Rx gate or ket after an Rz gate is applied
Rx(pi,ket(1,0)) Rx(pi)
Rx(pi,ket(1,0)) Rx(pi)
If no second argument is supplied, returns the matrix of an Ry rotation gate of the specified radians. If ket given as second argument, applies the Ry gate to the input ket and returns the resulting ket.
Ry(theta,...)
Ry(theta,...)
theta |
Radians to phase rotate the ket around the y-axis |
... |
No argument, or ket (column vector) that is input to the gate |
Matix of the Rz gate or ket after an Rz gate is applied
Ry(pi,ket(1,0)) Ry(pi)
Ry(pi,ket(1,0)) Ry(pi)
If no second argument is supplied, returns the matrix of an Rz rotation gate of the specified radians. If ket given as second argument, applies the Rz gate to the input ket and returns the resulting ket.
Rz(theta,...)
Rz(theta,...)
theta |
Radians to phase rotate the ket around the z-axis |
... |
No argument, or ket (column vector) that is input to the gate |
Matix of the Rz gate or ket after an Rz gate is applied
Rz(pi,ket(1,0)) Rz(pi)
Rz(pi,ket(1,0)) Rz(pi)
If no argument is supplied, returns the matrix of S gate. If ket given as input, applies an S gate to the input ket and returns the resulting ket
S(...)
S(...)
... |
No argument, or ket (column vector) that is input to the gate |
Matix of the S gate or ket after an S gate is applied
S(ket(1,1)) S()
S(ket(1,1)) S()
Implements Shor's algorithm by applying the quantum oracle, performing a QFT, measuring the output, and using continued fractions algorithm to find period. Period is then used with Euclidean algorithm to check if factors are legitimate prime factors. Is probabilistic and may fail. Factors 15 with ease and 21 occassionally.
Shor(N,trials=150,random=FALSE)
Shor(N,trials=150,random=FALSE)
N |
Number that Shor's algorithm is to factor |
trials |
Number of times to attempt before giving up |
random |
Boolean which determines whether seed is random or not |
Vector containing prime factors
Shor(15,trials=2)
Shor(15,trials=2)
Takes as input a gate and generates the matrix for that gate being applied to a single qubit in a ket by creating a tensor product of the matrix with Identity matrices. If a ket is supplied, the matrix will be applied to the ket
single(gate,n,t,...)
single(gate,n,t,...)
gate |
Single qubit gate to apply |
n |
Number of qubits that are in the target ket |
t |
Target qubit that the gate will be applied to, other qubits are unmodified. Indexed from 0. |
... |
Either no argument or a ket that the gate will be applied to |
The matrix representing the application of a single gate to one of the qubits in a ket or a ket after the gate has been applied
single(H(),4,1) single(H(),2,1,ket(1,0,0,0)) single(X(),2,0,ket(1,0,0,0))
single(H(),4,1) single(H(),2,1,ket(1,0,0,0)) single(X(),2,0,ket(1,0,0,0))
Implements the SWAP gate between two qubits, which can be in a larger ket. If no argument is supplied, returns the matrix of the gate. If ket given as input, applies the gate to the input ket and returns the resulting ket. In its default configuration it is the same as standard SWAP.
singleSWAP(nQubits=2,a=0,b=1,...)
singleSWAP(nQubits=2,a=0,b=1,...)
nQubits |
Number of qubits in target ket |
a |
Index of first qubit to swap, indexed from 0 |
b |
Index of second qubit to swap, indexed from 0 |
... |
No argument, or ket (column vector) that is input to the gate |
Matrix of the singleSWAP gate or ket after an singleSWAP gate is applied
singleSWAP(2,0,1, ket(1,2,3,4) ) singleSWAP(4,0,3, intket( c(1,5),4,c(1,2)) )
singleSWAP(2,0,1, ket(1,2,3,4) ) singleSWAP(4,0,3, intket( c(1,5),4,c(1,2)) )
Takes an unencoded single qubit ket and converts it to a 7-qubit Steane encoded ket
Steane(v)
Steane(v)
v |
Single qubit ket to Steane encode |
Steane encoded ket containing 7 qubits
Steane(ket(1,0)) Steane(ket(0,1)) Steane(ket(1,1))
Steane(ket(1,0)) Steane(ket(0,1)) Steane(ket(1,1))
Performs Steane error correction on an encoded qubit. Useful explanation provided by Devitt <DOI:10.1088/0034-4885/76/7/076001>
SteaneCorrect(v)
SteaneCorrect(v)
v |
Steane encoded qubit ket |
Steane encoded ket after error correction has been performed
## Not run: SteaneCorrect(Steane(ket(1,0))) SteaneCorrect(Steane(ket(0,1))) SteaneCorrect(Steane(ket(1,1))) SteaneCorrect(single(X(),n=7,t=2,Steane(ket(1,0)))) ## End(Not run)
## Not run: SteaneCorrect(Steane(ket(1,0))) SteaneCorrect(Steane(ket(0,1))) SteaneCorrect(Steane(ket(1,1))) SteaneCorrect(single(X(),n=7,t=2,Steane(ket(1,0)))) ## End(Not run)
If no argument is supplied, returns the matrix of SWAP gate. If ket given as input, applies an SWAP gate to the input ket and returns the resulting ket
SWAP(...)
SWAP(...)
... |
No argument, or ket (column vector) that is input to the gate |
Matrix of the SWAP gate or ket after an SWAP gate is applied
SWAP(ket(0,1,0,0)) SWAP()
SWAP(ket(0,1,0,0)) SWAP()
Encodes absolute square of inner product of two states, |<a|b>|^2, into an ancilliary qubit. It swaps the states of |a> and |b> conditioned on the ancilla which results in a state where the probability of measuring the ancilla qubit in the 0 state is equal to 1/2 - 1/2*(|<a|b>|^2). The ancilla qubit is inserted before qubit index 0, as the most significant qubit. Full explanation can be found in "Supervised Learning with Quantum Computers" <DOI:10.1007/978-3-319-96424-9>.
swapTest(v,a,b)
swapTest(v,a,b)
v |
Ket (column vector) that swap test is applied to. Should be a tensor product of two quantum state. |
a |
Vector of indices of |a> within v |
b |
Vector of indices of |b> within v |
Ket which contains the modified input ket, v, along with a leading ancillary qubit.
swapTest(intket(3,4),a=0:1,b=2:3) swapTest(intket(5,4),a=0:1,b=2:3)
swapTest(intket(3,4),a=0:1,b=2:3) swapTest(intket(5,4),a=0:1,b=2:3)
Converts the list form of a quantum circuit into a matrix representation. If the input is a single list, this function multiplies each entry. If each entry is a 4x4 unitary matrix, this function will multiply all, starting with the first, and generate a single 4x4 unitary matrix. If the input is a list of lists, this function will perform the same operation but interleave each list. The lists can be of different lengths.
SynthesizeCircuit(l)
SynthesizeCircuit(l)
l |
list containing the quantum operators of each cycle. The quantum operators should be unitary matrices which act on a number of qubits. Each entry in l should be of the same dimension. Optionally, l can be a of such lists, in which case each list will be interleaved. |
A matrix representing the result of applying each operation listed in l
## Not run: SynthesizeCircuit( list( tensor(X(),X()) , tensor(Y(),X()), tensor(I(),X()) , tensor(Z(),Z()) )) ## End(Not run) ## Not run: SynthesizeCircuit( list( list( tensor(X(),X()) , tensor(I(),X()) ), list( tensor(Y(),X()) , tensor(Z(),Z()) ) ) ) ## End(Not run)
## Not run: SynthesizeCircuit( list( tensor(X(),X()) , tensor(Y(),X()), tensor(I(),X()) , tensor(Z(),Z()) )) ## End(Not run) ## Not run: SynthesizeCircuit( list( list( tensor(X(),X()) , tensor(I(),X()) ), list( tensor(Y(),X()) , tensor(Z(),Z()) ) ) ) ## End(Not run)
If no argument is supplied, returns the matrix of T gate. If ket given as input, applies a T gate to the input ket and returns the resulting ket
T(...)
T(...)
... |
No argument, or ket (column vector) that is input to the gate |
Matix of the T gate or ket after an T gate is applied
T(ket(1,1)) T()
T(ket(1,1)) T()
Shows the steps of teleporting a single qubit
teleport(v)
teleport(v)
v |
Ket (column vector) to teleport |
String describing teleportation process
teleport(ket(2,1))
teleport(ket(2,1))
Takes all arguments and combines them as a tensor product. Can be used to create a unified vector that represents multiple qubits or to create higher dimensional gates. If the inputs are two n-dimensional kets, the output is a 2-n dimensional ket representing the combined system.
tensor(...)
tensor(...)
... |
kets (column vectosr) or gates (matrices) to take tensor product of |
The tensor product of all supplied arguments
tensor(ket(1,0),ket(0,1),ket(1,0),ket(1,0)) tensor(ket(1,1,1,1),ket(1,0,0,1)) tensor(X(),I()) tensor(H(),H(),H())
tensor(ket(1,0),ket(0,1),ket(1,0),ket(1,0)) tensor(ket(1,1,1,1),ket(1,0,0,1)) tensor(X(),I()) tensor(H(),H(),H())
Takes a given quantum gate and tests it with computational basis states as input. Can test a subset of possible inputs if specified, otherwise it tests all possible inputs. Useful for testing user defined gates.
testGate(g,inputs=0:(dim(g)[1]-1) )
testGate(g,inputs=0:(dim(g)[1]-1) )
g |
Matrix that represents a quantum gate (operation) |
inputs |
Vector of indices of computational basis states to test. Default is that all computational basis states will be tested |
None
testGate(CX()) testGate(CX(),inputs=c(0,1))
testGate(CX()) testGate(CX(),inputs=c(0,1))
If no argument is supplied, returns the matrix of TOFFOLI gate. If ket given as input, applies a TOFFOLI gate to the input ket and returns the resulting ket. If byCycle is TRUE, it generates the cycles which implement the TOFFOLI gate with standard gates.
TOFFOLI(...,byCycle=FALSE,n=3,cQubits=c(0,1),tQubit=2)
TOFFOLI(...,byCycle=FALSE,n=3,cQubits=c(0,1),tQubit=2)
... |
No argument, or an 8 dimensional (3 qubit) ket (column vector) that is input to the gate |
byCycle |
Boolean specifying if the circuit should be generated. If TRUE, rather than returning a matrix or performing a TOFFOLI gate, it returns a list of cycles of standard gates which implements the TOFFOLI gate. |
n |
Number of qubits in the system. |
cQubits |
Vector of control qubit indices. Indexed from 0. |
tQubit |
Index of target qubit. Indexed from 0. |
Matix of the TOFFOLI gate or ket after a TOFFOLI gate is applied. If byCycle is TRUE, a list of cycles implementing the TOFFOLI.
TOFFOLI(ket(1,1,1,1,0,1,0,1)) TOFFOLI()
TOFFOLI(ket(1,1,1,1,0,1,0,1)) TOFFOLI()
Takes as input a list of gates (in matrix form) and creates the tensor product, forming a higher dimensional gate. If the last argument is a ket, the gate is applied to the ket and the ket returned. If last argument is another gate, it returns the tensor product of all gates
U(...)
U(...)
... |
List of quantum gates in matrix form, optionally the last argument is ket (column vector) that is input to the gate |
Matix of the gate that is the tensor product of all input gates, or the ket which is the result of the gate applied to the input ket
U(X(),ket(1,0)) U(H(),H(),ket(1,0,0,0)) U(I(),X(),ket(1,0,1,0)) U(I(),X())
U(X(),ket(1,0)) U(H(),H(),ket(1,0,0,0)) U(I(),X(),ket(1,0,1,0)) U(I(),X())
Generates an operator (oracle) of specified size that implements the function that is passed to it. Assumes there are n qubits in data register and m qubits in target register.
Uf(fun,n,m)
Uf(fun,n,m)
fun |
Function of an n-bit argument that produces an m-bit result |
n |
Integer that specifies the number of qubits in the data register, same as number of bits to function |
m |
Integer that specifies the number of qubits in the target register, same as number of bits as output of function |
Matrix of the operator (oracle) which implements the specified function)
Uf(function(x){x - floor(x/2)*2},1,1) Uf(function(x){0},2,2) Uf(function(x){1},2,2) Uf(function(x){x - floor(x/4)*4},2,2) Uf(function(x){x^3},3,4)
Uf(function(x){x - floor(x/2)*2},1,1) Uf(function(x){0},2,2) Uf(function(x){1},2,2) Uf(function(x){x - floor(x/4)*4},2,2) Uf(function(x){x^3},3,4)
Determines whether an operation (matrix) is unitary by comparing its inverse to its adjoint
unitary(m,epsilon=1e-13)
unitary(m,epsilon=1e-13)
m |
gate operation (gate) that is to be checked |
epsilon |
Amount of error to tolerate. Accounts for numerical precision on practical computing systems |
boolean indicating whether matrix is unitary or not
unitary(mm(0,1,1,0)) unitary(mm(0,1,1,0),1e-15)
unitary(mm(0,1,1,0)) unitary(mm(0,1,1,0),1e-15)
If no argument is supplied, returns the matrix of X gate. If ket given as input, applies an X gate to the input ket and returns the resulting ket
X(...)
X(...)
... |
No argument, or ket (column vector) that is input to the gate |
Matix of the X gate or ket after an X gate is applied
X(ket(1,0)) X()
X(ket(1,0)) X()
If no argument is supplied, returns the matrix of the Y gate. If ket given as input, applies a Y gate to the input ket and return the resulting ket
Y(...)
Y(...)
... |
No argument, or ket (column vector) that is input to the gate |
Matrix of the Y gate or ket after a Y gate is applied
Y(ket(1,0)) Y()
Y(ket(1,0)) Y()
If no argument is supplied, returns the matrix of Z gate. If ket given as input, applies a Z gate to the input ket and returns the resulting ket
Z(...)
Z(...)
... |
No argument, or ket (column vector) that is input to the gate |
Matix of the Z gate or ket after a Z gate is applied
Z(ket(1,0)) Z()
Z(ket(1,0)) Z()