UQLink returning NaN in output: could it be because the command to execute the third party software does not explicitly specify input and output files?

I am linking a third party software to UQLabs using UQLink. The third party software is called Hi-sAFe which is used to simulate interactions between trees and crops for agriculture. The software uses multiple input files and output files which are all specified in a simulation file, along with some extra simulation parameters. In order to run the simulation, these input and output files are not explicitly specified in the execution command. The command only includes a simulation file which has the names of the input files in it.

When I try to evaluate the model for some specific values (just for testing), I get the following warning:

“Warning: Third party software returned an error for run #1: Returning NaN in the corresponding output”

I originally thought this was an issue with my output parser, however after running my output parser directly on the output file, I can confirm it works correctly. Thus, it has led me to believe that the issue comes from the fact that the input/output file is not specified in the execution command. This would make sense as UQLink would not be able to run the simulation changing the input file name. Is this correct of me to assume?

If that is the case, I have considered solving this by opening the simulation file and for each iteration changing the name of the input file for the one with the altered values generated by the code. Is this something I should try?

Any recommendations that anyone has would be great, thank you!

Dear @elisara1000

Do I understand correctly that you need to change the “simulation file” and the actual input file that is then specified in the “simulation file”? I think you can do this by making both files template files and specifying multiple input files for UQLink as described in section 2.7.6 of the manual:

And did you check if the command specified in the model options (Mopts.Command) is correct and Hi-sAFe get actually executed?

Best regards
Styfen

Hi Styfen,

Thank you for your response!

The simulation file just lists where all the input files for my simulation are. The template I made is for the input file, referenced by the simulation file, which I wish to use as input parameters. So I did not make a template for the simulation file. Would this work? From my understanding the template specifies the parameters which should be changed on each iteration. But can I specify two input files 1) the simulation file which would have to change the name of the input file to the one generated by UQLabs and 2) the input file with the list of parameters to alter? I assumed the markers placed for the parameters could only represent numeric values so this wouldn’t work. Is this a correct assumption?

I did ended up making a fix for it which is now working so I do not have this issue anymore. First, I created a script which opens the simulation file, finds the input file, and changes it to the input file generated by UQLabs. Then, I modified “uq_wrapper_uqlink.m” to insert my fix before the command is executed. This works when I the model is evaluated once. I am now having some confusion as to where the generated input file is stored. It seems that it is in the root folder where the code is running, and after one run, the input file is archived if Modelopts.Archiving.Action is set to ‘save’. However for some reason on the second run, I get an issue with my simulation software not finding the input file, even though I can see that it has been generated and is also in the root folder. Would you have any hints as to where the generated files are stored during runtime?

Thanks again for your comments.
Kind regards,
Elisa

Dear @elisara1000

Yes, what you describe in the first paragraph is what I would suggest. Since you know how UQLink changes the name of the input file, you can put a marker in the simulation file and also specify it as a template file. You are correct in assuming that you need to format the marker correctly. You can specify the format as follows: Mopts.Format = {'%1.8f', ..., '%06d'} (Section 2.7.4 in the manual). Note that there is a format specifiers for each input variable. The '%1.8f' should suffice for the variables of the input file, which (I assume) requires floating point numbers, and the '%06d' formats the generated file ID of the input file which you need in the simulation file. I think the '%06d' is what UQLink does by default. In case you’re not familiar with formatting strings you can check out:

Regarding your second paragraph, UQLink should generate it in the modelopts.ExecutionPath directory (Section 2.7.2 in the manual). Have you tried specifying it explicitly?
However, I would first try the other approach we discussed. That seems to me to be a less cumbersome way.

Best regards
Styfen

Dear @elisara1000

we have discussed your problem and it seems that it is more difficult than I first thought. The formatting refers only to the random variables and it is not possible to format other values than these variables. So the best thing to do is to update the uq_wrapper_uqlink.m file as you did.

Again, about your problem with the input file path: It sounds strange to me that you can see the input file in the expected directory, but your simulation software cannot. Did you check that the input file name was updated correctly in the simulation file after the first run, and that all paths are set correctly?

Keep us informed about your problem so we can find a solution.

Best regards
Styfen

Dear @styfen.schaer

Yes, the input file is correctly updated in the simulation file after the first run, and I think all the paths are correct especially because on the first run it works. Nevertheless, I will look further into it today and will keep you informed.

Thank you again for your support!

Best,
Elisa

Dear @styfen.schaer

Apologies for the delay with the response.

It turns out this is a problem with the third party simulation software. It requires input files to be in a specific location. Where are the input files generated based on the template? Or more specifically, do you know if there is a way for me to define where the generated input files should be stored during execution?

Kind regards,
Elisa

Hi @ Elisara1000
please did you find the solution to your problem? I have the same problem but with another software.
Cordially,
IHM

Hi @IHM,

Yes, I solved this problem. For me, this was because of the execution command that I needed to run in order to execute my third-party software. UQLabs assumes it is in the forms (based on their documentation):

  • <exe> <inputfilename> <argument1> <argument2> …
  • <exe> -i <inputfilename> -o <outputfilename> -a <argument> …

This was not the case for me. Thus, I ammended the place where the external software is executed. This is in modules/uq_mode/builtin/uq_uqlink/uq_wrapper_uqlink.m in section 2 starting in about line 304. The code is commented so it is realtively simple to ammend it. I found it helped tracing the code using Matlab’s breakpoints to find what the values of each variables are as the code is running to know what I had to change.

I hope this helps!
Elisa

1 Like

HI, @Elisara1000. Thank you for your reply. I tried it, it runs fine but just with the original executable and old models existing in third-party software. In my work, I need to create a new executable to take into account a model that I implemented. And my model in my third-party software works fine with the external executable but when I use it in UQlink the program runs empty with no error message. I point out that the two executables are called in the same command file which calls the new executable if it is a new model and the old if not. Could you please help me @styfen.schaer? when i stop UQlab’s run I have an error message saying my error is located at the line 433 of the file uq_wrapper_uqlink.m

Please @Elisara1000 can you show me your modification?