Open albi3ro opened 3 years ago
Thanks for catching this @albi3ro
If the model array is a default NumPy array, then the function should return a default NumPy array, but if the model array is a Pennylane tensor inherited from ndarray, then the function should return a Pennylane array.
:+1:
Hi, I saw that no one is working on this so is it fine if I take a stab at this issue?
Hi @kessler-frost! You're welcome to give it a shot (be warned however that I don't think this is a very straightforward or easy issue to fix).
If you're instead looking for a good first issue, have a look for any issue with a good-first-issue
tag.
I must've missed that tag. Thanks! I will try one of those and see if I can solve them.
@albi3ro I was looking at the issue and how much time it would be to fix it, but then I thought it would be much more elegant to move this functionality to the new qml.math
module and implement it in all interfaces. This would be consistent since it is classical processing on a tensor. What do you think?
How high is the priority of this?
I would say that this is not that high a priority, since it only affects the optimizers, and they already have a hotfix.
Mentioning here we should just try to get rid of flatten and unflatten somehow. I think it would be doable. They are only bring used in QNGOptimizer
, rms prop, and rotoselect.
qml.utils.unflatten(flat, model)
takes a flattened objectflat
and returns it to the shape ofmodel
.But currently,
qml.utils.unflatten
does not preserve therequires_grad
flag of a PennyLane NumPy tensor. All NumPy arrays get returned to as a standard non-Pennylane NumPy array.Many places in Pennylane use this function, so any change will cascade throughout the repository.
So solving this logical inconsistency will take:
qml.utils._unflatten
function itselfBonus idea: If the model array is a default NumPy array, then the function should return a default NumPy array, but if the model array is a Pennylane tensor inherited from ndarray, then the function should return a Pennylane array.
Example code: