Opened 6 years ago

Last modified 3 years ago

#5472 accepted enhancement

Allow to re-simulate a failed simulation

Reported by: Francesco Casella Owned by: John Tinnerholm
Priority: high Milestone:
Component: OMEdit Version: v1.14.0-dev-nightly
Keywords: Cc:

Description

If a simulation fails, it is not possible to change the solver parameters and re-simulate, one has to recompile the model from scratch every time.

It would be nice if one could re-simulate without re-compiling also in this case.

@adeas31, would this be easy to implement?

Change History (12)

comment:1 by John Tinnerholm, 6 years ago

Hello!

I will take this ticket :)

Best regards

John

comment:2 by Francesco Casella, 6 years ago

Owner: changed from Adeel Asghar to John Tinnerholm
Status: newassigned

Thank you John! Next time you can reassign it to you directly :)

comment:3 by massimo ceraolo, 6 years ago

See also #5177.
That one is harder since it involves a change in the result file format (possibly backwards-compatible?).
However, it is related to this ticket since it also regards enhancing the power of the re-simulate OM capability.

comment:4 by johti17@…, 6 years ago

@casella

I looked into this now. I am a new dev so excuse me for this lengthy question.
Currently if a simulation fails at initialization for instance this model:

model A
  parameter Real B = 0;
  Real Y;
equation
  assert(B > 0, "test");  
  Y = B * time;
end A;

We would have to recompile to resimulate, this is the case since ticket #4935 forbade resimulation iff the size of the result file is zero.
(We would never read the variables if that is the case, see code below)

Looking at the code this could be rewritten sligthty to disallow switching to the plotting view while still allowing resimulation in case of failure at initialization.

  /* ticket:4935 Check the simulation result size via readSimulationResultSize
   * If the result size is zero then don't switch to the plotting view.
   */
  bool resultFileNonZeroSize = MainWindow::instance()->getOMCProxy()->readSimulationResultSize(resultFileInfo.absoluteFilePath()) > 0;

  if (resultFileKnown && resultFileExists && resultFileNewer && resultFileNonZeroSize) {
    VariablesWidget *pVariablesWidget = MainWindow::instance()->getVariablesWidget();
    OMCProxy *pOMCProxy = MainWindow::instance()->getOMCProxy();
    QStringList list = pOMCProxy->readSimulationResultVars(resultFileInfo.absoluteFilePath());
    if (list.size() > 0) {
      if (OptionsDialog::instance()->getSimulationPage()->getSwitchToPlottingPerspectiveCheckBox()->isChecked()) {
        bool showPlotWindow = true;
#if !defined(WITHOUT_OSG)
        // if simulated with animation then open the animation directly.
        if (mpLaunchAnimationCheckBox->isChecked()) {
          showPlotWindow = false;
          if (simulationOptions.getFullResultFileName().endsWith(".mat")) {
            MainWindow::instance()->getPlotWindowContainer()->addAnimationWindow(MainWindow::instance()->getPlotWindowContainer()->subWindowList().isEmpty());
            AnimationWindow *pAnimationWindow = MainWindow::instance()->getPlotWindowContainer()->getCurrentAnimationWindow();
            if (pAnimationWindow) {
              pAnimationWindow->openAnimationFile(resultFileInfo.absoluteFilePath());
            }
          } else {
            QString msg = tr("Animation is only supported with mat result files.");
            MessagesWidget::instance()->addGUIMessage(MessageItem(MessageItem::Modelica, msg, Helper::scriptingKind,
                                                                  Helper::notificationLevel));
          }
        } else {
          showPlotWindow = true;
        }

The change would be to remove one and clause in the first if statement and place it here instead

     MainWindow::instance()->getPerspectiveTabBar()->setCurrentIndex(2);
        if (showPlotWindow) {
          QList<QMdiSubWindow*> subWindowsList = MainWindow::instance()->getPlotWindowContainer()->subWindowList(QMdiArea::ActivationHistoryOrder);
          if (!subWindowsList.isEmpty() && subWindowsList.last()->widget()->objectName().compare("diagramWindow") != 0) {
            OMPlot::PlotWindow *pPlotWindow = MainWindow::instance()->getPlotWindowContainer()->getTopPlotWindow();
            if (pPlotWindow) {   
//Here somewhere or above for OSGI
            MainWindow::instance()->getPlotWindowContainer()->setTopPlotWindowActive();
            }
          }
        }

Doing so would enable resimulation on initialization failure (And I guess being more true to what ticket 4935 describes)

Trying to replicate the issue that you decribe I use the model above. However, on my machine it does seem to allow me to change the parameters for the solver using resimulate setup with no problems. Could you please attach a model that replicate the behaviour that is described in the ticket. I will go from there

Best regards

John

in reply to:  4 ; comment:5 by Francesco Casella, 5 years ago

Replying to johti17@…:

We would have to recompile to resimulate, this is the case since ticket #4935 forbade resimulation iff the size of the result file is zero.

Not necessarily. My requirement in #4935 was not to forbid switching to the plotting tab (wherefrom you can push the re-simulate button), only not to do it automatically. I'm fine with manually selecting the plotting window and then pushing one of the two re-simulate buttons, as long as it is active :)

Trying to replicate the issue that you decribe I use the model above. However, on my machine it does seem to allow me to change the parameters for the solver using resimulate setup with no problems. Could you please attach a model that replicate the behaviour that is described in the ticket. I will go from there

This (doesn't) work for me:

model TestInitialFailure
  Real x(start = 1);
equation
  der(x) = -x + 1;
initial equation
  x^2 + 1 = 0;
end TestInitialFailure;

Let me know if it also (doesn't) work for you, so you can start from there.

in reply to:  5 comment:6 by John Tinnerholm, 5 years ago

Replying to casella:

Replying to johti17@…:

We would have to recompile to resimulate, this is the case since ticket #4935 forbade resimulation iff the size of the result file is zero.

Not necessarily. My requirement in #4935 was not to forbid switching to the plotting tab (wherefrom you can push the re-simulate button), only not to do it automatically. I'm fine with manually selecting the plotting window and then pushing one of the two re-simulate buttons, as long as it is active :)

Trying to replicate the issue that you decribe I use the model above. However, on my machine it does seem to allow me to change the parameters for the solver using resimulate setup with no problems. Could you please attach a model that replicate the behaviour that is described in the ticket. I will go from there

This (doesn't) work for me:

model TestInitialFailure
  Real x(start = 1);
equation
  der(x) = -x + 1;
initial equation
  x^2 + 1 = 0;
end TestInitialFailure;

Let me know if it also (doesn't) work for you, so you can start from there.

Right I am sorry Casella. What I wrote above was not totally correct if I for instance would use the following model:

model test
  Real X = time;
  parameter Real B = 0;
equation
  when time > 20 then
    assert(B > 0, "test")
  end if;
end test;

It is possible to resimulate. Even though the simulation failed.

For the one that you provided me with it is not possible. The reason being the changes in #4935.

I will fix it just now so that it does not switch automatically and allow resimulation when initial equations fails

comment:7 by John Tinnerholm, 5 years ago

Version: v1.14.0-dev-nightly

comment:8 by John Tinnerholm, 5 years ago

Status: assignedaccepted

comment:9 by Francesco Casella, 5 years ago

Milestone: 1.14.01.16.0

Releasing 1.14.0 which is stable and has many improvements w.r.t. 1.13.2. This issue is rescheduled to 1.16.0

comment:10 by Francesco Casella, 4 years ago

Milestone: 1.16.01.17.0

Retargeted to 1.17.0 after 1.16.0 release

comment:11 by Francesco Casella, 4 years ago

Milestone: 1.17.01.18.0

Retargeted to 1.18.0 because of 1.17.0 timed release.

comment:12 by Francesco Casella, 3 years ago

Milestone: 1.18.0

Ticket retargeted after milestone closed

Note: See TracTickets for help on using tickets.