Engines¶
Engines are the computational backends that perform low-level state operations. MPSTAB uses a modular engine architecture allowing different implementations to be swapped for specific use cases.
Two Engine Types:
Stabilizer Engines: Handle Clifford gates efficiently
Tensor Network Engines: Manage non-Clifford effects via MPO
Stabilizer Engines¶
Handle pure stabilizer/Clifford circuit simulation.
Native Stabilizer Engine: - Pure Python implementation - Highest compatibility - Suitable for all Clifford circuits - Can handle hundreds of qubits
Stim-based stabilizers engine.
- class mpstab.engines.stabilizers.stim.StimEngine[source]¶
Bases:
StabilizersEngineStabilizers engine powered by Stim.
Stim Engine: - Fast, C++-backed stabilizer simulator - Requires Stim library installation - Best for large Clifford circuits - Seamless integration with MPSTAB
Tensor Network Engines¶
Manage non-Clifford effects through Matrix Product Operator (MPO) representations.
- class mpstab.engines.tensor_networks.native.NativeTensorNetworkEngine[source]¶
Bases:
TensorNetworkEngineThin adapter that exposes the minimal API required by HybridSurrogate while reusing the existing evolutors.tensor_network implementation.
- build_circuit_mps(n: int, initial_state_amplitudes: Any, initial_state_circuit: Any, max_bond_dimension: int | None = None)[source]¶
Create a CircuitMPS initialised with initial_state. initial_state is passed as-is to CircuitMPS (the caller creates the array of single-qubit amplitudes as before).
- expval(state_circuit: CircuitMPS, operator: PauliMPO)[source]¶
Compute the expectation value of operator on state.
Native Tensor Network Engine: - Pure Python implementation - Direct control over MPS/MPO operations - Suitable for understanding tensor network mechanics - Good for small to medium systems
- class mpstab.engines.tensor_networks.quimb.QuimbEngine(backend: str = 'numpy', cache: bool = False, cache_directory: str | None = 'contractions_cache')[source]¶
Bases:
TensorNetworkEngineTensor network engine using Quimb for tensor network manipulations and contractions. The engine supports caching of contraction paths using cotengra’s ReusableOptimizer.
- PauliExp(pauli_string, theta)[source]¶
Returns the MPO for exp(-i * theta/2 * P) where P is a Pauli string. The euler formula is used: exp(-i * theta/2 * P) = cos(theta/2) * I + i * sin(theta/2) * P.
- build_circuit_mps(n: int, initial_state_amplitudes: Any, initial_state_circuit: Any, max_bond_dimension: int | None = None)[source]¶
Builds a Circuit MPS object in Quimb. The underlying tensor network is a Matrix Product State. truncation_fidelity is initialized.
- expval(state_circuit: MatrixProductState, operator: MatrixProductOperator)[source]¶
Compute the expectation value of operator on state_circuit. - state_circuit: MatrixProductState representing the state of the system - operator: MatrixProductOperator representing the observable whose expectation value we want to compute Due to truncation we loose unitary norm, so normalizing is needed when computing expectation.
Quimb Engine: - Advanced tensor network library integration - Optimized contraction paths via Cotengra - Excellent for larger systems with manageable bond dimensions - Automatic optimization of tensor operations
Engine Comparison¶
Engine |
Speed |
Best For |
Max Qubits* |
|---|---|---|---|
Native Stabilizer |
Medium |
Clifford only |
1000+ |
Stim |
Very Fast |
Clifford, large |
1000+ |
Native TN |
Moderate |
Understanding TN |
~20 |
Quimb |
Fast |
Mixed circuits |
~50 |
Approximate limits depend on bond dimension and circuit complexity. Performance scales with system size.
Selecting Engines¶
Engines are automatically selected based on your circuit type and parameters:
from qibo import Circuit, gates
from mpstab import HSMPO
from mpstab.models.ansatze import HardwareEfficient
clifford_circuit = Circuit(nqubits=10)
# Add only Clifford gates
for q in range(10):
clifford_circuit.add(gates.H(q))
clifford_circuit.add(gates.CNOT(q0=q%10, q1=(q+1)%10))
# Clifford circuit - uses stabilizer engine only
simulator = HSMPO(ansatz=clifford_circuit)
# Constructing a circuit with also magic gates
mixed_circuit = HardwareEfficient(
nqubits=10,
nlayers=3,
)
# Mixed circuit with bond limit - uses both engines
simulator = HSMPO(
ansatz=mixed_circuit,
max_bond_dimension=32 # Enables tensor network engine
)
For detailed guidance, see Working with Engines
Engine Interface¶
All engines implement standardized interfaces for compatibility.
Base Engine Classes:
from mpstab.engines import StabilizersEngine, TensorNetworkEngine
These abstract base classes define the required methods that any engine must implement.
Performance Tuning¶
Tips for optimal engine performance:
Stabilizer Engines: Can handle very large systems efficiently
Tensor Network Engines: Performance highly dependent on bond dimension
Quimb Engine: Automatic optimization may have startup overhead
Native TN Engine: Lower overhead but potentially slower for large systems
See Also¶
Working with Engines - Engine selection guide
A quick introduction to HSMPO - Practical examples