What are the best tensor network-based simulators libraries in Python?

In particular, I'm interested in calculating the expectation value of an observable measured at the end of a quantum circuit.

EDIT: Qiskit has a matrix product state simulation method, but I can't understand if I can compute the exact expectation values (without using the full state vector) or if I am limited to a finite number of shots.


1 Answer 1


In Qiskit, if you want to compute the expectation value of a given operator $\hat{O}$ using the matrix_product_state-based simulation, you can use the primitive BackendEstimator as follows:

from qiskit.circuit.random import random_circuit
from qiskit.quantum_info import SparsePauliOp
from qiskit_aer import AerSimulator
from qiskit.primitives import BackendEstimator

num_qubits = 5
psi = random_circuit(num_qubits=num_qubits, depth=10, seed=42)
O = SparsePauliOp('Z' * num_qubits)

mps_simulator = AerSimulator(method='matrix_product_state')
estimator = BackendEstimator(backend=mps_simulator)
job = estimator.run(circuits=[psi], observables=[O])


However, I don't think it is possible to compute $\langle \psi | \hat{O} | \psi \rangle$ exactly even if you pass shots=None to the method BackendEstimator.run(). The default number of shots is 1024 as you can see by printing the job result.

I also suggest to take a look at tenpy, which is a pure Python library for the simulation of quantum systems with tensor networks.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.