Python CHP Stabilizer Simulator
A simple reference python implementation of Scott Aaronson and Daniel Gottesman’s CHP simulator as defined in their 2004 paper “Improved Simulation of Stabilizer Circuits”. This simulator is capable of simulating quantum stabilizer circuits in polynomial time and space. Specifically, it uses O(q^2*m + q*c) time and O(q^2) space where q is the number of qubits, m is the number of measurements, and c is the number of Hadamard/CNOT/Phase gates.
Installation
The chp_sim package is available on pypi and can be installed using pip:
python -m pip install chp_sim
Alternatively, you can just copy paste the chp_sim directory of the github repository into your project. The only runtime dependency is numpy.
Usage
Here is an example of simulating a circuit:
import chp_sim
sim = chp_sim.ChpSimulator(num_qubits=3)
# Desired circuit:
# 0: -------X-------S---H---M---
# |
# 1: -------|---X---S---H---M---
# | |
# 2: ---H---@---@-------H---M---
sim.hadamard(2)
sim.cnot(2, 0)
sim.cnot(2, 1)
sim.phase(0)
sim.phase(1)
sim.hadamard(0)
sim.hadamard(1)
sim.hadamard(2)
# Show internal simulator state.
print(sim, '\n')
# prints:
# -Y..
# -.Y.
# +..X
# ----
# +X.X
# +.XX
# +YYZ
# Perform measurements
v0 = sim.measure(0)
v1 = sim.measure(1)
v2 = sim.measure(2)
print(v0)
print(v1)
print(v2)
# prints [note: one of four possible results for this circuit]:
# True (random)
# False (random)
# False (determined)
# Check pattern the outputs should satisfy.
assert not v0.determined
assert not v1.determined
assert v2.determined
assert bool(v0) ^ bool(v1) ^ bool(v2)
Packaging
(Notes to self on how to release a new version.)
Edit the source code as needed and run tests.
pytestBuild the wheel.
python3 setup.py -q bdist_wheel ls distUpload to test pypi.
twine upload dist/*.whl --repository-url=https://test.pypi.org/legacy/ --username="${TEST_TWINE_USERNAME}" --password="${TEST_TWINE_PASSWORD}"Verify the test package works.
mkvirtualenv test --python=/usr/bin/python3 pip install numpy pip install chp_sim --index-url=https://test.pypi.org/simple/ python -c "import chp_sim; print(chp_sim.__version__); print(chp_sim.ChpSimulator(4))"Upload to prod pypi.
twine upload dist/*.whl --username="${PROD_TWINE_USERNAME}" --password="${PROD_TWINE_PASSWORD}"Verify the prod package works.
mkvirtualenv test --python=/usr/bin/python3 pip install chp_sim python -c "import chp_sim; print(chp_sim.__version__); print(chp_sim.ChpSimulator(4))"
Metadata
Release files for chp-sim 0.1.1
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 |
|---|---|---|---|---|
| chp_sim-0.1.1-py3-none-any.whl | Python 3 | none | any | Details for chp_sim-0.1.1-py3-none-any.whl |
Release files / chp_sim-0.1.1-py3-none-any.whl
| Download URL | chp_sim-0.1.1-py3-none-any.whl |
|---|---|
| Size | 11.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
760cbab16cbd6d96923d2a1db790158b0d9f23ceacf1ae56220492b1b5941524
|
|
BLAKE2b-256 checksum How to use checksums |
307c8cd37f6f0bf0eae8c63b4366eddf84a7df230930fd5594da538c42810557
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.32.2 CPython/3.6.5
|
Security for chp-sim 0.1.1
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.