devs package

Submodules

devs.devs module

class devs.devs.AtomicBase

Bases: object

Python extension type, base type for DEVS Atomic Model

Python modules subclass this type and overwrite the methods

When initialized, the constructor (__init__) creates a new instance of the underlying C++ wrapper class Atomic (defined in the C++ header file). The C++ wrapper class Atomic inherits from adevs::Atomic and implements all the virtual functions. The C++ wrapper instance receives the function pointers to the cy_* helper functions defined here, as well as a pointer to the Python extension type instance. Whenever adevs calls one of the virtual functions of the C++ wrapper instance, the C++ wrapper instance routes it via the function pointer to the corresponding cy_* helper function. The cy_* helper function calls the corresponding method of the instance of the Python extension type.

http://stackoverflow.com/a/12700121/2366781 https://bitbucket.org/binet/cy-cxxfwk/src

When initialized, the constructor (__init__) creates a new instance of the underlying C++ wrapper class Atomic (defined in the C++ header file). Upon adding the model to a Digraph, the Digraph increases the reference count to this Python object, and decreases the reference count upon destruction. Note that the adevs C++ Digraph instance assumes ownership of the C++ wrapper instances. The C++ Digraph instance deletes all C++ wrapper instances upon destruction. So the Python object might still exist even though the C++ wrapper instance is long gone. When adevs deletes the C++ wrapper instance, the Python object is not deleted, when it is still referenced in the Python scope, but we can live with that.

The port type is integer. The value type is a generic Python object. This Python wrapper class abstracts away the underlying adevs C++ PortValue type.

adevs creates (copies) the C++ PortValue instance. https://github.com/smiz/adevs/blob/aae196ba660259ac32fc254bad810f4b4185d52f/include/adevs_digraph.h#L194 https://github.com/smiz/adevs/blob/aae196ba660259ac32fc254bad810f4b4185d52f/include/adevs_bag.h#L156

The only interface we need is to iterate over input (InputBag) in delta_ext and delta_conf, and to add output events (OutputBag) in output_func. Adding output events, the instance of this Python wrapper class increases the reference counter of the value Python object. The C++ wrapper class decreases the reference counter upon adevs’ call to the gc_output garbage collection function.

We deliberately break the adevs interface for the output_func method. In adevs, a reference to a Bag is supplied to the method returning void. Here, we choose the Pythonic way and take the return value of the method as the output bag. This is converted automatically by the cy_output_func helper function. output_func can either return

None (no output), a tuple (of length 2: port, value), or an iterable (of tuples of length 2: port, value).

For example, output_func can be implemented as a generator expression.

Similarly, the cy_delta_ext and cy_delta_conf helper functions convert the input bag to a Python list of port, value tuples.

delta_conf()
delta_ext()
delta_int()
output_func()
ta()
class devs.devs.Digraph

Bases: object

Python extension type that wraps the C++ wrapper class for the adevs Digraph class

For now, we only provide Atomic models. I.e. nested network models are not supported yet.

An instance of the C++ Digraph class takes ownership of added components, i.e. deletes the components at the end of its lifetime. This is why we increase the reference count to the Python object as soon as we add it to the Digraph. Upon deletion of the Digraph, the reference count is decreased. https://github.com/smiz/adevs/blob/aae196ba660259ac32fc254bad810f4b4185d52f/include/adevs_digraph.h#L205

__iter__

Generator to iterate over components of the digraph

http://docs.python.org/3/library/stdtypes.html#generator-types

Return AtomicBase Python objects upon each iteration

add()
couple()
class devs.devs.IOBag

Bases: object

Python extension base type that wraps an existing C++ I/O bag

For constant bags, only the internal pointer _thisconstptr is used. For non-const bags, both internal pointers _thisconstptr and _thisptr are used.

__iter__

Generator to iterate over elements in bag

http://docs.python.org/3/library/stdtypes.html#generator-types

Return (port, value) tuples upon each iteration

empty()
size()
class devs.devs.InputBag

Bases: devs.devs.IOBag

Python extension type that wraps an existing C++ I/O bag

class devs.devs.OutputBag

Bases: devs.devs.IOBag

Python extension type that wraps an existing C++ I/O bag

To construct an instance in Cython, use the CreateOutputBag factory function.

When inserting port/values, increase the reference counter for Python objects.

insert()
class devs.devs.Simulator

Bases: object

Python extension type that wraps the adevs C++ Simulator class

Note that the adevc C++ Simulator class does not assume ownership of the model. Hence, when using a Python wrapper Simulator instance, we need to keep the Python wrapper Digraph or AtomicBase-subclassed instance in scope as well. When the model Python instance goes out of scope, the internal C++ pointer gets deleted, rendering the Simulator defunct.

execute_next_event()
execute_until()
next_event_time()

Module contents

Copyright 2014 The pydevs Developers

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

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.