Repository: Qiskit/qiskit

Issue:
ImportError on Google Colab
<!-- ⚠️ If you do not respect this template, your issue will be closed -->
<!-- ⚠️ Make sure to browse the opened and closed issues -->

### Informations

- **Qiskit version**: newest version
- **Python version**: 3.7
- **Operating system**:
- Platform: Google Colab

### What is the current behavior?
After the update, the following pops up

/usr/local/lib/python3.7/dist-packages/pennylane_qiskit/qiskit_device.py in <module>()
25 from qiskit import ClassicalRegister, QuantumCircuit, QuantumRegister
26 from qiskit import extensions as ex
---> 27 from qiskit.circuit.measure import measure
28 from qiskit.compiler import transpile
29 from qiskit.converters import circuit_to_dag, dag_to_circuit

ImportError: cannot import name 'measure' from 'qiskit.circuit.measure' (/usr/local/lib/python3.7/dist-packages/qiskit/circuit/measure.py)

The original code worked well before the update in 06/12/2021.


Discussion:
This looks like `pennylane_qiskit` is importing a function that was never meant to be public in that location in the first place - the old function `qiskit.circuit.measure.measure` should actually have been accessed by the name `qiskit.QuantumCircuit.measure`.

Regardless, we shouldn't have removed that without first issuing a deprecation warning (I'm pretty sure I'm the culprit here), so we can add the function back for 0.19.1 with a deprecation warning.
Ok I see. Thank you for your prompt reply!

Resolving patch:
diff --git a/qiskit/circuit/measure.py b/qiskit/circuit/measure.py
--- a/qiskit/circuit/measure.py
+++ b/qiskit/circuit/measure.py
@@ -13,6 +13,9 @@
 """
 Quantum measurement in the computational basis.
 """
+
+import warnings
+
 from qiskit.circuit.instruction import Instruction
 from qiskit.circuit.exceptions import CircuitError
 
@@ -36,3 +39,32 @@ def broadcast_arguments(self, qargs, cargs):
                 yield qarg, [each_carg]
         else:
             raise CircuitError("register size error")
+
+
+def measure(circuit, qubit, clbit):
+    """Measure a quantum bit into classical bit.
+
+    .. deprecated:: Qiskit Terra 0.19
+        Use :meth:`.QuantumCircuit.measure` instead, either by calling
+        ``circuit.measure(qubit, clbit)``, or if a full function is required, then
+        ``QuantumCircuit.measure(circuit, qubit, clbit)``.
+
+    Args:
+        circuit (QuantumCircuit): the quantum circuit to attach the measurement to.
+        qubit (Union[Qubit, int]): the quantum bit to measure
+        clbit (Union[Clbit, int]): the classical bit to store the measurement result in.
+
+    Returns:
+        .InstructionSet: a handle to the created instruction.
+
+    Raises:
+        CircuitError: if either bit is not in the circuit, or is in a bad format.
+    """
+    warnings.warn(
+        "The loose 'measure' function is deprecated as of Qiskit Terra 0.19, and will be removed"
+        " in a future release.  Instead, you should call 'circuit.measure(qubit, clbit)', or if you"
+        " need a function, you can do `QuantumCircuit.measure(circuit, qubit, clbit)'.",
+        category=DeprecationWarning,
+        stacklevel=2,
+    )
+    return circuit.measure(qubit, clbit)
diff --git a/qiskit/circuit/reset.py b/qiskit/circuit/reset.py
--- a/qiskit/circuit/reset.py
+++ b/qiskit/circuit/reset.py
@@ -13,6 +13,9 @@
 """
 Qubit reset to computational zero.
 """
+
+import warnings
+
 from qiskit.circuit.instruction import Instruction
 
 
@@ -26,3 +29,30 @@ def __init__(self):
     def broadcast_arguments(self, qargs, cargs):
         for qarg in qargs[0]:
             yield [qarg], []
+
+
+def reset(circuit, qubit):
+    """Reset a quantum bit on a circuit.
+
+    .. deprecated:: Qiskit Terra 0.19
+        Use :meth:`.QuantumCircuit.reset` instead, either by calling ``circuit.reset(qubit)``, or if
+        a full function is required, then ``QuantumCircuit.reset(circuit, qubit)``.
+
+    Args:
+        circuit (QuantumCircuit): the quantum circuit to attach the reset operation to.
+        qubit (Union[Qubit, int]): the quantum bit to reset
+
+    Returns:
+        .InstructionSet: a handle to the created instruction.
+
+    Raises:
+        CircuitError: if the qubit is not in the circuit, or is in a bad format.
+    """
+    warnings.warn(
+        "The loose 'reset' function is deprecated as of Qiskit Terra 0.19, and will be removed"
+        " in a future release.  Instead, you should call 'circuit.reset(qubit)', or if you"
+        " need a function, you can do `QuantumCircuit.reset(circuit, qubit)'.",
+        category=DeprecationWarning,
+        stacklevel=2,
+    )
+    return circuit.reset(qubit)


Test patch:
diff --git a/test/python/circuit/test_circuit_operations.py b/test/python/circuit/test_circuit_operations.py
--- a/test/python/circuit/test_circuit_operations.py
+++ b/test/python/circuit/test_circuit_operations.py
@@ -948,6 +948,32 @@ def test_compare_a_circuit_with_none(self):
 
         self.assertFalse(qc1 == qc2)
 
+    def test_deprecated_measure_function(self):
+        """Test that the deprecated version of the loose 'measure' function works correctly."""
+        from qiskit.circuit.measure import measure
+
+        test = QuantumCircuit(1, 1)
+        with self.assertWarnsRegex(DeprecationWarning, r".*Qiskit Terra 0\.19.*"):
+            measure(test, 0, 0)
+
+        expected = QuantumCircuit(1, 1)
+        expected.measure(0, 0)
+
+        self.assertEqual(test, expected)
+
+    def test_deprecated_reset_function(self):
+        """Test that the deprecated version of the loose 'reset' function works correctly."""
+        from qiskit.circuit.reset import reset
+
+        test = QuantumCircuit(1, 1)
+        with self.assertWarnsRegex(DeprecationWarning, r".*Qiskit Terra 0\.19.*"):
+            reset(test, 0)
+
+        expected = QuantumCircuit(1, 1)
+        expected.reset(0)
+
+        self.assertEqual(test, expected)
+
 
 class TestCircuitPrivateOperations(QiskitTestCase):
     """Direct tests of some of the private methods of QuantumCircuit.  These do not represent