1
$\begingroup$

I have a SparsePauliOp object $H$ acting on $N = 21$ qubits, and a statevector $|\psi \rangle$ acting on $N=21$ qubits. I need the expectation of $H$ using this state $|\psi \rangle$: $$\langle H \rangle = \langle \psi|H|\psi\rangle$$ Unfortunately, due to the sheer size of the system, I cannot convert it to a matrix and then use numpy multiplication. Is there any other way I can find this expectation value efficiently enough?

$\endgroup$
1
  • $\begingroup$ Can $|\psi\rangle$ be an arbitrary state or does it have some constraints you might be able to exploit? $\endgroup$
    – forky40
    Commented Jul 19 at 18:37

1 Answer 1

2
$\begingroup$

You can use Statevector.expectation_value() method as follows:

from qiskit.quantum_info.random import random_statevector, random_pauli_list
from qiskit.quantum_info import SparsePauliOp

# Generate a 21-qubit random Statevector:
N = 21
sv = random_statevector(2 ** N)

# Generate random observable of 5 Paulis:
pauli_list = random_pauli_list(num_qubits=N, size=5)
H = SparsePauliOp(pauli_list)

# Compute the expectation value:
exp_val = sv.expectation_value(H)
print(exp_val)
$\endgroup$

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.