I'm doing parameter estimation for a numerical model of reaction diffusion between timepoints for which I have data. For example I have data at t = 0, 2, 4, and 6, and I'm trying to run the model from 0-2, 0-4, 0-6, but I know if the difference in times is too long the estimation will fail. So since it might not do 0-6, I would try 2-6 instead.

I set up a try-except block for this, but once it catches an exception, all future attempts fail. E.g. try 0-6, except if there's an error, try 2-6, then 4-6, etc. I've already tested 2-6 and know the solver works, but when it tries 0-6 first and fails, 2-6 and the rest fail with the same error and I'm not sure if I'm missing something.

I made sure everything is reset for the solver after it catches the exception, and all the variables are reset.

The code looks like this:

t     = [0,2,4,6]
start = 0
end   = 1
while end < len(t):
        solve(model, t(start), t(end))
        end += 1
    except Exception as e:
        start += 1
        if start == end:
            end += 1

Is there a way to reset the exception that I need to do so it stops getting thrown when it shouldn't be? Or what else could be happening?

0 Answers