Skip to content

SparsePauliOp.paulis setter does not propagate dimension info #10384

@ihincks

Description

@ihincks

Environment

  • Qiskit Terra version: 0.24.1
  • Python version: any
  • Operating system: any

What is happening?

Setting the paulis attribute (it has a @setter) on a SparsePauliOp instance does not update the BaseOperator shape attributes.

How can we reproduce the issue?

import qiskit.quantum_info as qi

pauli_x = qi.SparsePauliOp(["X"], [1])
pauli_x.paulis = ["XX"]
print(pauli_x, pauli_x.dim)

What should happen?

The above snippet produces the output

SparsePauliOp(['XX'],
              coeffs=[1.+0.j]) (2, 2)

whereas it should produce

SparsePauliOp(['XX'],
              coeffs=[1.+0.j]) (4, 4)

if changing the dimension is allowed, or raise an exception if it's not allowed.

Any suggestions?

I haven't looked closely, but it's possible that just updating _op_shape will be sufficient to fix the bug.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingmod: quantum infoRelated to the Quantum Info module (States & Operators)

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions