login about faq

I've spent about 2 days looking for a way to stop a simulation elegantly through a steppable but I've had no luck.

Simulator.finish() looks promising but I've only managed to get attr errors and to completely crash python when I'm calling it so I'm either doing it completely wrong, or this is not the function I'm looking for..

asked Oct 19 '11 at 05:58

fifnir's gravatar image

fifnir
11

If the answer provided was helpful please vote it up, or if it solved your problem "accept it" (click the check mark), this is probably best done for the answer you provided for yourself. It is important that your question/problem be re-solved, and the answer be marked for easy referral by others.

(Jan 03 at 22:31) acosmane ♦

As far as I know it is not something commonly needed. Perhaps you could revise your question or add a comment describing why you would like to do this.

If what you are trying to do is just end a simulation after a certain number of Monte Carlo steps that is easily done inside the main Python file using something like this:

cc3d=ElementCC3D("CompuCell3D")
potts=cc3d.ElementCC3D("Potts")
potts.ElementCC3D("Steps",{},20000)

One possible way to do what I think you are asking is to use the semaphores that the Player uses to pause or stop a simulation. To do this you would have to pass the simulation thread object to your steppable.

In the main Python script there is usually a line similar to:

sim,simthread = CompuCellSetup.getCoreSimulationObjects()

When you create your steppable create a parameter for the simthread object, something similar to:

def __init__(self,_simulator,_frequency=10,_simthread):
    ...
    self.simthread = _simthread
    ...

Then in the main Python script when you instantiate your steppable you would pass the simthread object to it:

mySteppable=MySteppabe(sim,simthread)

In your steppable when you would like to pause the simulation all you need to do is:

self.simthread.semPause.acquire()

To restart:

self.simthread.semPause.release()

To completely stop (end) your simulation:

self.simthread.setStopSimulation(True)

None of these functions (except of course for the ones setting the number of Monte Carlo steps) were meant to be used this way however, and you will certainly mess up the Player's button control during the course of your simulation.

link

answered Oct 23 '11 at 23:50

acosmane's gravatar image

acosmane ♦
61239

edited Oct 23 '11 at 23:51

Hi,

Thank you for the answer! What I want is to stop the simulation on conditions other than the mcsteps

it is now implemented in the latest built by calling

CompuCellSetup.stopSimulation()

from within the steppable

link

answered Oct 24 '11 at 04:12

fifnir's gravatar image

fifnir
11

I assume you mean the latest Windows 3.6.0 build? 3.6.0v2022?

If this is the solution you are satisfied with, please accept the answer by clicking the the check mark on the left. Doing this will help guide others trying to solve the same problem. Thank you.

(Oct 24 '11 at 04:29) acosmane ♦
Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or __italic__
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Tags:

×5
×2
×2
×2

Asked: Oct 19 '11 at 05:58

Seen: 182 times

Last updated: Jan 03 at 22:31

powered by OSQA