~ubuntu-branches/ubuntu/utopic/deap/utopic-proposed

« back to all changes in this revision

Viewing changes to deap/dtm/dtmTypes.py

  • Committer: Package Import Robot
  • Author(s): Daniel Stender, Miriam Ruiz, Daniel Stender, Jakub Wilk
  • Date: 2014-07-06 00:03:41 UTC
  • mfrom: (1.1.2)
  • Revision ID: package-import@ubuntu.com-20140706000341-s7gij1ki3d8xz6t9
Tags: 1.0.1-1
[ Miriam Ruiz ]
* New Upstream Release. Closes: #675200
* Upgraded Standards-Version from 3.9.2 to 3.9.5
* Switched to dh_python2
* Upgraded debian/compat to 9
* Added build-arch and build-indep targets to debian/rules
* Using awk to remove connection from the documentation to google analytics
* Using jquery.js and underscore.js from libjs-jquery and libjs-underscore
* Added patches/doc.patch

[ Daniel Stender ]
* deb/control:
  + Added myself to Uploaders.
  + Added version to b-p on python-all.
  + Updated Homepage.
  + Wrapped and sorted.
* deb/copyright:
  + Changed copyright file towards DEP-5.
  + Updated Source URI (project source moved to Github).
  + Added email addresses for copyright holders.
  + Dropped license for eap/toolbox.py (not included anymore).
  + Extended copyrights to 2014.
  + Added myself to copyrights for deb/*.
  + Specified license location.
* Added watch file [initial version by Jackson Doak].

[ Jakub Wilk ]
* Use canonical URIs for Vcs-* fields.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#    This file is part of DEAP.
2
 
#
3
 
#    DEAP is free software: you can redistribute it and/or modify
4
 
#    it under the terms of the GNU Lesser General Public License as
5
 
#    published by the Free Software Foundation, either version 3 of
6
 
#    the License, or (at your option) any later version.
7
 
#
8
 
#    DEAP is distributed in the hope that it will be useful,
9
 
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
10
 
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
 
#    GNU Lesser General Public License for more details.
12
 
#
13
 
#    You should have received a copy of the GNU Lesser General Public
14
 
#    License along with DEAP. If not, see <http://www.gnu.org/licenses/>.
15
 
 
16
 
DTM_TASK_STATE_IDLE = 0
17
 
DTM_TASK_STATE_RUNNING = 1
18
 
DTM_TASK_STATE_WAITING = 2
19
 
DTM_TASK_STATE_FINISH = 3
20
 
 
21
 
DTM_MSG_EXIT = 0
22
 
DTM_MSG_TASK = 1
23
 
DTM_MSG_REQUEST_TASK = 2
24
 
DTM_MSG_RESULT = 3
25
 
DTM_MSG_ACK_RECEIVED_TASK = 4
26
 
 
27
 
DTM_WAIT_NONE = 0
28
 
DTM_WAIT_SOME = 1
29
 
DTM_WAIT_ALL = 2
30
 
DTM_WAIT_ANY = 3
31
 
 
32
 
class TaskContainer(object):
33
 
    """
34
 
    Contains all the information about a task (running or not)
35
 
    """
36
 
    __slots__ = ('tid', # Unique ID of the task
37
 
                'creatorWid', # ID of the worker who creates this task
38
 
                'creatorTid', # ID of the task who creates this task (parent)
39
 
                'taskIndex', # Position into the parents task childs list
40
 
                'taskRoute', # Worker path followed by the job before begin
41
 
                'creationTime', # Time at the job creation
42
 
                'target', # Target function (or callable object) of the task
43
 
                'args', # Arguments (list)
44
 
                'kwargs', # Key-worded arguments (dictionnary)
45
 
                'threadObject', # Python representation of the thread
46
 
                'taskState')    # State of the task (DTM_TASK_*)
47
 
    def __init__(self, **kwargs):
48
 
        self.__setstate__(kwargs)    
49
 
    def __getstate__(self):
50
 
        d = {}
51
 
        for a in self.__slots__:
52
 
            d[a] = self.__getattribute__(a)
53
 
        return d    
54
 
    def __setstate__(self, state):
55
 
        for t in state:
56
 
            self.__setattr__(t, state[t])
57
 
    def __lt__(self, other):
58
 
        return self.creationTime < other.creationTime
59
 
 
60
 
class ResultContainer(object):
61
 
    """
62
 
    Used to store the result of a task so it can be sent
63
 
    """
64
 
    __slots__ = ('tid', # ID of the task which produced these results
65
 
                'parentTid', # Parent ID (waiting for these results)
66
 
                'taskIndex', # Position into the parents task childs list
67
 
                'execTime', # Total execution time (NOT waiting time)
68
 
                'success', # False if an exception occured
69
 
                'result')       # The result; if an exception occured, contains it
70
 
    def __init__(self, **kwargs):
71
 
        self.__setstate__(kwargs)    
72
 
    def __getstate__(self):
73
 
        d = {}
74
 
        for a in self.__slots__:
75
 
            d[a] = self.__getattribute__(a)
76
 
        return d    
77
 
    def __setstate__(self, state):
78
 
        for t in state:
79
 
            self.__setattr__(t, state[t])
80
 
 
81
 
class ExceptedResultContainer(object):
82
 
    """
83
 
    Keep the information of a result waited on the task creator side
84
 
    """
85
 
    __slots__ = ('tids', # List of IDs of the tasks which produce these results
86
 
                'waitingOn', # Is the parent task waiting on this result?
87
 
                'finished', # Boolean : is the task finished (i.e. result received)?
88
 
                'success', # Boolean : False if unfinished or if an exception occured
89
 
                'callbackFunc', # Callback function, FOR USE IN DTM, NO ARGUMENTS PASSED, or None
90
 
                'result')       # Result, or the exception occured
91
 
    def __init__(self, **kwargs):
92
 
        self.__setstate__(kwargs)   
93
 
    def __getstate__(self):
94
 
        d = {}
95
 
        for a in self.__slots__:
96
 
            d[a] = self.__getattribute__(a)
97
 
        return d    
98
 
    def __setstate__(self, state):
99
 
        for t in state:
100
 
            self.__setattr__(t, state[t])
101
 
            
102
 
class WaitInfoContainer(object):
103
 
    """
104
 
    Keep a track on the pending child tasks of a parent task.
105
 
    """
106
 
    __slots__ = ('threadObject', # Python representation of the thread
107
 
                'eventObject', # threading.Event flag (to wake up the thread)
108
 
                'waitBeginningTime', # Time when the thread started waiting (0 if not)
109
 
                'tasksWaitingCount', # How many tasks are we waiting on
110
 
                'waitingMode', # DTM_WAIT_* : waiting mode (None, One, Any, All)
111
 
                'rWaitingDict')     # List of ExceptedResultContainer, key : the first task ID
112
 
    def __init__(self, **kwargs):
113
 
        self.__setstate__(kwargs)  
114
 
    def __getstate__(self):
115
 
        d = {}
116
 
        for a in self.__slots__:
117
 
            d[a] = self.__getattribute__(a)
118
 
        return d    
119
 
    def __setstate__(self, state):
120
 
        for t in state:
121
 
            self.__setattr__(t, state[t])
122
 
 
123
 
class StatsContainer(object):
124
 
    """
125
 
    Contains stats about a target
126
 
    """
127
 
    __slots__ = ('rAvg', # RELATIVE average execution time
128
 
                'rStdDev', # RELATIVE standard deviation of the exec time
129
 
                'rSquareSum', # Square sum of the RELATIVE exec times
130
 
                'execCount')    # Number of executions
131
 
    def __init__(self, **kwargs):
132
 
        self.__setstate__(kwargs)    
133
 
    def __getstate__(self):
134
 
        d = {}
135
 
        for a in self.__slots__:
136
 
            d[a] = self.__getattribute__(a)
137
 
        return d    
138
 
    def __setstate__(self, state):
139
 
        for t in state:
140
 
            self.__setattr__(t, state[t])
141
 
 
142
 
class MessageContainer(object):
143
 
    """
144
 
    Generic message container
145
 
    If msgType == DTM_MSG_EXIT:
146
 
        msg = (Exit code, exit message)
147
 
    If msgType == DTM_MSG_TASK:
148
 
        msg = [TaskContainer, TaskContainer, TaskContainer, ...]
149
 
    If msgType == DTM_MSG_REQUEST_TASK:
150
 
        msg = None
151
 
    If msgType == DTM_MSG_RESULT:
152
 
        msg = [ResultContainer, ResultContainer, ResultContainer, ...]
153
 
    If msgType == DTM_MSG_ACK_RECEIVED_TASK:
154
 
        msg = AckId
155
 
    """
156
 
    __slots__ = ('msgType', # Message type (DTM_MSG_*)
157
 
                'senderWid', # Worker id of the sender
158
 
                'receiverWid', # Worker id of the receiver
159
 
                'loadsDict', # Load dictionnary of the sender
160
 
                'targetsStats', # Stats on the tasks of the sender
161
 
                'prepTime', # Time when it was ready to send
162
 
                'sendTime', # Time when sent
163
 
                'ackNbr', # ACK number (optionnal for some operations)
164
 
                'msg')          # Message (varies with msgType)
165
 
    def __init__(self, **kwargs):
166
 
        self.__setstate__(kwargs)  
167
 
    def __getstate__(self):
168
 
        d = {}
169
 
        for a in self.__slots__:
170
 
            d[a] = self.__getattribute__(a)
171
 
        return d    
172
 
    def __setstate__(self, state):
173
 
        for t in state:
174
 
            self.__setattr__(t, state[t])
175