qiskit-community / qiskit-algorithms

A library of quantum algorithms for Qiskit.
https://qiskit-community.github.io/qiskit-algorithms/
Apache License 2.0
116 stars 59 forks source link

Found Error in 11_VarQTE of Tutorial #171

Open touwax42 opened 7 months ago

touwax42 commented 7 months ago

Environment

What is happening?

When I tried the 11_VarQTE.ipynb in tutorial, I face an QiskitError: 'Invalid shape for PauliTable.' Then I reinstall the qiskit and qiskit-algorithms but it doesn't work.

How can we reproduce the issue?

The full message is below:

from qiskit.quantum_info import SparsePauliOp

hamiltonian = SparsePauliOp(["ZZ", "IX", "XI"], coeffs=[-0.2, -1, -1])

magnetization = SparsePauliOp(["IZ", "ZI"], coeffs=[1, 1])

and the error said:

---------------------------------------------------------------------------
QiskitError                               Traceback (most recent call last)
<ipython-input-1-594b2ee73c35> in <module>
      1 from qiskit.quantum_info import SparsePauliOp
      2 
----> 3 hamiltonian = SparsePauliOp(["ZZ", "IX", "XI"], coeffs=[-0.2, -1, -1])
      4 
      5 magnetization = SparsePauliOp(["IZ", "ZI"], coeffs=[1, 1])

[~\AppData\Roaming\Python\Python38\site-packages\qiskit\quantum_info\operators\symplectic\sparse_pauli_op.py] in __init__(self, data, coeffs)
     57             coeffs = data._coeffs
     58         else:
---> 59             table = PauliTable(data)
     60             if coeffs is None:
     61                 coeffs = np.ones(table.size, dtype=complex)

[~\AppData\Roaming\Python\Python38\site-packages\qiskit\quantum_info\operators\symplectic\pauli_table.py] in __init__(self, data)
    161             self._array = np.reshape(self._array, (1, self._array.size))
    162         if self._array.ndim != 2 or self._array.shape[1] % 2 != 0:
--> 163             raise QiskitError("Invalid shape for PauliTable.")
    164 
    165         # Set size properties

QiskitError: 'Invalid shape for PauliTable.'

What should happen?

The tutorial works well.

Any suggestions?

No response

woodsp-ibm commented 7 months ago

The tutorial is run in CI and passes fine. The code snippet above works fine for me locally - I just tried. The published tutorial https://qiskit-community.github.io/qiskit-algorithms/tutorials/11_VarQTE.html as you can see if you scroll to the bottom, where there is the version table, was run with Qiskit 1.0.2.

The file it is showing in your trace, where it's erroring out, is PauliTable and this was deprecated and removed from Qiskit some time ago. I would check the environment that you are running the notebook in and make sure its using the qiskit versions you believe. You can run that cell at the end which prints the versions if that helps.