PennyLaneAI / pennylane-qiskit

The PennyLane-Qiskit plugin integrates the Qiskit quantum computing framework and IBM Q with PennyLane.
https://docs.pennylane.ai/projects/qiskit
Apache License 2.0
190 stars 66 forks source link

Problem with qiskit version 0.33.0 related to the function `measure` #164

Closed andreamari closed 2 years ago

andreamari commented 2 years ago

Describe the bug In the last version (0.33.0) of qiskit the function measure has been removed from qiskit.circuit.measure. In pennylane_qiskit.qiskit_device.py there is however this line that now can create problems: https://github.com/PennyLaneAI/pennylane-qiskit/blob/0998b85dc730566d3f5c167e6f789ebaef255b93/pennylane_qiskit/qiskit_device.py#L27

To Reproduce Note sure how to reproduce, but the problem shows up in a Mitiq PR https://github.com/unitaryfund/mitiq/pull/1040. See this line: https://github.com/unitaryfund/mitiq/runs/4442208499?check_suite_focus=true#step:6:2449

Possible Fix Removing the import: https://github.com/PennyLaneAI/pennylane-qiskit/blob/0998b85dc730566d3f5c167e6f789ebaef255b93/pennylane_qiskit/qiskit_device.py#L27

and replacing https://github.com/PennyLaneAI/pennylane-qiskit/blob/0998b85dc730566d3f5c167e6f789ebaef255b93/pennylane_qiskit/qiskit_device.py#L232 with self._circuit.measure(qr, cr) may fix the problem. Not tested.

CatalinaAlbornoz commented 2 years ago

Hi @andreamari, thank you for pointing this out and for suggesting the fix!

rmoyard commented 2 years ago

Thanks @andreamari, I'll open a PR for the new version of Qiskit!

jakelishman commented 2 years ago

Apologies everyone - this shouldn't have been removed without a deprecation warning, and I'll add it back (with a deprecation warning) in Terra 0.19.1 later this week. The loose measure function here was never meant to be public; it was just a hold-over from how we used to build up the QuantumCircuit object with monkey-patching, and in a tidy-up for Terra 0.19 it got removed. The solution Andrea suggested is identical to the current code, and what the deprecation warning will suggest you do in the future. (Literally - the exact measure function you were importing was bound to QuantumCircuit.measure.)

See Qiskit/qiskit-terra#7370 for our tracking issue on this.

jakelishman commented 2 years ago

Terra 0.19.1 and Qiskit 0.33.1 are live on PyPI now, which re-instated these functions with deprecation warnings.

antalszava commented 2 years ago

Thank you @jakelishman! :pray: