# 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
Metadata
Release files for pyqbit 0.2.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| pyqbit-0.2.2-py3-none-any.whl | Python 3 | none | any | Details for pyqbit-0.2.2-py3-none-any.whl |
Release files / pyqbit-0.2.2-py3-none-any.whl
| Download URL | pyqbit-0.2.2-py3-none-any.whl |
|---|---|
| Size | 6.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
22794e4356d7187d039f7f533d9266d91e17bd030fec011f09d7d1213d5fb7ab
|
|
BLAKE2b-256 checksum How to use checksums |
0667c3c7b992b84e09c3234eef4963397972c9a12683a6fb249d93048aabb087
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is 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
|
Security for pyqbit 0.2.2
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.