Dear Colleagues, I'm trying to run the example from http://www.dolfin-adjoint.org/en/latest/documentation/mpec/mpec.html using firedrake_adjoint (see the attached code) but I get the below error message. I appreciate your help. Thank you. Regards --------------------------------------------------------------------------- TypeError Traceback (most recent call last) <ipython-input-8-1a7944c0c864> in <module> 40 ic.update(y_opt) 41 ---> 42 alpha.assign(float(alpha) / 2) 43 print("Set alpha to %f." % float(alpha)) ~/opt/Computational_venv/src/firedrake/firedrake/adjoint/constant.py in wrapper(self, *args, **kwargs) 34 other = args[0] 35 if not isinstance(other, OverloadedType): ---> 36 other = create_overloaded_object(ndarray(other)) 37 38 block = ConstantAssignBlock(self, other) TypeError: 'float' object cannot be interpreted as an integer
Dear Hicham, It seems that this is a bug in the code, the `ndarray` seems to be wrong here `create_overloaded_object(other)` should be the correct line. Also, I have noticed another bug at the line 38 it should be ` ConstantAssignBlock(other)` and not ` ConstantAssignBlock(self, other)`. I have created a branch (and a PR) for this fix: *https://github.com/firedrakeproject/firedrake/pull/1618 <https://github.com/firedrakeproject/firedrake/pull/1618>*. You can either move to the new branch or manually fix this. I have checked and these two changes fix your problem. Also, I think you could just directly specify `alpha/2` instead of `float(alpha)/2`. Thank you, Regards Nacime BOUZIANI Le ven. 28 févr. 2020 à 20:45, Moulay Hicham TBER <hicham.tber@gmail.com> a écrit :
Dear Colleagues,
I'm trying to run the example from http://www.dolfin-adjoint.org/en/latest/documentation/mpec/mpec.html using firedrake_adjoint (see the attached code) but I get the below error message.
I appreciate your help. Thank you.
Regards
--------------------------------------------------------------------------- TypeError Traceback (most recent call last) <ipython-input-8-1a7944c0c864> in <module> 40 ic.update(y_opt) 41 ---> 42 alpha.assign(float(alpha) / 2) 43 print("Set alpha to %f." % float(alpha))
~/opt/Computational_venv/src/firedrake/firedrake/adjoint/constant.py in wrapper(self, *args, **kwargs) 34 other = args[0] 35 if not isinstance(other, OverloadedType): ---> 36 other = create_overloaded_object(ndarray(other)) 37 38 block = ConstantAssignBlock(self, other)
TypeError: 'float' object cannot be interpreted as an integer _______________________________________________ firedrake mailing list firedrake@imperial.ac.uk https://mailman.ic.ac.uk/mailman/listinfo/firedrake
Hi Nacime, Thank you very much for your help. That solved the problem. The `float(alpha)/2` seems to be necessary. Regards N.B. There was missing "Placeholder(alpha)" and a minus sign in the previous code. I attached the working code for the record.
participants (2)
- 
                
                Moulay Hicham TBER
- 
                
                Nacime Bouziani