diff --git a/doc/releases/changelog-dev.md b/doc/releases/changelog-dev.md
index e0b6a4e3ab4..9394ac111da 100644
--- a/doc/releases/changelog-dev.md
+++ b/doc/releases/changelog-dev.md
@@ -455,6 +455,9 @@
the last axis (`axis=-1`). Without the fix, it would wrongly return `tensor[indices]`.
[(#4605)](https://github.com/PennyLaneAI/pennylane/pull/4605)
+* Ensure the logging `TRACE` level works with gradient-free execution.
+ [(#4669)](https://github.com/PennyLaneAI/pennylane/pull/4669)
+
Contributors ✍️
This release contains contributions from (in alphabetical order):
@@ -472,6 +475,7 @@ Lillian M. A. Frederiksen,
Vincent Michaud-Rioux,
Romain Moyard,
Daniel F. Nino,
+Lee James O'Riordan,
Mudit Pandey,
Matthew Silverman,
Jay Soni,
diff --git a/pennylane/interfaces/autograd.py b/pennylane/interfaces/autograd.py
index 6ca0e2a7d76..79fbbe6103d 100644
--- a/pennylane/interfaces/autograd.py
+++ b/pennylane/interfaces/autograd.py
@@ -116,10 +116,10 @@ def _execute(
tapes,
repr(device),
execute_fn
- if not (logger.isEnabledFor(qml.logging.TRACE) and callable(execute_fn))
+ if not (logger.isEnabledFor(qml.logging.TRACE) and inspect.isfunction(execute_fn))
else "\n" + inspect.getsource(execute_fn) + "\n",
gradient_fn
- if not (logger.isEnabledFor(qml.logging.TRACE) and callable(gradient_fn))
+ if not (logger.isEnabledFor(qml.logging.TRACE) and inspect.isfunction(gradient_fn))
else "\n" + inspect.getsource(gradient_fn) + "\n",
gradient_kwargs,
_n,
@@ -179,10 +179,10 @@ def vjp(
tapes,
repr(device),
execute_fn
- if not (logger.isEnabledFor(qml.logging.TRACE) and callable(execute_fn))
+ if not (logger.isEnabledFor(qml.logging.TRACE) and inspect.isfunction(execute_fn))
else "\n" + inspect.getsource(execute_fn) + "\n",
gradient_fn
- if not (logger.isEnabledFor(qml.logging.TRACE) and callable(gradient_fn))
+ if not (logger.isEnabledFor(qml.logging.TRACE) and inspect.isfunction(gradient_fn))
else "\n" + inspect.getsource(gradient_fn) + "\n",
gradient_kwargs,
_n,
diff --git a/pennylane/interfaces/execution.py b/pennylane/interfaces/execution.py
index 202ed42488a..6a6a0b437fe 100644
--- a/pennylane/interfaces/execution.py
+++ b/pennylane/interfaces/execution.py
@@ -292,13 +292,13 @@ def cache_execute(fn: Callable, cache, pass_kwargs=False, return_tuple=True, exp
logger.debug(
"Entry with args=(fn=%s, cache=%s, pass_kwargs=%s, return_tuple=%s, expand_fn=%s) called by=%s",
fn
- if not (logger.isEnabledFor(qml.logging.TRACE) and callable(fn))
+ if not (logger.isEnabledFor(qml.logging.TRACE) and inspect.isfunction(fn))
else "\n" + inspect.getsource(fn),
cache,
pass_kwargs,
return_tuple,
expand_fn
- if not (logger.isEnabledFor(qml.logging.TRACE) and callable(expand_fn))
+ if not (logger.isEnabledFor(qml.logging.TRACE) and inspect.isfunction(expand_fn))
else "\n" + inspect.getsource(expand_fn) + "\n",
"::L".join(str(i) for i in inspect.getouterframes(inspect.currentframe(), 2)[1][1:3]),
)
@@ -519,7 +519,7 @@ def cost_fn(params, x):
tapes,
repr(device),
gradient_fn
- if not (logger.isEnabledFor(qml.logging.TRACE) and callable(gradient_fn))
+ if not (logger.isEnabledFor(qml.logging.TRACE) and inspect.isfunction(gradient_fn))
else "\n" + inspect.getsource(gradient_fn) + "\n",
interface,
grad_on_execution,
@@ -529,7 +529,7 @@ def cost_fn(params, x):
max_diff,
override_shots,
expand_fn
- if not (logger.isEnabledFor(qml.logging.TRACE) and callable(gradient_fn))
+ if not (logger.isEnabledFor(qml.logging.TRACE) and inspect.isfunction(expand_fn))
else "\n" + inspect.getsource(expand_fn) + "\n",
max_expansion,
device_batch_transform,
diff --git a/pennylane/interfaces/jacobian_products.py b/pennylane/interfaces/jacobian_products.py
index f00e1782843..241f6a68586 100644
--- a/pennylane/interfaces/jacobian_products.py
+++ b/pennylane/interfaces/jacobian_products.py
@@ -201,7 +201,7 @@ def __init__(
logger.debug(
"TransformJacobianProduct being created with (%s, %s, %s)",
inspect.getsource(inner_execute)
- if logger.isEnabledFor(qml.logging.TRACE)
+ if (logger.isEnabledFor(qml.logging.TRACE) and inspect.isfunction(inner_execute))
else inner_execute,
gradient_transform,
gradient_kwargs,
diff --git a/pennylane/interfaces/jax.py b/pennylane/interfaces/jax.py
index 4e1325063cf..d6a90e908ce 100644
--- a/pennylane/interfaces/jax.py
+++ b/pennylane/interfaces/jax.py
@@ -106,10 +106,10 @@ def execute(tapes, device, execute_fn, gradient_fn, gradient_kwargs, _n=1, max_d
tapes,
repr(device),
execute_fn
- if not (logger.isEnabledFor(qml.logging.TRACE) and callable(execute_fn))
+ if not (logger.isEnabledFor(qml.logging.TRACE) and inspect.isfunction(execute_fn))
else "\n" + inspect.getsource(execute_fn) + "\n",
gradient_fn
- if not (logger.isEnabledFor(qml.logging.TRACE) and callable(gradient_fn))
+ if not (logger.isEnabledFor(qml.logging.TRACE) and inspect.isfunction(gradient_fn))
else "\n" + inspect.getsource(gradient_fn) + "\n",
gradient_kwargs,
_n,
diff --git a/pennylane/interfaces/tensorflow.py b/pennylane/interfaces/tensorflow.py
index a8e2b18388f..2ae127c7976 100644
--- a/pennylane/interfaces/tensorflow.py
+++ b/pennylane/interfaces/tensorflow.py
@@ -172,10 +172,10 @@ def execute(tapes, device, execute_fn, gradient_fn, gradient_kwargs, _n=1, max_d
tapes,
repr(device),
execute_fn
- if not (logger.isEnabledFor(qml.logging.TRACE) and callable(execute_fn))
+ if not (logger.isEnabledFor(qml.logging.TRACE) and inspect.isfunction(execute_fn))
else "\n" + inspect.getsource(execute_fn) + "\n",
gradient_fn
- if not (logger.isEnabledFor(qml.logging.TRACE) and callable(gradient_fn))
+ if not (logger.isEnabledFor(qml.logging.TRACE) and inspect.isfunction(gradient_fn))
else "\n" + inspect.getsource(gradient_fn) + "\n",
gradient_kwargs,
_n,
diff --git a/pennylane/interfaces/torch.py b/pennylane/interfaces/torch.py
index 2a4172078b7..33e72e2c903 100644
--- a/pennylane/interfaces/torch.py
+++ b/pennylane/interfaces/torch.py
@@ -282,10 +282,10 @@ def execute(tapes, device, execute_fn, gradient_fn, gradient_kwargs, _n=1, max_d
tapes,
repr(device),
execute_fn
- if not (logger.isEnabledFor(qml.logging.TRACE) and callable(execute_fn))
+ if not (logger.isEnabledFor(qml.logging.TRACE) and inspect.isfunction(execute_fn))
else "\n" + inspect.getsource(execute_fn) + "\n",
gradient_fn
- if not (logger.isEnabledFor(qml.logging.TRACE) and callable(gradient_fn))
+ if not (logger.isEnabledFor(qml.logging.TRACE) and inspect.isfunction(gradient_fn))
else "\n" + inspect.getsource(gradient_fn) + "\n",
gradient_kwargs,
_n,
diff --git a/pennylane/qnode.py b/pennylane/qnode.py
index 480aa9dfaa4..e77d2ae6b26 100644
--- a/pennylane/qnode.py
+++ b/pennylane/qnode.py
@@ -400,7 +400,7 @@ def __init__(
logger.debug(
"""Creating QNode(func=%s, device=%s, interface=%s, diff_method=%s, expansion_strategy=%s, max_expansion=%s, grad_on_execution=%s, cache=%s, cachesize=%s, max_diff=%s, gradient_kwargs=%s""",
func
- if not (logger.isEnabledFor(qml.logging.TRACE) and callable(func))
+ if not (logger.isEnabledFor(qml.logging.TRACE) and inspect.isfunction(func))
else "\n" + inspect.getsource(func),
repr(device),
interface,