I am trying to implement an autograd-based solver for a nonlinear PDE. As with most PDE's, I need to be able to operate in individual entries of my input vector, but apparently this breaks autograd. I have created this simple example to show the issue I'm facing:
The following code works:
def my_equation(x):
eq = x
return eq
x = np.random.randn(2,)
jac = autograd.jacobian(my_equation)
jacval = jac(x)
print(jacval)
The following code does not work:
def my_equation(x):
eq = x
# This breaks the code, although is a
# trivial line
eq[1] = x[1]
return eq
x = np.random.randn(2,)
jac = autograd.jacobian(my_equation)
jacval = jac(x)
print(jacval)
I've read in a couple of places that you can't assign elements in autograd. Is this actually true. Is there any workaround? Or maybe another library to suggest?
Thank you!