question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

SparsePauliOp does not yield correct results

See original GitHub issue

Environment

  • Qiskit Terra version:0.20.0
  • Python version: 3.10.4
  • Operating system: MacOS

What is happening?

Two Z gates on the same qubit make the identity, not a single Z gate

How can we reproduce the issue?

>>> from qiskit.quantum_info import SparsePauliOp
>>> sparse_list = [("ZZ", [0,0], 1)]
>>> SparsePauliOp.from_sparse_list(sparse_list, num_qubits = 5)
SparsePauliOp(['IIIIZ'],
              coeffs=[1.+0.j])
>>>

What should happen?

Ideally, it should return

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

Any suggestions?

No response

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:10 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
Cryoriscommented, May 10, 2022

I agree raising an error would be good. For performance we could also add a do_checks flag or so that is True per default but can be turned off if you know that you’re strings are valid? 😄

0reactions
ikkohamcommented, May 9, 2022

Initialization with the same index should not be allowed and should be explicitly compose (@). The issue is whether to check for errors (/warning) or just document it.

Since this is a difficult behavior for users to find wrong cases, I think it would be better to make it Error. I don’t think it would be that so costly to check if it is already assigned (i.e., not I) here.

Read more comments on GitHub >

github_iconTop Results From Across the Web

SparsePauliOp does not respect phase of Pauli product #5603
The SparsePauliOp class does not obtain the correct phase when constructed from the product of two Paulis. Here are some example ...
Read more >
qiskit.quantum_info.operators.symplectic.sparse_pauli_op
Args: other (SparsePauliOp): an operator object. atol: Absolute numerical tolerance for checking equivalence. Returns: bool: True if the operator is ...
Read more >
Qiskit PrimitiveOp compose function giving weird output
I am executing the following code. ... It gives a warning and a very deeply nested numpy array. ... But if I set...
Read more >
Get started with the Estimator primitive - IBM Cloud Docs
When you start a session, it caches the data you send so it doesn't have to be ... Higher levels generate more accurate...
Read more >
Qiskit Pocket Guide
The views expressed in this work are those of the authors and do not ... Returns the result of right-multiplying this operator with...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found