QSimSimulator.simulate_expectation_values for identity operators is wrong
yor-dev opened this issue · 1 comments
yor-dev commented
QSimSimulator.simulate_expectation_values returns wrong results for identity operators in observables.
As the following example shows, identity operators in observables seem to be regarded as zero matrices.
This is a straightforward example.
import cirq
import qsimcirq
circuit = cirq.Circuit()
q = cirq.LineQubit.range(1)
ps = cirq.PauliString(cirq.I(q[0]))
sim = qsimcirq.QSimSimulator()
evs = sim.simulate_expectation_values(
circuit, ps)
print("qsim", evs)
cirq_sim = cirq.Simulator()
evs = cirq_sim.simulate_expectation_values(
circuit, ps)
print("cirq", evs)
And the result is here.
qsim [0j]
cirq [(1+0j)]
95-martin-orion commented
Identity operators are ignored because cirq.PauliString
does not include identities in its .items()
representation. The reason for this is tied to some messy details of Cirq's concept of Paulis; thankfully, a workaround is possible (#566).