Skip to content

Commit c6b9408

Browse files
authored
Update README.md (#2)
1 parent b742089 commit c6b9408

3 files changed

Lines changed: 129 additions & 107 deletions

File tree

README.md

Lines changed: 0 additions & 106 deletions
This file was deleted.

README.rst

Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
Python CHP Stabilizer Simulator
2+
-------------------------------
3+
4+
A simple reference python implementation of Scott Aaronson and Daniel Gottesman's CHP simulator
5+
as defined in
6+
`their 2004 paper "Improved Simulation of Stabilizer Circuits" <https://arxiv.org/abs/quant-ph/0406196>`__.
7+
This simulator is capable of simulating quantum stabilizer circuits in polynomial time and space.
8+
Specifically, it uses ``O(q^2*m + q*c)`` time and ``O(q^2)`` space where
9+
``q`` is the number of qubits,
10+
``m`` is the number of measurements,
11+
and ``c`` is the number of Hadamard/CNOT/Phase gates.
12+
13+
Installation
14+
------------
15+
16+
The ``chp_sim`` package is available on pypi and can be installed using ``pip``:
17+
18+
.. code-block:: bash
19+
20+
python -m pip install chp_sim
21+
22+
Alternatively, you can just copy paste the ``chp_sim`` directory of the github
23+
repository into your project.
24+
The only runtime dependency is ``numpy``.
25+
26+
Usage
27+
-----
28+
29+
Here is an example of simulating
30+
`a circuit <https://algassert.com/quirk#circuit=%7B%22cols%22%3A%5B%5B1%2C1%2C%22H%22%5D%2C%5B%22X%22%2C1%2C%22%E2%80%A2%22%5D%2C%5B1%2C%22X%22%2C%22%E2%80%A2%22%5D%2C%5B%22Z%5E%C2%BD%22%2C%22Z%5E%C2%BD%22%5D%2C%5B%22H%22%2C%22H%22%2C%22H%22%5D%2C%5B%22Measure%22%2C%22Measure%22%2C%22Measure%22%5D%2C%5B%22Chance3%22%5D%5D%7D>`__:
31+
32+
.. code-block:: python
33+
34+
import chp_sim
35+
sim = chp_sim.ChpSimulator(num_qubits=3)
36+
37+
# Desired circuit:
38+
# 0: -------X-------S---H---M---
39+
# |
40+
# 1: -------|---X---S---H---M---
41+
# | |
42+
# 2: ---H---@---@-------H---M---
43+
44+
sim.hadamard(2)
45+
sim.cnot(2, 0)
46+
sim.cnot(2, 1)
47+
sim.phase(0)
48+
sim.phase(1)
49+
sim.hadamard(0)
50+
sim.hadamard(1)
51+
sim.hadamard(2)
52+
53+
# Show internal simulator state.
54+
print(sim, '\n')
55+
# prints:
56+
# -Y..
57+
# -.Y.
58+
# +..X
59+
# ----
60+
# +X.X
61+
# +.XX
62+
# +YYZ
63+
64+
# Perform measurements
65+
v0 = sim.measure(0)
66+
v1 = sim.measure(1)
67+
v2 = sim.measure(2)
68+
print(v0)
69+
print(v1)
70+
print(v2)
71+
# prints [note: one of four possible results for this circuit]:
72+
# True (random)
73+
# False (random)
74+
# False (determined)
75+
76+
# Check pattern the outputs should satisfy.
77+
assert not v0.determined
78+
assert not v1.determined
79+
assert v2.determined
80+
assert bool(v0) ^ bool(v1) ^ bool(v2)
81+
82+
83+
Packaging
84+
---------
85+
86+
(Notes to self on how to release a new version.)
87+
88+
1. Edit the source code as needed and run tests.
89+
90+
.. code-block:: bash
91+
92+
pytest
93+
94+
2. Build the wheel.
95+
96+
.. code-block:: bash
97+
98+
python3 setup.py -q bdist_wheel
99+
ls dist
100+
101+
3. Upload to test pypi.
102+
103+
.. code-block:: bash
104+
105+
twine upload dist/*.whl --repository-url=https://test.pypi.org/legacy/ --username="${TEST_TWINE_USERNAME}" --password="${TEST_TWINE_PASSWORD}"
106+
107+
4. Verify the test package works.
108+
109+
.. code-block:: bash
110+
111+
mkvirtualenv test --python=/usr/bin/python3
112+
pip install numpy
113+
pip install chp_sim --index-url=https://test.pypi.org/simple/
114+
python -c "import chp_sim; print(chp_sim.__version__); print(chp_sim.ChpSimulator(4))"
115+
116+
5. Upload to prod pypi.
117+
118+
.. code-block:: bash
119+
120+
twine upload dist/*.whl --username="${PROD_TWINE_USERNAME}" --password="${PROD_TWINE_PASSWORD}"
121+
122+
6. Verify the prod package works.
123+
124+
.. code-block:: bash
125+
126+
mkvirtualenv test --python=/usr/bin/python3
127+
pip install chp_sim
128+
python -c "import chp_sim; print(chp_sim.__version__); print(chp_sim.ChpSimulator(4))"

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
"for efficiently simulating quantum stabilizer circuits.")
2424

2525
# README file as long_description.
26-
long_description = io.open('README.md', encoding='utf-8').read()
26+
long_description = io.open('README.rst', encoding='utf-8').read()
2727

2828
# Read in requirements
2929
requirements = open('requirements.txt').readlines()

0 commit comments

Comments
 (0)