Error Messages/41108


Error message examples

Cycle encountered during evaluation of Slice(*, Time, *).

Cause

The use of the Slice function inside the Dynamic loop has caused a cycle. Not specifying the offset in the call to Slice is a possible cause of this error.

The following dynamic call below would trigger this error:

Dynamic(100, Slice(DynamicVar, Time, @Time - 0)*1.1)

You might also get this error if the offsets in your Dynamic loop jump around in time, eventually returning to the same time value and thus causing a cycle. For example:

A := Dynamic(a0, f(B[@Time = @Time - 1]))
B := Dynamic(b0, g(A[@Time = @Time + 1]))

We've noticed that even though the error message says Slice is used, this error message sometimes occurs when Subscript is being used -- e.g.:

Dynamic(x0, y[Time = t2])

Remedies

Remove the cycle by passing an offset to the Slice operation.

In a large dynamic loop, it can be difficult to debug the loop and find the offending variable, which for example might be a variable that requests a value at a future time point, ultimately causing the loop. The error message is reported for the variable at which Analytica discovers a loop -- i.e., the first variable where a value x[Time = t] is requested when a computation of x[Time = t] is already in progress. But where Analytica first detects the cycle is not necessarily the same place where your actual model bug is. There are a few secret tricks that can be helpful in debugging these cycles, which we'll reveal here.

One of the most helpful things is to get an evaluation trace, which you can do as follows:

  1. Press F12 to open the Typescript Window.
  2. In the typescript window, type: Verbosity: 6
  3. Re-evaluate the offending variable until the error message appears again.
  4. View the trace in the typescript window.
  5. Turn tracing back off by typing: Verbosity: 2

If your trace is too long to view in the typescript window, then use these steps:

  1. In the typescript window, type:
    • Photo "C:\Trace.log"
    • Verbosity: 6
  2. Re-evaluate the variable until the error message appears again
  3. In Typescript, type:
    • EndPhoto
    • Verbosity: 2
  4. Open "C:\trace.log" in a text editor (Notepad, Textpad, etc).

When you view the trace, keep in mind that a line is printed each time the evaluation cycle requests a variable's value at a particular time point. In many cases the request will come from the definition of the line immediately following, but in other cases it will originate from an earlier line in the trace. The call-graph order is not revealed by the trace, just the sequence of calls, but in many cases, this is sufficient.

Once the error occurs, there will be some Dynamic variables that are partially computed in memory. For example, the variable X may have completed the computation of X[Time = 2010] and X[Time = 2011], but values X[Time = 2012] and beyond are not computed because the error occurred before computation of these was complete. In some cases, viewing these partially computed results can be helpful when debugging these problems, but you cannot view the partial result by showing the result window for X, because doing so will cause X to attempt to finish the remaining evaluation which won't be possible because it will encounter your cycle error. But there is a trick for viewing these partial results. Create a new variable node (which you'll have around only temporarily for debugging purposes) and define it as Value of X. Then show its result. If you see a Calculate button appear, and re-appear each time you press it, this means that the variable X is entirely uncomputed -- it hasn't computed any time steps. If any time steps is computed, you'll see an array result indexed by Time, where all the uncomputed slots are empty cells.

See Also

Comments


You are not allowed to post comments.