4
$\begingroup$

I am using Mathematia 12.1 on Windows. I experience a front-end freeze when I evaluate a certain Manipulate expression. I have reduced the code down to a rather simple case.

I found that when I evaluate

Manipulate[
  Table[u = a, {a, {1, 2, 3}}], 
  {i, {1, 2, 3}}]

there is no problem. The output is

enter image description here

However, when I evaluate

Manipulate[
 Table[u = a; u, {a, {1, 2, 3}}], 
 {i, {1, 2, 3}}]

the output is

enter image description here

Notice that the output cell seems always running, and my front-en freezes. I have to kill it in task manager.

What is wrong?

$\endgroup$
4
  • 2
    $\begingroup$ add the option TrackedSymbols :> {i}? $\endgroup$
    – kglr
    Oct 15, 2020 at 12:20
  • $\begingroup$ @kglr Hi, kglr. I tried TrackedSymbols :> {i}, it remove the stuck. But I don't understand what is going on. Why we must need TrackedSymbols :> {i}? $\endgroup$
    – matheorem
    Oct 15, 2020 at 12:33
  • 3
    $\begingroup$ matheorem, you might find the section Controlling Automatic Reevaluation in the tutorial AdvancedManipulateFunctionality useful. $\endgroup$
    – kglr
    Oct 15, 2020 at 12:51
  • $\begingroup$ @kglr Thank you so much! Exactly what I am missing :) $\endgroup$
    – matheorem
    Oct 15, 2020 at 13:31

1 Answer 1

2
$\begingroup$

The code you give that produces constant re-evaluation by the front-end can be further reduced to

busy

But on my system (I'n running V12.1 on MacOS 10.13.4), there is no freeze. The cell bracket is only saying the cell is busy. Other evaluations can be made while the Manipulate output cell is in the busy state. The evaluation can be stopped by simply deleting the output cell.

The same is true for the code in you post. In fact, I can get both my reduced version and your posted version to run at the same time and still do other computations.

The problem, if it is to be considered a problem, arises because Manipulate expressions are rewritten when they are evaluated and all free variables in the expression become local variables of a DynamicModule that gets wrapped around the Manipulate code. By default, such variables are automatically tracked by the front-end while the Manipulate is running. Hence, the busyness.

In a comment to your questions, kglr describes the standard practice for reducing the busyness.

Manipulate[
  Table[u = a; u, {a, {1, 2, 3}}],
  {i, None},
  TrackedSymbols :> {}]

Here are two more:

Manipulate[
  Table[Block[{u}, u = a; u], {a, {1, 2, 3}}],
  {i, None}]

Manipulate[
  Once @ Table[u = a; u, {a, {1, 2, 3}}],
  {i, None}]

The 1st works by localizing u in the Table expression, so it doesn't get put into the list of dynamic variables of the DynamicModule wrapper. The 2nd works by telling Mathematica to evaluate the table just once and remember the result.

$\endgroup$
2
  • $\begingroup$ Thank you so much, m_goldberg. You are right. I also have noticed that Linux version Mathematica doesn't get frozen when such Manipulate evaluates. But windows version does get frozen(at least mine). That's too bad for windows. I always feel my windows Mathematica has a slow front end. Why haven't the developers found this issue? Maybe they mostly develope Mathematica on Linux :) $\endgroup$
    – matheorem
    Oct 17, 2020 at 6:17
  • $\begingroup$ @matheorem. As s MacOS user, I naturally think it is a better OS than Windows, but I still think Windows gets a great deal of attention from the Mathematica developers because it is important market for Wolfram Research. Probably more important than Linux. Maybe more important than MacOS. Also, since MacOS is based on BSD Unix, it behaves more like Linux than Windows. $\endgroup$
    – m_goldberg
    Oct 17, 2020 at 14:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.