Skip to content

Commit 847c760

Browse files
authored
TSIM and STIM intro (#317)
1 parent 1bd41cd commit 847c760

File tree

1 file changed

+45
-2
lines changed

1 file changed

+45
-2
lines changed

docs/quick_start/circuits/index.md

Lines changed: 45 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,7 @@ While it is possible to write your own compiler passes and optimizations - for t
4646
## Pick your backend: simulation and hardware
4747

4848
Once you have your program written and optimized to a point at which you are satisfied, it is time to think about execution.
49-
Bloqade Digital is a hardware-first SDK, which means that simulation tries to mirror execution on hardware as closely as possible.
50-
Choosing the hardware you want to run on is therefore mostly interchangeable with simulator backends.
49+
5150

5251
### Simulation with PyQrack
5352

@@ -66,6 +65,50 @@ There are also some things available in the simulator which cannot be obtained w
6665
sim.state_vector(ghz, args=(4,))
6766
```
6867

68+
### Simulation with STIM and TSIM
69+
70+
71+
For QEC workflows, it may be required to sample millions or billions of shots from the same kernel.
72+
For this, bloqade-circuit provides tight integration with the [STIM](https://github.com/quantumlib/Stim) and [TSIM](https://github.com/QuEraComputing/tsim) libraries.
73+
74+
STIM is a sampling simulator for Clifford circuits. TSIM is a sampling simulator for universal quantum circuits
75+
that contain few non-Clifford gates. Both simulators support Pauli noise channels. TSIM optionally provides GPU acceleration. For more information, please refer to the [TSIM documentation](https://queracomputing.github.io/tsim/latest/).
76+
77+
To use these simulators, first instantiate a `Circuit` object from your kernel. Then compile the circuit into a sampler. This step enables efficient sampling of millions or billions of shots:
78+
```python
79+
from bloqade.tsim import Circuit
80+
81+
@squin.kernel
82+
def main():
83+
q = squin.qalloc(2)
84+
squin.h(q[0])
85+
squin.t(q[0])
86+
squin.broadcast.depolarize(0.01, q)
87+
squin.cx(q[0], q[1])
88+
bits = squin.broadcast.measure(q)
89+
squin.set_detector(bits, coordinates=[0, 1])
90+
squin.set_observable([bits[0]], idx=0)
91+
92+
93+
circuit = Circuit(main)
94+
sampler = circuit.compile_sampler()
95+
sampler.sample(shots=1_000_000, batch_size=100_000) # On GPU, large batch size improves performance
96+
```
97+
98+
TSIM and STIM provide two types of samplers that are created via the `compile_sampler` and `compile_detector_sampler` methods, respectively. The regular sampler ignores any `set_detector` and `set_observable` statements and returns measurement bits for each `measure` instruction in the order
99+
of measurement. The detector sampler samples detector and observable bits.
100+
101+
```python
102+
from bloqade.stim import Circuit
103+
104+
circuit = Circuit(main)
105+
sampler = circuit.compile_detector_sampler()
106+
detector_bits, observable_bits = sampler.sample(shots=1_000_000, separate_observables=True)
107+
108+
```
109+
A detailed tutorial of how to use TSIM for QEC workflows is available [here](https://bloqade.quera.com/latest/digital/examples/tsim/magic_state_distillation/).
110+
111+
69112
### Hardware execution
70113

71114
!!! note

0 commit comments

Comments
 (0)