MockTensorKeeper¶
MockTensorKeeper is TensorKeeper's interface with nothing behind it. It takes
the same constructor and the same execute call as TkSimulator, refuses
exactly what TkSimulator refuses, and returns a real QCSResults full of
nothing: all-zero samples, zero amplitudes and expectation values, fidelity 1.0.
It is for validating the data models, what a MIMIQ backend accepts and what it hands back, on a machine that has no licence. That is a common shape of acceptance test: a CI job checks that its circuits build, that its options are accepted, and that its results parse and round-trip, with no interest in the physics.
import mimiqcircuits as mc
from tensorkeeper import MockTensorKeeper
sim = MockTensorKeeper(bonddim=64, disentangle_period="auto")
c = mc.Circuit()
c.push(mc.GateH(), 0)
c.push(mc.GateCX(), 0, 1)
c.push(mc.Measure(), [0, 1], [0, 1])
res = sim.execute(c, nsamples=1000, seed=42)
res.simulator # 'MockTensorKeeper'
len(res.cstates) # 1000, every one a real BitString
res.histogram() # {bs"00": 1000}
res.saveproto("out.pb")
Swapping it for the real thing is a one-line change, because the two take the same arguments:
from tensorkeeper import TkSimulator as Sim # licensed
from tensorkeeper import MockTensorKeeper as Sim # unlicensed CI
MockTkSimulator is the same class under the name that matches TkSimulator.
examples/00_mock_backend walks through it.
What it guarantees¶
It subclasses TkSimulator and overrides only the places where physics would
happen: build_state, which returns a MockState whose read-outs answer zero,
and evolve, which leaves the state alone. Everything that defines the
interface is inherited, so the two cannot drift apart:
- the constructor, with all its arguments and checks: a
bonddim,linalgormax_num_threadsTensorKeeper rejects is rejected here; capabilities(),limits(),topology()andcan_handle(), so admission and the anti-capability sweep every MIMIQ backend runs give identical verdicts;execute()and the wholeLocalBackenddriver, which chooses between the sampling and trajectory routes and builds theQCSResultsitself.
tests/test_mock.py asserts those methods are inherited rather than
overridden, and that the constructor takes TkSimulator's arguments.
What it does not do is compute. It is not an approximation or a fast mode. Nothing is simulated.
The public wheel¶
MockTensorKeeper is in every build, licensed or not, so one test suite can
run against both. It is also the only backend in the wheel published on
public PyPI:
No token, no index URL, no licence. The same wheel is also published as
mimiq-tensorkeeper-mock, for projects that need the licensed package and the
mock under different names; Testing
shows both setups. That wheel is the only one built with
--features no-kernels: gate application, the Clifford frame updates,
measurement, sampling, noise and expectation values are kept from the compiler
by #[cfg], in the CAMPS core and in the MPS core under it, rather than
stripped afterwards. What is left is a zero CAMPS state and its read-only
accessors. TkSimulator refuses to construct there and says so.
Before it can be published, the release audit (scripts/build_wheel.py
--audit-only) loads each engine in the wheel and requires has_kernels() to
be False with every compute method of CampsCore absent, and scans every file
in the wheel for those method names and for the source paths of the removed
modules.
Which wheel am I running?¶
The two distributions share a name and a version number, so
pip install mimiq-tensorkeeper works both with and without the QPerfect index
configured. They are told apart at runtime:
| public PyPI | QPerfect index | |
|---|---|---|
tk.has_kernels() |
False |
True |
TkSimulator() |
raises RuntimeError |
works |
MockTensorKeeper() |
works | works |
| licence required | none | yes |
Install the licensed wheel with an exclusive --index-url, as
Getting Started shows, not
--extra-index-url: with both indexes in play, pip may take either copy of a
name it finds in both.