Memory error from Matlab

Hi there UQlab devs,

Is there a way to retrieve the computed PCE from UQlab even after Matlab gives the error due to full memory?

I am running a PCE for a large problem and testing various PCE degree truncations. For some degree, however, Matlab produces an error due to its limited memory. Is there a possibility to retrieve the last successful PCE that did not fill the memory?

Thank you
Gianni :slight_smile:

Hi @giansteve

I can think of many ways to do this. Two very easy ones are:

  • Dump every successfully create PCE model to a file and after the memory error occurred load the one you need
  • Wrap everything into a try-catch block like so:
for i = 1:100
    try
        a = zeros(10^i);
    catch ME
        % Check the exact error you got
        if strcmp(ME.identifier, 'MATLAB:array:SizeLimitExceeded')
            break % or continue (depends on what you want)
        else
            rethrow(ME);
        end
    end
end
% This is the last sucessfully allocated matrix
disp(size(a))

Hope this helps!

Best regards
Styfen

Amazing!

I will try this out and let you know :slight_smile:
Thank you for this for now

hey @styfen.schaer,

i checked it out and I added a little modification to collect another kind of error.

for i = 1:100
    try
        a = zeros(10^i);
    catch ME
        % Check the exact error you got
        if strcmp(ME.identifier, 'MATLAB:array:SizeLimitExceeded') | strcmp(ME.identifier, 'MATLAB:nomem')
            break % or continue
        else
            rethrow(ME);
        end
    end
end
% This is the last sucessfully allocated matrix
disp(size(a))

Thank you again
Best
Gian :slight_smile: