UQLink: pass paremeters to parser


I do a couple of RBDO-Problems on the same construction pit, using an UQ link-model, linking ZSWalls with UQLab.

I am working on MATLAB R2020a and UQLab 1.3.0.

As the parsers for the different problems are quite similar, I would like to pass a parameter to the parser function. In my case the parameter would be a cell array of strings, telling the parser, which results to include in which order (e.g. {‘deviation’, ‘max. moment’}.

UQ standard models allow passing parameters, using the .Parameters option. Is there something similar for link models?

Does someone have a good idea of how to work around this problem?

Hi @Colette_Jost ,

This is quite an interesting use case.

As far as I know, there is no field similar to Parameters of the default (i.e., standard) MODEL object in UQLink model, but I have some ideas for a workaround:

  • The most straightforward thing to do is to create multiple parsers (yes, duplicate the files) each having a fixed value for the parameter. Granted, if you want to change the parameters on the fly or you have many combinations of results you want to include or not include, this is not ideal; or
  • Modify the internal property of UQLink object, namely myModel.Internal.Output.Parser (the name myModel is your choice), after the object is created. I’d like to recommend this approach because this is not intrusive, although there are some steps involved and a couple of MATLAB particularities you need to keep in mind.

Following up the second option, assuming your parser has the following signature:

function Y = myParser(outputfile,params)

you can modify the .Internal.Output.Parser field of the MODEL object and assign to it a function handle as follows:

myModel.Internal.Output.Parser = @(outputfile) myParser(outputfile,{'deviation','max. moment'});

Such a handle is required because internally, UQLink always calls the parser function with a single argument (i.e., the output file).

The above solution works as is for parameter given as a literal. Now if you put the parameter into a variable such as:

params = {'deviation','max. moment'};
myModel.Internal.Output.Parser = @(outputfile) myParser(outputfile,params);

you need to define the parameter first before you create the function handle, just like the above. So for instance, if below is the first time you use params:

myModel.Internal.Output.Parser = @(outputfile) myParser(outputfile,params);
params = {'deviation','max. moment'};
Y = uq_evalModel(myModel,X);

it will throw an error because params at the time the handle is created is not yet defined and it remains undefined when the handle is used later on by UQLink (from calling uq_evalModel) to parse the output file.

Also, every time you change the value of the parameter, you need to recreate the function handle and reassign it to the .Internal.Output.Parser field before calling uq_evalModel. Otherwise the new value will not be used.

Of course, you can wrap these steps into a single separate function that takes a parameter value and update the MODEL object so not to forget; you don’t need to explicitly return an updated MODEL object, because the object is passed by-reference.

I hope this helps (and let me know if it does, or doesn’t)! :smiley:

PS: You cannot assign a function handle as a configuration option before the object is created. That is, the following won’t work:

ModelOpts.Output.Parser = @(outputfile) myParser(outputfile,{'deviation','max. moment'});
myModel = uq_createModel(ModelOpts);

Because apparently during the object initialization, the value to ModelOpts.Output.Parser is checked if it’s a char array; if not, an error is thrown. This is despite Table 3 of the UQLink User Manual stating the option may accept a function handle :sweat_smile: (we’ll check it out!)

1 Like

Thanks for your idea! The approach using a function handle works like charm, with a little addition:

I created an empty file named dummyparser.m and set the

ModelOpts.Output.Parser = ‘dummyparser’;

Otherwise on model initiation I would get errors, such as:

The output file parser should be provided!
The output parser name is incorrect or does not belong to the current MATLAB path

Great to hear that! :smile:

Yes, we are aware of that issue (see my PS above :smiley:). The point is to specify as the parser before the object is created a filename (a char array) that exists in the current path and not a function handle.

Because you are going to anyway change the parser after the object is created, this parser file can indeed be a dummy file, just like you did.