Group Abstract Group Abstract

Message Boards Message Boards

0
|
1.8K Views
|
8 Replies
|
6 Total Likes
View groups...
Share
Share this post:

Skipped instances using Dynamic

Posted 2 years ago

When I execute the following sample code using a large Map operation and many Graphics3D objects, the end result (i=20) is shown without showing the intermediate results (i=1,i=2,..., i=19). I want to show each and every step. Can someone help?

Dynamic[a]
For[i = 1, i <= 20, i++,
b = RandomReal[{-1, 1}, {10000, 3}];
TextStr = {Text["i=" <> ToString[i], {0, 0, 5}]};
b3g = Map[Sphere[#, 1] &, b];
a = Graphics3D[{TextStr, b3g}, 
PlotRange -> {{-5, 5}, {-5, 5}, {-5, 5}}];
]

As a comparison, the sample code below without a large Map operation and with little Graphics3D objects, each and every individual step is visible.

Dynamic[c]
For[i = 1, i <= 20, i++,
d = RandomReal[{-1, 1}, {10000000, 3}];
TextStr = {Text["i=" <> ToString[i], {0, 0, 5}]};
c = Graphics3D[{TextStr, Sphere[d[[1]], 1]}, 
PlotRange -> {{-5, 5}, {-5, 5}, {-5, 5}}];
]
POSTED BY: John Lee
8 Replies
Posted 2 years ago

Eric, thanks again for the comment.

but now you're happy with completely externalizing the results for offline inspection.

If you run the last code example I uploaded, you may be able to monitor the Graphics3D output in real time at every intermediate step (i=1,2,3,...,20) as they are evaluated. Yes they are saved to the SSD as png files also but the important point is that it enables real-time screen monitoring without skipping any of the results and I am happy with that. If I save all the steps' outputs (hundreds or thousands of them) to an array and use ListAnimate, it may take up too much memory for my computer to handle so I rather decided to use For loop to keep updating the vector array variable as the calculation goes on, rather than keep appending it to another giant array of arrays. I am not as fluent as most of the experts here including you in Mathematica and I learned a lot from your comments. I guess that the problem might be ultimately solved if Dynamic can have an option to increase its graphical rendering priority as you implied, or there is a Pause-like function that waits until Dynamic finishes updating all of its graphical output.

POSTED BY: John Lee
Posted 2 years ago

Eric, thanks for the suggestion again. I inserted a png file Export command in place of the Pause as shown below and it just works fine and shows each and every step now. Probably the png Export requires the output of the updated Graphics3D object a enforcing it to wait until the graphics update is finished internally, or it simply took just enough time :).

a = Graphics3D[{}];
Dynamic[a]
For[i = 1, i <= 20, i++, b = RandomReal[{-1, 1}, {10000, 3}];
 TextStr = {Text["i=" <> ToString[i], {0, 0, 5}]};
 b3g = Map[Sphere[#, 1] &, b];
 a = Graphics3D[{TextStr, b3g}, 
   PlotRange -> {{-5, 5}, {-5, 5}, {-5, 5}}];
 Export["D:\\Downloads\\a" <> ToString[i] <> ".png", a]
 ]
POSTED BY: John Lee
Posted 2 years ago
POSTED BY: Eric Rimbey
Posted 2 years ago

I would expect that Dynamic is given lower priority for computation time compare to the "main thread". So I think this approach is generally doomed to fail.

I wanted to check each and every single cycle result real time on screen as the calculation goes on

I guess I still don't understand enough of your context. If the computations are going at "machine speed" with no pauses, then how could you even mentally process what you're seeing if you monitor the computations "in real time"?

If you want to inspect every step of the computation, your best bet is to save them and then review them after the computation is complete. If you want to watch things progress as the computation is happening, then I think you're going to need some pauses.

Probably Monitor would be better than Dynamic, but I don't think you'll be able to avoid using pauses. If you're adamant about no pauses, you could insert a dialog, maybe something like this:

For[i = 1, i <= 2, i++, b = RandomReal[{-1, 1}, {10000, 3}];
 TextStr = {Text["i=" <> ToString[i], {0, 0, 5}]};
 b3g = Map[Sphere[#, 1] &, b];
 ChoiceDialog[
  Graphics3D[{TextStr, b3g}, 
   PlotRange -> {{-5, 5}, {-5, 5}, {-5, 5}}]];]

But I'm not really familiar with the best monitoring/debugging techniques, so hopefully someone else will jump in. I'm also not sure I understand what you really need, so if there's more info/context you can provide, maybe that would help.

POSTED BY: Eric Rimbey
Posted 2 years ago
POSTED BY: John Lee
Posted 2 years ago

You could do something like this instead:

centers = RandomReal[{-1, 1}, {20, 3}];
spheres = MapIndexed[
   Graphics3D[{Text["i=" <> ToString[#2[[1]]], {0, 0, 5}], 
      Sphere[#1]}, PlotRange -> {{-5, 5}, {-5, 5}, {-5, 5}}] &, 
   centers];
ListAnimate[spheres]
POSTED BY: Eric Rimbey
Posted 2 years ago

Why are you generating 10 million random triples when you only need 20?

POSTED BY: Eric Rimbey
Posted 2 years ago
POSTED BY: Eric Rimbey
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard