当前位置: 首页>>代码示例>>Python>>正文


Python Scheduler.get_schedule方法代码示例

本文整理汇总了Python中scheduler.Scheduler.get_schedule方法的典型用法代码示例。如果您正苦于以下问题:Python Scheduler.get_schedule方法的具体用法?Python Scheduler.get_schedule怎么用?Python Scheduler.get_schedule使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在scheduler.Scheduler的用法示例。


在下文中一共展示了Scheduler.get_schedule方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: __init__

# 需要导入模块: from scheduler import Scheduler [as 别名]
# 或者: from scheduler.Scheduler import get_schedule [as 别名]
class NeuronGroup:
    def __init__(self, size, a=0.1, b=0.2, c=-65.0, d=2.0):
        self.scheduler = Scheduler(size)
        self.size = size

        v_peak = 30.0
        tau = 0.5

        self.v = v = theano.shared(np.full(size, c, dtype=floatX), name="v", borrow=True)
        self.u = u = theano.shared(np.full(size, b * c, dtype=floatX), name="u", borrow=True)
        self.I = I = theano.shared(np.zeros(size, dtype=floatX), name="I", borrow=True)

        dv = tau * (0.04 * (v * v) + (v * 5.0) + 140.0 - u + I)
        du = tau * (a * ((b * v) - u))

        now = T.iscalar("now")
        DC = T.vector("DC")
        spikes = T.vector("spikes")
        schedule = T.vector("schedule")

        self.recv = theano.function([DC, schedule], I, updates=[(I, I + DC + schedule)])
        self.tick_v = theano.function([], v, updates=[(v, v + dv)])
        self.tick_u = theano.function([], u, updates=[(u, u + du)])
        self.threshold = theano.function([], v >= v_peak)
        self.reset = theano.function([spikes], [v, u, I], updates=[
            (v, T.switch(spikes, c, v)),
            (u, T.switch(spikes, u + d, u)),
            (I, T.zeros_like(I)),
        ])

        window_size = 40
        rate_mul = 1000.0 / window_size

        self.spike_counter = spike_counter = theano.shared(np.zeros((window_size, size), dtype=floatX), name="spike_counter", borrow=True)
        self.rate = rate = theano.shared(np.zeros(size, dtype=floatX), name="rate", borrow=True)

        self.count_spikes = theano.function([now, spikes], spike_counter, updates=[
            (spike_counter, T.set_subtensor(spike_counter[now % window_size], spikes))
        ], name="count_spikes")

        self.sum_rate = theano.function([], rate, updates=[
            (rate, T.sum(spike_counter, axis=0) * rate_mul)
        ])

    def tick(self, now, DC):
        # TODO: can this be accomplished in a single update?
        schedule = self.scheduler.get_schedule(now)
        self.scheduler.clear_schedule(now)

        self.recv(DC, schedule)

        self.tick_v()
        self.tick_u()

        self.tick_v()
        self.tick_u()

        self.spikes = self.threshold()

        self.count_spikes(now, self.spikes)
        self.sum_rate()

        self.reset(self.spikes)
        return self.spikes
开发者ID:BarkingMouseStudio,项目名称:neural-py,代码行数:66,代码来源:neuron_group.py

示例2: SchedulerTestCase

# 需要导入模块: from scheduler import Scheduler [as 别名]
# 或者: from scheduler.Scheduler import get_schedule [as 别名]
class SchedulerTestCase(unittest.TestCase):
    sch = None

    def __init__(self, *args, **kwargs):
        super(SchedulerTestCase, self).__init__(*args, **kwargs)

        if self.sch is None:
            configuration.select('marvinctld',
                                 preset={'inventory': {'sync': False},
                                         'database': TEMP_DB,
                                         'repository': {
                                                 'deployment':'server.xyz'},
                                         'log': {'level': 50,
                                                 'file': TEMP_LOG}})

            from scheduler import Scheduler
            self.sch = Scheduler()

            c = self.sch.db().cursor()
            now = int(time.time())
            c.execute("INSERT OR IGNORE INTO nodes VALUES (?, ?, ?, ?)",
                  ('1', 'test-node', 'active', now))
            c.execute("INSERT OR IGNORE INTO nodes VALUES (?, ?, ?, ?)",
                  ('2', 'test-node 2', 'active', now))
            c.execute("INSERT OR REPLACE INTO node_interface "
                  "VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)",
                  ('1', 'a', 'ab', 'abc', 'abcd', 0, 0, 0, 0, 0, 0))
            c.execute("INSERT OR REPLACE INTO node_interface "
                  "VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)",
                  ('2', 'a', 'ab', 'abc', 'abcd', 0, 0, 0, 0, 0, 0))
            self.sch.db().commit()
            self.sch.set_node_types(1, 'status:test')

    def test_00_db_exists(self):
        self.assertTrue(os.path.isfile(TEMP_DB))
        self.assertIsNotNone(self.sch.db())

    def test_01_create_user(self):
        userid, error = self.sch.create_user('admin', 'admin', 'admin')
        self.assertIsNotNone(userid)
        user = self.sch.get_users(ssl='admin')
        self.assertIsNotNone(user)
        self.assertEqual(user[0].get('id', None), 1)
        self.assertGreater(user[0].get('quota_time', 0), 0)
        self.assertGreater(user[0].get('quota_data', 0), 0)
        self.assertGreater(user[0].get('quota_storage', 0), 0)
        role = self.sch.get_role(ssl='admin')
        self.assertEqual(role, 'admin')
        # not an user
        user = self.sch.get_users(userid=5)
        self.assertIsNone(user)

    def test_02_created_node(self):
        result = self.sch.get_nodes(nodetype='status:test')
        self.assertEqual(result[0].get('id', None), 1)

    def test_03_delete_user(self):
        userid, error = self.sch.create_user('foo', 'foo', 'foo')
        self.assertIsNotNone(userid)
        ok = self.sch.delete_user(userid)
        self.assertTrue(ok)

    def test_04_get_empty_schedule(self):
        self.assertEqual(self.sch.get_schedule(), [])

    def test_05_get_empty_experiments(self):
        self.assertIsNone(self.sch.get_experiments())

    def test_06_get_scheduling_period(self):
        p = self.sch.get_scheduling_period()
        self.assertGreater(p[1]-p[0], 0)

    def test_10_allocate(self):
        now = int(time.time())
        # basic a few minutes into the future
        r = self.sch.allocate(1,'test', now + 500, 500, 1, 'status:test,-status:foo,-status:bar', '...', {})
        self.assertEqual(r[2]['nodecount'], 1)
        # not available
        r = self.sch.allocate(1,'test', now + 500, 500, 1, 'status:test', '...', {})
        self.assertEqual(r[2]['available'], 0)
        # too soon
        r = self.sch.allocate(1,'test', now, 500, 1, 'status:test', '...', {})
        self.assertIsNone(r[0])
        # too soon after the previous experiment
        r = self.sch.allocate(1,'test', now + 1000, 500, 1, 'status:test', '...', {})
        self.assertIsNone(r[0])
        # too short
        r = self.sch.allocate(1,'test', now + 1500, 1, 1, 'status:test', '...', {})
        self.assertIsNone(r[0])
        # zero node count
        r = self.sch.allocate(1,'test', now + 1500, 500, 0, 'status:test', '...', {})
        self.assertIsNone(r[0])
        # too many nodes
        r = self.sch.allocate(1,'test', now + 1500, 500, 2, 'status:test', '...', {})
        self.assertEqual(r[2]['available'], 1)
        # too much storage requested
        r = self.sch.allocate(1,'test', now + 1500, 500, 1, 'status:test', '...',
                              {'storage': 501 * 1000000000})
        self.assertEqual(r[2]['requested'], 501 * 1000000000)

#.........这里部分代码省略.........
开发者ID:MONROE-PROJECT,项目名称:Scheduler,代码行数:103,代码来源:test_scheduler.py


注:本文中的scheduler.Scheduler.get_schedule方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。