On Mar 12, 2020, at 8:31 PM, Sajid Ali 
<sajidsyed2...@u.northwestern.edu<mailto:sajidsyed2...@u.northwestern.edu>> 
wrote:


Hi Hong,

For the optimal control example, the cost function has an integral term which 
necessitates the setup of a sub-TS quadrature. The Jacobian with respect to 
parameter, (henceforth denoted by Jacp) has dimensions that depend upon the 
number of steps that the TS integrates for.

I'm trying to implement a simpler case where the cost function doesn't have an 
integral term but the parameters are still time dependent. For this, I modified 
the standard Van der Pol example (ex20adj.c) to make mu a time dependent 
parameter (though it has the same value at all points in time and I also made 
the initial conditions & params independent).

Since the structure of Jacp doesn't depend on time (i.e. it is the same at all 
points in time, the structure being identical to the time-independent case), is 
it necessary that I create a Jacp matrix size whose dimensions are [dimensions 
of time-independent Jacp] * -ts_max_steps ? Keeping Jacp dimensions the same as 
dimensions of time-independent Jacp causes the program to crash (possibly due 
to the fact that Jacp and adjoint vector can't be multiplied). Ideally, it 
would be nice to have a Jacp analog of TSRHSJacobianSetReuse whereby I specify 
the Jacp routine once and TS knows how to reuse that at all times. Is this 
possible with the current petsc-master ?

When the parameters are time dependent, they have to be discretized in time. In 
the optimal control example, the parameter at each discrete point is treated as 
a new parameter. If you have np time-dependent parameters, you can consider the 
total number of parameters to be Np = np*the number of discrete points (which 
is typically the total number of time steps). And you need to create a Jacp 
matrix of dimension N * Np, where N is the dimension of the ODE system. Mu 
should have the dimension Np. This is why we can simply create Mu from the 
matrix with

MatCreateVecs(Jacp,&Mu[0],NULL)

Alternatively, you can set up the solver in the same way that you do for time 
constant parameters — create a Jacp of N * np and a mu of np. Be aware that 
after TSAdjointSolve Mu gives only the derivative wrt the parameters at 
beginning time. You can access the intermediate values of Mu by using a 
customized TSAdjoint monitor. I think this does what want with a flag like 
TSRHSJacobianSetReuse.


Another question I have is regarding exclusive calculation of one adjoint. If 
I'm not interested in adjoint with respect to initial conditions, can I ask 
TSAdjoing to not calculate that ? Setting the initialization for adjoint vector 
with respect to initial conditions to be NULL in TSSetCostGradients doesn't 
work.

No, you cannot. Lambda is needed internally by the adjoint solver to calculate 
the sensitivities wrt parameters.

Hong


Thank You,
Sajid Ali | PhD Candidate
Applied Physics
Northwestern University
s-sajid-ali.github.io<http://s-sajid-ali.github.io/>

Reply via email to