Stim Simulation#
- stimulate(func: Callable) Callable[source]#
Evaluate a Jasp-traceable function containing only Clifford gates, using the Stim simulator.
Stim is a popular tool to simulate quantum error correction codes. Using a non-Clifford gate raises an exception rather than an incorrect result. Internally, this calls
simulate_jasprwithsimulator="stim", so the same equation-by-equation execution model applies.Note
To use this simulator, you need stim installed, which can be achieved via
pip install stim.- Parameters:
- funccallable
The function to simulate.
- Returns:
- callable
A function performing the simulation.
Examples
We simulate a function creating a simple GHZ state, which collapses to either
0or31upon measurement:>>> from qrisp import * >>> from qrisp.jasp import * >>> @stimulate ... def main(): ... qf = QuantumFloat(5) ... h(qf[0]) ... for i in range(1, 5): ... cx(qf[0], qf[i]) ... return measure(qf) >>> main() 31
The
stimulatedecorator can also simulate real-time features:>>> @stimulate ... def main_with_feedback(): ... qf = QuantumFloat(5) ... h(qf[0]) ... cl_bl = measure(qf[0]) ... with control(cl_bl): ... for i in range(1, 5): ... x(qf[i]) ... return measure(qf) >>> main_with_feedback() 31