Concepts¶
Read this page before the rest of the manual. Every tuning knob and every performance surprise in TensorKeeper follows from what is here.
It assumes you are comfortable with quantum circuits and have a rough picture of a Matrix Product State: a chain of tensors whose bond dimension \(\chi\) grows with entanglement. If MPS is new, read TensorWeaver's concepts page first. TensorKeeper uses TensorWeaver for the MPS half of its state.
The problem with entanglement as a cost model¶
An MPS pays for entanglement. Bond dimension \(\chi\) across a cut must be at least the Schmidt rank there, so a state that is highly entangled across every cut is expensive no matter how simple it was to prepare.
That cost model is a good one for most circuits. It is a bad one for Clifford circuits.
A Clifford circuit is built from \(H\), \(S\) and \(\text{CNOT}\) (and anything they generate: \(X\), \(Y\), \(Z\), \(\text{CZ}\), \(\text{SWAP}\), and so on). By the Gottesman-Knill theorem, such a circuit is classically simulable in polynomial time. It is easy. Yet a Clifford circuit can produce a state that is maximally entangled across every cut, needing \(\chi = 2^{\lfloor n/2 \rfloor}\) in an MPS.
So a plain MPS simulator can be defeated by a circuit that is provably easy. It spends exponential memory storing entanglement that carries no hard information.
The CAMPS factorization¶
TensorKeeper splits the state in two:
- \(C\) is a Clifford unitary, stored as a stabilizer tableau. It costs \(O(n^2)\) bits, and applying a Clifford gate to it costs \(O(n)\). Entanglement in \(C\) is free.
- \(|\varphi\rangle\) is an MPS, called the residual. It carries only what \(C\) cannot.
This is the Clifford-Augmented Matrix Product State of Liu & Clark, Classical simulability of Clifford+T circuits with Clifford-augmented matrix product states, Phys. Rev. Research 8, 023116 (2026).
A pure Clifford circuit now costs nothing: every gate goes into \(C\), and \(|\varphi\rangle\) stays \(|0\dots0\rangle\) at \(\chi = 1\), however deep the circuit runs. The exponential blow-up is gone because the representation finally matches what the theorem says about the difficulty.
Magic is the resource¶
If Clifford gates are free, what is not?
Non-Clifford gates. \(T\), controlled-phase at a generic angle, Toffoli. The quantity that governs cost is nonstabilizerness, also called magic: how far the state is from being a stabilizer state. In TensorKeeper this is concrete. Bond dimension in \(|\varphi\rangle\) grows with the magic in the circuit, not with its entanglement and not with its depth.
That gives a sharp design point. A circuit that is mostly Clifford with a bounded amount of magic stays cheap at any width and any depth:
| Circuit | Plain MPS | TensorKeeper |
|---|---|---|
| Clifford, any depth | up to \(\chi = 2^{n/2}\) | \(\chi = 1\) |
| Clifford + a few \(T\) | large \(\chi\) | \(\chi\) set by the \(T\) count |
| Magic everywhere | large \(\chi\) | large \(\chi\), plus frame overhead |
The last row is the honest one. TensorKeeper is not a better MPS simulator in general. On a circuit whose difficulty is genuinely spread everywhere it does the same work as an MPS and pays a little extra to carry the frame. Use it where the magic is sparse: Clifford+\(T\), magic state cultivation, error correction.
Magic also does not have to be paid for the moment it arrives. On a wide register the first non-Clifford gates are typically absorbed at no bond cost at all, so \(\chi\) can sit at 1 for a while and only then start to climb. \(\chi = 1\) therefore does not mean "no magic": a product residual can carry plenty of it. How long the free run lasts depends on the circuit, and it is of order \(n\) rather than exactly \(n\).
Where each operation goes¶
Every operation is routed to whichever half can absorb it cheaply.
| Operation | Goes to | Cost |
|---|---|---|
| Clifford gate | the frame, \(C \leftarrow GC\) | \(O(n)\), MPS untouched |
| Pauli noise | the frame, after sampling one branch | \(O(n)\), MPS untouched |
| Non-Clifford gate \(G\) | the MPS, as the dressed gate \(\hat G\) | depends on \(\hat G\)'s support |
| Measurement, reset | both: a Pauli read from the frame, a projector on the MPS |
The interesting case is the third.
Dressed gates¶
A non-Clifford gate \(G\) acts on \(|\psi\rangle\), but the MPS holds \(|\varphi\rangle\). Pushing \(G\) through the frame gives
so the MPS sees the dressed gate \(\hat G = C^\dagger G C\) and the frame is unchanged.
Conjugation by a Clifford maps Paulis to Paulis, so \(\hat G\) stays easy to describe. It need not act on the same qubits as \(G\), though. A \(T\) gate on one qubit can dress into an operator whose support spans much of the register, because the frame has scrambled that qubit's \(X\) and \(Z\) images across the chain.
That is the one asymmetry to keep in mind: support width is not gate width. TensorKeeper never expands \(\hat G\) into a dense \(2^k\) matrix over its support. Its cost is exponential in the width of the original gate (1 for \(T\), 2 for controlled-phase, 3 for Toffoli) and only linear in the width of the dressed support. Wide dressed support costs time, not memory.
Disentangling: why bond dimension does not have to grow¶
Two mechanisms keep \(|\varphi\rangle\) small. Both are exact: they change the split between \(C\) and \(|\varphi\rangle\), never \(|\psi\rangle\).
Optimization-free disentangling (OFD) applies when a rotation \((\alpha I + \beta P)\) lands on the MPS. Whenever the residual is still a product state somewhere in \(P\)'s support, the rotation goes on as a single-qubit gate with no bond growth at all, and the rest of \(P\) is absorbed by the frame. A \(T\) gate on a fresh qubit is therefore free, not merely cheap. This is what makes the early \(T\) gates on a wide register cost nothing.
The Clifford disentangler (OBD) runs as a periodic sweep. At each cut it looks for a two-qubit Clifford that lowers the entropy there, applies it to the MPS and compensates it in the frame. This recovers entanglement that earlier operations left in \(|\varphi\rangle\) but that is really gauge, not magic. It is on by default, after every operation on the MPS; see Accuracy and Tuning.
What bond dimension means here¶
state.bond_dim reports the bond dimension of \(|\varphi\rangle\), not of
\(|\psi\rangle\).
This is the number that matters for cost, and it is the one
limits().max_bond_dim caps. It is not the physical state's Schmidt rank. A
maximally entangled stabilizer state reads back as \(\chi = 1\), because all of its
entanglement lives in the frame. So do not read a physical entanglement measure
off the bond dimension. This backend declines SchmidtRank and
VonNeumannEntropy outright, rather than answer them about \(|\varphi\rangle\)
when the question is about \(|\psi\rangle\).
The same caveat applies to the BondDim circuit instruction.
Truncation and fidelity¶
Two settings bound the MPS: a maximum bond dimension bonddim, and a
singular-value cutoff sv_cutoff. When a compression discards weight, the result
is approximate, and evolve says so in its second return value:
ExactFidelity(): thebonddimcap never bound, so nothing it would cut was ever at risk. A pure Clifford circuit always reports this.TruncationLowerBound(v): the cap bound at least once, and the fidelity is at leastv.
Weight below sv_cutoff is the tolerance you set and counts against neither.
TruncationLowerBound(1.0) is deliberately not ExactFidelity(). The claim
is about what could have been cut, not what happened to be. The two settings,
what the bound is worth, and how to confirm a run has converged are covered in
Accuracy and Tuning.
Relationship to MIMIQ and TensorWeaver¶
TensorKeeper is a MIMIQ backend. It implements
mimiqcircuits.backends.LocalBackend, so it takes the same Circuit objects and
returns the same QCSResults as any other backend, and you can swap it for one
without changing your circuit code.
The MPS half is TensorWeaver, used as a library. The Clifford half is a tableau in TensorKeeper's Rust core. Both bindings, Python and Julia, sit on that one core, so they agree numerically to machine precision.
Where to go next¶
- Getting Started: install and run a first circuit.
- Circuit Execution: measurement, noise, observables, results.
- Accuracy and Tuning:
bonddim,sv_cutoff, the disentangler. - Examples: a curriculum of runnable scripts.