Template Class AdjointJacobian¶
Defined in File AdjointJacobianLQubit.hpp
Inheritance Relationships¶
Base Type¶
public AdjointJacobianBase< StateVectorT, AdjointJacobian< StateVectorT > >
Class Documentation¶
-
template<class StateVectorT>
class AdjointJacobian : public AdjointJacobianBase<StateVectorT, AdjointJacobian<StateVectorT>>¶ Adjoint Jacobian evaluator following the method of arXiv:2009.02823.
- Template Parameters:
StateVectorT – State vector type.
Public Functions
-
AdjointJacobian() = default¶
-
inline void adjointJacobianSingleObservable(std::span<PrecisionT> jac, const OpsData<StateVectorT> &ops, const std::vector<std::string> &ops_name, const std::vector<std::size_t> &tp, const Observable<StateVectorT> &ob, StateVectorLQubitManaged<PrecisionT> &lambda)¶
Helper function to calculate the Jacobian for a single observale.
This method is differnet from
adjointJacobianin that it is optimized for the case where there is only a single observable in the circuit via the use of only two statevectors rather than a vector of statevectors.- Parameters:
jac – Preallocated vector for Jacobian data results.
ops – The operations from the PennyLane tape
ops_name – The operation names from the PennyLane tape
tp – The trainable parameters retrieved from the JacobianData
ob – The (single) observable to apply
lambda – The final statevector of the forward pass of the circuit prior to calculation.
-
inline void adjointJacobian(std::span<PrecisionT> jac, const JacobianData<StateVectorT> &jd, const StateVectorT &ref_data = {0}, bool apply_operations = false)¶
Calculates the Jacobian for the statevector for the selected set of parametric gates.
For the statevector data associated with
psiof lengthnum_elements, we make internal copies, one per required observable. Theoperationswill be applied to the internal statevector copies, with the operation indices participating in the gradient calculations given intrainableParams, and the overall number of parameters for the gradient calculation provided withinnum_params. The resulting row-major orderedjacmatrix representation will be of sizejd.getSizeStateVec() * jd.getObservables().size(). OpenMP is used to enable independent operations to be offloaded to threads.Note
Only gates with pre-defined generators can be differentiated. For example,
QubitUnitaryis not differentiable as there is no generator defined for this gate.Note
For circuits with single observable, this method dispatches to
adjointJacobianSingleObservablefor higher performance.- Parameters:
jac – Preallocated vector for Jacobian data results.
jd – JacobianData represents the QuantumTape to differentiate.
apply_operations – Indicate whether to apply operations to tape.psi prior to calculation.