Template Class AdjointJacobianBase

Class Documentation

template<class StateVectorT, class Derived>
class AdjointJacobianBase

Adjoint Jacobian evaluator following the method of arXiV:2009.02823.

Template Parameters

StateVectorT – State vector type.

Public Functions

~AdjointJacobianBase() = default

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 to UpdatedStateVectorT.

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, size_t op_idx)

Apply the adjoint indexed operation from OpsData<StateVectorT> object to UpdatedStateVectorT.

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, size_t op_idx)

Apply the adjoint indexed operation from several OpsData<StateVectorT> objects to UpdatedStateVectorT objects.

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<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<size_t> &controlled_wires, const std::vector<bool> &controlled_values, const std::vector<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 to StateVectorT.

Parameters
  • state – Statevector to be updated.

  • observable – Observable to apply.

inline void applyObservables(std::vector<StateVectorT> &states, const StateVectorT &reference_state, const std::vector<std::shared_ptr<Observable<StateVectorT>>> &observables)

Apply several Observable<StateVectorT> object. to StateVectorT objects.

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.

  • jdJacobianData represents the QuantumTape to differentiate.

  • apply_operations – Indicate whether to apply operations to tape.psi prior to calculation.