Skip to content
Permalink
Browse files

clean up todos; fix tests

  • Loading branch information
artgoldberg committed Aug 29, 2019
1 parent c927b92 commit 433fa715e9ed19a538c3ea843e4151a36094d397
Showing with 16 additions and 15 deletions.
  1. +9 −5 de_sim/simulation_engine.py
  2. +0 −2 de_sim/simulation_object.py
  3. +7 −8 tests/test_simulation_engine.py
@@ -46,6 +46,10 @@ class SimulationEngine(object):
Raises:
:obj:`SimulatorError`: if the `stop_condition` is not callable
"""
# Termination messages
NO_EVENTS_REMAIN = " No events remain"
END_TIME_EXCEEDED = " End time exceeded"
TERMINATE_WITH_STOP_CONDITION_SATISFIED = " Terminate with stop condition satisfied"

def __init__(self, shared_state=None, debug_log=False, stop_condition=None):
if shared_state is None:
@@ -241,15 +245,15 @@ def simulate(self, end_time, epsilon=None, stop_condition=None, progress=False):

try:
self.progress.start(end_time)
# todo: perhaps 'while True':
# TODO(Arthur): perhaps 'while True':
while self.time <= end_time:
# use the stop condition
if self.stop_condition is not None and self.stop_condition(self.time):
self.log_with_time(" Terminate with stop condition satisfied")
self.log_with_time(self.TERMINATE_WITH_STOP_CONDITION_SATISFIED)
self.progress.end()
break

# TODO(Arthur): provide dynamic control
# TODO(Arthur): provide dynamic logging control
# self.log_simulation_state()

# get the earliest next event in the simulation
@@ -259,12 +263,12 @@ def simulate(self, end_time, epsilon=None, stop_condition=None, progress=False):
next_sim_obj = self.event_queue.next_event_obj()

if float('inf') == next_time:
self.log_with_time(" No events remain")
self.log_with_time(self.NO_EVENTS_REMAIN)
self.progress.end()
break

if end_time < next_time:
self.log_with_time(" End time exceeded")
self.log_with_time(self.END_TIME_EXCEEDED)
self.progress.end()
break

@@ -456,8 +456,6 @@ def _SimulationEngine__handle_event_list(self, event_list):
Raises:
:obj:`SimulatorError`: if a message in `event_list` has an invalid type
"""
# TODO(Arthur): rationalize naming between simulation message, event, & event_list.
# The PDES field needs this clarity.
self.num_events += 1

# write events to a plot log
@@ -28,7 +28,7 @@
from de_sim.shared_state_interface import SharedStateInterface
from wc_utils.util.misc import most_qual_cls_name
from wc_utils.util.dict import DictUtil

config = core.get_debug_logs_config()

ALL_MESSAGE_TYPES = [InitMsg, Eg1]

@@ -221,10 +221,9 @@ def test_simulation_engine_exceptions(self):
self.assertRegex(str(context.exception), "epsilon (.*) plus end time (.*) must exceed end time")

def test_simulation_end(self):
# TODO(Arthur): make this a test or discard it
self.simulator.add_object(BasicExampleSimulationObject('name'))
self.simulator.initialize()
# log "No events remain"
# TODO(Arthur): test that the "No events remain" message is logged
self.simulator.simulate(5.0)

def test_simulation_stop_condition(self):
@@ -236,6 +235,8 @@ def test_simulation_stop_condition(self):
# execute to time <= end_time, with 1st event at time = 1
self.assertEqual(simulator.simulate(end_time), end_time)

# TODO(Arthur): fix: this is misleading, because __stop_cond_end is treated like a time, but
# simulate() returns a count of events executed
__stop_cond_end = 3
def stop_cond_eg(time):
return __stop_cond_end <= time
@@ -248,7 +249,7 @@ def stop_cond_eg(time):
simulator.add_object(PeriodicSimulationObject('name', 1))
simulator.initialize()
self.assertEqual(simulator.simulate(end_time, stop_condition=stop_cond_eg), __stop_cond_end)
# todo: test log of 'Terminate with stop condition satisfied'
# TODO(Arthur): test that the 'Terminate with stop condition satisfied' message is logged

with self.assertRaisesRegex(SimulatorError, 'stop_condition is not a function'):
SimulationEngine(stop_condition='hello')
@@ -294,11 +295,10 @@ def make_cyclical_messaging_network_sim(self, num_objs):

def test_cyclical_messaging_network(self):
# test event times at simulation objects; this test should succeed with any
# natural number for num_objs and any non-negative value of sim_duration
# natural number for num_objs and any non-negative value of end_time
self.make_cyclical_messaging_network_sim(10)
self.simulator.initialize()
self.simulator.simulate(20)
# todo: this method doesn't contain tests
self.assertTrue(0<self.simulator.simulate(20))

def test_message_queues(self):
warnings.simplefilter("ignore")
@@ -336,7 +336,6 @@ def restore_logging(self):
global config
config = self.saved_config

@unittest.skip("todo: fix")
def test_log_conf(self):
console_level = config['debug_logs']['handlers']['debug.console']['level']
self.suspend_logging()

0 comments on commit 433fa71

Please sign in to comment.
You can’t perform that action at this time.