public class Circuit extends ArrayList<QuantumGate> implements Serializable
Modifier and Type | Field and Description |
---|---|
static String[] |
gatelist
In this array the names of all possible quantum gates are stored.
|
modCount
Constructor and Description |
---|
Circuit()
Creates an empty quantum circuit.
|
Modifier and Type | Method and Description |
---|---|
void |
addCNOT(int[] qubits,
boolean yRegister)
Adds a CNOT gate on the two qubits specified by the two numbers
in the qubit array;
if the flag
yRegister is set, it is added to the
y-register, otherwise to the x-register. |
void |
addFunction(FunctionParser function)
Adds a function evaluating gate to the circuit, specified by the input function.
|
void |
addGrover(int needle)
Adds the Grover gate searching for the specified needle to the circuit.
|
void |
addHadamard(int i,
boolean yRegister)
Adds a Hadamard gate on the i-th qubit of the quantum circuit;
if the flag
yRegister is set, it is added to the i-th qubit
of the y-register, otherwise it is the i-th qubit of the
x-register. |
void |
addInvQFT(boolean yRegister)
Adds the inverse Fourier transform gate to the circuit;
if the flag
yRegister is set, it is added to the
y-register, otherwise to the x-register. |
void |
addInvSGate(int i,
boolean yRegister)
Adds an S* gate, the inverse or adjoint of the S gate,
on the i-th qubit of the quantum circuit;
if the flag
yRegister is set, it is added to the i-th qubit
of the y-register, otherwise it is the i-th qubit of the
x-register. |
void |
addMeasurement(int[] qubits,
boolean yRegister)
Adds a measurement gate on the qubits specified by the qubit array;
if the flag
yRegister is set, it is added to the
y-register, otherwise to the x-register. |
void |
addPauliX(int i,
boolean yRegister)
Adds a Pauli-X gate on the i-th qubit of the quantum circuit;
if the flag
yRegister is set, it is added to the i-th qubit
of the y-register, otherwise it is the i-th qubit of the
x-register. |
void |
addPauliY(int i,
boolean yRegister)
Adds a Pauli-Y gate on the i-th qubit of the quantum circuit;
if the flag
yRegister is set, it is added to the i-th qubit
of the y-register, otherwise it is the i-th qubit of the
x-register. |
void |
addPauliZ(int i,
boolean yRegister)
Adds a Pauli-Z gate on the i-th qubit of the quantum circuit;
if the flag
yRegister is set, it is added to the i-th qubit
of the y-register, otherwise it is the i-th qubit of the
x-register. |
void |
addQFT(boolean yRegister)
Adds the Fourier transform gate to the circuit;
if the flag
yRegister is set, it is added to the
y-register, otherwise to the x-register. |
void |
addRotation(int[] qubits,
boolean yRegisterChosen,
String axis,
int phiAsPartOfPi)
Adds a rotation gate to the circuit.
|
void |
addSGate(int i,
boolean yRegister)
Adds an S gate on the i-th qubit of the quantum circuit;
if the flag
yRegister is set, it is added to the i-th qubit
of the y-register, otherwise it is the i-th qubit of the
x-register. |
void |
addSqrtX(int i,
boolean yRegister)
Adds a √X, or √NOT gate on the i-th qubit of the quantum circuit;
if the flag
yRegister is set, it is added to the i-th qubit
of the y-register, otherwise it is the i-th qubit of the
x-register. |
void |
addTGate(int i,
boolean yRegister)
Adds a T gate on the i-th qubit of the quantum circuit;
if the flag
yRegister is set, it is added to the i-th qubit
of the y-register, otherwise it is the i-th qubit of the
x-register. |
void |
addToffoli(int[] qubits,
boolean yRegister)
Adds a Toffoli gate on the three qubits specified by the three numbers
in the qubit array;
if the flag
yRegister is set, it is added to the
y-register, otherwise to the x-register. |
boolean |
executeAll()
Executes the entire quantum circuit and returns
true if
the algorithm is terminated. |
ArrayList<QuantumGate> |
getGates()
Provides the entire list of quantum gates of this quantum circuit.
|
QuantumGate |
getNextGate()
Yields the current gate in this quantum circuit which is to be executed next.
|
int |
getNextGateNumber()
Returns the number of the gate to be executed next in this quantum circuit.
|
int |
getNumberOfWires()
Returns the number of wires of this quantum circuit.
|
QuantumGate |
getPreviousGate()
Yields the previous gate in this quantum circuit which just had been executed.
|
Register |
getXRegister()
Returns the x-register of this quantum circuit.
|
int |
getXRegisterSize()
Yields the size of the x-register of this quantum circuit.
|
Register |
getYRegister()
Returns the y-register of this quantum circuit.
|
int |
getYRegisterSize()
Yields the size of the y-register of this quantum circuit.
|
void |
initialize(int[] registerSizes,
ArrayList<QuantumGate> gates)
Constructs and initializes this quantum cicuit according to the
specified sizes of the registers and the list of quantum gates.
|
boolean |
initialize(int xRegisterSize,
int yRegisterSize,
int initialState)
Initializes this quantum circuit and deletes all quantum gates.
|
void |
initializeRegisters()
Initializes this quantum register according to the initial qubit state
given by quantum gate number 0.
|
void |
setFinalStep()
Sets the quantum cicuit into its final state.
|
void |
setInitialQubits(int[] initialQubits)
Sets the initial states of the qubits of this quantum circuit.
|
void |
setInitialState(int[] initialQubits)
Determines the initial state of the quantum circuit.
|
void |
setNextStep()
Executes the next quantum gate in this quantum circuit.
|
void |
setPreviousStep()
Executes the inverse of the previously executed quantum gate in this quantum circuit.
|
add, add, addAll, addAll, clear, clone, contains, ensureCapacity, forEach, get, indexOf, isEmpty, iterator, lastIndexOf, listIterator, listIterator, remove, remove, removeAll, removeIf, removeRange, replaceAll, retainAll, set, size, sort, spliterator, subList, toArray, toArray, trimToSize
equals, hashCode
containsAll, toString
finalize, getClass, notify, notifyAll, wait, wait, wait
containsAll, equals, hashCode
parallelStream, stream
public static String[] gatelist
public int getXRegisterSize()
public int getYRegisterSize()
public int getNumberOfWires()
public void setInitialQubits(int[] initialQubits)
initialQubits
- the initial states of the qubits of this quantum circuitpublic QuantumGate getNextGate()
public QuantumGate getPreviousGate()
public int getNextGateNumber()
public Register getXRegister()
public Register getYRegister()
public ArrayList<QuantumGate> getGates()
public void initialize(int[] registerSizes, ArrayList<QuantumGate> gates)
registerSizes
- the sizes of the registers, where
registerSizes[0]
denotes the size of the x-register, and
registerSizes[1]
denotes the size of the y-registergates
- the list of quantum gates this quantum gate consists ofpublic boolean initialize(int xRegisterSize, int yRegisterSize, int initialState)
xRegisterSize
- size of the x-registeryRegisterSize
- size of the y-registerinitialState
- initial state of the registerpublic void initializeRegisters()
public void setFinalStep()
public void setNextStep()
IllegalArgumentException
- if the quantum gate is unknownpublic void setPreviousStep()
IllegalArgumentException
- if the quantum gate is unknown or if it is a measurement gatepublic void setInitialState(int[] initialQubits)
initialQubits
specifies the indices of qubits
either set to |0> or |1>. That is, an initial state corresponds to a
classical bit state.initialQubits
- the indices of qubitspublic void addHadamard(int i, boolean yRegister) throws NoWireException
yRegister
is set, it is added to the i-th qubit
of the y-register, otherwise it is the i-th qubit of the
x-register.i
- the number of qubityRegister
- flag whether the gate is added in the y-registerNoWireException
- if the register is not existingpublic void addCNOT(int[] qubits, boolean yRegister) throws NoWireException
yRegister
is set, it is added to the
y-register, otherwise to the x-register.qubits
- the numbers of qubit; array size must be twoyRegister
- flag whether the gate is added in the y-registerNoWireException
- if the register is not existingpublic void addPauliX(int i, boolean yRegister) throws NoWireException
yRegister
is set, it is added to the i-th qubit
of the y-register, otherwise it is the i-th qubit of the
x-register.i
- the number of qubityRegister
- flag whether the gate is added in the y-registerNoWireException
- if the register is not existingpublic void addPauliY(int i, boolean yRegister) throws NoWireException
yRegister
is set, it is added to the i-th qubit
of the y-register, otherwise it is the i-th qubit of the
x-register.i
- the number of qubityRegister
- flag whether the gate is added in the y-registerNoWireException
- if the register is not existingpublic void addPauliZ(int i, boolean yRegister) throws NoWireException
yRegister
is set, it is added to the i-th qubit
of the y-register, otherwise it is the i-th qubit of the
x-register.i
- the number of qubityRegister
- flag whether the gate is added in the y-registerNoWireException
- if the register is not existingpublic void addSGate(int i, boolean yRegister) throws NoWireException
yRegister
is set, it is added to the i-th qubit
of the y-register, otherwise it is the i-th qubit of the
x-register.i
- the number of qubityRegister
- flag whether the gate is added in the y-registerNoWireException
- if the register is not existingpublic void addInvSGate(int i, boolean yRegister) throws NoWireException
yRegister
is set, it is added to the i-th qubit
of the y-register, otherwise it is the i-th qubit of the
x-register.i
- the number of qubityRegister
- flag whether the gate is added in the y-registerNoWireException
- if the register is not existingaddSGate(int, boolean)
public void addTGate(int i, boolean yRegister) throws NoWireException
yRegister
is set, it is added to the i-th qubit
of the y-register, otherwise it is the i-th qubit of the
x-register.i
- the number of qubityRegister
- flag whether the gate is added in the y-registerNoWireException
- if the register is not existingpublic void addSqrtX(int i, boolean yRegister) throws NoWireException
yRegister
is set, it is added to the i-th qubit
of the y-register, otherwise it is the i-th qubit of the
x-register.i
- the number of qubityRegister
- flag whether the gate is added in the y-registerNoWireException
- if the register is not existingpublic void addToffoli(int[] qubits, boolean yRegister) throws NoWireException
yRegister
is set, it is added to the
y-register, otherwise to the x-register.qubits
- the numbers of qubit; array size must be threeyRegister
- flag whether the gate is added in the y-registerNoWireException
- if the register is not existingpublic void addInvQFT(boolean yRegister) throws NoWireException
yRegister
is set, it is added to the
y-register, otherwise to the x-register.yRegister
- flag whether the gate is in the y-registerNoWireException
- if the number of wires vanishespublic void addQFT(boolean yRegister) throws NoWireException
yRegister
is set, it is added to the
y-register, otherwise to the x-register.yRegister
- flag whether the gate is in the y-registerNoWireException
- if the number of wires vanishespublic void addFunction(FunctionParser function) throws NoWireException
function
- the parsed functionNoWireException
- if the numbers of wires is not positivepublic void addRotation(int[] qubits, boolean yRegisterChosen, String axis, int phiAsPartOfPi) throws NoWireException
"x"
, "y"
,
"z"
, respectively.
The rotation angle is specified as the integer part of π.qubits
- the qubit numbers being involvedyRegisterChosen
- flag whether the gate is added to the y-registeraxis
- the rotation axisphiAsPartOfPi
- the integer part of π representing the rotation angleNoWireException
- if the number of wires vanishespublic void addGrover(int needle) throws NoWireException
needle
- the searched for value of the Grover gateNoWireException
- if the number of wires vanishespublic void addMeasurement(int[] qubits, boolean yRegister) throws NoWireException
yRegister
is set, it is added to the
y-register, otherwise to the x-register.qubits
- the numbers of qubityRegister
- flag whether the gate is added in the y-registerNoWireException
- if the register is not existingpublic boolean executeAll()
true
if
the algorithm is terminated.true
after termination of execution