re-added docs
This commit is contained in:
parent
be9252e1c0
commit
9fe2910fc8
5 changed files with 521 additions and 0 deletions
172
docs/Gate.md
Normal file
172
docs/Gate.md
Normal file
|
|
@ -0,0 +1,172 @@
|
|||
# Gates
|
||||
|
||||
Here is the list of all the main gates in quantum algorithm available in the library. In the following formulas, `i` represents the complex number.
|
||||
|
||||
## H(q: QuBit) -> None
|
||||
`Hadamard's gate`.
|
||||
|
||||
- q: the qubit manipulated by the gate. This function is in-place.
|
||||
|
||||
- matrix:
|
||||
```math
|
||||
\begin{pmatrix}
|
||||
\frac {1} {\sqrt 2} & \frac {1} {\sqrt 2}\\
|
||||
\frac {1} {\sqrt 2} & -\frac {1} {\sqrt 2}
|
||||
\end{pmatrix}
|
||||
```
|
||||
|
||||
## X(q: QuBit) -> None
|
||||
`Pauli-X gate` or `NOT gate`. Inplementes a rotation aroud the x-axis of $\pi$ radians.
|
||||
|
||||
- q: the qubit manipulated by the gate. This function is in-place.
|
||||
|
||||
- matrix:
|
||||
```math
|
||||
\begin{pmatrix}
|
||||
0 & 1\\
|
||||
1 & 0
|
||||
\end{pmatrix}
|
||||
```
|
||||
|
||||
## Y(q: QuBit) -> None
|
||||
`Pauli-Y gate`. Inplementes a rotation aroud the y-axis of $\pi$ radians.
|
||||
|
||||
- q: the qubit manipulated by the gate. This function is in-place.
|
||||
|
||||
- matrix:
|
||||
```math
|
||||
\begin{pmatrix}
|
||||
0 & -i\\
|
||||
i & 0
|
||||
\end{pmatrix}
|
||||
```
|
||||
|
||||
## Z(q: QuBit) -> None
|
||||
`Pauli-Z gate`. Inplementes a rotation aroud z-axis of $\pi$ radians.
|
||||
|
||||
- q: the qubit manipulated by the gate. This function is in-place.
|
||||
|
||||
- matrix:
|
||||
```math
|
||||
\begin{pmatrix}
|
||||
1 & 0\\
|
||||
0 & -1
|
||||
\end{pmatrix}
|
||||
```
|
||||
|
||||
## S(q: QuBit) -> None
|
||||
`NOT gate`. Invert the state |0> and |1> of the QuiBit q.
|
||||
|
||||
- q: the qubit manipulated by the gate. This function is in-place.
|
||||
|
||||
- matrix:
|
||||
```math
|
||||
\begin{pmatrix}
|
||||
1 & 0\\
|
||||
0 & i
|
||||
\end{pmatrix}
|
||||
```
|
||||
|
||||
## T(q: QuBit) -> None
|
||||
`NOT gate`. Invert the state |0> and |1> of the QuiBit q.
|
||||
|
||||
- q: the qubit manipulated by the gate. This function is in-place.
|
||||
|
||||
- matrix:
|
||||
```math
|
||||
\begin{pmatrix}
|
||||
1 & 0\\
|
||||
0 & e^{i\frac\pi4}
|
||||
\end{pmatrix}
|
||||
```
|
||||
|
||||
## Rx(q: QuBit, phi: float) -> None
|
||||
`NOT gate`. Inplementes a rotation aroud x-axis of $\phi$ radians.
|
||||
|
||||
- q: the qubit manipulated by the gate. This function is in-place.
|
||||
|
||||
- matrix:
|
||||
```math
|
||||
\begin{pmatrix}
|
||||
\cos(\frac\phi2) & -\sin(\frac\phi2)\\
|
||||
\sin(\frac\phi2) & \cos(\frac\phi2)
|
||||
\end{pmatrix}
|
||||
```
|
||||
|
||||
## Ry(q: QuBit, phi: float) -> None
|
||||
`NOT gate`. Inplementes a rotation aroud y-axis of $\pi$ radians.
|
||||
|
||||
- q: the qubit manipulated by the gate. This function is in-place.
|
||||
|
||||
- matrix:
|
||||
```math
|
||||
\begin{pmatrix}
|
||||
e^{-i\frac\phi2} & 0\\
|
||||
0 & e^{i\frac\phi2}
|
||||
\end{pmatrix}
|
||||
```
|
||||
|
||||
## R1(q: QuBit, phi: float) -> None
|
||||
`NOT gate`. Invert the state |0> and |1> of the QuiBit q.
|
||||
|
||||
- q: the qubit manipulated by the gate. This function is in-place.
|
||||
|
||||
- matrix:
|
||||
```math
|
||||
\begin{pmatrix}
|
||||
1 & 0\\
|
||||
0 & e^{i\frac\phi2}
|
||||
\end{pmatrix}
|
||||
```
|
||||
|
||||
## CNOT(q: MuBit, n1: int, n2: int) -> None
|
||||
`X-controlled gate`. Invert the state |0> and |1> of the QuiBit in n2 if the state of the QuBit in n1 is 1.
|
||||
|
||||
- q: the qubit manipulated by the gate. This function is in-place.
|
||||
- n1: the first QuBit to manipualte.
|
||||
- n2: the second QuBit to manipulate
|
||||
|
||||
- matrix:
|
||||
```math
|
||||
\begin{pmatrix}
|
||||
1 & 0 & 0 & 0\\
|
||||
0 & 1 & 0 & 0\\
|
||||
0 & 0 & 0 & 1\\
|
||||
0 & 0 & 1 & 0
|
||||
\end{pmatrix}
|
||||
```
|
||||
|
||||
## SWAP(q: MuBit, n1: int, n2: int) -> None
|
||||
`NOT gate`. Invert the state |0> and |1> of the QuiBit q.
|
||||
|
||||
- q: the qubit manipulated by the gate. This function is in-place.
|
||||
- n1: the first QuBit to manipualte.
|
||||
- n2: the second QuBit to manipulate
|
||||
|
||||
- matrix:
|
||||
```math
|
||||
\begin{pmatrix}
|
||||
1 & 0 & 0 & 0\\
|
||||
0 & 0 & 1 & 0\\
|
||||
0 & 1 & 0 & 0\\
|
||||
0 & 0 & 0 & 1
|
||||
\end{pmatrix}
|
||||
```
|
||||
|
||||
## Cu(q: MuBit, u: list[list[float]], n1: int, n2: int) -> None
|
||||
`controlled-u gate`. Applies the gate u to the QuBit in n2 if the Qubit in n1 is 1.
|
||||
|
||||
- q: the qubit manipulated by the gate. This function is in-place.
|
||||
- the list respresentation of a matrix of the size 2 by 2.
|
||||
- n1: the first QuBit to manipualte.
|
||||
- n2: the second QuBit to manipulate
|
||||
|
||||
- matrix:
|
||||
```math
|
||||
\begin{pmatrix}
|
||||
1 & 0 & 0 & 0\\
|
||||
0 & 1 & 0 & 0\\
|
||||
0 & 0 & u_{00} & u_{01}\\
|
||||
0 & 0 & u_{10} & u_{11}
|
||||
\end{pmatrix}
|
||||
```
|
||||
196
docs/Matrix.md
Normal file
196
docs/Matrix.md
Normal file
|
|
@ -0,0 +1,196 @@
|
|||
## Matrix
|
||||
|
||||
Matrix(l: list[list[complexe]])
|
||||
|
||||
- l: representation of the matrix in a list
|
||||
|
||||
### Attributes
|
||||
|
||||
- ```__m: list[list[complexe]]```
|
||||
|
||||
the values contained in the matrix.
|
||||
|
||||
- ```__size: tuple[int, int]```
|
||||
|
||||
the size of the matrix
|
||||
|
||||
### Methode
|
||||
|
||||
- ```__init__(l: list[list[complex]]=[]) -> None```
|
||||
|
||||
initiates the matrix
|
||||
|
||||
- ```__mul__(__value: "Matrix") -> Matrix```
|
||||
|
||||
defines the natural multiplication as the Koeneger product for matrices
|
||||
|
||||
- ```__apply(x: list[complex]) -> list[complex]```
|
||||
|
||||
takes a list to represent a vector in a colonne, and return the proctuct of the matrix by this vector
|
||||
|
||||
- ```__str__() -> str```
|
||||
|
||||
returns a string representation of the matrix
|
||||
|
||||
|
||||
### Staticmethods
|
||||
|
||||
- ```I() -> Matrix```
|
||||
|
||||
returns the matrix
|
||||
|
||||
```math
|
||||
\begin{pmatrix}
|
||||
1 & 0\\
|
||||
0 & 1
|
||||
\end{pmatrix}
|
||||
```
|
||||
|
||||
- ```H() -> Matrix```
|
||||
|
||||
returns the matrix
|
||||
|
||||
```math
|
||||
\begin{pmatrix}
|
||||
\frac {1} {\sqrt 2} & \frac {1} {\sqrt 2}\\
|
||||
\frac {1} {\sqrt 2} & -\frac{1} {\sqrt 2}
|
||||
\end{pmatrix}
|
||||
```
|
||||
|
||||
- ```X() -> Matrix```
|
||||
|
||||
returns the matrix
|
||||
|
||||
```math
|
||||
\begin{pmatrix}
|
||||
0 & 1\\
|
||||
1 & 0
|
||||
\end{pmatrix}
|
||||
```
|
||||
|
||||
- ```Y() -> Matrix```
|
||||
|
||||
returns the matrix
|
||||
|
||||
```math
|
||||
\begin{pmatrix}
|
||||
0 & -i\\
|
||||
i & 0
|
||||
\end{pmatrix}
|
||||
```
|
||||
|
||||
- ```Z() -> Matrix```
|
||||
|
||||
returns the matrix
|
||||
|
||||
```math
|
||||
\begin{pmatrix}
|
||||
1 & 0\\
|
||||
0 & -1
|
||||
\end{pmatrix}
|
||||
```
|
||||
|
||||
- ```S() -> Matrix```
|
||||
|
||||
returns the matrix
|
||||
|
||||
```math
|
||||
\begin{pmatrix}
|
||||
1 & 0\\
|
||||
0 & i
|
||||
\end{pmatrix}
|
||||
```
|
||||
|
||||
- ```T() -> Matrix```
|
||||
|
||||
returns the matrix
|
||||
|
||||
```math
|
||||
\begin{pmatrix}
|
||||
1 & 0\\
|
||||
0 & e^{i\frac {\pi} {4}}
|
||||
\end{pmatrix}
|
||||
```
|
||||
|
||||
- ```Rx(phi: float) -> Matrix```
|
||||
|
||||
returns the matrix
|
||||
|
||||
```math
|
||||
\begin{pmatrix}
|
||||
\cos(\frac \phi 2) & -i\sin(\frac \phi 2)\\
|
||||
-i\sin(\frac \phi 2) & \cos(\frac \phi 2)
|
||||
\end{pmatrix}
|
||||
```
|
||||
|
||||
- ```Ry(phi: float) -> Matrix```
|
||||
|
||||
returns the matrix
|
||||
|
||||
```math
|
||||
\begin{pmatrix}
|
||||
\cos(\frac \phi 2) & -\sin(\frac \phi 2)\\
|
||||
\sin(\frac \phi 2) & \cos(\frac \phi 2)
|
||||
\end{pmatrix}
|
||||
```
|
||||
|
||||
- ```Rz(phi: float) -> Matrix```
|
||||
|
||||
returns the matrix
|
||||
|
||||
```math
|
||||
\begin{pmatrix}
|
||||
e^{-i\frac \phi 2} & 0\\
|
||||
0 & e^{i\frac \phi 2}
|
||||
\end{pmatrix}
|
||||
```
|
||||
|
||||
- ```R1(phi: float) -> Matrix```
|
||||
|
||||
returns the matrix
|
||||
|
||||
```math
|
||||
\begin{pmatrix}
|
||||
1 & p\\
|
||||
0 & e^{i\phi}
|
||||
\end{pmatrix}
|
||||
```
|
||||
|
||||
- ```CNOT() -> Matrix```
|
||||
|
||||
returns the matrix
|
||||
|
||||
```math
|
||||
\begin{pmatrix}
|
||||
1 & 0 & 0 & 0\\
|
||||
0 & 1 & 0 & 0\\
|
||||
0 & 0 & 0 & 1\\
|
||||
0 & 0 & 1 & 0
|
||||
\end{pmatrix}
|
||||
```
|
||||
|
||||
- ```SWAP() -> Matrix```
|
||||
|
||||
returns the matrix
|
||||
|
||||
```math
|
||||
\begin{pmatrix}
|
||||
1 & 0 & 0 & 0\\
|
||||
0 & 0 & 1 & 0\\
|
||||
0 & 1 & 0 & 0\\
|
||||
0 & 0 & 0 & 0
|
||||
\end{pmatrix}
|
||||
```
|
||||
|
||||
- ```Cu(u: Matrix) -> Matrix```
|
||||
|
||||
returns the matrix
|
||||
|
||||
```math
|
||||
\begin{pmatrix}
|
||||
1 & 0 & 0 & 0\\
|
||||
0 & 1 & 0 & 0\\
|
||||
0 & 0 & u_{00} & u_{01}\\
|
||||
0 & 0 & u_{10} & u_{11}
|
||||
\end{pmatrix}
|
||||
```
|
||||
48
docs/QuBit/IQuBit.md
Normal file
48
docs/QuBit/IQuBit.md
Normal file
|
|
@ -0,0 +1,48 @@
|
|||
## IQuBit
|
||||
|
||||
IQuBit(n: int, mb: MuBit)
|
||||
|
||||
IQuBit(QuBit)
|
||||
|
||||
- n: the position of the QuBit in the list of intricated QuBits
|
||||
- mb: the MuBit which organises the intricated QuBit
|
||||
|
||||
### Attributes
|
||||
|
||||
- ```__n: int```
|
||||
|
||||
the position of the QuBit in the list of intricated QuBits
|
||||
|
||||
- ```__Mubit: MuBit```
|
||||
the MuBit which organises the intricated QuBit
|
||||
|
||||
- ```__intricated: bool```
|
||||
|
||||
tells if the QuBit is intricated or not
|
||||
|
||||
|
||||
### Methode
|
||||
|
||||
- ```__init__(n: int, mb: MuBit) -> None```
|
||||
|
||||
initiates the qubit
|
||||
|
||||
- ```is_intricated() -> bool```
|
||||
|
||||
returns the value of __intricated
|
||||
|
||||
- ```get_MuBit() -> MuBit```
|
||||
|
||||
returns the MuBit in wich the QuBit is intricated.
|
||||
|
||||
- ```__str__() -> str```
|
||||
|
||||
returns a string representation of the list of __state
|
||||
|
||||
- ```__apply(m: Matrix) -> None```
|
||||
|
||||
takes a Matrix and modifies the QuBit according the matrix
|
||||
|
||||
- ```observe() -> list[int]```
|
||||
|
||||
forces the QuBit in a state, where the probabilities are given throught __state. Returns the new __state obtained.
|
||||
63
docs/QuBit/MuBit.md
Normal file
63
docs/QuBit/MuBit.md
Normal file
|
|
@ -0,0 +1,63 @@
|
|||
## MuBit
|
||||
|
||||
MuBit(n: int)
|
||||
|
||||
- n: number of intricated QuBits
|
||||
|
||||
### Attributes
|
||||
|
||||
- ```__n: int```
|
||||
|
||||
the number of intricated QuBits represented by this MuBit
|
||||
|
||||
- ```__state: list[complexe]```
|
||||
|
||||
list of the values for the state |0...0>, |0...01>, |0...010>, |0...011> etc...
|
||||
|
||||
### Methode
|
||||
|
||||
- ```__init__(n: int=2) -> None```
|
||||
|
||||
initiates the mubit with n QuBits.
|
||||
|
||||
- ```get_size() -> int```
|
||||
|
||||
return __n
|
||||
|
||||
- ```__str__() -> str```
|
||||
|
||||
returns a string representation of the list of __state. Each state is named and draw in a new line.
|
||||
|
||||
- ```__set(i: int, value: int)```
|
||||
|
||||
force the i-th QuBit of the MuBit to take the state value. Value must be 0 or 1.
|
||||
|
||||
- ```__iter__() -> Iterator[IQuBit]```
|
||||
|
||||
creates an interator of __state.
|
||||
|
||||
- ```__getitem__(item: int) -> IQubIt```
|
||||
|
||||
creates an intricated QuBit corresponding to the item-th QuBit.
|
||||
|
||||
- ```__apply(m: Matrix) -> None```
|
||||
|
||||
takes a Matrix and modifies the QuBits according the matrix.
|
||||
|
||||
- ```__mapply(m: Matrix, i: int) -> None```
|
||||
|
||||
takes a Matrix and modifies the i-th QuBit according the matrix.
|
||||
|
||||
- ```__getProbs(i: int) -> float```
|
||||
|
||||
returns the probability to get the i-th QuBit in the state |0>.
|
||||
|
||||
- ```observe() -> list[int]```
|
||||
|
||||
forces the QuBits in a state, where the probabilities are given throught __state. Returns the list of the state of each QuBit.
|
||||
|
||||
### Staticmethods
|
||||
|
||||
- ```intricateThem(*args: QuBit) -> MuBit```
|
||||
|
||||
returns a new QuBit, independent of the args, but corresponding to the intrication of all given QuBits
|
||||
42
docs/QuBit/QuBit.md
Normal file
42
docs/QuBit/QuBit.md
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
## QuBit
|
||||
|
||||
QuBit(alpha: complexe, beta: complexe)
|
||||
|
||||
- alpha: complexe value for |0>
|
||||
- beta: complexe value for |1>
|
||||
|
||||
### Attributes
|
||||
|
||||
- ```__state: list[complexe]```
|
||||
|
||||
list of the values for the state |0> and |1>
|
||||
|
||||
- ```__intricated: bool```
|
||||
|
||||
tells if the qubit is intricated or not
|
||||
|
||||
### Methode
|
||||
|
||||
- ```__init__(alpha: complexe=1, beta: complexe=0) -> None```
|
||||
|
||||
initiates the qubit
|
||||
|
||||
- ```is_intricated() -> bool```
|
||||
|
||||
returns the value of __intricated
|
||||
|
||||
- ```get_MuBit() -> None```
|
||||
|
||||
returns the MuBit in wich the QuBit is intricated. If not intricated, rerurns None
|
||||
|
||||
- ```__str__() -> str```
|
||||
|
||||
returns a string representation of the list of __state
|
||||
|
||||
- ```__apply(m: Matrix) -> None```
|
||||
|
||||
takes a Matrix and modifies the QuBit according the matrix
|
||||
|
||||
- ```observe() -> list[int]```
|
||||
|
||||
forces the QuBit in a state, where the probabilities are given throught __state. Returns the state obtained.
|
||||
Loading…
Reference in a new issue