Closed epapoutsellis closed 4 months ago
Surely numba has nothing to do with it as it is the _proximal_numpy
method that fails?
If I follow the code correctly, it fails at a call to proximal
of MixedL21Norm
. This in turn calls _proximal_numpy
.
where
I suppose this fails during an update
of PDHG, and I presume the error creeps up at this line
So, if I understand correctly the thing that fails is
np.abs(pdhg_explicit_tv_precond.sigma, dtype=np.float32)
because sigma
is a BlockDataContainer and np.abs
doesn't know what to do with it, and our containers are not NEP-13 and 18 compliant, see https://github.com/TomographicImaging/CIL/issues/1156#issuecomment-1483037384.
Lastly, which version of CIL are you running?
Thanks @epapoutsellis . I think I now fixed my test: I was not passing to the method the right objects, also in view of where the code fails
Now my test code is the following:
from cil.optimisation.functions.MixedL21Norm import _proximal_step_numpy
from cil.framework import ImageGeometry, AcquisitionGeometry
from cil.optimisation.operators import LinearOperator, GradientOperator
ag = AcquisitionGeometry.create_Parallel2D()\
.set_panel(3)\
.set_angles(np.linspace(0,360,4), angle_unit='degree')
ig = ag.get_ImageGeometry()
L = LinearOperator(domain_geometry=ig, range_geometry=ag)
L.set_norm(1)
Grad = GradientOperator(ig)
K = BlockOperator(L, Grad)
tmp_sigma = K.range_geometry().allocate(1)
sigma1 = 1./tmp_sigma
tmp = K.range_geometry().allocate(1.5)
a = _proximal_step_numpy(tmp, sigma1)
It does fail at calculating the pnorm(2)
of the sigma1
BlockDataContainer
, see this new unit test which fails with ValueError: Incompatible for operation add
. BTW if the containers in the block have the same shape, this works.
pnorm
: the new (old) bugLooking at the definition of pnorm
in BlockDataContainer
it is not clear what it is supposed to return. The code is making a reduction for both pnorm(1)
and pnorm(2)
.
pnorm(1)
is accumulating in a floatpnorm(2)
is accumulating in a container of the same type as the first element in the BlockDataContainer
In practice, in this case both methods will accumulate in a BlockDataContainer
of the same type the range of the GradientOperator
because the BlockDataContainer
algebra takes precedence w.r.t. DataContainer
algebra, thanks to the __container_priority__
class variable.
As we can use add
with different types of DataContainer
s, the only important thing is that the shape of the containers are consistent for the pnorm
to return something and not to crash.
There is no docstring attached to the pnorm
so the question is: what is pnorm
supposed to return?
This problem has already arisen https://github.com/TomographicImaging/CIL/issues/474
The following code initially implemented here fails due to possible numba implementation in MixedL21Norm.
Implicit PDHG with preconditioning works with no problems.