Gradient Evaluation

The gradient can be computed with a function call which is similar to that of eval_forward, but with the additional target argument, which is the target gate we wish to implement.

The intended way of computing the gradient is the discrete adjoint method, which can be called using the discrete_adjoint function, but the functions eval_grad_forced and eval_grad_finite_difference can also be used, for example to check the correctness of the discrete adjoint method.

QuantumGateDesign.discrete_adjointFunction
discrete_adjoint(prob, controls, pcof, target; [order=2, cost_type=:Infidelity, return_lambda_history=false])

Compute the gradient using the discrete adjoint method. Return the gradient.

Arguments

  • prob::SchrodingerProb: Object containing the Hamiltonians, number of timesteps, etc.
  • controls: An AstractControl or vector of controls, where the i-th control corresponds to the i-th control Hamiltonian.
  • pcof::AbstractVector{<: Real}: The control vector.
  • target::AbstractMatrix{Float64}: The target gate, in 'stacked' real-valued format.
  • order::Int64=2: Which order of the method to use.
  • cost_type=:Infidelity: The cost function to use (ONLY USE INFIDELITY, OTHERS HAVE NOT BEEN TESTED RECENTLY).
  • return_lambda_history=false: Whether to return the history of the adjoint variable lambda.
source
QuantumGateDesign.eval_grad_finite_differenceFunction
eval_grad_finite_difference(prob, controls, pcof, target; [dpcof=1e-5, order=2, cost_type=:Infidelity, abstol=1e-10, reltol=1e-10])

Compute the gradient using centered difference for each control parameter. Return the gradient.

Arguments

  • prob::SchrodingerProb: Object containing the Hamiltonians, number of timesteps, etc.
  • controls: An AstractControl or vector of controls, where the i-th control corresponds to the i-th control Hamiltonian.
  • pcof::AbstractVector{<: Real}: The control vector.
  • target::AbstractMatrix{Float64}: The target gate, in 'stacked' real-valued format.
  • dpcof=1e-5: The spacing to be used in the centered difference method.
  • cost_type=:Infidelity: The cost function to use (ONLY USE INFIDELITY, OTHERS HAVE NOT BEEN TESTED RECENTLY)
  • order::Int64=2: Which order of the method to use.
source
QuantumGateDesign.eval_grad_forcedFunction
eval_grad_forced(prob, controls, pcof, target; [order=2, cost_type=:Infidelity, return_forcing=false])

Compute the gradient by differentiating Schrodinger's equation w.r.t each control parameter (the GOAT method). Return the gradient.

Arguments

  • prob::SchrodingerProb: Object containing the Hamiltonians, number of timesteps, etc.
  • controls: An AstractControl or vector of controls, where the i-th control corresponds to the i-th control Hamiltonian.
  • pcof::AbstractVector{<: Real}: The control vector.
  • target::AbstractMatrix{Float64}: The target gate, in 'stacked' real-valued format.
  • cost_type=:Infidelity: The cost function to use (ONLY USE INFIDELITY, OTHERS HAVE NOT BEEN TESTED RECENTLY).
  • return_forcing=false: Whether to return the forcing array computed for the last control parameter (for debugging).
  • order::Int64=2: Which order of the method to use.
  • abstol::Float64=1e-10: Absolute tolerance to use in GMRES.
  • reltol::Float64=1e-10: Relative tolerance to use in GMRES.
source