Template Class AdjointJacobianBase¶
Defined in File AdjointJacobianBase.hpp
Class Documentation¶
-
template<class StateVectorT, class Derived>
class AdjointJacobianBase¶ Adjoint Jacobian evaluator following the method of arXiv:2009.02823.
This class uses the Curiously Recurring Template Pattern (CRTP) to provide static polymorphism for the adjoint differentiation method. To use this class, derive from it passing your class as the Derived template parameter:
class LThunderAdjointJacobian : public AdjointJacobianBase<LThunderStateVector, LThunderAdjointJacobian> { public: // Must implement this method as required by the base class void adjointJacobian(std::span<PrecisionT> jac, const JacobianData<StateVectorT> &jd, const StateVectorT &ref_data, bool apply_operations) { // Your implementation here } };
- Template Parameters:
StateVectorT – State vector type.
Derived – The derived class implementing the concrete adjointJacobian method.
Public Functions
-
virtual ~AdjointJacobianBase() = default¶
Protected Types
-
using ComplexT = typename StateVectorT::ComplexT¶
-
using PrecisionT = typename StateVectorT::PrecisionT¶
Protected Functions
-
AdjointJacobianBase() = default¶
-
AdjointJacobianBase(const AdjointJacobianBase&) = default¶
-
AdjointJacobianBase(AdjointJacobianBase&&) noexcept = default¶
-
AdjointJacobianBase &operator=(const AdjointJacobianBase&) = default¶
-
AdjointJacobianBase &operator=(AdjointJacobianBase&&) noexcept = default¶
-
template<class UpdatedStateVectorT>
inline void applyOperations(UpdatedStateVectorT &state, const OpsData<StateVectorT> &operations, bool adj = false)¶ Apply all operations from given
OpsData<StateVectorT>object toUpdatedStateVectorT.- Template Parameters:
UpdatedStateVectorT –
- Parameters:
state – Statevector to be updated.
operations – Operations to apply.
adj – Take the adjoint of the given operations.
-
template<class UpdatedStateVectorT>
inline void applyOperationAdj(UpdatedStateVectorT &state, const OpsData<StateVectorT> &operations, std::size_t op_idx)¶ Apply the adjoint indexed operation from
OpsData<StateVectorT>object toUpdatedStateVectorT.- Template Parameters:
UpdatedStateVectorT – updated state vector type.
- Parameters:
state – Statevector to be updated.
operations – Operations to apply.
op_idx – Adjointed operation index to apply.
-
inline void applyOperationsAdj(std::vector<StateVectorT> &states, const OpsData<StateVectorT> &operations, std::size_t op_idx)¶
Apply the adjoint indexed operation from several
OpsData<StateVectorT>objects toUpdatedStateVectorTobjects.- Parameters:
states – Vector of all statevectors; 1 per observable
operations – Operations list.
op_idx – Index of given operation within operations list to take adjoint of.
-
inline auto applyGenerator(StateVectorT &sv, const std::string &op_name, const std::vector<std::size_t> &wires, const bool adj) -> PrecisionT¶
Applies the gate generator for a given parametric gate. Returns the associated scaling coefficient.
- Parameters:
sv – Statevector data to operate upon.
op_name – Name of parametric gate.
wires – Wires to operate upon.
adj – Indicate whether to take the adjoint of the operation.
- Returns:
PrecisionT Generator scaling coefficient.
-
inline auto applyGenerator(StateVectorT &sv, const std::string &op_name, const std::vector<std::size_t> &controlled_wires, const std::vector<bool> &controlled_values, const std::vector<std::size_t> &wires, const bool adj) -> PrecisionT¶
Applies the gate generator for a given parametric gate. Returns the associated scaling coefficient.
- Parameters:
sv – Statevector data to operate upon.
op_name – Name of parametric gate.
controlled_wires – Control wires.
controlled_values – Control values (false or true).
wires – Wires to operate upon.
adj – Indicate whether to take the adjoint of the operation.
- Returns:
PrecisionT Generator scaling coefficient.
-
inline void applyObservable(StateVectorT &state, const Observable<StateVectorT> &observable)¶
Apply a given
Observable<StateVectorT>object toStateVectorT.- Parameters:
state – Statevector to be updated.
observable – Observable to apply.
Apply several
Observable<StateVectorT>object. toStateVectorTobjects.- Parameters:
states – Vector of statevector copies, one per observable.
reference_state – Reference statevector
observables – Vector of observables to apply to each statevector.
-
inline void adjointJacobian(std::span<PrecisionT> jac, const JacobianData<StateVectorT> &jd, const StateVectorT &ref_data = {0}, bool apply_operations = false)¶
Calculates the statevector’s Jacobian for the selected set of parametric gates.
- 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.