Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test_adjoint_solver.py failing due to autograd-related error #2539

Closed
oskooi opened this issue May 30, 2023 · 3 comments · Fixed by #2554
Closed

test_adjoint_solver.py failing due to autograd-related error #2539

oskooi opened this issue May 30, 2023 · 3 comments · Fixed by #2554
Labels

Comments

@oskooi
Copy link
Collaborator

oskooi commented May 30, 2023

Several of the unit tests in test_adjoint_solve.py are failing due to an error related to autograd. See below for output from the test logs. I think this could be due to the recent changes made to the adjoint filters in #2465 and #2518.

Since there does not seem to have been any significant functional changes to autograd recently, it's not clear why these errors were not triggered in the Github CI.

____________________ TestAdjointSolver.test_periodic_design ____________________

>               solid_grad = grad(mpa.constraint_solid, 0)(
                    p,
                    c,
                    eta_e,
                    filter_f,
                    threshold_f,
                    self.design_region_resolution,
                    periodic_axes,
                )

tests/test_adjoint_solver.py:999:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
../autograd/wrap_util.py:20: in nary_f
    return unary_operator(unary_f, x, *nary_op_args, **nary_op_kwargs)
../autograd/differential_operators.py:29: in grad
    return vjp(vspace(ans).ones())
../autograd/core.py:14: in vjp
    def vjp(g): return backward_pass(g, end_node)
../autograd/core.py:21: in backward_pass
    ingrads = node.vjp(outgrad[0])
../autograd/core.py:67: in <lambda>
    return lambda g: (vjp(g),)
../autograd/numpy/fft.py:17: in <lambda>
    return lambda g: match_complex(x, truncate_pad(fft_fun(g, *args, **kwargs), vs.shape))
../autograd/tracer.py:48: in f_wrapped
    return f_raw(*args, **kwargs)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

x = array([[-1.28056837e-07+0.00000000e+00j,  1.13440917e-07-6.88609116e-09j,
        -7.57466336e-08+1.16364222e-08j, .......,
        -2.43666044e-10+9.31947518e-10j, -5.38423198e-09-5.29486095e-09j,
         8.57666150e-09+9.03418206e-09j]])
shape = (91, 273)

    @primitive
    def truncate_pad(x, shape):
        # truncate/pad x to have the appropriate shape
        slices = [slice(n) for n in shape]
        pads = list(zip(anp.zeros(len(shape), dtype=int),
                   anp.maximum(0, anp.array(shape) - anp.array(x.shape))))
>       return anp.pad(x, pads, 'constant')[slices]
E       IndexError: only integers, slices (`:`), ellipsis (`...`), numpy.newaxis (`None`) and integer or boolean arrays are valid indices

../autograd/numpy/fft.py:101: IndexError
@oskooi oskooi added the bug label May 30, 2023
@smartalecH
Copy link
Collaborator

(cc @mawc2019)

@oskooi
Copy link
Collaborator Author

oskooi commented May 30, 2023

Looks like the problem was the outdated version of Autograd 1.2 (Nov. 2017) I was using.

We should mention in the documentation that the adjoint solver requires the most recent version 1.5 (Sep. 2022).

@mawc2019
Copy link
Contributor

Looks like the problem was the outdated version of Autograd 1.2 (Nov. 2017) I was using.

I am using Autograd 1.3 and there is no error. So a version $\geq 1.3$ seems needed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants