public class Register extends Object
α = (α0, α1, ..., αq-1) = α0 |0> + α1 |1> + ... + αq-1 |q-1>.
A qubit register as an object of this class then is given by the two arraysreal[]
and imaginary
where
real
[j] = Re αj
and
imaginary
[j] = Im αj
for j = 0, 1, ..., q-1.Modifier and Type | Field and Description |
---|---|
static double |
ACCURACY
The accuracy up to which calculations are done.
|
int |
size
The number of qubits of this register.
|
Constructor and Description |
---|
Register(int size)
Creates a register of n qubits, initialized to the state |0>.
|
Register(int size,
boolean asGraphRegister)
Creates a register of n qubits, initialized to the state |0>.
|
Modifier and Type | Method and Description |
---|---|
void |
cNOT(int j,
int k)
Applies the c-NOT gate to this register, where j is the control
qubit and k the target qubit.
|
boolean |
equals(Object o)
Returns true if and only if the specified object represents a quantum
register which is physically equivalent to this register.
|
Register |
evaluateFunction(Register yRegister,
FunctionParser function,
int z)
Applies the function evaluation of a parsed function f(z) to the
y-register.
|
HashMap<Integer,ArrayList<Integer>> |
getEntanglement()
Returns a map of a list containing the numbers of states being entangled with each other.
|
GraphRegister |
getGraphState()
Returns the graph register state representing this quantum register as long as
it is a stabilizer state according to the Gottesman-Knill theorem.
|
double[] |
getImaginary()
Returns the array containing the imaginary parts of the qubit state components
of this register.
|
double[] |
getReal()
Returns the array containing the real parts of the qubit state components
of this register.
|
int |
getSize()
Returns the size of this quantum register.
|
void |
grover(int needle)
Performs a Grover operator, or Grover iteration step,
on this quantum register.
|
static int |
groverSteps(int size)
The optimal number r of Grover iterations to successfully apply
Grover's search algorithm.
|
void |
hadamard(int j)
Hadamard transformation of the j-th qubit.
|
int |
hashCode()
Returns the hash code of the current state of this quantum register.
|
void |
inverseGrover(int needle)
Applies the inverse of the Grover operator.
|
void |
inverseQft(int q,
int size)
Applies the inverse quantum Fourier transform (QFT-1) to this register.
|
void |
inverseSGate(int j)
Applies the inverse S gate to the j-th qubit.
|
void |
inverseSqrtX(int j)
Applies the inverse √X, or √NOT gate to the j-th qubit.
|
void |
inverseTGate(int j)
Applies the inverse T gate to the j-th qubit.
|
boolean |
isStabilizerState()
Indicates whether the current state of this quantum register is a stabilizer
state.
|
int |
measure()
Returns the random value of a quantum measurement of this register.
|
int |
measure(int j)
Returns the random value of a quantum measurement of the j-th
qubit of this register, j = 0, 1, ..., n - 1 where
n is the size of this register.
|
void |
qft(int q,
int size)
Applies the quantum Fourier transform (QFT) to this register.
|
void |
rotate(int[] cQubits,
String axis,
double phi)
Applies one of the three basic rotation operators
Rx(φ), Ry(φ),
or Rz(φ) to this register.
|
void |
setImaginary(double[] imaginary)
Returns the array containing the imaginary parts of the qubit state components
of this register.
|
void |
setReal(double[] real)
Returns the array containing the real parts of the qubit state components
of this register.
|
void |
sGate(int j)
Applies the S gate to the j-th qubit.
|
String |
show(int nMax)
Returns a string representation of the first
nMax qubits of
this register. |
void |
sqrtX(int j)
Applies the √X, or √NOT gate to the j-th qubit.
|
void |
tGate(int j)
Applies the T gate to the j-th qubit.
|
void |
toffoli(int j1,
int j2,
int k)
Applies the Toffoli gate to this register.
|
String |
toString()
Returns a string representation of this register.
|
String |
toString(int nMax)
Returns a string representation of the first
nMax qubits of
this register. |
void |
xPauli(int j)
Applies the Pauli-X gate to the j-th qubit; on a classical bit, the
X gate acts equally to a a classical NOT.
|
void |
yPauli(int j)
Applies the Pauli-Y gate to the j-th qubit.
|
void |
zPauli(int j)
Applies the Pauli-Z gate to the j-th qubit.
|
public static final double ACCURACY
public int size
public Register(int size)
size
- the number of qubits this register consists ofpublic Register(int size, boolean asGraphRegister)
asGraphRegister
is set true
,
this register is represented efficiently as a graph state consisting of
n vertices representing the n qubits.
If asGraphRegister
is set false
, this register
is represented by two double
arrays of size 2n
storing the complex amplitudes.size
- the number of qubits this register consists ofasGraphRegister
- indicates whether this register shall be represented
as a graph statepublic int getSize()
public void setReal(double[] real)
real
- array of the real parts of this quantum registerIllegalArgumentException
- if real.length
is not equal
to 2n where n is the size of this registerpublic double[] getReal()
public void setImaginary(double[] imaginary)
imaginary
- array of the imaginary parts of this quantum registerIllegalArgumentException
- if imaginary.length
is not equal
to 2n where n is the size of this registerpublic double[] getImaginary()
public boolean isStabilizerState()
true
if and only if this quantum register is in a stabilizer statepublic GraphRegister getGraphState()
null
.public HashMap<Integer,ArrayList<Integer>> getEntanglement()
public void hadamard(int j)
j
- the number of the qubit (1 ≤ j ≤ qubit size).public void cNOT(int j, int k)
j
- the control qubitk
- the target qubitpublic void xPauli(int j)
j
- the number of the qubit (1 ≤ j ≤ qubit size).public void yPauli(int j)
j
- the number of the qubit (1 ≤ j ≤ qubit size).public void zPauli(int j)
j
- the number of the qubit (1 ≤ j ≤ qubit size).public void sGate(int j)
j
- the number of the qubit (1 ≤ j ≤ qubit size).public void inverseSGate(int j)
j
- the number of the qubit (1 ≤ j ≤ qubit size).public void tGate(int j)
j
- the number of the qubit (1 ≤ j ≤ qubit size).public void inverseTGate(int j)
j
- the number of the qubit (1 ≤ j ≤ qubit size).public void sqrtX(int j)
j
- the number of the qubit (1 ≤ j ≤ qubit size).public void inverseSqrtX(int j)
j
- the number of the qubit (1 ≤ j ≤ qubit size).public void toffoli(int j1, int j2, int k)
j1
- the first control qubitj2
- the second control qubitk
- the target qubitpublic void qft(int q, int size)
QFT( |j> ) | = |
|
| e2πijk/q |k>. |
Here q denotes the total number of different basis states of the
register. If q = 2n where n
is the number of qubits of this register, then the fast Fourier transform
is applied. Otherwise, a new quantum register with size
basis states is created from this register where only the first q
register states are transformed.
Note that both q and size
must be less than or equal
2n where n is the qubit size of this register.
q
- the total number of register basis states
|0>, |1>, ..., |q - 1> to be transformedsize
- the number of register basis states of the transformed registerinverseQft(int,int)
public void inverseQft(int q, int size)
QFT-1( |j> ) | = |
|
| e2πijk/q |k>. |
Here q denotes the total number of different basis states of the
register. If q = 2n where n
is the number of qubits of this register, then the inverse fast Fourier transform
is applied. Otherwise, a new quantum register with size
basis states is created from this register where only the first q
register states are transformed.
Note that both q and size
must be less than or equal
2n where n is the qubit size of this register.
q
- the total number of register basis states
|0>, |1>, ..., |q - 1> to be transformedsize
- the number of register basis states of the transformed registerqft(int,int)
public void rotate(int[] cQubits, String axis, double phi)
cQubits
- an array containing the control qubits and, as its last entry, the target qubitaxis
- a string representing the axis, i.e., either "x", "y", or "z"phi
- the rotation angle in radianspublic Register evaluateFunction(Register yRegister, FunctionParser function, int z)
yRegister
- the y-register where the function values are storedfunction
- the parsed function f(z)z
- the value at which f(z) is to be evaluatedBufferOverflowException
- if y-register is too small to
store all function valuespublic void grover(int needle)
-I0(|x>) = -|x> if x ≠ 0.
In practice, an oracle could be a cryptologic algorithm in a known-plaintext attack which applies a secret key to a given ciphertext and yields -1 if the deciphered text equals the known plaintex, and +1 otherwise.
needle
- the value to be searched forIllegalArgumentException
- if the needle value is out of register rangepublic void inverseGrover(int needle)
needle
- the value to be searched forgrover(int)
public static int groverSteps(int size)
r ≈ |
|
≈ |
|
= 2(n - 4)/2 π |
where n ≥ 2 is the size of the register, i.e., the number of its qubits.
size
- the size of the registerpublic int measure()
To implement the random collapse, a random number f with 0 ≤ f < 1 is chosen. Then successively the probabilities of the single qubits are subtracted, starting with the first qubit state |0>, until f gets negative. The last qubit |j> that caused the sign change is the measured qubit state.
measure(int)
public int measure(int j)
All qubits in the register vanish if they are entangled with the qubit state corresponding to the value not measured: if "0" is measured, these are the states |m> with m & 2j-1 = 0, if "1" is measured, these are |m> with m & 2j-1 > 0. The probability amplitudes of the remaining states must be normalized such that the whole register is in a unit state.
To implement the random collapse, a random number f with 0 ≤ f < 1 is chosen. If f < Σ |αm|2, where m & 2j-1 = 0, the measured value is "0", otherwise it is "1".j
- the qubit to be measuredmeasure()
public boolean equals(Object o)
ACCURACY
.public int hashCode()
public String show(int nMax)
nMax
qubits of
this register.nMax
- specifies the maximum number of considered qubitsnMax
qubits
of this registerpublic String toString(int nMax)
nMax
qubits of
this register.nMax
- specifies the maximum number of considered qubitsnMax
qubits
of this register