Quanbit is a pythonic package for simulating quantum computer. It faciliate basic quantum algorithm exploration on a classic computer.
Quanbit is a pure python package supporting Windows
, Linux
and MacOS
.
Example: Quantum Teleportation
from quanbit import X, Y, Z, BellBasis
from quanbit import qubit, bell_state, Measure
import numpy as np
# Alice has an unknown qubit C
theta, phi, alpha = np.random.rand(3)
qubit_C = qubit(theta, phi, alpha)
# To teleport the qubit, Alice and Bob need to share a maximally entangled state
# Anyone of the four states is sufficient, we choose 1/sqrt(2) (|00> + |11>) here
qubit_AB = bell_state(0)
# Now the total state is, where @ represent tensor product:
total_state = qubit_C @ qubit_AB
# Project the state of Alice's two qubits as a superpositions of the Bell basis
total_state = BellBasis(total_state, indices=[0, 1])
# Measuring her two cubits in Bell basis
CA, B_state = Measure(total_state, indices=[0, 1])
# Rotate Bob's state based on the measurement result
# if CA == (0, 0), no change need to be made
# when CA is in state \Psi+
if CA == (0, 1):
B_state = X(B_state)
# when CA is in state \Psi-
elif CA == (1, 0):
B_state = Z(X(B_state))
# when CA is in state \Phi-
elif CA == (1, 1):
B_state = Z(B_state)
# Now Bob's state is the same as Alice initial qubit_C.
Quanbit is distributed under BSD 3-Clause.
- Installation requirements:
numpy
- Testing requirement:
pytest
- QA requirement:
tox
To install Quanbit with pip:
pip install quanbit
To run tests:
pytest quanbit
To install Quanbit to system:
pip install .
To install editable Quanbit locally:
pip install -e .
To run tests:
pytest tests
To run QA locally:
tox