Qiskit / qiskit

Qiskit is an open-source SDK for working with quantum computers at the level of extended quantum circuits, operators, and primitives.
https://www.ibm.com/quantum/qiskit
Apache License 2.0
5.28k stars 2.37k forks source link

marginal_counts is using deprecated functionality #13084

Closed eendebakpt closed 2 months ago

eendebakpt commented 2 months ago

Environment

What is happening?

The qiskit marginal_counts method uses deprecated functionality when a Result object is used as input.

How can we reproduce the issue?

from qiskit.circuit import QuantumCircuit
from qiskit.result.utils import marginal_counts
from qiskit_aer import AerSimulator
import qiskit_aer
qiskit_aer.__version__

import warnings
warnings.simplefilter('default')

qc = QuantumCircuit(1, 1)
qc.h(0)
qc.measure_all()

backend = AerSimulator()
result = backend.run(qc, shots=100, memory=False).result()
result = marginal_counts(result, [0])

# qiskit 1.2.0
# qiskit_aer: 0.15.0

What should happen?

No warnings should be generated, but instead the output is

C:\develop\Python312\Lib\copy.py:434: DeprecationWarning: The class ``qiskit.qobj.common.QobjDictField`` is deprecated as of qiskit 1.2. It will be removed in the 2.0 release. The `Qobj` class and related functionality are part of the deprecated `BackendV1` workflow,  and no longer necessary for `BackendV2`. If a user workflow requires `Qobj` it likely relies on deprecated functionality and should be updated to use `BackendV2`.
  y = func(*args)

Any suggestions?

No response

1ucian0 commented 2 months ago

hmm... std copy raises this warning. Maybe @jakelishman knows what's going on.

jakelishman commented 2 months ago

All of these warnings have their stack levels set correctly so that they do not blame user code. Setting the warnings to "show all warnings despite the filters" does show additional warnings, but there is some degree to which this is expected when deprecated functionality is in the process of being removed.

Fwiw, the actual deprecated functionality coming from the Result object that Aer is producing - the trouble is that Aer is still putting various deprecated Qobj things in its Result object, which are then dutifully deepcopyed. Qiskit isn't actually using deprecated functionality, the problem is just that it's deepcopying some deprecated objects that Aer actually created.

eendebakpt commented 2 months ago

This indeed seems like an issue with qiskit-aer using deprecated functionality. I created https://github.com/Qiskit/qiskit-aer/issues/2233 and will close this issue.