[Avida-cvs] [avida-svn] r861 - branches/developers/avida-edward/source/python/AvidaGui2
avidaedward@myxo.css.msu.edu
avidaedward at myxo.css.msu.edu
Mon Jul 31 19:48:28 PDT 2006
Author: avidaedward
Date: 2006-07-31 22:48:27 -0400 (Mon, 31 Jul 2006)
New Revision: 861
Removed:
branches/developers/avida-edward/source/python/AvidaGui2/pySessionWorkThreadHdlr.py
Modified:
branches/developers/avida-edward/source/python/AvidaGui2/pyAvida.py
branches/developers/avida-edward/source/python/AvidaGui2/pyAvidaThreadedDriver.py
branches/developers/avida-edward/source/python/AvidaGui2/pyOrganismScopeCtrl.py
branches/developers/avida-edward/source/python/AvidaGui2/pySessionCtrl.py
branches/developers/avida-edward/source/python/AvidaGui2/pyTemporaryReloads.py
branches/developers/avida-edward/source/python/AvidaGui2/pyWriteGenesisEvent.py
Log:
Test cpu is now used to determine merits of injected organisms.
Modified: branches/developers/avida-edward/source/python/AvidaGui2/pyAvida.py
===================================================================
--- branches/developers/avida-edward/source/python/AvidaGui2/pyAvida.py 2006-07-31 22:49:59 UTC (rev 860)
+++ branches/developers/avida-edward/source/python/AvidaGui2/pyAvida.py 2006-08-01 02:48:27 UTC (rev 861)
@@ -14,12 +14,15 @@
import qt
from AvidaCore import *
+from descr import *
+
class pyAvida(qt.QObject):
def __init__(self):
qt.QObject.__init__(self, None, self.__class__.__name__)
def construct(self, genesis):
+ descr()
self.m_name = genesis.GetFilename()
self.m_environment = cEnvironment()
cConfig.Setup(genesis)
@@ -34,20 +37,33 @@
cConfig.SetNumTasks(self.m_environment.GetTaskLib().GetSize())
cConfig.SetNumReactions(self.m_environment.GetReactionLib().GetSize())
cConfig.SetNumResources(self.m_environment.GetResourceLib().GetSize())
+ descr("cConfig.Set...() called.")
+
# Test-CPU creation.
test_interface = cPopulationInterface()
+ descr("cPopulationInterface() called.")
+
BuildTestPopInterface(test_interface)
+ descr("BuildTestPopInterface(test_interface) called.")
+
cTestCPU.Setup(
self.m_environment.GetInstSet(),
self.m_environment,
self.m_environment.GetResourceLib().GetSize(),
test_interface)
+ descr("cTestCPU.Setup() called.")
self.m_avida_threaded_driver = pyAvidaThreadedDriver(self.m_environment)
+ descr("pyAvidaThreadedDriver(self.m_environment) called.")
+
self.m_avida_threaded_driver.construct()
+ descr("self.m_avida_threaded_driver.construct() done.")
+
self.m_population = self.m_avida_threaded_driver.GetPopulation()
- print "Population made"
+ descr("self.m_avida_threaded_driver.GetPopulation() done.")
+
+ self.m_name = genesis.GetFilename()
self.m_avida_thread_mdtr = pyMdtr()
self.m_should_update = False
@@ -111,8 +127,15 @@
self.destruct()
print("pyAvida.__del__() done.")
+ def shouldUpdate(self):
+ return self.m_should_update
+
+ def isUpdating(self):
+ return self.m_is_updating
+
def updateCheckSlot(self):
if self.m_avida_threaded_driver.m_updated_semaphore.acquire(False):
+ self.m_is_updating = False
self.m_avida_thread_mdtr.emit(qt.PYSIGNAL("AvidaUpdatedSig"),())
if True == self.m_should_update:
self.doUpdateAvidaSlot()
@@ -126,6 +149,7 @@
def doUpdateAvidaSlot(self):
try:
+ self.m_is_updating = True
self.m_avida_threaded_driver.doUpdate()
except AttributeError:
pass
Modified: branches/developers/avida-edward/source/python/AvidaGui2/pyAvidaThreadedDriver.py
===================================================================
--- branches/developers/avida-edward/source/python/AvidaGui2/pyAvidaThreadedDriver.py 2006-07-31 22:49:59 UTC (rev 860)
+++ branches/developers/avida-edward/source/python/AvidaGui2/pyAvidaThreadedDriver.py 2006-08-01 02:48:27 UTC (rev 861)
@@ -2,6 +2,8 @@
from AvidaCore import pyAvidaDriver
import atexit, threading
+from descr import descr
+
class pyAvidaThreadedDriver(pyAvidaDriver):
def construct(self):
@@ -84,9 +86,9 @@
# print("pyAvidaThreadedDriver.doExit() done.")
def doUpdate(self):
-# print("pyAvidaThreadedDriver.doUpdate()...")
+ #descr("updating...")
self.m_do_update_semaphore.release()
-# print("pyAvidaThreadedDriver.doUpdate() done.")
+ #descr("done.")
def doSetProcessBitesize(self, bitesize):
self.m_lock.acquire()
Modified: branches/developers/avida-edward/source/python/AvidaGui2/pyOrganismScopeCtrl.py
===================================================================
--- branches/developers/avida-edward/source/python/AvidaGui2/pyOrganismScopeCtrl.py 2006-07-31 22:49:59 UTC (rev 860)
+++ branches/developers/avida-edward/source/python/AvidaGui2/pyOrganismScopeCtrl.py 2006-08-01 02:48:27 UTC (rev 861)
@@ -1,7 +1,7 @@
# -*- coding: utf-8 -*-
from pyOrganismScopeView2 import pyOrganismScopeView2
-from AvidaCore import cAnalyzeGenotype, cGenome, cInstruction, cInstUtil, cString
+from AvidaCore import cAnalyzeGenotype, cGenome, cInstruction, cInstUtil, cRandom, cString, cTools
from pyHardwareTracer import pyHardwareTracer
from pyTimeline import pyTimeline, TimelineFlag
@@ -137,16 +137,34 @@
self.progress_bar.setProgress(step)
qApp.processEvents()
+
+ # If and Avida population is running, pause it.
+ is_avida_updating = self.m_avida.shouldUpdate()
+ if is_avida_updating:
+ self.m_session_mdl.m_session_mdtr.emit(PYSIGNAL("statusBarMessageSig"), ("Pausing Avida...",))
+ self.m_session_mdl.m_session_mdtr.emit(PYSIGNAL("doPauseAvidaSig"), ())
+ progress_callback = ProgressCallback(self.m_session_mdl.m_session_mdtr)
+ # Give the user something to watch while we wait for Avida population
+ # to pause. Calling the progress callback also causes the gui to
+ # process pending events, so the gui doesn't completely lock-up.
+ while self.m_avida.isUpdating():
+ progress_callback(0)
+ progress_callback.clear()
+
+ # Save random number generator state.
+ random_number_generator_state = cRandom(cTools.globalRandom())
+
+ # Tell user we're about to start organism analysis.
self.m_session_mdl.m_session_mdtr.emit(PYSIGNAL("setOneOrganismViewNameLabelTextSig"), (organism_filename,))
self.m_session_mdl.m_session_mdtr.emit(PYSIGNAL("statusBarMessageSig"), ("Analyzing organism...",))
progress_callback = ProgressCallback(self.m_session_mdl.m_session_mdtr)
+ # Analyze organism.
hardware_tracer = pyHardwareTracer(progress_callback)
hardware_tracer.setTestCPUCopyMutationRate(self.m_test_cpu_mutation_rate)
hardware_tracer.traceAnalyzeGenotype(analyze_genotype, self.m_avida.m_environment, should_use_resources = False)
progress_callback(2000)
- #del progress_callback
self.m_session_mdl.m_session_mdtr.emit(PYSIGNAL("statusBarMessageSig"), ("Setting up organism scope...",))
qApp.processEvents()
@@ -171,6 +189,15 @@
progress_callback.clear()
self.m_session_mdl.m_session_mdtr.emit(PYSIGNAL("statusBarClearSig"), ())
+ # Restore random number generator state.
+ cTools.globalRandom().Clone(random_number_generator_state)
+
+ # If we paused a running population, restart it.
+ if is_avida_updating:
+ self.m_session_mdl.m_session_mdtr.emit(PYSIGNAL("doStartAvidaSig"), ())
+ self.m_session_mdl.m_session_mdtr.emit(PYSIGNAL("statusBarMessageSig"), ("Unpaused Avida after organism analysis.",))
+
+
else:
# XXX Temporary. @kgn
warning_message_box = QMessageBox.warning(
Modified: branches/developers/avida-edward/source/python/AvidaGui2/pySessionCtrl.py
===================================================================
--- branches/developers/avida-edward/source/python/AvidaGui2/pySessionCtrl.py 2006-07-31 22:49:59 UTC (rev 860)
+++ branches/developers/avida-edward/source/python/AvidaGui2/pySessionCtrl.py 2006-08-01 02:48:27 UTC (rev 861)
@@ -44,7 +44,6 @@
# Variables tracking the state of the session
self.sessionInitialized = False
- self.m_should_update = False
# Create "model" for storing state data.
class pyMdl: pass
@@ -150,7 +149,6 @@
def restartPopulationSlot(self):
self.sessionInitialized = False
- self.m_should_update = False
def setAvidaSlot(self, avida):
"print *** pySessionCtrl setAvidaSlot ***"
@@ -223,11 +221,9 @@
PYSIGNAL("doInitializeAvidaPhaseISig"),
(self.m_session_mdl.m_tempdir,))
self.sessionInitialized = True
- self.m_should_update = True
self.m_session_mdl.m_session_mdtr.emit(PYSIGNAL("doStartAvidaSig"), ())
def doPauseSlot(self):
- self.m_should_update = False
self.m_session_mdl.m_session_mdtr.emit(PYSIGNAL("doPauseAvidaSig"), ())
def avidaUpdatedSlot(self):
Deleted: branches/developers/avida-edward/source/python/AvidaGui2/pySessionWorkThreadHdlr.py
===================================================================
--- branches/developers/avida-edward/source/python/AvidaGui2/pySessionWorkThreadHdlr.py 2006-07-31 22:49:59 UTC (rev 860)
+++ branches/developers/avida-edward/source/python/AvidaGui2/pySessionWorkThreadHdlr.py 2006-08-01 02:48:27 UTC (rev 861)
@@ -1,169 +0,0 @@
-import pyAvidaThreadedDriver; reload(pyAvidaThreadedDriver)
-from pyAvidaThreadedDriver import *
-
-import pyMdtr; reload(pyMdtr)
-from pyMdtr import *
-
-import qt
-
-class pyDeleteCheck:
- def __del__(self):
- print "pyDeleteCheck.__del__()"
-
-class pySessionWorkThreadHdlr(qt.QObject):
-
- def __init__(self):
- qt.QObject.__init__(self, None, self.__class__.__name__)
-
- def construct(self, session_mdl):
- self.m_session_mdl = session_mdl
- self.m_session_mdl.m_avida_threaded_driver = pyAvidaThreadedDriver(
- self.m_session_mdl.m_avida_core_data.m_environment)
- self.m_avida_threaded_driver = pyAvidaThreadedDriver(
- self.m_session_mdl.m_avida_core_data.m_environment)
- self.m_updated_semaphore = \
- self.m_session_mdl.m_avida_threaded_driver.m_updated_semaphore
- self.m_updated_semaphore = \
- self.m_avida_threaded_driver.m_updated_semaphore
- self.m_should_update = False
- self.m_session_mdl.m_avida_threaded_driver.construct()
- self.m_avida_threaded_driver.construct()
- self.m_session_mdl.m_population = \
- self.m_avida_threaded_driver.GetPopulation()
-
- self.connect(
- self.m_session_mdl.m_session_mdtr,
- qt.PYSIGNAL("doPauseAvidaSig"),
- self.doPauseAvidaSlot)
- self.connect(
- self.m_session_mdl.m_session_mdtr,
- qt.PYSIGNAL("doStartAvidaSig"),
- self.doStartAvidaSlot)
- self.connect(
- self.m_session_mdl.m_session_mdtr,
- qt.PYSIGNAL("doUpdateAvidaSig"),
- self.doUpdateAvidaSlot)
- self.connect(
- self.m_session_mdl.m_session_mdtr,
- qt.PYSIGNAL("doCloseAvidaSig"),
- self.doCloseAvidaSlot)
-
- self.m_update_ck_timer = qt.QTimer()
- self.connect(
- self.m_update_ck_timer,
- qt.SIGNAL("timeout()"),
- self.updateCheckSlot)
- self.m_update_ck_timer.start(100)
-
-
- def destruct(self):
- print("pySessionWorkThreadHdlr.destruct()...")
- self.m_session_mdl.m_session_mdtr.emit(
- qt.PYSIGNAL("doCloseAvidaSig"),())
- if hasattr(self, "m_update_ck_timer"):
- self.m_update_ck_timer.stop()
- del self.m_update_ck_timer
- else:
- print("pySessionWorkThreadHdlr.destruct() self.m_update_ck_timer missing.")
-
- self.disconnect(
- self.m_session_mdl.m_session_mdtr,
- qt.PYSIGNAL("doPauseAvidaSig"),
- self.doPauseAvidaSlot)
- self.disconnect(
- self.m_session_mdl.m_session_mdtr,
- qt.PYSIGNAL("doStartAvidaSig"),
- self.doStartAvidaSlot)
- self.disconnect(
- self.m_session_mdl.m_session_mdtr,
- qt.PYSIGNAL("doUpdateAvidaSig"),
- self.doUpdateAvidaSlot)
- self.disconnect(
- self.m_session_mdl.m_session_mdtr,
- qt.PYSIGNAL("doCloseAvidaSig"),
- self.doCloseAvidaSlot)
-
- if hasattr(self, "updated_semaphore"):
- del self.m_updated_semaphore
- else:
- print("pySessionWorkThreadHdlr.destruct() self.m_updated_semaphore missing.")
-
- #if hasattr(self.m_session_mdl, "m_avida_threaded_driver"):
- if hasattr(self, "m_avida_threaded_driver"):
- self.m_avida_threaded_driver.doExit()
- self.m_avida_threaded_driver.m_thread.join()
-# del self.m_avida_threaded_driver.m_thread
- #del self.m_session_mdl.m_avida_threaded_driver
- del self.m_avida_threaded_driver
- else:
- #print("pySessionWorkThreadHdlr.destruct() self.m_session_mdl.m_avida_threaded_driver missing.")
- print("pySessionWorkThreadHdlr.destruct() self.m_avida_threaded_driver missing.")
-
- print("pySessionWorkThreadHdlr.destruct() done.")
-
- def __del__(self):
- print("pySessionWorkThreadHdlr.__del__()...")
- self.destruct()
- print("pySessionWorkThreadHdlr.__del__() done.")
-
- def updateCheckSlot(self):
- if self.m_updated_semaphore.acquire(False):
- self.m_session_mdl.m_session_mdtr.emit(
- qt.PYSIGNAL("AvidaUpdatedSig"),())
- if True == self.m_should_update:
- self.doUpdateAvidaSlot()
-
- pass
- def doPauseAvidaSlot(self):
- self.m_should_update = False;
-
- def doStartAvidaSlot(self):
- self.m_should_update = True;
- self.doUpdateAvidaSlot()
-
- def doUpdateAvidaSlot(self):
- try:
- #self.session_mdl.avida_threaded_driver.doUpdate()
- self.m_avida_threaded_driver.doUpdate()
- except AttributeError:
- pass
-
- def doStepAvidaSlot(self, cell_id):
- print("doStepAvidaSlot")
-
- def doCloseAvidaSlot(self):
- #self.m_session_mdl.m_avida_threaded_driver.doExit()
- self.m_avida_threaded_driver.doExit()
- #self.m_session_mdl.m_avida_threaded_driver.m_thread.join()
- if self.m_avida_threaded_driver.m_thread.isAlive():
- self.m_avida_threaded_driver.m_thread.join()
- else:
- print("pySessionWorkThreadHdlr.doCloseAvidaSlot() thread is dead!")
-
-
-# Unit tests.
-
-from pyUnitTestSuiteRecurser import *
-from pyUnitTestSuite import *
-from pyTestCase import *
-
-from pmock import *
-
-class pyUnitTestSuite_pySessionWorkThreadHdlr(pyUnitTestSuite):
- def adoptUnitTests(self):
- print """
- -------------
- %s
- """ % self.__class__.__name__
- print """
- FIXME: pySessionWorkThreadHdlr
- pySessionWorkThreadHdlr has no unit tests.
- """
- self.adoptUnitTestSuite("pyAvidaThreadedDriver")
- self.adoptUnitTestSuite("pyMdtr")
-
- # Dummy test case.
- class crashDummy(pyTestCase):
- def test(self):
- self.test_is_true(True)
- self.adoptUnitTestCase(crashDummy())
Modified: branches/developers/avida-edward/source/python/AvidaGui2/pyTemporaryReloads.py
===================================================================
--- branches/developers/avida-edward/source/python/AvidaGui2/pyTemporaryReloads.py 2006-07-31 22:49:59 UTC (rev 860)
+++ branches/developers/avida-edward/source/python/AvidaGui2/pyTemporaryReloads.py 2006-08-01 02:48:27 UTC (rev 861)
@@ -37,7 +37,6 @@
#"AvidaGui.UnitTest_pyMdtr",
#"AvidaGui.UnitTest_pySessionControllerFactory",
#"AvidaGui.UnitTest_pySessionCtrl",
- #"AvidaGui.UnitTest_pySessionWorkThreadHdlr",
]
nontest_module_names = [
Modified: branches/developers/avida-edward/source/python/AvidaGui2/pyWriteGenesisEvent.py
===================================================================
--- branches/developers/avida-edward/source/python/AvidaGui2/pyWriteGenesisEvent.py 2006-07-31 22:49:59 UTC (rev 860)
+++ branches/developers/avida-edward/source/python/AvidaGui2/pyWriteGenesisEvent.py 2006-08-01 02:48:27 UTC (rev 861)
@@ -2,6 +2,10 @@
import shutil, string, pyInstructionSet, os.path
+from AvidaCore import *
+
+from descr import *
+
# Class to write the working genesis, event and environment files based on
# the contents of settings dictionary
@@ -79,9 +83,6 @@
organisms_dict[str(i)] = org_string
- self.modifyEventFile(cells_dict, organisms_dict, ancestor_link_dict,
- os.path.join(tmp_in_dir, "events.cfg"), tmp_out_dir)
-
shutil.copyfile(os.path.join(workspace_dir, "inst_set.default"), os.path.join(tmp_in_dir, "inst_set.default"))
settings_dict["EVENT_FILE"] = os.path.join(tmp_in_dir, "events.cfg")
@@ -89,8 +90,44 @@
self.writeEnvironmentFile(workspace_dir, settings_dict)
settings_dict["INST_SET"] = os.path.join(tmp_in_dir, "inst_set.default")
# settings_dict["START_CREATURE"] = os.path.join(tmp_in_dir, settings_dict["START_CREATURE"])
- self.writeGenesisFile(workspace_dir, tmp_in_dir, settings_dict)
+ genesis_file_name = self.writeGenesisFile(workspace_dir, tmp_in_dir, settings_dict)
+ # There's a loop around organisms_dict
+ # organism number is key, sequence is value.
+ # I need to make a merits_dict with organism number as key, and
+ # merit as value.
+ genesis = cGenesis()
+ cConfig.Setup(genesis)
+ genesis.Open(cString(genesis_file_name))
+ environment = cEnvironment()
+ environment.Load(cString(settings_dict["ENVIRONMENT_FILE"]))
+ environment.GetInstSet().SetInstLib(cHardwareCPU.GetInstLib())
+ cHardwareUtil.LoadInstSet(cString(settings_dict["INST_SET"]), environment.GetInstSet())
+ cConfig.SetNumInstructions(environment.GetInstSet().GetSize())
+ cConfig.SetNumTasks(environment.GetTaskLib().GetSize())
+ cConfig.SetNumReactions(environment.GetReactionLib().GetSize())
+ cConfig.SetNumResources(environment.GetResourceLib().GetSize())
+ test_interface = cPopulationInterface()
+ BuildTestPopInterface(test_interface)
+ cTestCPU.Setup(
+ environment.GetInstSet(),
+ environment,
+ environment.GetResourceLib().GetSize(),
+ test_interface)
+
+ inst_set = environment.GetInstSet()
+ merits_dict = {}
+ for key in organisms_dict.keys():
+ genome = organisms_dict[key]
+ analyze_genotype = cAnalyzeGenotype(cString(genome), inst_set)
+ analyze_genotype.Recalculate()
+ merit = analyze_genotype.GetMerit()
+ #descr("key", key, "genome", genome, "merit", merit)
+ merits_dict[key] = merit
+
+ self.modifyEventFile(cells_dict, organisms_dict, ancestor_link_dict,
+ merits_dict, os.path.join(tmp_in_dir, "events.cfg"), tmp_out_dir)
+
# Read the default genesis file, if there is a equivilent line in the
# dictionary replace it the new values, otherwise just copy the line
@@ -124,6 +161,7 @@
out_genesis_file.write(line)
out_genesis_file.close()
+ return out_genesis_file.name
# Read the default environment file, if there is a reward in the
# dictionary for a given resource print out that line in working env. file
@@ -175,7 +213,7 @@
out_environment_file.close()
- def modifyEventFile(self, cells_dict, organisms_dict, ancestor_link_dict,
+ def modifyEventFile(self, cells_dict, organisms_dict, ancestor_link_dict, merits_dict,
event_file_name, tmp_out_dir = None):
# Routine to add to the event.cfg file by inject creatures into the
@@ -184,12 +222,14 @@
event_out_file = open(event_file_name, 'a')
for cell in cells_dict.keys():
part1 = "u begin inject_sequence " + organisms_dict[cells_dict[cell]]
- part2 = " " + cell + " " + str(int(cell)+1) + " -1 "
+ part2 = " " + cell + " " + str(int(cell)+1)
+ #part3 = " -1 "
+ part3 = " " + str(merits_dict[cells_dict[cell]]) + " "
if (ancestor_link_dict.has_key(cells_dict[cell])):
- part3 = ancestor_link_dict[cells_dict[cell]] + "\n"
+ part4 = ancestor_link_dict[cells_dict[cell]] + "\n"
else:
- part3 ="\n"
- event_out_file.write(part1 + part2 + part3)
+ part4 ="\n"
+ event_out_file.write(part1 + part2 + part3 + part4)
# write the .dat files to the correct directory
More information about the Avida-cvs
mailing list