Initial commit

This commit is contained in:
Yentl Van Tendeloo 2016-08-04 17:38:43 +02:00
commit 66a6860316
407 changed files with 1254365 additions and 0 deletions

View file

@ -0,0 +1,15 @@
# Copyright 2014 Modelling, Simulation and Design Lab (MSDL) at
# McGill University and the University of Antwerp (http://msdl.cs.mcgill.ca/)
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

View file

@ -0,0 +1,43 @@
# Copyright 2014 Modelling, Simulation and Design Lab (MSDL) at
# McGill University and the University of Antwerp (http://msdl.cs.mcgill.ca/)
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
class MyAllocator(object):
"""
Allocate all models at the start of the simulation. After this, model relocation is handed over to a relocator.
"""
def allocate(self, models, edges, nrnodes, totalActivities):
"""
Calculate allocations for the nodes, using the information provided.
:param models: the models to allocte
:param edges: the edges between the models
:param nrnodes: the number of nodes to allocate over. Simply an upper bound!
:param totalActivities: activity tracking information from each model
:returns: allocation that was found
"""
# Return something of the form: {0: 0, 1: 0, 2: 0, 3: 1}
# To allocate model_ids 0, 1 and 2 to node 0 and model_id 3 to node 1
return {0: 0, 1: 0, 2: 0, 3: 1}
def getTerminationTime(self):
"""
Returns the time it takes for the allocator to make an 'educated guess' of the advised allocation.
This time will not be used exactly, but as soon as the GVT passes over it. While this is not exactly
necessary, it avoids the overhead of putting such a test in frequently used code.
:returns: float -- the time at which to perform the allocations (and save them)
"""
# No need for any run time information means 0.0
return 0.0

View file

@ -0,0 +1,55 @@
# Copyright 2014 Modelling, Simulation and Design Lab (MSDL) at
# McGill University and the University of Antwerp (http://msdl.cs.mcgill.ca/)
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# Create a simulator with your model
model = Model()
sim = Simulator(model)
# Some of the most common options
# Enable verbose tracing
sim.setVerbose("output")
# End the simulation at simulation time 200
sim.setTerminationTime(200)
# Or use a termination condition to do the same
#def cond(model, time):
# return time >= 200
#sim.setTerminationCondition(cond)
# If you want to reinit it later
sim.setAllowLocalReinit(True)
# Finally simulate it
sim.simulate()
# Now possibly use the altered model by accessing the model attributes
# !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
# !!! Only possible in local simulation, distributed simulation requires !!!
# !!! another configuration option to achieve this. !!!
# !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
# You might want to rerun the simulation (for whatever reason)
# Just call the simulate method again, all configuration from before will be
# used again. Altering configuration options is possible (to some extent)
sim.simulate()
# Or if you want to alter a specific attribute
sim.setReinitState(model.generator, GeneratorState())
sim.setReinitStateAttr(model.generator, "generated", 4)
sim.setReinitAttributes(model.generator, "delay", 1)
# Now run it again
sim.simulate()

View file

@ -0,0 +1,58 @@
# Copyright 2014 Modelling, Simulation and Design Lab (MSDL) at
# McGill University and the University of Antwerp (http://msdl.cs.mcgill.ca/)
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""
Relocator for user-provided relocation directives
"""
class MyRelocator(object):
"""
Main class
"""
def __init__(self):
"""
Initialize the relocator
"""
pass
def setController(self, controller):
"""
Sets the controller
"""
pass
def getRelocations(self, gvt, activities, horizon):
"""
Fetch the relocations that are pending for the current GVT
:param gvt: current GVT
:param activities: the activities being passed on the GVT ring
:returns: dictionary containing all relocations
"""
# Perform a relocation, for example move the model with ID 1 to node 2, and the model with ID 3 to node 0
# Remaps are allowed to happen to the current location, as they will simply be discarded by the actual relocator
relocate = {1: 2, 3: 0}
return relocate
def lastStateOnly(self):
"""
Should the sum of all activities within this horizon be used, or simply the activity from the last state?
This has no effect on performance, but defines which activities the relocator can read.
Use 'last state only' if you require an abstracted view of the activities at a single timestep (equal to the GVT).
Use 'all states' if you require all information to be merged, such as in activity tracking.
"""
# "all states"
return False

View file

@ -0,0 +1,68 @@
# Copyright 2014 Modelling, Simulation and Design Lab (MSDL) at
# McGill University and the University of Antwerp (http://msdl.cs.mcgill.ca/)
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
class Scheduler(object):
def __init__(self, models, epsilon, totalModels):
"""
Constructor
:param models: all models in the simulation
"""
# Do your initialisation and schedule all models that are passed in the 'models' parameter
# NOTE: make a copy of these lists if you want to modify them
pass
def schedule(self, model):
"""
Schedule a new model, that was NOT present in the scheduler before
:param model: the model to schedule
"""
pass
def unschedule(self, model):
"""
Unschedule a model, so remove it from the scheduler for good
:param model: model to unschedule
"""
pass
def massReschedule(self, reschedule_set):
"""
Reschedule all models provided, all of them should already be scheduled previously and all should still be left in the scheduler after the rescheduling.
:param reschedule_set: iterable containing all models to reschedule
"""
pass
def readFirst(self):
"""
Returns the time of the first model that has to transition
:returns: timestamp of the first model
"""
pass
def getImminent(self, time):
"""
Returns an iterable of all models that transition at the provided time, with the epsilon deviation (from the constructor) allowed.
For efficiency, this method should only check the **first** elements, so trying to invoke this function with a timestamp higher
than the value provided with the *readFirst* method, will **always** return an empty iterable.
:param time: timestamp to check for models
:returns: iterable -- all models for that time
"""
pass

View file

@ -0,0 +1,93 @@
# Copyright 2014 Modelling, Simulation and Design Lab (MSDL) at
# McGill University and the University of Antwerp (http://msdl.cs.mcgill.ca/)
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from util import runTraceAtController
import sys
class MyTracer(object):
"""
A custom tracer
"""
def __init__(self, uid, server, myOwnArg1, myOwnArg2):
"""
Constructor
:param uid: the UID of this tracer
:param server: the server object, to make remote calls
:param myOwnArg_: custom arguments for this tracer
"""
self.server = server
self.uid = uid
# Own processing
def startTracer(self, recover):
"""
Starts up the tracer
:param recover: whether or not this is a recovery call (so whether or not the file should be appended to)
"""
pass
def stopTracer(self):
"""
Stop the tracer
"""
pass
def trace(self, time, myCustomParam1, myCustomParam2):
"""
Actual tracing function, will do something that is irreversible. If this function is called,
it is guaranteed that the trace operation will *not* be rolled back.
:param time: time at which this trace happened
:param myCustomParam_: custom parameters
"""
pass
def traceInternal(self, aDEVS):
"""
Tracing done for the internal transition function
:param aDEVS: the model that transitioned
"""
# You should only vary the 'myCustomParam_' part
runTraceAtController(self.server, self.uid, aDEVS, [myCustomParam1, myCustomParam2])
def traceConfluent(self, aDEVS):
"""
Tracing done for the confluent transition function
:param aDEVS: the model that transitioned
"""
# You should only vary the 'myCustomParam_' part
runTraceAtController(self.server, self.uid, aDEVS, [myCustomParam1, myCustomParam2])
def traceExternal(self, aDEVS):
"""
Tracing done for the external transition function
:param aDEVS: the model that transitioned
"""
# You should only vary the 'myCustomParam_' part
runTraceAtController(self.server, self.uid, aDEVS, [myCustomParam1, myCustomParam2])
def traceInit(self, aDEVS):
"""
Tracing done for the initialisation
:param aDEVS: the model that was initialised
"""
# You should only vary the 'myCustomParam_' part
runTraceAtController(self.server, self.uid, aDEVS, [myCustomParam1, myCustomParam2])