Repository: PennyLaneAI/pennylane
Pull request #4695 (2023-10-19 14:47:04)

add logging call to default_qubit.execute
**Context:**
Logging at device.execute wasn't included when porting from DQL

**Description of the Change:**
Copy-paste the logging call from DQL so we have it with DQ as well

**Benefits:**
More logs!

**Possible Drawbacks:**
Too many logs?

github-actions[bot]: Hello. You may have forgotten to update the changelog!
Please edit [`doc/releases/changelog-dev.md`](/PennyLaneAI/pennylane/blob/master/doc/releases/changelog-dev.md) with:
* A one-to-two sentence description of the change. You may include a small working example for new features.
* A link back to this PR.
* Your name (or GitHub username) in the contributors section.
codecov[bot]: ## [Codecov](https://app.codecov.io/gh/PennyLaneAI/pennylane/pull/4695?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=PennyLaneAI) Report
All modified and coverable lines are covered by tests :white_check_mark:
> Comparison is base [(`32a15ac`)](https://app.codecov.io/gh/PennyLaneAI/pennylane/commit/32a15ace27e8ce02e0f403c834659c9c02aab50a?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=PennyLaneAI) 99.64% compared to head [(`3f18a96`)](https://app.codecov.io/gh/PennyLaneAI/pennylane/pull/4695?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=PennyLaneAI) 99.64%.
> Report is 3 commits behind head on master.

<details><summary>Additional details and impacted files</summary>


```diff
@@           Coverage Diff            @@
##           master    #4695    +/-   ##
========================================
  Coverage   99.64%   99.64%            
========================================
  Files         376      377     +1     
  Lines       33788    33986   +198     
========================================
+ Hits        33667    33865   +198     
  Misses        121      121            
```


| [Files](https://app.codecov.io/gh/PennyLaneAI/pennylane/pull/4695?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=PennyLaneAI) | Coverage Δ | |
|---|---|---|
| [pennylane/devices/default\_qubit.py](https://app.codecov.io/gh/PennyLaneAI/pennylane/pull/4695?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=PennyLaneAI#diff-cGVubnlsYW5lL2RldmljZXMvZGVmYXVsdF9xdWJpdC5weQ==) | `100.00% <100.00%> (ø)` | |

... and [11 files with indirect coverage changes](https://app.codecov.io/gh/PennyLaneAI/pennylane/pull/4695/indirect-changes?src=pr&el=tree-more&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=PennyLaneAI)


</details>

[:umbrella: View full report in Codecov by Sentry](https://app.codecov.io/gh/PennyLaneAI/pennylane/pull/4695?src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=PennyLaneAI).   
:loudspeaker: Have feedback on the report? [Share it here](https://about.codecov.io/codecov-pr-comment-feedback/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=PennyLaneAI).


Patch:
diff --git a/pennylane/devices/default_qubit.py b/pennylane/devices/default_qubit.py
index 2453fe8a2..485598ceb 100644
--- a/pennylane/devices/default_qubit.py
+++ b/pennylane/devices/default_qubit.py
@@ -20,6 +20,8 @@ from functools import partial
 from numbers import Number
 from typing import Union, Callable, Tuple, Optional, Sequence
 import concurrent.futures
+import inspect
+import logging
 import numpy as np
 
 import pennylane as qml
@@ -43,6 +45,9 @@ from .qubit.simulate import simulate, get_final_state, measure_final_state
 from .qubit.sampling import get_num_shots_and_executions
 from .qubit.adjoint_jacobian import adjoint_jacobian, adjoint_vjp, adjoint_jvp
 
+logger = logging.getLogger(__name__)
+logger.addHandler(logging.NullHandler())
+
 Result_or_ResultBatch = Union[Result, ResultBatch]
 QuantumTapeBatch = Sequence[QuantumTape]
 QuantumTape_or_Batch = Union[QuantumTape, QuantumTapeBatch]
@@ -442,6 +447,15 @@ class DefaultQubit(Device):
         circuits: QuantumTape_or_Batch,
         execution_config: ExecutionConfig = DefaultExecutionConfig,
     ) -> Result_or_ResultBatch:
+        if logger.isEnabledFor(logging.DEBUG):
+            logger.debug(
+                """Entry with args=(circuits=%s) called by=%s""",
+                circuits,
+                "::L".join(
+                    str(i) for i in inspect.getouterframes(inspect.currentframe(), 2)[1][1:3]
+                ),
+            )
+
         is_single_circuit = False
         if isinstance(circuits, QuantumScript):
             is_single_circuit = True


Test patch:
diff --git a/tests/logging/test_logging_autograd.py b/tests/logging/test_logging_autograd.py
index aca061083..ce7de9614 100644
--- a/tests/logging/test_logging_autograd.py
+++ b/tests/logging/test_logging_autograd.py
@@ -78,7 +78,7 @@ class TestLogging:
 
             circuit(params)
 
-        assert len(caplog.records) == 3
+        assert len(caplog.records) == 4
 
         log_records_expected = [
             (
@@ -99,7 +99,7 @@ class TestLogging:
             assert all(msg in actual.getMessage() for msg in expected[1])
 
     @pytest.mark.parametrize(
-        "diff_method,num_records", [("parameter-shift", 7), ("backprop", 3), ("adjoint", 7)]
+        "diff_method,num_records", [("parameter-shift", 9), ("backprop", 4), ("adjoint", 7)]
     )
     def test_dq_qnode_execution_grad(self, caplog, diff_method, num_records):
         "Test logging of QNode with parameterised gradients"