Skip to main content

Helper library for quantum matrix math

Project description

QGates

Build Status PyPI PyPI - Python Version GitHub last commit PyPI - License

created by Austin Poor

A small file with some helper functions and quantum gates represented as numpy matrices.

Requirements

Installation

pip install qgates

Usage

Helper Functions

qgates.tens(a,*b)

Computes the tensor product of two or more numbers, vectors, or matrices.

qgates.matmul(a,*b)

Multiplies two or more vectors, or matrices. Wrapper around the built-in matmul operator.

qgates.state(arr)

Creates a state vector from either an iterable of 1s and 0s (or from an int that will be converted to a state vector based on its binary representation.

qgates.conjugate(v)

Computes the complex conjugate of a number or numpy array.

State Vectors

Basic Qubits

qgates.QB0: Quantum state 0

qgates.QB1: Quantum state 1

qgates.QB00: Quantum state 00

qgates.QB01: Quantum state 01

qgates.QB10: Quantum state 10

qgates.QB11: Quantum state 11

Bell States

qgates.BELL00: Bell state 00

qgates.BELL01: Bell state 01

qgates.BELL10: Bell state 10

qgates.BELL11: Bell state 11

Gate Matrices

qgates.IDEN: 2x2 Identity matrix

[[ 1, 0 ],
 [ 0, 1 ]]

qgates.NOT: 2x2 NOT matrix

[[ 0, 1 ],
 [ 1, 0 ]]

qgates.OR: 2x4 OR matrix

[[ 1, 0, 0, 0 ],
 [ 0, 1, 1, 1 ]]

qgates.AND: 2x4 AND matrix

[[ 1, 1, 1, 0 ],
 [ 0, 0, 0, 1 ]]

qgates.XOR: 2x4 XOR matrix

[[ 1, 0, 0, 1 ],
 [ 0, 1, 1, 0 ]]

qgates.NOR: 2x4 NOR matrix

[[ 0, 1, 1, 1 ],
 [ 1, 0, 0, 0 ]]

qgates.NAND: 2x4 NAND matrix

[[ 0, 0, 0, 1 ],
 [ 1, 1, 1, 0 ]]

qgates.COPY: A 4x2 gate matrix for copying a state vector

[[ 1, 0 ],
 [ 0, 0 ],
 [ 0, 0 ],
 [ 0, 1 ]]

qgates.SWAP: A 4x4 gate matrix for swapping a the middle two positions of a length-4 state vector

[[ 1, 0, 0, 0 ],
 [ 0, 0, 1, 0 ],
 [ 0, 1, 0, 0 ],
 [ 0, 0, 0, 1 ]]

qgates.CNOT: 4x4 Conditional-NOT gate. (Read more here)

[[ 1, 0, 0, 0 ],
 [ 0, 1, 0, 0 ],
 [ 0, 0, 0, 1 ],
 [ 0, 0, 1, 0 ]]

qgates.TOFFOLI: 8x8 Toffoli gate. (Read more here)

[[1, 0, 0, 0, 0, 0, 0, 0],
 [0, 1, 0, 0, 0, 0, 0, 0],
 [0, 0, 1, 0, 0, 0, 0, 0],
 [0, 0, 0, 1, 0, 0, 0, 0],
 [0, 0, 0, 0, 1, 0, 0, 0],
 [0, 0, 0, 0, 0, 1, 0, 0],
 [0, 0, 0, 0, 0, 0, 0, 1],
 [0, 0, 0, 0, 0, 0, 1, 0]]

qgates.HAD: 2x2 Hadamard gate. (Read more here)

[[ 1/√2,  1/√2 ],
 [ 1/√2, -1/√2 ]]

Project details


Download files

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

Source Distribution

qgates-1.0.3.tar.gz (2.7 kB view hashes)

Uploaded Source

Built Distribution

qgates-1.0.3-py3-none-any.whl (14.6 kB view hashes)

Uploaded Python 3

Supported by

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