Forum Discussion

FICO's avatar
FICO
Community Manager
4 years ago

Run multiple experiments for the same model with different input data in a loop

Hi,

I am trying to run all my experiments (e.g. same model, slightly different input parameter values) in a consecutive loop instead of separate. Such that I do not have to change my input .xlsx file manually.

I now tried it with 'expRUN as "mpproblem".

! Start loop over different experiments

forall(E in 1..2) do

with expRUN(E) do

EXP:=strfmt(E,1) !create loop

FixedInput:=EXP+'_Cheese.xlsx'

initializations from "mmsheet.xlsx:"+FixedInput

[...]

end-initializations.

However, I get the error message: "SHEET: Non dynamic set for a `write'."

As I do manage to read different exel-sheets from the same .xlsx file in a loop, within a mmproblem, I am a bit lost why I cannot change the .xlsx file as I do with changing the excel-sheet.

Is it possible to run multiple experiments in one go as I wish? And if yes, how should it be done?

6 Replies

  • FICO's avatar
    FICO
    Community Manager

    Would you be able to share a complete model, or at least a larger extract that shows how you have declared the relevant model entities and how they get initialized?

    Most likely this error relates to Mosel's auto-finalization feature. It might be sufficient if you declare the concerned set explicitly as 'dynamic' - however, without having seen the complete example this is difficult to answer.

  • FICO's avatar
    FICO
    Community Manager

    Hello,

    Yes I can share part of my model.

    I removed the actual optimization, however that part works perfectly fine.

    I hope this allows you to see where I made the mistake.

  • FICO's avatar
    FICO
    Community Manager

    The loops in your model perform a 'reset' of the mpproblem entities, however, there does not seem to be any reset/deletion for the data that is input in individual loop iterations: I assume that not only data values (=values of array entries) but also certain index sets (=which index tuples are defined for arrays in a given loop iteration) change between iterations, this means that most likely it will help if you declare all arrays that are initialized repeatedly as 'dynamic' and call 'reset' for each data array at the end of the relevant loop.

  • FICO's avatar
    FICO
    Community Manager

    So if I understand well, I need to declare all my arrays as "dynamic" (but only the arrays, not the 'single' numbers?) AND I need to reset all data arrays? Is there a quick way of doing that or should I go for 'reset(array1), reset(array2)' and so on?

  • FICO's avatar
    FICO
    Community Manager

    Scalar values are simply replaced when they are assigned new values. If you are re-initializing an array with new data there are 2 cases: (a) the new data set defines the same index tuples: reading will overwrite existing contents, so there is no need for 'reset' or dynamic; (b) the data sets have different index tuples: you need to make sure to clear the entire array before re-initializing it, this is done when applying 'reset' to a sparse array (array declared as 'dynamic' or 'hashmap'). The 'reset' needs to be called individually for every array.

    An alternative to the above might be to move the contents of the loop along with the declarations into a subroutine so that the loop invokes a subroutine in every iteration: by moving declarations into a subroutine you turn them into local entities that only exist within the respective subroutine, that is, there is no need for an explicit call to 'reset' as the arrays will disappear at the end of the subroutine where they have been declared.

  • FICO's avatar
    FICO
    Community Manager

    Thank you, it now works well :-)