AttributeError:“函数”对象没有属性“ block_variable”

问题描述

我写了torch_fenics的子类。在这种情况下,输入是来自DG空间的向量。我在弱公式中使用此输入,然后计算解。此外,我需要相对于给定输入的解的梯度。


I get the following error log on running the same

〜/ miniconda3 / envs / py37 / lib / python3.7 / site-packages / torch / autograd / function.py in apply(self,* args) 75 76 def apply(自身,* args): ---> 77返回self._forward_cls.backward(self,* args) 78 79

〜/ miniconda3 / envs / py37 / lib / python3.7 / site-packages / torch_fenics / torch_fenics.py向后(ctx,* grad_outputs) 88#检查需要计算的梯度 89控件=列表(map(fenics_adjoint.Control, ---> 90(如果是g,则为c,如果是g,则为zip(ctx.needs_input_grad [1:],ctx.fenics_inputs)中的c))) 91 92#计算并累积每个输出相对于每个输入的梯度

〜/ miniconda3 / envs / py37 / lib / python3.7 / site-packages / pyadjoint / control.py在 init 中(自我,控制) 38 def init (自我,控制): 39 self.control =控制 ---> 40 self.block_variable = control.block_variable 41 42 def数据(自己):

AttributeError:“函数”对象没有属性“ block_variable”

解决方法

请勿在您的代码中导入dolfin。它将解决问题。