# Error with KerasLayer and Amplitude Embedding

**URL:** <https://discuss.pennylane.ai/t/error-with-keraslayer-and-amplitude-embedding/3924>\
**Category:** PennyLane Help\
**Created:** [January 18, 2024, 4:01pm UTC](https://discuss.pennylane.ai/t/error-with-keraslayer-and-amplitude-embedding/3924 "2024-01-18T16:01:11Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Laia\_Domingo](https://yyz2.discourse-cdn.com/flex012/user_avatar/discuss.pennylane.ai/laia_domingo/32/2212_2.png) [@Laia\_Domingo](https://discuss.pennylane.ai/u/Laia_Domingo)\
**Post date:** [January 18, 2024, 4:01pm UTC](https://discuss.pennylane.ai/t/error-with-keraslayer-and-amplitude-embedding/3924/1 "2024-01-18T16:01:11Z")

</div>

Hi there! I’m getting an error when trying to create a Keras layer with AmplitudeEmbedding. It has to do with casting the input to complex128. Here’s my code:

```auto
import pennylane as qml
from pennylane import numpy as qnp
from pennylane.transforms import richardson_extrapolate, fold_global
import numpy as np
import tensorflow as tf

# Hyperparameters of the circui
nqbits=4
depth=1

# Device definition
dev_ideal = qml.device('default.mixed', wires=nqbits)
dev_mixed = qml.transforms.insert(dev_ideal, qml.DepolarizingChannel, 0.1) # Adding noise

@qml.transforms.mitigate_with_zne([1, 2, 3], fold_global, richardson_extrapolate) # Adding error mitigation
@qml.qnode(dev_mixed)
def mitigated_qnode(inputs, weights):
    qml.AmplitudeEmbedding(features=inputs, wires=range(nqbits),normalize=True)
    qml.templates.StronglyEntanglingLayers(weights, wires=range(nqbits))
    return [qml.expval(qml.PauliZ(wires=i)) for i in range(nqbits)]

# Create keras model
weight_shapes = {"weights": (depth, nqbits,3)}
qlayer = qml.qnn.KerasLayer(mitigated_qnode, weight_shapes, output_dim=nqbits)

# Make a prediction
inputs = qnp.random.normal(2, 4,(1, 2**nqbits), requires_grad=False)
qlayer(inputs)

```

And here’s the full error message below:

```auto
ValueError Traceback (most recent call last)
<ipython-input-32-37ce10b2c2b7> in <cell line: 29>()
     27 # Make a prediction
     28 inputs = qnp.random.normal(2, 4,(1, 2**nqbits), requires_grad=False)
---> 29 qlayer(inputs)

15 frames
/usr/local/lib/python3.10/dist-packages/pennylane/math/single_dispatch.py in <lambda>(x, **kwargs)
    266 
    267 ar.register_function(
--> 268 "tensorflow", "asarray", lambda x, **kwargs: _i("tf").convert_to_tensor(x,**kwargs)
    269 )
    270 ar.register_function(

ValueError: Exception encountered when calling layer "keras_layer_7" (type KerasLayer).

Tensor conversion requested dtype complex128 for Tensor with dtype float32: <tf.Tensor: shape=(16,), dtype=float32, numpy=
array([ 0.32765773, 0.04465814, -0.05177495, -0.19328678, 0.28668392,
        0.40516296, -0.09485355, -0.10624942, 0.05358212, 0.16164567,
       -0.00984542, 0.45717812, 0.21692467, 0.3813239 , -0.3816654 ,
        0.08793645], dtype=float32)>

Call arguments received:
  • inputs=tf.Tensor(shape=(1, 16), dtype=float32)

```

I’m using Google Colab to test this, here’s the output of qml.about:

```auto
Name: PennyLane
Version: 0.34.0
Summary: PennyLane is a Python quantum machine learning library by Xanadu Inc.
Home-page: https://github.com/PennyLaneAI/pennylane
Author: 
Author-email: 
License: Apache License 2.0
Location: /usr/local/lib/python3.10/dist-packages
Requires: appdirs, autograd, autoray, cachetools, networkx, numpy, pennylane-lightning, requests, rustworkx, scipy, semantic-version, toml, typing-extensions
Required-by: PennyLane-Lightning

Platform info: Linux-6.1.58+-x86_64-with-glibc2.35
Python version: 3.10.12
Numpy version: 1.23.5
Scipy version: 1.11.4
Installed devices:
- lightning.qubit (PennyLane-Lightning-0.34.0)
- default.gaussian (PennyLane-0.34.0)
- default.mixed (PennyLane-0.34.0)
- default.qubit (PennyLane-0.34.0)
- default.qubit.autograd (PennyLane-0.34.0)
- default.qubit.jax (PennyLane-0.34.0)
- default.qubit.legacy (PennyLane-0.34.0)
- default.qubit.tf (PennyLane-0.34.0)
- default.qubit.torch (PennyLane-0.34.0)
- default.qutrit (PennyLane-0.34.0)
- null.qubit (PennyLane-0.34.0)

```

Thanks!!

---

<div class="post-metadata">

**Author:** ![isaacdevlugt](https://yyz2.discourse-cdn.com/flex012/user_avatar/discuss.pennylane.ai/isaacdevlugt/32/1159_2.png) [@isaacdevlugt](https://discuss.pennylane.ai/u/isaacdevlugt)\
**Post date:** [January 19, 2024, 10:51pm UTC](https://discuss.pennylane.ai/t/error-with-keraslayer-and-amplitude-embedding/3924/2 "2024-01-19T22:51:17Z")

</div>

Hey @Laia_Domingo,

Thanks! I was able to replicate your error and was a little perplexed. I tried running your code without ZNE stuff and with regular `default.qubit` and it worked, but simply using `default.mixed` instead is causing problems. You’ve found a bug! 🐛

I made an issue on our repository: [[BUG] Tensorflow type promotion error with `default.mixed` · Issue #5085 · PennyLaneAI/pennylane · GitHub](https://github.com/PennyLaneAI/pennylane/issues/5085). We will update you here when there’s a fix!

---

<div class="post-metadata">

**Author:** ![Laia\_Domingo](https://yyz2.discourse-cdn.com/flex012/user_avatar/discuss.pennylane.ai/laia_domingo/32/2212_2.png) [@Laia\_Domingo](https://discuss.pennylane.ai/u/Laia_Domingo)\
**Post date:** [January 22, 2024, 8:04am UTC](https://discuss.pennylane.ai/t/error-with-keraslayer-and-amplitude-embedding/3924/3 "2024-01-22T08:04:28Z")

</div>

Hi @isaacdevlugt,

Thank you for your help! 🙂

---

<div class="post-metadata">

**Author:** ![Laia\_Domingo](https://yyz2.discourse-cdn.com/flex012/user_avatar/discuss.pennylane.ai/laia_domingo/32/2212_2.png) [@Laia\_Domingo](https://discuss.pennylane.ai/u/Laia_Domingo)\
**Post date:** [January 22, 2024, 10:39am UTC](https://discuss.pennylane.ai/t/error-with-keraslayer-and-amplitude-embedding/3924/4 "2024-01-22T10:39:36Z")

</div>

Hi again!

Unable to create a Keras layer with ZNE, I attempted to create a Torch layer instead, encountering a new issue. The code functions correctly when the batch size is set to 1, but an error arises when I increase the batch size beyond 1. While such errors are typically associated with qnodes not utilizing input parameters, this is not the source of the problem in this scenario. Interestingly, removing the ZNE component resolves the error. Here’s my code:

```auto
import pennylane as qml
from pennylane import numpy as qnp
from pennylane.transforms import richardson_extrapolate, fold_global
import numpy as np
import torch

# Hyperparameters of the circui
nqbits=4
depth=1
batch_size = 2

# Device definition
dev_ideal = qml.device('default.mixed', wires=nqbits)
dev_mixed = qml.transforms.insert(dev_ideal, qml.DepolarizingChannel, 0.1) # Adding noise

@qml.transforms.mitigate_with_zne([1, 2, 3], fold_global, richardson_extrapolate) # Adding error mitigation
@qml.qnode(dev_mixed)
def mitigated_qnode(inputs, weights):
    qml.AmplitudeEmbedding(features=inputs, wires=range(nqbits),normalize=True)
    qml.templates.StronglyEntanglingLayers(weights, wires=range(nqbits))
    return [qml.expval(qml.PauliZ(wires=i)) for i in range(nqbits)]

# Creating pytorch quantum layer
weight_shapes = {"weights": (depth, nqbits,3)}
qlayer = qml.qnn.TorchLayer(mitigated_qnode, weight_shapes)

# Running layer with batch_size >1
inputs = torch.tensor(qnp.random.normal(2, 4,(batch_size, 2**nqbits)))
qlayer(inputs)

```

And here’s the error I get:

```auto
---------------------------------------------------------------------------
RuntimeError Traceback (most recent call last)
Cell In[46], line 30
     28 # Running layer with batch_size >1
     29 inputs = torch.tensor(qnp.random.normal(2, 4,(batch_size, 2**nqbits)))
---> 30 qlayer(inputs)

File c:\Users\laiad\anaconda3\envs\Quantum4\Lib\site-packages\torch\nn\modules\module.py:1501, in Module._call_impl(self, *args, **kwargs)
   1496 # If we don't have any hooks, we want to skip the rest of the logic in
   1497 # this function, and just call forward.
   1498 if not (self._backward_hooks or self._backward_pre_hooks or self._forward_hooks or self._forward_pre_hooks
   1499 or _global_backward_pre_hooks or _global_backward_hooks
   1500 or _global_forward_hooks or _global_forward_pre_hooks):
-> 1501 return forward_call(*args, **kwargs)
   1502 # Do not call functions when jit is used
   1503 full_backward_hooks, non_full_backward_hooks = [], []

File c:\Users\laiad\anaconda3\envs\Quantum4\Lib\site-packages\pennylane\qnn\torch.py:402, in TorchLayer.forward(self, inputs)
    399 inputs = torch.reshape(inputs, (-1, inputs.shape[-1]))
    401 # calculate the forward pass as usual
--> 402 results = self._evaluate_qnode(inputs)
    404 # reshape to the correct number of batch dims
    405 if has_batch_dim:

File c:\Users\laiad\anaconda3\envs\Quantum4\Lib\site-packages\pennylane\qnn\torch.py:423, in TorchLayer._evaluate_qnode(self, x)
...
-> 1100 return _VF.tensordot(a, b, dims_a, dims_b) # type: ignore[attr-defined]
   1101 else:
   1102 return _VF.tensordot(a, b, dims_a, dims_b, out=out)

RuntimeError: contracted dimensions need to match, but first has size 3 in dim -1 and second has size 4 in dim -2

```

Any idea of what is happening here? Thanks!!

---

<div class="post-metadata">

**Author:** ![isaacdevlugt](https://yyz2.discourse-cdn.com/flex012/user_avatar/discuss.pennylane.ai/isaacdevlugt/32/1159_2.png) [@isaacdevlugt](https://discuss.pennylane.ai/u/isaacdevlugt)\
**Post date:** [January 23, 2024, 11:09pm UTC](https://discuss.pennylane.ai/t/error-with-keraslayer-and-amplitude-embedding/3924/5 "2024-01-23T23:09:19Z")

</div>

Hey @Laia_Domingo,

Everything works fine without the error mitigation transform, but when it’s introduced then we get problems. I’ll get back to you on this 🤔

---

<div class="post-metadata">

**Author:** ![isaacdevlugt](https://yyz2.discourse-cdn.com/flex012/user_avatar/discuss.pennylane.ai/isaacdevlugt/32/1159_2.png) [@isaacdevlugt](https://discuss.pennylane.ai/u/isaacdevlugt)\
**Post date:** [January 24, 2024, 3:07pm UTC](https://discuss.pennylane.ai/t/error-with-keraslayer-and-amplitude-embedding/3924/6 "2024-01-24T15:07:45Z")

</div>

Hey @Laia_Domingo,

If you add the `qml.transforms.broadcast_expand` transform it should work.

```auto
# Hyperparameters of the circui
nqbits=4
depth=1
batch_size = 2

# Device definition
dev_ideal = qml.device('default.mixed', wires=nqbits)
dev_mixed = qml.transforms.insert(dev_ideal, qml.DepolarizingChannel, 0.1) # Adding noise

#@qml.qnode(dev_ideal)
@qml.transforms.mitigate_with_zne([1, 2, 3], fold_global, richardson_extrapolate) # Adding error mitigation
@qml.transforms.broadcast_expand
@qml.qnode(dev_mixed)
def mitigated_qnode(inputs, weights):

    qml.AmplitudeEmbedding(features=inputs, wires=range(nqbits),normalize=True)
    qml.templates.StronglyEntanglingLayers(weights, wires=range(nqbits))

    return [qml.expval(qml.PauliZ(wires=i)) for i in range(nqbits)]

# Creating pytorch quantum layer
weight_shapes = {"weights": (depth, nqbits, 3)}
qlayer = qml.qnn.TorchLayer(mitigated_qnode, weight_shapes)

# Running layer with batch_size >1
inputs = torch.tensor(qnp.random.normal(2, 4,(batch_size, 2**nqbits)))
qlayer(inputs)

```

The problem is that error mitigation doesn’t support broadcasting — a bug! 2 bugs in one forum post… excellent work 🕵️‍♂️! I made a bug report here and we’ll make sure to update you with progress when it happens.

> <https://github.com/PennyLaneAI/pennylane/issues/5100>
>
> \### Expected behavior
> 
> A QNode transformed with \`mitigate\_with\_zne\` should accep…t parameters with a leading dimension.
> 
> \### Actual behavior
> 
> A QNode transformed with \`mitigate\_with\_zne\` does not accept parameters with a leading dimension. Adding \`qml.transforms.broadcast\_expand\` fixes it.
> 
> \### Additional information
> 
> Reported here: https://discuss.pennylane.ai/t/error-with-keraslayer-and-amplitude-embedding/3924
> 
> Please update this forum post when there is progress made.
> 
> \### Source code
> 
> \`\`\`shell
> import pennylane as qml
> from pennylane import numpy as np
> from pennylane.transforms import richardson\_extrapolate, fold\_global
> 
> nqbits=4
> batch\_size = 2
> 
> dev\_ideal = qml.device('default.mixed', wires=nqbits)
> dev\_mixed = qml.transforms.insert(dev\_ideal, qml.DepolarizingChannel, 0.1) # Adding noise
> 
> \#@qml.transforms.broadcast\_expand
> @qml.qnode(dev\_mixed)
> def original\_qnode(inputs):
> qml.AmplitudeEmbedding(features=inputs, wires=range(nqbits), normalize=True)
> return \[qml.expval(qml.PauliZ(wires=i)) for i in range(nqbits)\]
> 
> mitigated\_qnode = qml.transforms.mitigate\_with\_zne(original\_qnode, \[1,2,3\], fold\_global, richardson\_extrapolate)
> 
> inputs = np.random.uniform(0, 1, size=(batch\_size, 2\*\*nqbits))
> mitigated\_qnode(inputs)
> \`\`\`
> 
> 
> \### Tracebacks
> 
> \`\`\`shell
> \---------------------------------------------------------------------------
> ValueError Traceback (most recent call last)
> Cell In\[16\], line 20
> 17 mitigated\_qnode = qml.transforms.mitigate\_with\_zne(original\_qnode, \[1,2,3\], fold\_global, richardson\_extrapolate)
> 19 inputs = np.random.uniform(0, 1, size=(batch\_size, 2\*\*nqbits))
> \---\> 20 mitigated\_qnode(inputs)
> 
> File ~/.virtualenvs/pennylane-torch/lib/python3.11/site-packages/pennylane/qnode.py:1039, in QNode.\_\_call\_\_(self, \*args, \*\*kwargs)
> 1034 full\_transform\_program.\_set\_all\_argnums(
> 1035 self, args, kwargs, argnums
> 1036 ) # pylint: disable=protected-access
> 1038 # pylint: disable=unexpected-keyword-arg
> \-\> 1039 res = qml.execute(
> 1040 (self.\_tape,),
> 1041 device=self.device,
> 1042 gradient\_fn=self.gradient\_fn,
> 1043 interface=self.interface,
> 1044 transform\_program=full\_transform\_program,
> 1045 config=config,
> 1046 gradient\_kwargs=self.gradient\_kwargs,
> 1047 override\_shots=override\_shots,
> 1048 \*\*self.execute\_kwargs,
> 1049 )
> 1051 res = res\[0\]
> 1053 # convert result to the interface in case the qfunc has no parameters
> 
> File ~/.virtualenvs/pennylane-torch/lib/python3.11/site-packages/pennylane/interfaces/execution.py:649, in execute(tapes, device, gradient\_fn, interface, transform\_program, config, grad\_on\_execution, gradient\_kwargs, cache, cachesize, max\_diff, override\_shots, expand\_fn, max\_expansion, device\_batch\_transform, device\_vjp)
> 647 if no\_interface\_boundary\_required:
> 648 results = inner\_execute(tapes)
> \--\> 649 return post\_processing(results)
> 651 \_grad\_on\_execution = False
> 653 if config.use\_device\_jacobian\_product and interface in jpc\_interfaces:
> 
> File ~/.virtualenvs/pennylane-torch/lib/python3.11/site-packages/pennylane/interfaces/execution.py:641, in execute.\<locals\>.post\_processing(results)
> 640 def post\_processing(results):
> \--\> 641 return program\_post\_processing(program\_pre\_processing(results))
> 
> File ~/.virtualenvs/pennylane-torch/lib/python3.11/site-packages/pennylane/transforms/core/transform\_program.py:86, in \_apply\_postprocessing\_stack(results, postprocessing\_stack)
> 63 """Applies the postprocessing and cotransform postprocessing functions in a Last-In-First-Out LIFO manner.
> 64 
> 65 Args:
> (...)
> 83 
> 84 """
> 85 for postprocessing in reversed(postprocessing\_stack):
> \---\> 86 results = postprocessing(results)
> 87 return results
> 
> File ~/.virtualenvs/pennylane-torch/lib/python3.11/site-packages/pennylane/transforms/core/transform\_program.py:56, in \_batch\_postprocessing(results, individual\_fns, slices)
> 30 def \_batch\_postprocessing(
> 31 results: ResultBatch, individual\_fns: List\[PostProcessingFn\], slices: List\[slice\]
> 32 ) -\> ResultBatch:
> 33 """Broadcast individual post processing functions onto their respective tapes.
> 34 
> 35 Args:
> (...)
> 54 
> 55 """
> \---\> 56 return tuple(fn(results\[sl\]) for fn, sl in zip(individual\_fns, slices))
> 
> File ~/.virtualenvs/pennylane-torch/lib/python3.11/site-packages/pennylane/transforms/core/transform\_program.py:56, in \<genexpr\>(.0)
> 30 def \_batch\_postprocessing(
> 31 results: ResultBatch, individual\_fns: List\[PostProcessingFn\], slices: List\[slice\]
> 32 ) -\> ResultBatch:
> 33 """Broadcast individual post processing functions onto their respective tapes.
> 34 
> 35 Args:
> (...)
> 54 
> 55 """
> \---\> 56 return tuple(fn(results\[sl\]) for fn, sl in zip(individual\_fns, slices))
> 
> File ~/.virtualenvs/pennylane-torch/lib/python3.11/site-packages/pennylane/transforms/mitigate.py:541, in mitigate\_with\_zne.\<locals\>.processing\_fn(results)
> 536 for i in range(0, len(results), reps\_per\_factor):
> 537 # The stacking ensures the right interface is used
> 538 # averaging over axis=0 is critical because the qnode may have multiple outputs
> 539 results\_flattened.append(mean(qml.math.stack(results\[i : i + reps\_per\_factor\]), axis=0))
> \--\> 541 extrapolated = extrapolate(scale\_factors, results\_flattened, \*\*extrapolate\_kwargs)
> 543 extrapolated = extrapolated\[0\] if shape(extrapolated) == (1,) else extrapolated
> 545 # unstack the results in the case of multiple measurements
> 
> File ~/.virtualenvs/pennylane-torch/lib/python3.11/site-packages/pennylane/transforms/mitigate.py:320, in richardson\_extrapolate(x, y)
> 297 def richardson\_extrapolate(x, y):
> 298 r"""Polynomial fit where the degree of the polynomial is fixed to being equal to the length of \`\`x\`\`.
> 299 
> 300 In a nutshell, this function is calling :func:\`~.pennylane.transforms.poly\_extrapolate\` with \`\`order = len(x)-1\`\`.
> (...)
> 318 
> 319 """
> \--\> 320 return poly\_extrapolate(x, y, len(x) - 1)
> 
> File ~/.virtualenvs/pennylane-torch/lib/python3.11/site-packages/pennylane/transforms/mitigate.py:293, in poly\_extrapolate(x, y, order)
> 269 def poly\_extrapolate(x, y, order):
> 270 r"""Extrapolator to :math:\`f(0)\` for polynomial fit.
> 271 
> 272 The polynomial is defined as \`\`f(x) = p\[0\] \* x\*\*deg + p\[1\] \* x\*\*(deg-1) + ... + p\[deg\]\`\` such that \`\`deg = order + 1\`\`.
> (...)
> 291 
> 292 """
> \--\> 293 coeff = \_polyfit(x, y, order)
> 294 return coeff\[-1\]
> 
> File ~/.virtualenvs/pennylane-torch/lib/python3.11/site-packages/pennylane/transforms/mitigate.py:264, in \_polyfit(x, y, order)
> 262 c = qml.math.linalg.pinv(qml.math.transpose(X) @ X)
> 263 c = c @ qml.math.transpose(X)
> \--\> 264 c = qml.math.dot(c, y)
> 265 c = qml.math.transpose(qml.math.transpose(c) / scale)
> 266 return c
> 
> File ~/.virtualenvs/pennylane-torch/lib/python3.11/site-packages/pennylane/math/multi\_dispatch.py:151, in multi\_dispatch.\<locals\>.decorator.\<locals\>.wrapper(\*args, \*\*kwargs)
> 148 interface = interface or get\_interface(\*dispatch\_args)
> 149 kwargs\["like"\] = interface
> \--\> 151 return fn(\*args, \*\*kwargs)
> 
> File ~/.virtualenvs/pennylane-torch/lib/python3.11/site-packages/pennylane/math/multi\_dispatch.py:358, in dot(tensor1, tensor2, like)
> 354 return x @ y
> 356 return np.tensordot(x, y, axes=\[\[-1\], \[-2\]\], like=like)
> \--\> 358 return np.dot(x, y, like=like)
> 
> File ~/.virtualenvs/pennylane-torch/lib/python3.11/site-packages/autoray/autoray.py:80, in do(fn, like, \*args, \*\*kwargs)
> 31 """Do function named \`\`fn\`\` on \`\`(\*args, \*\*kwargs)\`\`, peforming single
> 32 dispatch to retrieve \`\`fn\`\` based on whichever library defines the class of
> 33 the \`\`args\[0\]\`\`, or the \`\`like\`\` keyword argument if specified.
> (...)
> 77 \<tf.Tensor: id=91, shape=(3, 3), dtype=float32\>
> 78 """
> 79 backend = choose\_backend(fn, \*args, like=like, \*\*kwargs)
> \---\> 80 return get\_lib\_fn(backend, fn)(\*args, \*\*kwargs)
> 
> ValueError: shapes (3,3) and (3,4,2) not aligned: 3 (dim 1) != 4 (dim 1)
> \`\`\`
> 
> 
> \### System information
> 
> \`\`\`shell
> Name: PennyLane
> Version: 0.34.0
> Summary: PennyLane is a Python quantum machine learning library by Xanadu Inc.
> Home-page: https://github.com/PennyLaneAI/pennylane
> Author: 
> Author-email: 
> License: Apache License 2.0
> Location: /Users/isaac/.virtualenvs/pennylane-torch/lib/python3.11/site-packages
> Requires: appdirs, autograd, autoray, cachetools, networkx, numpy, pennylane-lightning, requests, rustworkx, scipy, semantic-version, toml, typing-extensions
> Required-by: PennyLane-Lightning
> 
> Platform info: macOS-14.2.1-arm64-arm-64bit
> Python version: 3.11.6
> Numpy version: 1.26.2
> Scipy version: 1.11.4
> Installed devices:
> \- lightning.qubit (PennyLane-Lightning-0.34.0)
> \- default.gaussian (PennyLane-0.34.0)
> \- default.mixed (PennyLane-0.34.0)
> \- default.qubit (PennyLane-0.34.0)
> \- default.qubit.autograd (PennyLane-0.34.0)
> \- default.qubit.jax (PennyLane-0.34.0)
> \- default.qubit.legacy (PennyLane-0.34.0)
> \- default.qubit.tf (PennyLane-0.34.0)
> \- default.qubit.torch (PennyLane-0.34.0)
> \- default.qutrit (PennyLane-0.34.0)
> \- null.qubit (PennyLane-0.34.0)
> \`\`\`
> 
> 
> \### Existing GitHub issues
> 
> \- \[X\] I have searched existing GitHub issues to make sure the issue does not already exist.

---

<div class="post-metadata">

**Author:** ![Astral\_Cai](https://yyz2.discourse-cdn.com/flex012/user_avatar/discuss.pennylane.ai/astral_cai/32/1254_2.png) [@Astral\_Cai](https://discuss.pennylane.ai/u/Astral_Cai)\
**Post date:** [February 5, 2024, 5:11pm UTC](https://discuss.pennylane.ai/t/error-with-keraslayer-and-amplitude-embedding/3924/7 "2024-02-05T17:11:39Z")

</div>

This PR should fix it:

> <https://github.com/PennyLaneAI/pennylane/pull/5155>
>
> \### Before submitting
> 
> Please complete the following checklist when submitting… a PR:
> 
> \- \[\] All new features must include a unit test.
> If you've fixed a bug or added code that should be tested, add a test to the
> test directory!
> 
> \- \[\] All new functions and code must be clearly commented and documented.
> If you do make documentation changes, make sure that the docs build and
> render correctly by running \`make docs\`.
> 
> \- \[\] Ensure that the test suite passes, by running \`make test\`.
> 
> \- \[\] Add a new entry to the \`doc/releases/changelog-dev.md\` file, summarizing the
> change, and including a link back to the PR.
> 
> \- \[\] The PennyLane source code conforms to
> \[PEP8 standards\](https://www.python.org/dev/peps/pep-0008/).
> We check all of our code against \[Pylint\](https://www.pylint.org/).
> To lint modified files, simply \`pip install pylint\`, and then
> run \`pylint pennylane/path/to/file.py\`.
> 
> When all the above are checked, delete everything above the dashed
> line and fill in the pull request template.
> 
> \------------------------------------------------------------------------------------------------------------
> 
> \*\*Context:\*\*
> 
> \*\*Description of the Change:\*\*
> 
> \*\*Benefits:\*\*
> 
> \*\*Possible Drawbacks:\*\*
> 
> \*\*Related GitHub Issues:\*\*

---

<div class="post-metadata">

**Author:** ![Astral\_Cai](https://yyz2.discourse-cdn.com/flex012/user_avatar/discuss.pennylane.ai/astral_cai/32/1254_2.png) [@Astral\_Cai](https://discuss.pennylane.ai/u/Astral_Cai)\
**Post date:** [February 13, 2024, 2:23pm UTC](https://discuss.pennylane.ai/t/error-with-keraslayer-and-amplitude-embedding/3924/8 "2024-02-13T14:23:27Z")

</div>

This PR should fix it:

> <https://github.com/PennyLaneAI/pennylane/pull/5195>
>
> \*\*Context:\*\*
> A QNode transformed with \`mitigate\_with\_zne\` does not accept param…eters with a leading dimension
> 
> \*\*Description of the Change:\*\*
> 1. Replace \`qml.math.dot\` with \`qml.math.tensordot\` in \`\_polyfit\`
> 2. Test case added for parameter broadcasting with \`mitigate\_with\_zne\`
> 
> \*\*Benefits:\*\*
> BugFix
> 
> \*\*Related GitHub Issues:\*\*
> https://github.com/PennyLaneAI/pennylane/issues/5100
> 
> \*\*Related Shortcut Story:\*\*
> \[sc-55298\]
