A fast library for analyzing with quantum stabilizer circuits.
Project description
Stim
Stim is a fast simulator for quantum stabilizer circuits.
API references are available on the stim github wiki: https://github.com/quantumlib/stim/wiki
Stim can be installed into a python 3 environment using pip:
pip install stim
Once stim is installed, you can import stim
and use it.
There are three supported use cases:
- Interactive simulation with
stim.TableauSimulator
. - High speed sampling with samplers compiled from
stim.Circuit
. - Independent exploration using
stim.Tableau
andstim.PauliString
.
Interactive Simulation
Use stim.TableauSimulator
to simulate operations one by one while inspecting the results:
import stim
s = stim.TableauSimulator()
# Create a GHZ state.
s.h(0)
s.cnot(0, 1)
s.cnot(0, 2)
# Look at the simulator state re-inverted to be forwards:
t = s.current_inverse_tableau()
print(t**-1)
# prints:
# +-xz-xz-xz-
# | ++ ++ ++
# | ZX _Z _Z
# | _X XZ __
# | _X __ XZ
# Measure the GHZ state.
print(s.measure_many(0, 1, 2))
# prints one of:
# [True, True, True]
# or:
# [False, False, False]
High Speed Sampling
By creating a stim.Circuit
and compiling it into a sampler, samples can be generated very quickly:
import stim
# Create a circuit that measures a large GHZ state.
c = stim.Circuit()
c.append("H", [0])
for k in range(1, 30):
c.append("CNOT", [0, k])
c.append("M", range(30))
# Compile the circuit into a high performance sampler.
sampler = c.compile_sampler()
# Collect a batch of samples.
# Note: the ideal batch size, in terms of speed per sample, is roughly 1024.
# Smaller batches are slower because they are not sufficiently vectorized.
# Bigger batches are slower because they use more memory.
batch = sampler.sample(1024)
print(type(batch)) # numpy.ndarray
print(batch.dtype) # numpy.uint8
print(batch.shape) # (1024, 30)
print(batch)
# Prints something like:
# [[1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1]
# [0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0]
# [1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1]
# ...
# [1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1]
# [1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1]
# [0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0]
# [1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1]]
This also works on circuits that include noise:
import stim
import numpy as np
c = stim.Circuit("""
X_ERROR(0.1) 0
Y_ERROR(0.2) 1
Z_ERROR(0.3) 2
DEPOLARIZE1(0.4) 3
DEPOLARIZE2(0.5) 4 5
M 0 1 2 3 4 5
""")
batch = c.compile_sampler().sample(2**20)
print(np.mean(batch, axis=0).round(3))
# Prints something like:
# [0.1 0.2 0. 0.267 0.267 0.266]
You can also sample annotated detection events using stim.Circuit.compile_detector_sampler
.
For a list of gates that can appear in a stim.Circuit
, see the latest readme on github.
Independent Exploration
Stim provides data types stim.PauliString
and stim.Tableau
, which support a variety of fast operations.
import stim
xx = stim.PauliString("XX")
yy = stim.PauliString("YY")
assert xx * yy == -stim.PauliString("ZZ")
s = stim.Tableau.from_named_gate("S")
print(repr(s))
# prints:
# stim.Tableau.from_conjugated_generators(
# xs=[
# stim.PauliString("+Y"),
# ],
# zs=[
# stim.PauliString("+Z"),
# ],
# )
s_dag = stim.Tableau.from_named_gate("S_DAG")
assert s**-1 == s_dag
assert s**1000000003 == s_dag
cnot = stim.Tableau.from_named_gate("CNOT")
cz = stim.Tableau.from_named_gate("CZ")
h = stim.Tableau.from_named_gate("H")
t = stim.Tableau(5)
t.append(cnot, [1, 4])
t.append(h, [4])
t.append(cz, [1, 4])
t.prepend(h, [4])
assert t == stim.Tableau(5)
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distributions
Hashes for stim-1.14.dev1716327428-cp312-cp312-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a51b2e305f72c2300f24d196e366426bceeaeb6f7b7966f3a0866609e99d603e |
|
MD5 | 1946c8f4bea267bbf92ce82679746a7e |
|
BLAKE2b-256 | b78e3f7c4fa3c41156694e5e74c2f07f4cff7b75a4aeeed67568a9443baab30f |
Hashes for stim-1.14.dev1716327428-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 968a24bbe383f64079230ba434df37324e339f1cccaffae6c1a66327999dabc3 |
|
MD5 | a841601521e6fe325c8df5c0ce8d5993 |
|
BLAKE2b-256 | 00ffd209a8b82dff2397edde7c6e43428576a3b2fffd90fd85fa3fa1d2a9bb98 |
Hashes for stim-1.14.dev1716327428-cp312-cp312-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e6695773e6f693cb3678e2b5d12c240851172b18b7ad529d9f7f7084fc3b2d07 |
|
MD5 | cbd9344bbad5ad51dcd65dde6b84441d |
|
BLAKE2b-256 | 97e470cf8c5406f089b7bc1c340e9880bd1d654196dac03f0f3df5a57169587b |
Hashes for stim-1.14.dev1716327428-cp312-cp312-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 06915c9e3a232f7aaa0809b75be1dd29c04fcaa3c3d41bf111382bba1ca04a07 |
|
MD5 | 087bbf5823b7bd1f4958344e5fb5c386 |
|
BLAKE2b-256 | 40d1e21457c65ac047179fb1b8eb70fa46ba801b8ab8529dc8affcfa61f6309a |
Hashes for stim-1.14.dev1716327428-cp311-cp311-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3c188bc36de2993258823845c8427699b9e67dd8aade5ef9f57fa62aba5bf165 |
|
MD5 | ee3fa75af4fcacc5891d52205a563205 |
|
BLAKE2b-256 | 35db78b28d0b07f35a9fb13aeb220dca67c63570c6f7c4bfc36f883f22bae134 |
Hashes for stim-1.14.dev1716327428-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7085af2748ba963e47119a130031f4634ce16fc7a615c5bdd560d7c23e4faad0 |
|
MD5 | e7e15858f4478532ffeff2de532b7cc9 |
|
BLAKE2b-256 | 93ca1796bc2444fc51e3ca7c0e45b4e17236e7dec52d684e5b2a0d9df4720f39 |
Hashes for stim-1.14.dev1716327428-cp311-cp311-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d4d12c0048a0c39841a2190d00a20b97379b118c6ec3f40cde0c48e094c3bf47 |
|
MD5 | 0456c4efc2b9b995e69b55c56e3b5a91 |
|
BLAKE2b-256 | f501a7639232c8b980a9e35a7e15009ad8da44317f102c7b9ae23a265c7dc6c6 |
Hashes for stim-1.14.dev1716327428-cp311-cp311-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c60689d28e5c8de972194c390acac20b8f68b8e4309babdef45d046bd080ced1 |
|
MD5 | f00b6c379007d48b9f1fef27cbe8e55d |
|
BLAKE2b-256 | b87a5eb9224f8a90c6681a9025fa610f2c630b27622501ab950958ee2249ef26 |
Hashes for stim-1.14.dev1716327428-cp310-cp310-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6a1eac4c3cc2fe2f1b62a436b697cea8bd8c600bd02bc1bc6a1f1d1ff839b068 |
|
MD5 | 0b76e21bb60f2e8d129cd1412b3de741 |
|
BLAKE2b-256 | 4b44d8a4618d38b6d33b1038fee07fb6d3da89665f94aff16107443a1ca44d7a |
Hashes for stim-1.14.dev1716327428-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4fc16403c926b55e3d16e05e067a50ccea7fcce1ab671477e5026ae7bede73b4 |
|
MD5 | fda2f9f735f121e92913260948f744a6 |
|
BLAKE2b-256 | 10a3a89363a4492664c93e460494a00356cce2e5577ed872040054e982570cc4 |
Hashes for stim-1.14.dev1716327428-cp310-cp310-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 15622316b5cd9d639866899ceedb5b57ea99ef8446e2c2be0a5cbfefda6aaccd |
|
MD5 | 8f2692d24b2d5b9ce98c3bbf9f311088 |
|
BLAKE2b-256 | 020719d5345d18b8c055f7841c1d2e656b956c10af8eead28997d0e21b63e6c4 |
Hashes for stim-1.14.dev1716327428-cp310-cp310-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c9bdf73f732085decd1647149bd73f511bcedd7a6866262761c469db52dc9a36 |
|
MD5 | 159e3501227443317aba4a7094df415c |
|
BLAKE2b-256 | 42476cd20ad6d72eec434d1fcf8becb4de74528a847d2c62eb08ad7b560d9a90 |
Hashes for stim-1.14.dev1716327428-cp39-cp39-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 062efc146edb66ec3dbb3436229561624de11f4c64ef845eae90c41dd8eafa70 |
|
MD5 | 55624e93f833243e242b06c846614f98 |
|
BLAKE2b-256 | f9e2201ab9e2a0dcc1dbddab3b5bacf9092a618bdcf772ae7c8f80668b9d6085 |
Hashes for stim-1.14.dev1716327428-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e61b3537d572605cd90d5db5b37d172f03df66f45fe6c8f28e43ba300c7dcf25 |
|
MD5 | 9fb9a684649050e25d8778475ad49bd8 |
|
BLAKE2b-256 | 7072f4533fee7ad630efe208e90cfddd0ef81f2868b16557c0659a4ee4caa7fe |
Hashes for stim-1.14.dev1716327428-cp39-cp39-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2d1c0f50346a3a74dfe37023067a0771258d551a05c0093432f6fc412f66d32a |
|
MD5 | 62793828ea147028c774a79cd6f706ed |
|
BLAKE2b-256 | e041350036981a2e04e8faf9111166b4526e09119e1e465b79ead0d2ee95f65d |
Hashes for stim-1.14.dev1716327428-cp39-cp39-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9840283f878b5b2b4cb65a53e7b5f539c5d1f53b33edbd237611bba026683f8b |
|
MD5 | 572884c1d37ee50838dc10c4dfea8aa1 |
|
BLAKE2b-256 | ab92defb5c5d7fc966e401c1bf009aa5eae45536705059bab7fdffa2e89455c1 |
Hashes for stim-1.14.dev1716327428-cp38-cp38-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3eec54178e8be0025e4010396ff6cf1c63e6b51862e2635bce4ee92a0a002a9f |
|
MD5 | 923d12c551e5febb2d298437fa0f2b7b |
|
BLAKE2b-256 | e89ab57be6eb5622cceb30835d429c8b2200fc1a7964adf7d07a538409d7a37b |
Hashes for stim-1.14.dev1716327428-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 645e23654cad19824202a2f1cc91d592fe12a9533bbc077980312982fa0b320f |
|
MD5 | bf7fb5c4de71ba4e77173376e7dc44d1 |
|
BLAKE2b-256 | d02c19725cbcd59d4294536c2dec7c4c60a337a911e280302f69497447a50c56 |
Hashes for stim-1.14.dev1716327428-cp38-cp38-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e4a5c85dddd8340bdbb4399ed509be79ea4a129805dec2fe19a35071aa060744 |
|
MD5 | 0bba598f984aaa1b01b78b75d62aa46c |
|
BLAKE2b-256 | 80342ec665c9f55597aabb246663f8d9d872a8b0d0c2642e350003dcc56704d7 |
Hashes for stim-1.14.dev1716327428-cp38-cp38-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1a2bef2977290c5d55b70964a5772e6fa4f138a8446379e5b43edc4e1425aae7 |
|
MD5 | 2736e7a0cbfec54198dd8d2395575b59 |
|
BLAKE2b-256 | 51fb798da89487b6607c58ee2cf26226df6bfef606ecdbd1015bdee62caf3a4f |
Hashes for stim-1.14.dev1716327428-cp37-cp37m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 76e23e96e3787bc14d7fe1ec13a9beeb7570751868e290aad4eea9d087d8a93b |
|
MD5 | 3ad66481a173ade4694f2def7936c1d8 |
|
BLAKE2b-256 | 22da1f362977b551e8353047706b06886d7f10c86dd895c09c5403a766fbabba |
Hashes for stim-1.14.dev1716327428-cp37-cp37m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | dac0b3caeb9d3140533b111008e8552cd2ac7b658658311ba384890ec20689f1 |
|
MD5 | 7f4f064dde802eea6f015805e9fa6249 |
|
BLAKE2b-256 | 6a0a5c4c3f16dca3c6c97a93bc9bc7b4065bf1bffc0a6b238cfda574bae46f8e |
Hashes for stim-1.14.dev1716327428-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c28e9b4fe31b8a34164935905fa9999f60443f0a89f8ba0563be6138fc199a9a |
|
MD5 | 7622a79bf5da49179238f99dc7bf62fd |
|
BLAKE2b-256 | 5767a34b9a6f52ce0126af7ac50b77a8b13f01725d552c8050750145d66084fa |
Hashes for stim-1.14.dev1716327428-cp37-cp37m-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8fdc988459102244c7005631a3b7e0f2298cd44a05ca7bdc122f8ba8aca427cf |
|
MD5 | 36a10aa232f4639a3a73506447dc12fa |
|
BLAKE2b-256 | 368699ed79d62b351f80bd462402a63bb4b60ae3132f48a118624204b2a162d8 |
Hashes for stim-1.14.dev1716327428-cp37-cp37m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ca4ec80161fa85aa568576164ffa19f633089d713dd352c99c95d1e26246dbab |
|
MD5 | 24ae5ff1358129eec8c657e07a6f67d2 |
|
BLAKE2b-256 | 70e5df85c4cfc0f973c5ed00861c4b56ce64189a242b552694c8adb98d1342b0 |
Hashes for stim-1.14.dev1716327428-cp36-cp36m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 46a7cf122fdf5dbbc0c7be48fbbac0974b55963ac0f8c375ef9fe8217b4819a2 |
|
MD5 | 08c3a7da868ed7f7cf50f366351590a0 |
|
BLAKE2b-256 | 564f7e3b61a1b6c0ba65d6d4a1d71154ec0a781ed4ae89725905bdb7785ea9ce |
Hashes for stim-1.14.dev1716327428-cp36-cp36m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 00ecb7f06e46d4730240770bc022168e1a3d0a015e91aaf1b4fb07f284c7b044 |
|
MD5 | 04b202837e8e11f52053384151058803 |
|
BLAKE2b-256 | 2ae1cbee8b5a25506c1ff31b1ab3ee9ea44a3aa4c0e9af12aaa241084b3200f5 |
Hashes for stim-1.14.dev1716327428-cp36-cp36m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 63d6b74afc43e8e665f65b11d0b3584469dad588147e0d88eb23d13f863f16bf |
|
MD5 | 5879ef6b541c6384690b1fd958a00f52 |
|
BLAKE2b-256 | 56972aba43cc545aba39f4cb6736b7770ca17657e57a86178b7948033d8d88c6 |
Hashes for stim-1.14.dev1716327428-cp36-cp36m-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5cb6a12b7247b45a0b06386961ce43c37fadf102bf7abbac8b2cc3c69ea4df2e |
|
MD5 | 5a629af25ad0ac76b663d4a0f3967001 |
|
BLAKE2b-256 | d72acbd9ab06b3ff5c96337cda44a095d7488bd41571cb4aaaed845a644ce8bc |
Hashes for stim-1.14.dev1716327428-cp36-cp36m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8876050a9ce352c7250960576b93a2869d605713cdf97fba25fbf2cf20644334 |
|
MD5 | 8340761142fcc892789d4d4d74a8173c |
|
BLAKE2b-256 | b198aebde3e8efba07ff30ef169c39b1b41c73f5eddbdda8c61b634eb3f5eaa8 |