NetLogo / models

NetLogo Models Library
106 stars 95 forks source link

Some Models Library models make unnecessary use of `wait` #140

Closed TheBizzle closed 9 years ago

TheBizzle commented 9 years ago

Greetings from the land of NetLogo Web. As I've been implementing various primitives, off in my dungeon, I've noticed that many models seem to be on the cusp of working in NetLogo Web, but are being held back by usages of wait—one of the handful of primitives that has natural problems with translating into JavaScript, since programs in the browser are single-threaded, and blocking your only thread will lead to locking up the entire UI.

You might argue that that is my problem—and I wouldn't say that you were wrong—but I think there are many models that needlessly use wait, and I would support seeing these usages removed.

To gather some data on this, I looked through all of the models in the Models Library to see how wait is being used, and to diagnose the usefulness of these wait calls. Here are my results:

Doesn't Need wait

nicolaspayette commented 9 years ago

Well, the atmosphere in your dungeon seem to be conducive to especially well researched issue reports!

I think there are many models that needlessly use wait, and I would support seeing these usages removed.

Agreed. I recently came across such a case while doing a checkout. Your investigation clearly shows that it wasn't an isolated one.

I will add wait to the "forbidden" primitives test and use your list to help me determine which models warrant an exception or not...

OASCCL commented 9 years ago

Thanks Jason for starting this discussion.

—Uri

Uri Wilensky

On Oct 1, 2015, at 4:02 PM, Jason Bertsche notifications@github.com wrote:

Greetings from the land of NetLogo Web. As I've been implementing various primitives, off in my dungeon, I've noticed that many models seem to be on the cusp of working in NetLogo Web, but are being held back by usages of wait—one of the handful of primitives that has natural problems with translating into JavaScript, since programs in the browser are single-threaded, and blocking your only thread will lead to locking up the entire UI.

You might argue that that is my problem—and I wouldn't say that you were wrong—but I think there are many models that needlessly use wait, and I would support seeing these usages removed.

To gather some data on this, I looked through all of the models in the Models Library to see how wait is being used, and to diagnose the usefulness of these wait calls. Here are my results:

Doesn't Need wait

Curricular Models/Connected Chemistry/Connected Chemistry 1 Bike Tire.nlogo Does literally nothing Curricular Models/ProbLab/4 Blocks.nlogo Just use speed slider Sample Models/Art/Fireworks.nlogo Can be emulated with ticks Sample Models/Art/Unverified/Geometron Top-Down.nlogo Can be emulated with ticks Sample Models/Mathematics/Voronoi - Emergent.nlogo Has no apparent effect Sample Models/Social Science/Unverified/Traffic Intersection.nlogo Hidden in the "switch" button; delays the visual effects of clicking the button for what is, IMO, a needlessly inferior user experience Sample Models/Mathematics/Probability/ProbLab/Unverified/9-Blocks.nlogo Just use speed slider Sample Models/Mathematics/Probability/ProbLab/Unverified/Expected Value.nlogo Another of these usages with no apparent purpose, but that leads to an inferior user experience on button-click Sample Models/Mathematics/Probability/ProbLab/Unverified/Partition Perms Distrib.nlogo Can be emulated with ticks Needs wait

Code Examples/Sound/Sound Workbench.nlogo Curricular Models/BEAGLE Evolution/HubNet Activities/Fish Spotters HubNet.nlogo HubNet Activities/Bug Hunters Camouflage HubNet.nlogo HubNet Activities/Memory HubNet.nlogo Sample Models/Mathematics/Probability/ProbLab/Unverified/Central Limit Theorem.nlogo Probably Needs wait, but Wasn't Well-Investigated

Curricular Models/BEAGLE Evolution/DNA Replication Fork.nlogo HubNet Activities/Gridlock HubNet.nlogo HubNet Activities/Unverified/Gridlock Alternate HubNet.nlogo HubNet Activities/Unverified/Polling Advanced HubNet.nlogo HubNet Activities/Unverified/Public Good HubNet.nlogo Sample Models/Mathematics/Probability/ProbLab/Unverified/Equidistant Probability.nlogo Sample Models/Mathematics/Probability/ProbLab/Unverified/Expected Value Advanced.nlogo Sample Models/Mathematics/Probability/ProbLab/Unverified/Random Combinations and Permutations.nlogo Sample Models/Games/Unverified/Pac-Man Level Editor.nlogo Enigmatic

Sample Models/Biology/Disease Solo.nlogo Uses wait in the preview commands for some reason...? Sample Models/Biology/Evolution/Bug Hunt Camouflage.nlogo Using wait for flashing the bugs is acceptable, but the way it's done here is really, really weird. Basically, there's an ask-concurrent that has each bug call wait for a period of time. What's strange about this is that the "flashes" take much longer, the more bugs there are. Logically, the wait should be occurring outside of any form of ask. The HubNet version of this model does it correctly. Sample Models/Games/Tetris.nlogo Uses wait in the preview commands for some reason...? — Reply to this email directly or view it on GitHub https://github.com/NetLogo/models/issues/140.

nicolaspayette commented 9 years ago

@TheBizzle, could you elaborate on what you mean by "Can be emulated with ticks"? I'm guessing that, at least for Fireworks and Partitions Perms Distrib, it means adding a "go once" button in addition to the "go forever" button, but this doesn't really apply to Geometron Top-Down. Unless you meant a "color-shift once" button?

SethTisue commented 9 years ago

For Fireworks, a pause can be emulated with a countdown timer that counts down ticks. Currently the model is coded in a slightly strange way (iirc it's me that did it this way) where each complete firework display is a single tick. But it wouldn't be super hard to recode it in the standard NetLogo idiom where each increment of motion is a tick. Then the pause between displays is just a pause of e.g. 50 ticks, or whatever, instead of x number of seconds.

TheBizzle commented 9 years ago

Yes, what Seth said is precisely what I meant with most—if not all—of my "Can be emulated with ticks" comments.

nicolaspayette commented 9 years ago

Makes sense! (At least for Fireworks - I haven't looked as closely at the other two.) Thanks guys!

TheBizzle commented 9 years ago

Thanks a ton! I'm very excited to try these out in NLW.

nicolaspayette commented 9 years ago

Let me know how it goes! And see https://github.com/NetLogo/models/blob/master/src/test/scala/org/nlogo/models/CodeTests.scala#L102 for the list of models that still use wait.

nicolaspayette commented 9 years ago

Most of the leftover models are ProbLab models that have many small pauses inside a tick and a longer pause after each tick. Just using the speed slider doesn't preserve this short/long relationship, and "emulating with ticks" doesn't really work either because each tick represents a "trial" and adding extra ticks to make a pause would mess with that.

Other models still using wait are HubNet models that won't work in NLW in the short term term anyway.

TheBizzle commented 9 years ago

The following models are now fully operable in a version of NetLogo Web that I'm looking forward to deploying in the near future:

(A few others have started to compile but don't work particularly great, and that's something to be solved on my end.)

Thanks a ton for your help with this, Nicolas.