Can autograd in principle work on python wrapped C functions?
The C function I'd like to differentiate expects arguments with a REAL8 data type, and I can successfully call it in python by giving it either float
or np.float64
arguments.
Upon closer inspection with my debugger, I found that I get a TypeError when autograd changes the float
or np.float64
to an ArrayBox object to when it attempts to evaluate the gradient.
Is there a way to allow autograd to proceed in this scenario?
Is there another strategy that might be better for my situation?
Are there any primitives I can code up to fix this?
Background:
Bilby is a newer python library that wraps an older code (LALSIMULATION) written in C. It provides extensive precoded gravitational wave models, and I would like to use these pre-coded models in my research. My first task is to figure out how to calculate accurate Hessian's and gradients of these models. I'd like to use automatic differentiation to solve this problem due to its infamous numerical accuracy, but I'm stuck.
import autograd.numpy as np
from autograd import grad
import BILBY_TAYLORF2 # My own class that wraps Bilby
model = BILBY_TAYLORF2()
gradient_likelihood = grad(model.logLikelihood)
gradient_likelihood(np.array([10., 10.]))
TypeError: in method 'SimInspiralChooseFDWaveform', argument 3 of type 'REAL8'
SimInspiralChooseFDWaveform is the first call to C code for reference.