Skip to main content

Quantum bit and the usual gates in numeric forms straight from the Wikipedia

Project description

# 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

### equal The equal is a test if the two qubit states

>>> equal(One(), One())
True
>>> equal(One(), Zero())
False

## 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([[ 1,  0],
       [ 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]])

## Pauli group

### P1 P1 is the First Pauli Group done from the cross product of [-1, 1, -1j, 1j] and [Identity(), PauliX(), PauliY(), PauliZ()]

>>> P1
P1
>>> p1 = list(P1())
>>> len(p1)
16
>>> equal(p1[0], -1*Identity())
True
>>> equal(p1[1], 1*Identity())
True
>>> equal(p1[2], -1j*Identity())
True
>>> equal(p1[3], 1j*Identity())
True
>>> equal(p1[15], 1j*PauliZ())
True

p1 is a group, so these apply:

Associativy:

>>> all([ any([equal(apply(a,b), c) for c in P1()]) for a in P1() for b in P1()])
True

Identity:

>>> equal( Identity(), p1[1])
True
>>> all([ equal(apply(a, Identity()), a) for a in P1()])
True

Inverse element:

>>> all([ any([equal(apply(a, b), Identity()) for b in P1()]) for a in P1() ])
True

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pyqbit-0.2.2-py3-none-any.whl (6.9 kB view details)

Uploaded Python 3

File details

Details for the file pyqbit-0.2.2-py3-none-any.whl.

File metadata

  • Download URL: pyqbit-0.2.2-py3-none-any.whl
  • Upload date:
  • Size: 6.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.11.0 pkginfo/1.4.2 requests/2.19.1 setuptools/40.0.0 requests-toolbelt/0.8.0 tqdm/4.23.4 CPython/2.7.12

File hashes

Hashes for pyqbit-0.2.2-py3-none-any.whl
Algorithm Hash digest
SHA256 22794e4356d7187d039f7f533d9266d91e17bd030fec011f09d7d1213d5fb7ab
MD5 17cfa5e962c8a3127dfe9bbe3d239368
BLAKE2b-256 0667c3c7b992b84e09c3234eef4963397972c9a12683a6fb249d93048aabb087

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page