Skip to content

LightCone reverses the association between bit_terms and observable indices #16866

Description

Environment

  • Qiskit version: 2.5.2
    Also reproduced on 2.6.0.dev0+b6f798f (b6f798f0bd88965821a54bff3785323a39c3a6c5)
  • Python version: 3.12.13
  • Operating system: Linux

What is happening?

LightCone reverses the association between bit_terms and indices when constructing its initial observable.

The sparse observable interface associates the entries positionally. Therefore:

bit_terms = "XZ"
indices = [0, 1]

represents:

X(q0) Z(q1)

However, the implementation constructs:

lightcone_qubits = [dag.qubits[i] for i in self.indices]
lightcone_operations = [
    (PauliGate(self.bit_terms), lightcone_qubits)
]

Relevant source:

lightcone_qubits = [dag.qubits[i] for i in self.indices]
# `lightcone_operations` is a list of tuples, each containing (operation, list_of_qubits)
lightcone_operations = [(PauliGate(self.bit_terms), lightcone_qubits)]

A PauliGate label uses Qiskit's dense Pauli convention: the rightmost character acts on local qubit 0. Consequently:

PauliGate("XZ") on [q0, q1]

acts as:

Z(q0) X(q1)

This reverses the requested observable and can cause the pass to remove noncommuting gates.

How can we reproduce the issue?

import numpy as np

from qiskit import QuantumCircuit
from qiskit.quantum_info import SparsePauliOp, Statevector
from qiskit.transpiler import PassManager
from qiskit.transpiler.passes import LightCone


# Sparse form: X acts on q0 and Z acts on q1.
observable = SparsePauliOp.from_sparse_list(
    [("XZ", [0, 1], 1.0)],
    num_qubits=2,
)

bit_terms, indices, _ = observable.to_sparse_list()[0]

source = QuantumCircuit(2)
source.h(0)
source.z(0)

output = PassManager(
    [
        LightCone(
            bit_terms=bit_terms,
            indices=indices,
        )
    ]
).run(source)

source_expectation = Statevector.from_instruction(
    source
).expectation_value(observable).real

output_expectation = Statevector.from_instruction(
    output
).expectation_value(observable).real

print("bit_terms:", bit_terms)
print("indices:", indices)
print(
    "source operations:",
    [instruction.operation.name for instruction in source.data],
)
print(
    "output operations:",
    [instruction.operation.name for instruction in output.data],
)
print("source expectation:", source_expectation)
print("output expectation:", output_expectation)

assert np.isclose(source_expectation, -1.0)

# Fails on the affected implementation.
assert np.isclose(output_expectation, source_expectation)

Observed output:

bit_terms: XZ
indices: [0, 1]
source operations: ['h', 'z']
output operations: ['h']
source expectation: approximately -1.0
output expectation: approximately 1.0

The Z(q0) gate should be retained because it does not commute with the requested observable X(q0) Z(q1).

Instead, LightCone interprets the observable as Z(q0) X(q1), concludes that Z(q0) commutes, and removes it. This changes the expectation value from -1 to 1.

What should happen?

LightCone should preserve the positional association:

bit_terms[i] -> indices[i]

For this example, the Z(q0) gate should remain and the transformed circuit should preserve:

expectation value = -1

Any suggestions?

Construct the initial Pauli operation without changing the sparse term/index association. For example, the label must be reversed before being passed to PauliGate, or represented directly in a sparse Pauli form.

A regression test should use an asymmetric observable such as "XZ" on indices [0, 1] and verify the expectation value before and after the pass.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions