petsc4py.PETSc.Error: error code 55

You can have a look at: Error setting PETSc options repeatedly - #2 by nate
as I currently do not have time to parse your code in detail. Note that you can create a separate function for the previous solution, and assign data to it after each iteration (similar to any time stepping demo), to avoid recompilation. See for instance the dolfinx tutorial.