ket.mps

Matrix Product State (MPS) Quantum Simulator Backend.

This module provides the MPS backend, which leverages Tensor Networks (via quimb.tensor) and JAX’s Automatic Differentiation to simulate quantum circuits with a 1D linear topology. It supports calculating exact expectation values and their gradients, making it suitable for running parameterized quantum algorithms like VQE efficiently.

Summary

Classes

MPS

Matrix Product State (MPS) backend simulator.

Classes

class MPS(
num_qubits: int,
max_bond: int = None,
double_precision: bool = False,
execution: Literal['live', 'batch'] | None = None,
gradient: bool = False,
)[source]

Bases: BatchExecution, LiveExecution

Matrix Product State (MPS) backend simulator.

The MPS backend is specialized for executing quantum circuits with 1D linear topologies. It uses tensor network contractions via the quimb library, augmented by JAX to support exact parameter gradient evaluations for parameterized circuits.

Parameters:
  • num_qubits – Total number of qubits to simulate.

  • max_bond – Maximum bond dimension for SVD truncations during the simulation. If specified, it restricts entanglement and keeps the MPS strictly 1D, enabling the simulation of large numbers of qubits. However, this dynamically changes tensor shapes and disables JAX’s jit compilation, which may result in slower evaluations. If None, the network is built in 2D and contracted fully at the end, which is JIT-compatible but may scale poorly with depth. Defaults to None.

  • double_precision – Whether to enable 64-bit floating point precision (double precision) in JAX. Defaults to False. Set to True for higher accuracy in deep circuits.

connect()[source]

Configure the connection to the MPS simulator.

pauli_x(target, control)[source]

Apply a Pauli-X gate to the target qubit.

pauli_y(target, control)[source]

Apply a Pauli-Y gate to the target qubit.

pauli_z(target, control)[source]

Apply a Pauli-Z gate to the target qubit.

hadamard(target, control)[source]

Apply a Hadamard gate to the target qubit.

rotation_x(target, control, angle)[source]

Apply a X-Rotation gate to the target qubit.

rotation_y(target, control, angle)[source]

Apply a Y-Rotation gate to the target qubit.

rotation_z(target, control, angle)[source]

Apply a Z-Rotation gate to the target qubit.

phase(target, control, angle)[source]

Apply a Phase gate to the target qubit.

sample(*args)[source]

Execute the circuit and sample the given qubits.

Warning

This method is called by Libket and should not be called directly.

exp_value(*args)[source]

Execute the circuit and compute expectation values.

Warning

This method is called by Libket and should not be called directly.

gradient(gates, hamiltonian)[source]

Execute the circuit, compute expectation values and the parameters gradient.

Warning

This method is called by Libket and should not be called directly.