uniqc.simulator.mps_simulator module¶
Matrix-Product-State (MPS) simulator for nearest-neighbour 1D circuits.
This is a pure-NumPy MPS simulator suitable for circuits whose entanglement
stays bounded by a moderate bond dimension. Compared to the C++
Simulator it trades off generality for scale: an open-boundary
qubit chain at chi_max=64 and N=64 qubits is comfortably tractable here
while a dense statevector at the same N is not.
When to use this simulator¶
1D / line topology circuits where every two-qubit gate is between consecutive qubits (qubit
qand qubitq+1).Low-to-moderate entanglement growth (e.g. shallow brick-work, dynamical simulation of local Hamiltonians, single-excitation propagation).
Sampling from a chip-shaped circuit that you have already compiled into a nearest-neighbour 1D chain.
When NOT to use this simulator¶
Long-range two-qubit gates. They are refused (rather than swap-routed silently). Compile to NN first, or use the dense
Simulator.Circuits that need
CONTROL ... ENDCONTROLblocks. Decompose to native gates first.Noise simulation. The MPS path is currently noiseless; route noisy work through
NoisySimulatorordummy:<platform>:<chip>.
Public API¶
MPSConfig— bond / cutoff / seed configuration.MPSSimulator— front-end with thesimulate_pmeasure/simulate_shots/simulate_statevectorsurface used elsewhere inuniqc.simulator.
The simulator does not inherit uniqc.simulator.base_simulator.BaseSimulator
so as to avoid the eager C++ OpcodeSimulator import and to keep the
qubit indexing 1:1 with the parsed OriginIR (no encounter-order remapping).
- class uniqc.simulator.mps_simulator.MPSConfig(chi_max=64, svd_cutoff=1e-12, seed=None)[source]¶
Bases:
objectConfiguration for
MPSSimulator.- Variables:
chi_max (int) – Maximum bond dimension after each two-qubit SVD truncation. Larger
chi_maxis more accurate but quadratically more memory-intensive and cubically more compute-intensive per gate.svd_cutoff (float) – Singular-value cutoff (relative to the spectrum norm) below which Schmidt values are dropped even if
chi_maxis not yet reached.seed (int | None) – Optional RNG seed used by
MPSSimulator.simulate_shots().
- Parameters:
- class uniqc.simulator.mps_simulator.MPSSimulator(config=None, *, chi_max=None, svd_cutoff=None, seed=None, available_qubits=None, available_topology=None)[source]¶
Bases:
objectOriginIR-driven MPS simulator with the same call surface as
uniqc.simulator.Simulator.Unlike that class, this simulator:
is pure NumPy (no C++ extension required);
operates on qubits
[0..n-1]exactly as written in OriginIR (no least-qubit remapping); the qubit count comes fromQINIT;refuses long-range two-qubit gates (use the dense simulator or compile to NN first);
refuses
CONTROL ... ENDCONTROLblocks andDAGGERblocks around unsupported gates (the per-gatedaggerflag is honoured);has no noise model.
- Parameters:
config (MPSConfig | None) – Bond / cutoff / seed configuration.
chi_max (int | None) – Convenience override for
config.chi_maxwhenconfigis not supplied.svd_cutoff (float | None) – Convenience override for
config.svd_cutoff.seed (int | None) – Convenience override for
config.seed.available_qubits (list[int] | None) – Optional list of allowed qubit indices. If set, any opcode touching a qubit outside the list raises.
available_topology (list[list[int]] | None) – Optional list of allowed
[u, v]edges. If set, NN gates that violate this list raise (this lets the same instance enforce a virtual-line / chip-shaped chain).
- parser: OriginIR_BaseParser | None¶
- simulate_pmeasure(originir)[source]¶
Return exact measurement probabilities, length
2 ** kwherekis the number of measured qubits (or all qubits if noMEASUREwas issued).Index convention: bit
jof the integer index corresponds to thej-th measured qubit (in the order they appear in the result of_measure_order()), with qubit 0 being the LSB. This matchesuniqc.simulator.Simulator.simulate_pmeasure().For circuits with > 24 measured qubits this method raises — the dense probability vector would be infeasibly large. Use
simulate_shots()instead.
- simulate_shots(originir, shots)[source]¶
Sample
shotsmeasurement outcomes by per-site MPS sampling.Returns a
{int: count}dict matchinguniqc.simulator.Simulator.simulate_shots(). The integer key encodes bits with the first measured qubit as the LSB.This routes through
_MPSState.sample_one()(costO(N * chi^3)per shot) so it stays tractable for largeN.