Examples¶
The package ships eight runnable scripts, ordered so that each builds on the one
before. Read in order, they take you from a first circuit to competent use of the
whole simulator. Every script is deterministic for a fixed seed and ends with
asserts that check the numbers it printed, so an example that stops being true
fails rather than misleading you.
Where they are¶
The examples are bundled inside the installed package:
From a source checkout they live in
tensorkeeper-python/python/tensorkeeper/examples/.
Running¶
cd tensorkeeper-python
uv run maturin develop
uv run python python/tensorkeeper/examples/01_bell_pair/main.py
Most scripts accept --seed and a few topic-specific flags. Pass --help.
Index¶
| # | Folder | What it teaches |
|---|---|---|
| 01 | 01_bell_pair |
The simplest entangled circuit. Both API paths: execute for shots, build_state/compile/evolve for the state itself. Amplitudes, probabilities, histogram. |
| 02 | 02_clifford_is_free |
A wide, deep Clifford circuit stays at bond dimension 1 and reports ExactFidelity. Includes the bond dimension a plain MPS would have needed, and a proof that the state really is entangled. |
| 03 | 03_adding_magic |
Add \(T\) gates and watch bond dimension follow the \(T\) count rather than the depth. Why the first gates are free, and where the ceiling is. |
| 04 | 04_measurement_and_shots |
Mid-circuit measurement and reset, the classical register, trajectory mode, histograms. Also why resetting an entangled qubit is not a local operation. |
| 05 | 05_feed_forward |
IfStatement: applying a gate conditioned on a measured bit. |
| 06 | 06_noise |
Depolarizing sampled into the frame, one Pauli branch per shot, at no MPS cost. And why AmplitudeDamping is refused instead of approximated. |
| 07 | 07_observables |
ExpectationValue of Pauli strings and of general one- and two-qubit operators, read through the frame without touching the state. Amplitude and BondDim into the z-register. |
| 08 | 08_tuning |
bonddim, sv_cutoff, disentangle_period. A convergence sweep, what the reported fidelity is measuring, and how far to trust it. |
Reading order¶
Read 01 to 08 if you are new to the simulator. The arc is: build and run (01), understand the cost model (02, 03), then the operations that need more than a unitary (04, 05, 06), then observables (07), then accuracy (08).
If you already know CAMPS and want specific things:
- 02 and 03 are the pair that shows what makes TensorKeeper different from an MPS simulator. If you read only two, read these.
- 08 for the accuracy and fidelity contract, before you trust a number.
- 06 if your workload is noisy: the supported-channel restriction is a real constraint, and better met here than mid-project.
The Julia examples in tensorkeeper-julia/examples/ mirror these one for one.
Reading a pair side by side is a good way to learn the simulator across both
bindings.