Not Able to Compute Gradient


TransformError Traceback (most recent call last)
Cell In[41], line 1
----> 1 qml.gradients.param_shift(cost_function)(thetas,weights)

File /opt/anaconda3/lib/python3.12/site-packages/pennylane/transforms/core/transform_dispatcher.py:334, in TransformDispatcher._qfunc_transform..qfunc_transformed(*args, **kwargs)
331 transformed_tapes, processing_fn = self._transform(tape, *targs, **tkwargs)
333 if len(transformed_tapes) != 1:
→ 334 raise TransformError(
335 "Impossible to dispatch your transform on quantum function, because more than "
336 “one tape is returned”
337 )
339 transformed_tape = transformed_tapes[0]
341 if self.is_informative:

TransformError: Impossible to dispatch your transform on quantum function, because more than one tape is returned

Hi @mdaamir , welcome to the Forum!

Are you able to share your code so that we can try to replicate the issue?

Most likely the way your qnode(s) or cost function is set up is the cause for the issue. It’s rare to use qml.gradients.param_shift to calculate gradients, most of the time setting the differentiation method in the qnode, or letting PennyLane choose it automatically is best. So if you share your code (or a simplified but self-contained version of your code) I can help you figure out the cause for the issue.