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.dev1710897753-cp312-cp312-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 48c3d822336ed21bce718f0904f8337b8027dd96d00775a96531731a45e8624d |
|
MD5 | c28329f6558e3fcc86c4ded9a70ce483 |
|
BLAKE2b-256 | eec4ce72a34bae91386f71decc91a4985ff106a7a5fea0f73d533e1b9351ace0 |
Hashes for stim-1.14.dev1710897753-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 018244709cd600dadc69e2522b3203338f4b915ddb2395b61f00c918ebf3ebfb |
|
MD5 | f3a8954b9e9b799fbd720e2750c1d6ed |
|
BLAKE2b-256 | 22eee42c2e60e9a0f4224d9c1736f14877c55e00d4b9518bcfbc2142f54408ea |
Hashes for stim-1.14.dev1710897753-cp312-cp312-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 37e161ed3cd22f09250499b838941ce8634ecc3319fa1c326aa43bd5a8f51080 |
|
MD5 | bef412f0f8df53b6debe1ee9a85f0d36 |
|
BLAKE2b-256 | 4da9d40bbb1d435cf7a6577e949f734e591c7476d954d571c4c9783e2ef1d919 |
Hashes for stim-1.14.dev1710897753-cp312-cp312-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | eff4c6a9d97b7ef6e2e7c016799fd3dd262456528690b5a454904d0fb06a133b |
|
MD5 | 1806c748a12d65117f646b1b51cf2783 |
|
BLAKE2b-256 | 5e446e0bb0f3286a5cb89266f27e8f005ee5ad0ac4521dd6432fda5cbce6cb1d |
Hashes for stim-1.14.dev1710897753-cp311-cp311-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 244cfd84d2a18e15fa7d7461775931f152ea39bf64a998994177b825cfbd3aae |
|
MD5 | dd51b0677659a911be16cd71d2e96385 |
|
BLAKE2b-256 | 14b3d4191a992abe30b54921b71411d9fd776d61b1f4f03eb6b29692585fb8af |
Hashes for stim-1.14.dev1710897753-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 963afeb9f2623426965d3cda3db76ce19c759fd8c269696bbc0e73f5329b039b |
|
MD5 | 390e34ad6006e295b8169c8a185ccca7 |
|
BLAKE2b-256 | 1c2dca2e0bec4759e197e611636b71f53487c5ed72c7982dc388422f0a2c4b94 |
Hashes for stim-1.14.dev1710897753-cp311-cp311-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | deab0263b16c441552265ca5cd442567ae04459f577c8dea20332875177a6d38 |
|
MD5 | 4c7e0f6b5ad4495d3c0b6c3aa432409f |
|
BLAKE2b-256 | 56a909438608f130b4bf169cecebaafc41190a5b81631adf286bafaa11228c0b |
Hashes for stim-1.14.dev1710897753-cp311-cp311-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8ce237ad6ad58e9747dc128b40b668e1c52d7568d848ef7590afd9091050fd35 |
|
MD5 | a15eef0ea0017e74565579ef7800d9a2 |
|
BLAKE2b-256 | eeda42a11d30a3becfebd9877eb0de0cd11f22da708ccc3fa26aeda365d05883 |
Hashes for stim-1.14.dev1710897753-cp310-cp310-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 77e462697406b0c376976586ddf126d1fe61e27cdbe3d4adaee932eff55740ce |
|
MD5 | 57f786f20b3144a9b009415ee7fe4aa1 |
|
BLAKE2b-256 | 9704e13fb956a0e5b719d8c8e01567d06f1aab4337ec485a3ad516661c10de01 |
Hashes for stim-1.14.dev1710897753-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 03119a58599ff38e2f2b21221cea45c6ce11e8b22dfe03745b7f35e27f8e2bea |
|
MD5 | f117650541278905042e822abde260fb |
|
BLAKE2b-256 | b692ae9eb35c39cd51276c1f9e4bf5be383ecbbb9d63cf1eee6d7c6e38fecc03 |
Hashes for stim-1.14.dev1710897753-cp310-cp310-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3b1b2df1009322535975c15e2fdfe048af38b833c433d90699e2e3c8bb463414 |
|
MD5 | 1eec623ebc7249d39ba03f5adaaa31ea |
|
BLAKE2b-256 | 465b7650aafb8b6063bd58c90956cea42c4385e629cc8435691d9309057b4c2a |
Hashes for stim-1.14.dev1710897753-cp310-cp310-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 39a901c62f852caf6ba4c67f7fcfd71deac35ed2490ae408e7ffa080d36e047b |
|
MD5 | 7ad0ce63a018802eb3c57c82f66b2ede |
|
BLAKE2b-256 | 358b500d4055caafb8e53bc6fd71759dcdebae9ce4324e1e62da57bb36fb7e46 |
Hashes for stim-1.14.dev1710897753-cp39-cp39-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1e77cedef04effe9f65f6dcd9bb71933a5075b2ab7f6960091f27c0a0d27c057 |
|
MD5 | 7831e1476ef9235c7d8d74894b33a7de |
|
BLAKE2b-256 | c3cd958c8f544ff1e6042b442857337d6aa9656cf6d0215041fcd6732332a190 |
Hashes for stim-1.14.dev1710897753-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c9a0884053d57a4dba95ab76261272f66a440c60ddb3bafb9e9a8d3ba6f65a9a |
|
MD5 | 7ab9ee06b0d7d31bb6d9488beb02f7a9 |
|
BLAKE2b-256 | 85e550baf872a3fa40d283d79702d81ee39d5ec2041df5b0c0e88da9f62aa3ad |
Hashes for stim-1.14.dev1710897753-cp39-cp39-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f3b55345a5484fd4161f8e26d9d8b121c97ff7913ca30d40b2cff2a1802ada90 |
|
MD5 | d043e9befdf47a8c4cfe095d074e400d |
|
BLAKE2b-256 | f9d34cc9fa9b0041a487ba646dedf0090776fa8d7bd17941564c77fd07736792 |
Hashes for stim-1.14.dev1710897753-cp39-cp39-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4f79beb272ba165d07d073ecedc96ab46cfdb4395ead30a3afdf3384ce740fec |
|
MD5 | e0ba2db836cbff835ef280c5a9940966 |
|
BLAKE2b-256 | 8a841b33cb87f56db67a76a023763e9df28049364625de2961e7db5e29613143 |
Hashes for stim-1.14.dev1710897753-cp38-cp38-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1bc461a384dab0930e315dd52469383ccb2de67342a1ca5c896814ae46338673 |
|
MD5 | 169b9aef77a9ca90b1f79a386e802b33 |
|
BLAKE2b-256 | ad5e8f1dc8567be2684768de211cce09c12924996970688619a3ceca7b950572 |
Hashes for stim-1.14.dev1710897753-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 94c2292b066a499bc45ea66e9219f9f7d7add8fc20699d77f3e6873d9e696910 |
|
MD5 | c7a13ff6ca3207e7a2c01971afcc4834 |
|
BLAKE2b-256 | 6ec124f6d2f562c8f59660d088e29e9683efa676306341c99251cc7740d660c0 |
Hashes for stim-1.14.dev1710897753-cp38-cp38-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4eb54c6dc0ea178014949d8b1d80351ca5c1e53e10ee9064cbf557d9ea10a0d9 |
|
MD5 | 0b6a3ff7595232a373a595fdc82917cb |
|
BLAKE2b-256 | 46442cad9283797973ff10dea1fbc969e14419720dfc1c18a459bccb59afd13b |
Hashes for stim-1.14.dev1710897753-cp38-cp38-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | df4dc92f1a9761541bfae978d6c4bccf127e495d6d52da08c3ff31142b4b92af |
|
MD5 | 66e4da400a58ed834b8ce9d0623dfd1a |
|
BLAKE2b-256 | b4752c50e60701e04eb2671230b32ec0054637ed14fd991a15f4c7064d193939 |
Hashes for stim-1.14.dev1710897753-cp37-cp37m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d89fe2631adf46f05cbeb53652e0e4ddcf744252e4206e7410bde1df45835a26 |
|
MD5 | e008dc4db79f221bbad0f96168c46d98 |
|
BLAKE2b-256 | 4793ac6c3936e94c12b61179a868d78cfcf511eea06daf6997ed03b755a89d5e |
Hashes for stim-1.14.dev1710897753-cp37-cp37m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7ade0ba7227f5e1460eba6fac74e0141b5dffd42c88df84bd7d80460e1caf175 |
|
MD5 | d53a00a18cf93869cb6a0d68015c40db |
|
BLAKE2b-256 | 9989f3260cac022e62cc6114dbcf3f261d1b4b96eba4aa3adf58cb1ae1799c58 |
Hashes for stim-1.14.dev1710897753-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 31f4ec3a308b3e3f82407d966f660adcb1efc29eba5c8df3562bcd1bf69729d3 |
|
MD5 | 033a047f7081fafdbbc4700001ca4893 |
|
BLAKE2b-256 | 8fc267afcd042a702e9116cff2a3a3aab21cf34d3107dd792361b8e9a441cf9a |
Hashes for stim-1.14.dev1710897753-cp37-cp37m-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 290610f2a2cb37e35bde87447108c0afe46cf714cc6073801e7889c2636cf156 |
|
MD5 | 7aa6aeace0f6441c260ca8435b6841f0 |
|
BLAKE2b-256 | ce19848b7c29fb030f7de8c2395a272dc3cb8f505f6e9653b64cd222f513a6a7 |
Hashes for stim-1.14.dev1710897753-cp37-cp37m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b94c9874eeedc9f4be812e79dabce7c7f75cad0fc5117a5d4564612ebc69d76f |
|
MD5 | e5d9c073e88641998bb1bff1e8450702 |
|
BLAKE2b-256 | 7cb69fa5697fafdf62cbfc1c69513ac551e5ae4bcd42b9428a1baea497b81cd5 |
Hashes for stim-1.14.dev1710897753-cp36-cp36m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 432223a8f7fad2aca7a2d6f2d21a26d21d9efdc3489cbc3028a151b08fcca3eb |
|
MD5 | 85e76680c2d0fbedeba8f58b1b0aa99f |
|
BLAKE2b-256 | 44799c341b02d3c0c610bed3e5adcb71783e227cba48feaf42b8193973748b23 |
Hashes for stim-1.14.dev1710897753-cp36-cp36m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f06435470577119c6fc755427e06f33420c303360c772c633323148c025d9945 |
|
MD5 | a4497747f86c274c2f4773c21102021e |
|
BLAKE2b-256 | cf97f89b1ef9edb9664f2c784613a7b28396ad3cff08696e884568908024c5a4 |
Hashes for stim-1.14.dev1710897753-cp36-cp36m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6a8a75a2f6d37e04a9aa4f73e03df1bd534bcc2afe52412d46a06911a85dadf6 |
|
MD5 | 968472a22e8a7cc4851edf6f640cddc1 |
|
BLAKE2b-256 | 6d66431a1e888d3f1fd9f427ce6386a2c6c5314aa8d839385f0e210a87dfb740 |
Hashes for stim-1.14.dev1710897753-cp36-cp36m-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d37b0c0a6a85b7b794dfca2501b989e4a86da4542b99b0571e7cf76f6d0c4699 |
|
MD5 | 01ce4f3dd9d30be5d2efb23474198142 |
|
BLAKE2b-256 | 3887226a74faef2ca5020106644fde105b985edadbabc907864891e7f8ca2151 |
Hashes for stim-1.14.dev1710897753-cp36-cp36m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | db474a968f7430716a5da60227f02f5a3e01f36e7bfcd4c719063d76a516ed42 |
|
MD5 | a9b1a3be58135deab49cd61f7a72748c |
|
BLAKE2b-256 | 0e7f5e8293e4d5e721f13996c6d21364ef298281abf14eb89183f4952b7bc5d6 |