Metadata-Version: 2.1
Name: pyqbit
Version: 0.1.0
Summary: Quantum bit and the usual gates in numeric forms straight from the Wikipedia
Home-page: https://github.com/kummahiih/pyqubit
Author: Pauli Rikula
Author-email: UNKNOWN
License: MIT
Platform: UNKNOWN
Classifier: License :: OSI Approved :: MIT License
Classifier: Programming Language :: Python :: 3.6
Requires-Python: ~=3.6
Requires-Dist: numpy (>=1.18.1)

# pyqbit
Quantum bit and the usual gates in numeric forms straight from the Wikipedia.
## Apply
Apply gate to a state

For example this chain evaluates to zero:

    >>> from functools import reduce
    >>> s = reduce( Apply, [Zero(), H(), PauliZ(), H(), PauliX()])
    >>> Measure.One(s)
    0

Swap places of a bit

    >>> one = Combine(Zero(), One())
    >>> Measure.One(one)
    1
    >>> one
    array([[0],
           [1],
           [0],
           [0]])
    >>> two = Apply(one, SWAP())
    >>> Measure.One(two)
    2
    >>> two
    array([[0],
           [0],
           [1],
           [0]])



## Quantum bit definitions

### Zero
Qubit that evaluates as zero every single time

    >>> Zero
    |0>
    >>> Zero()
    array([[1],
           [0]])
    >>> Measure.One(Zero())
    0


### One
Qubit that evaluates as one every single time

    >>> One
    |1>
    >>> One()
    array([[0],
           [1]])
    >>> Measure.One(One())
    1


### Plus
Qubit that evaluates as one and zero evenly

    >>> Plus
    |+>
    >>> Plus()
    array([[0.70710678],
           [0.70710678]])


### Minus
Qubit that evaluates as one and zero evenly

    >>> Minus
    |->
    >>> Minus()
    array([[ 0.70710678],
           [-0.70710678]])


### Measure
Simulates the measure process of the qubit

    >>> Measure.One(One())
    1


### Combine
Use Kronecker product of two arrays to combine qubits.

    >>> Combine(Zero(),Zero())
    array([[1],
           [0],
           [0],
           [0]])


    >>> from functools import reduce
    >>> reduce(Combine, [One(), Zero(), Zero()])
    array([[0],
           [0],
           [0],
           [0],
           [1],
           [0],
           [0],
           [0]])

Each row represents the probability of getting it's index's value as a result

    >>> Measure.One(Combine(Zero(),Zero()))
    0

    >>> Measure.One( Combine(One(), Combine(Zero(),Zero())) )
    4


## Quantum gates

### Identity
Identity gate

    >>> Identity
    Identity
    >>> Identity()
    array([[1, 0],
           [0, 1]])


### H
Hadamard gate

    >>> H
    H
    >>> H()
    array([[ 0.70710678,  0.70710678],
           [ 0.70710678, -0.70710678]])


### PauliX
Pauli X gate

    >>> PauliX
    X
    >>> PauliX()
    array([[0, 1],
           [1, 0]])


### PauliY
Pauli Y gate

    >>> PauliY
    Y
    >>> PauliY()
    array([[ 0.+0.j, -0.-1.j],
           [ 0.+1.j,  0.+0.j]])


### PauliZ
Pauli Z gate

    >>> PauliZ
    Z
    >>> PauliZ()
    array([[ 0,  1],
           [ 0, -1]])


### Phase
Phase (S, P) gate

    >>> Phase
    P
    >>> Phase()
    array([[1.+0.j, 0.+0.j],
           [0.+0.j, 0.+1.j]])


### R
R is the custom phase shift gate

    >>> from math import pi
    >>> R(pi/4)
    R(0.7853981633974483)
    >>> R(pi/4)()
    array([[1.        +0.j        , 0.        +0.j        ],
           [0.        +0.j        , 0.70710678+0.70710678j]])


### CNOT
CNOT is the Controlled Not gate (CX)

    >>> CNOT
    CX
    >>> CNOT()
    array([[1, 0, 0, 0],
           [0, 1, 0, 0],
           [0, 0, 0, 1],
           [0, 0, 1, 0]])


### CPauliZ
CPauliZ is the Controlled Pauli Z gate (CZ)

    >>> CPauliZ
    CZ
    >>> CPauliZ()
    array([[ 1,  0,  0,  0],
           [ 0,  1,  0,  0],
           [ 0,  0,  1,  0],
           [ 0,  0,  0, -1]])


### SWAP
SWAP is the qbit swap gate

    >>> SWAP
    SWAP
    >>> SWAP()
    array([[1, 0, 0, 0],
           [0, 0, 1, 0],
           [0, 1, 0, 0],
           [0, 0, 0, 1]])



