PennyLane is a cross-platform Python library for quantum computing, quantum machine learning, and quantum chemistry. Train a quantum computer the same way as a neural network.
this was originally reported as a bug, but it is known behaviour so it will instead be considered a feature request. In short, the request here is to make classical jacobian computation compatible with non-scalar parameters.
Expected behavior
Applying a gradient_transform manually to a QNode that has non-scalar parameters on the tape level works and returns correct Jacobians.
Actual behavior
For mixed-shape trainable parameters on the tape level, an error is raised. For consistent non-scalar trainable tape-level parameters, wrong Jacobians may be returned.
Additional information
The problem is with qml.transforms.classical_jacobian and the contraction of the resulting classical Jacobian with the quantum Jacobian in gradient_transform.default_qnode_wrapper.
For mixed-shape parameters, stacking the tape parameters is not allowed, but stack is used in classical_preprocessing within classical_jacobian.
For non-scalar parameters, the reshaping of the quantum and classical Jacobians, as well as the contraction axes, are incorrect, leading to errors or wrong results.
Edit from original submission
this was originally reported as a bug, but it is known behaviour so it will instead be considered a feature request. In short, the request here is to make classical jacobian computation compatible with non-scalar parameters.
Expected behavior
Applying a
gradient_transform
manually to aQNode
that has non-scalar parameters on the tape level works and returns correct Jacobians.Actual behavior
For mixed-shape trainable parameters on the tape level, an error is raised. For consistent non-scalar trainable tape-level parameters, wrong Jacobians may be returned.
Additional information
The problem is with
qml.transforms.classical_jacobian
and the contraction of the resulting classical Jacobian with the quantum Jacobian ingradient_transform.default_qnode_wrapper
.For mixed-shape parameters, stacking the tape parameters is not allowed, but
stack
is used inclassical_preprocessing
withinclassical_jacobian
.For non-scalar parameters, the reshaping of the quantum and classical Jacobians, as well as the contraction axes, are incorrect, leading to errors or wrong results.
Source code
Tracebacks
System information
Existing GitHub issues