quantumlib/qsim

SegFault for many-local observables

Closed this issue · 2 comments

I've been getting segfaults when trying to compute expectation values for long Pauli strings.

When I run the following code for qsim==0.10.2 (pip package) on my laptop it reproduces the problem:

import qsimcirq
import cirq
simulator = qsimcirq.QSimSimulator()

for n in range(2, 12):
    qubits = cirq.GridQubit.rect(1, n)
    circuit = cirq.Circuit(*(cirq.H(q) for q in qubits))

    # prepare n-local paulistring
    obs = cirq.X(qubits[0])
    for q in qubits[1:n]:
        obs *= cirq.X(q)
    simulator.simulate_expectation_values(program=circuit, observables=[obs])
    print(f"{n}-local observable works.")

This outputs

2-local observable works.
3-local observable works.
4-local observable works.
5-local observable works.
6-local observable works.
Segmentation fault (core dumped)

fwiw the corresponding code using cirq.Simulator and obs.expectation_from_state_vector works fine.

This is a limitation of the qsim expectation value calculation code - it only supports up to 6-qubit operators. For larger expectation values I recommend using the Cirq tools as you described.

Oh I didn't realize that. Thanks.