From libadjoint to pyadjoint
Hi, After having installed `pyadjoint` by running `firedrake-update --install pyadjoint` I am getting `AttributeError: 'CoordinatelessFunction' object has no attribute 'block_variable'` on all calls to `solve` or `assemble` e.g.: ``` solve(F == 0, self.I, bcs=bcs) File "/home/bock/bin/firedrake/src/pyadjoint/fenics_adjoint/solving.py", line 28, in solve block = SolveBlock(*args, **kwargs) File "/home/bock/bin/firedrake/src/pyadjoint/fenics_adjoint/solving.py", line 112, in __init__ self.add_dependency(c.block_variable) File "/home/bock/bin/firedrake/src/firedrake/firedrake/function.py", line 275, in __getattr__ return getattr(self._data, name) AttributeError: 'CoordinatelessFunction' object has no attribute 'block_variable' ```
From the error above it seems that the constellation of my imports is incorrect, and that the (I believe) correct `Function` in firedrake_adjoint/types/function.py is not used. I have been playing around with different combinations of `from {firedrake_adjoint, pyadjoint} import *` without success.
Can you please point me in the direction of documentation that can help me modify my code to cater for the new change? `firedrake-status`: ``` --------------------------------------------------------------------------- |Package |Branch |Revision |Modified | --------------------------------------------------------------------------- |COFFEE |master |5bb1b30 |False | |FInAT |master |ef12759 |False | |PyOP2 |master |8a918cfc |False | |fiat |master |4a201c7 |False | |firedrake |master |3cf27a5f |False | |h5py |firedrake |c1e4a81 |False | |libspatialindex |master |4768bf3 |True | |petsc |firedrake |3c589c124b|False | |petsc4py |firedrake |3f09f6d |False | |pyadjoint |master |89b15bd |False | |tsfc |master |e6882a1 |False | |ufl |master |bd0376da |False | --------------------------------------------------------------------------- ``` <mailto:firedrake%40imperial.ac.uk> Best regards, Andreas Bock
This indeed suggests that somewhere in your system you're using a `firedrake.function.Function` instead of a `firedrake_adjoint.types.function.Function`. You should indeed be using `from firedrake_adjoint import *`. Note that if you are using both firedrake and firedrake_adjoint imports (firedrake_adjoint currently doesn't seem to provide everything that firedrake provides), then the firedrake_adjoint import should be last. If your code spreads multiple modules, they all need to use the same firedrake_adjoint imports. You can check the type of the coefficients in your system with: print([type(c) for c in F.coefficients()]) Cheers Stephan On 08/03/18 20:57, Bock, Andreas wrote:
Hi,
After having installed `pyadjoint` by running `firedrake-update --install pyadjoint` I am getting `AttributeError: 'CoordinatelessFunction' object has no attribute 'block_variable'` on all calls to `solve` or `assemble` e.g.:
``` solve(F == 0, self.I, bcs=bcs) File "/home/bock/bin/firedrake/src/pyadjoint/fenics_adjoint/solving.py", line 28, in solve block = SolveBlock(*args, **kwargs) File "/home/bock/bin/firedrake/src/pyadjoint/fenics_adjoint/solving.py", line 112, in __init__ self.add_dependency(c.block_variable) File "/home/bock/bin/firedrake/src/firedrake/firedrake/function.py", line 275, in __getattr__ return getattr(self._data, name) AttributeError: 'CoordinatelessFunction' object has no attribute 'block_variable' ```
From the error above it seems that the constellation of my imports is incorrect, and that the (I believe) correct `Function` in firedrake_adjoint/types/function.py is not used. I have been playing around with different combinations of `from {firedrake_adjoint, pyadjoint} import *` without success.
Can you please point me in the direction of documentation that can help me modify my code to cater for the new change?
`firedrake-status`:
``` --------------------------------------------------------------------------- |Package |Branch |Revision |Modified | --------------------------------------------------------------------------- |COFFEE |master |5bb1b30 |False | |FInAT |master |ef12759 |False | |PyOP2 |master |8a918cfc |False | |fiat |master |4a201c7 |False | |firedrake |master |3cf27a5f |False | |h5py |firedrake |c1e4a81 |False | |libspatialindex |master |4768bf3 |True | |petsc |firedrake |3c589c124b|False | |petsc4py |firedrake |3f09f6d |False | |pyadjoint |master |89b15bd |False | |tsfc |master |e6882a1 |False | |ufl |master |bd0376da |False | --------------------------------------------------------------------------- ```
<mailto:firedrake%40imperial.ac.uk>
Best regards,
Andreas Bock
_______________________________________________ firedrake mailing list firedrake@imperial.ac.uk https://mailman.ic.ac.uk/mailman/listinfo/firedrake
Hi Stephan, Thank you for confirming my suspicion. I am everywhere in my modules importing as follows: from firedrake import * from firedrake_adjoint import * which is aligned with your comments. I am now getting (the same) error after my initial forward solve, namely when I assemble the objective functional: J = assemble(c* advection_term + inner(v0, v0)*dx) File "/home/bock/bin/firedrake/src/pyadjoint/fenics_adjoint/assembly.py", line 23, in assemble block = AssembleBlock(form) File "/home/bock/bin/firedrake/src/pyadjoint/fenics_adjoint/assembly.py", line 65, in __init__ self.add_dependency(c.block_variable) File "/home/bock/bin/firedrake/src/firedrake/firedrake/function.py", line 275, in __getattr__ return getattr(self._data, name) AttributeError: 'CoordinatelessFunction' object has no attribute 'block_variable' Perhaps I have installed pyadjoint incorrectly? I ran the Firedrake install script after which I invoked `firedrake-update --install pyadjoint`. It seems the fenics_adjoint/assembly is not finding the correct function.py module. Thanks again, Andreas ________________________________ From: firedrake-bounces@imperial.ac.uk <firedrake-bounces@imperial.ac.uk> on behalf of Stephan Kramer <s.kramer@imperial.ac.uk> Sent: 09 March 2018 00:21:57 To: firedrake Subject: Re: [firedrake] From libadjoint to pyadjoint This indeed suggests that somewhere in your system you're using a `firedrake.function.Function` instead of a `firedrake_adjoint.types.function.Function`. You should indeed be using `from firedrake_adjoint import *`. Note that if you are using both firedrake and firedrake_adjoint imports (firedrake_adjoint currently doesn't seem to provide everything that firedrake provides), then the firedrake_adjoint import should be last. If your code spreads multiple modules, they all need to use the same firedrake_adjoint imports. You can check the type of the coefficients in your system with: print([type(c) for c in F.coefficients()]) Cheers Stephan On 08/03/18 20:57, Bock, Andreas wrote:
Hi,
After having installed `pyadjoint` by running `firedrake-update --install pyadjoint` I am getting `AttributeError: 'CoordinatelessFunction' object has no attribute 'block_variable'` on all calls to `solve` or `assemble` e.g.:
``` solve(F == 0, self.I, bcs=bcs) File "/home/bock/bin/firedrake/src/pyadjoint/fenics_adjoint/solving.py", line 28, in solve block = SolveBlock(*args, **kwargs) File "/home/bock/bin/firedrake/src/pyadjoint/fenics_adjoint/solving.py", line 112, in __init__ self.add_dependency(c.block_variable) File "/home/bock/bin/firedrake/src/firedrake/firedrake/function.py", line 275, in __getattr__ return getattr(self._data, name) AttributeError: 'CoordinatelessFunction' object has no attribute 'block_variable' ```
From the error above it seems that the constellation of my imports is incorrect, and that the (I believe) correct `Function` in firedrake_adjoint/types/function.py is not used. I have been playing around with different combinations of `from {firedrake_adjoint, pyadjoint} import *` without success.
Can you please point me in the direction of documentation that can help me modify my code to cater for the new change?
`firedrake-status`:
``` --------------------------------------------------------------------------- |Package |Branch |Revision |Modified | --------------------------------------------------------------------------- |COFFEE |master |5bb1b30 |False | |FInAT |master |ef12759 |False | |PyOP2 |master |8a918cfc |False | |fiat |master |4a201c7 |False | |firedrake |master |3cf27a5f |False | |h5py |firedrake |c1e4a81 |False | |libspatialindex |master |4768bf3 |True | |petsc |firedrake |3c589c124b|False | |petsc4py |firedrake |3f09f6d |False | |pyadjoint |master |89b15bd |False | |tsfc |master |e6882a1 |False | |ufl |master |bd0376da |False | --------------------------------------------------------------------------- ```
<mailto:firedrake%40imperial.ac.uk>
Best regards,
Andreas Bock
_______________________________________________ firedrake mailing list firedrake@imperial.ac.uk https://mailman.ic.ac.uk/mailman/listinfo/firedrake
_______________________________________________ firedrake mailing list firedrake@imperial.ac.uk https://mailman.ic.ac.uk/mailman/listinfo/firedrake
participants (2)
- 
                
                Bock, Andreas
- 
                
                Stephan Kramer