| Home | Trees | Indices | Help |
|
|---|
|
|
object --+
|
param.parameterized.Parameterized --+
|
object --+ |
| |
OptionalSingleton --+
|
Simulation
A simulation class that uses a simple sorted event list (instead of e.g. a sched.scheduler object) to manage events and dispatching.
Simulation is a singleton: there is only one instance of Simulation, no matter how many times it is instantiated.
|
|||
|
Inherited from |
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
Inherited from Inherited from Inherited from Inherited from |
|||
|
|||
|
Inherited from |
|||
|
|||
|
|||
|
|||
time_type = param.Parameter(default= float, constant= True, doThe numeric type to use for Simulation's time values. |
|||
time_type_args = param.Parameter(default= (), constant= True, Tuple of arguments to give to time_type whenever a new instance of the time_type is being created (e.g. |
|||
register = param.Boolean(default= True, constant= True, doc= Whether or not to register this Simulation. |
|||
startup_commands = param.Parameter(instantiate= True, default=List of string commands that will be exec'd in __main__.__dict__ (i.e. |
|||
time_printing_format = param.String("%(_time)09.2f", doc= Format string to be used when the simulation time must be formatted as a string, e.g. |
|||
basename_format = param.String("%(name)s_%(timestr)s", doc= Format string to be used by the basename() function. |
|||
eps_to_start = list() -> new list list(sequence) -> new list initialized from sequence's items |
|||
name = param.Parameter(constant= False)String identifier for this object. |
|||
_inst = Simulation(basename_format='%(name)s_%(timestr)s', namA simulation class that uses a simple sorted event list (instead of e.g. |
|||
|
Inherited from |
|||
|
|||
|
Inherited from |
|||
|
|||
staticmethod(function) -> method Convert a function to be a static method. A static method does not receive an implicit first argument. To declare a static method, use this idiom:
It can be called either on the class (e.g. C.f()) or on an instance (e.g. C().f()). The instance is ignored except for its class. Static methods in Python are similar to those found in Java or C++. For a more advanced concept, see the classmethod builtin.
|
|
|
|
Add ep to the simulation, setting its name to ep_name. ep must be an EventProcessor. If ep_name already exists in the simulation, ep overwrites the original object (as for a dictionary). Note: EventProcessors do not necessarily have to be added to the simulation to be used, but otherwise they will not receive the start() message. Adding a node to the simulation also sets the backlink node.simulation, so that the node can enqueue events and read the simulation time. |
Dictionary-style deletion of EPs from the simulation; see __delete_ep(). Deletes EP from simulation, plus connections that come into it and connections that go out of it. |
Remove the specified EventProcessor from the simulation, plus delete connections that come into it and connections that go from it. (Used by 'del sim[ep_name]' (as for a dictionary) to delete an event processor from the simulation.) |
Return the current simulation time as a FixedPoint object. If the time returned will be used in the computation of a floating point variable, it should be cast into a floating point number by float(). |
|
|
Process simulation events for the specified duration or until the specified time. Arguments:
If both duration and until are used, the one that is reached first will apply. Note that duration and until should be specified in a format suitable for conversion (coercion?) into the Simulation's _time_type. |
|
Add a command to execute in __main__.__dict__ at the specified time. The command should be a string. |
Save a copy of the current state of the simulation for later restoration. The saved copy includes all the events on the simulator stack (saved using event_push()). Each EventProcessor is also asked to save its own state. This operation is useful for testing something while being able to roll back to the original state.
|
Pop the most recently saved state off the stack. See state_push() for more details.
|
Save a copy of the events queue for later restoration. Same as state_push(), but does not ask EventProcessors to save their state. |
Pop the most recently saved events queue off the stack. Same as state_pop(), but does not restore EventProcessors' state. |
Clear out all scheduled events of the specified type. For instance, with event_type=EPConnectionEvent, this function can be used to ensure that no pending EPConnectionEvents will remain on the queue during some analysis or measurement operation. One will usually want to do a state_push before using this function, then clear out the events that should be deleted, do the measurement or analysis, and then do state_pop to restore the original state. |
Connect the src EventProcessor to the dest EventProcessor. The src and dest should be string names of existing EPs. Returns the connection that was created. If the connection hasn't been given a name, it defaults to 'srcTodest'. |
Return a dictionary of simulation objects having the specified base class. All simulation objects have a base class of EventProcessor, and so the baseclass must be either EventProcessor or one of its subclasses. If there is a simulator called s, you can type e.g. s.objects().keys() to see a list of the names of all objects. |
Return a nearly runnable script recreating this simulation. Needs some work to make the result truly runnable. Only scheduled commands that have not yet been executed are included, because executed commands are not kept around. |
Set the layout_location of simulation objects in a grid pattern. Takes a list of lists of simulation objects, or names of simulation objects, and positions them with layout_locations left-to-right, top-to-bottom, starting at (xstart,ystart) and advancing by xstep and ystep. The object None can be placed in the grid to skip a grid space. |
|
|||
time_typeThe numeric type to use for Simulation's time values. Simulation's time type can be set to any numeric type that supports the usual Python numeric operations, including at least multiplication, addition, and subtraction. Most of the code assumes that fractional values are supported, as they are for floats, but it may be possible to use an integer type instead if various default fractional values are overridden. For instance, one might wish to use arbitrary precision floating-point time to avoid accumulating rounding errors. For instance, if stepping through a simulation every 0.05 time units, after 20 such steps using floats the simulation will not reach 1.0 exactly, but will instead be slightly higher or lower. With an arbitrary precision float type such a series of steps can be guaranteed to reach 1.0 exactly. Alternatively, one might wish to use a rational type so that events can be guaranteed to happen a certain number of times in a given interval, even if the ratio cannot be expressed as an even decimal or binary fraction. Extra arguments can be passed to time_type when it is being used to create the Simulation's time: see time_type_args. Some potentially useful number classes:: - gmpy.mpq: gmpy provides Python with access to the fast GNU Multi-Precision library (which requires GMP to be built); gmpy.mpq is gmpy's rational type. - fixedpoint.FixedPoint: pure Python fixed-point number, but quite slow. - Python's Decimal class: in the standard library, but also quite slow.
|
time_type_argsTuple of arguments to give to time_type whenever a new instance of the time_type is being created (e.g. when a Simulation is created).
|
registerWhether or not to register this Simulation. If True, this Simulation (when created explicitly or when unpickled) will replace any existing registered Simulation (if one exists). Thus only one Simulation with register=True can exist at any one time, which makes it simpler to handle defining and reloading a series of simulations without polluting the memory space with unused simulations.
|
startup_commandsList of string commands that will be exec'd in __main__.__dict__ (i.e. as if they were entered at the command prompt) every time this simulation is unpickled (and will be executed before the simulation is itself unpickled). For example, allows items to be imported before scheduled_commands are run.
|
time_printing_formatFormat string to be used when the simulation time must be formatted as a string, e.g. for display or for basename(). When the string is evaluated, the time will be available as the attribute '_time'.
|
basename_formatFormat string to be used by the basename() function. When the string is evaluated, the formatted time from time_printing_format will be available as the attribute 'timestr'.
|
_instA simulation class that uses a simple sorted event list (instead of e.g. a sched.scheduler object) to manage events and dispatching. Simulation is a singleton: there is only one instance of Simulation, no matter how many times it is instantiated.
|
| Home | Trees | Indices | Help |
|
|---|
| Generated by Epydoc 3.0.1 on Sun Oct 12 22:26:31 2008 | http://epydoc.sourceforge.net |