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


Python Pattern.interface[m1_sel_out_gpot]方法代码示例

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


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

示例1: test_transmit_spikes_one_to_many

# 需要导入模块: from neurokernel.pattern import Pattern [as 别名]
# 或者: from neurokernel.pattern.Pattern import interface[m1_sel_out_gpot] [as 别名]
    def test_transmit_spikes_one_to_many(self):
        m1_sel_in_gpot = Selector('')
        m1_sel_out_gpot = Selector('')
        m1_sel_in_spike = Selector('')
        m1_sel_out_spike = Selector('/m1/out/spike[0:4]')
        m1_sel, m1_sel_in, m1_sel_out, m1_sel_gpot, m1_sel_spike = \
            make_sels(m1_sel_in_gpot, m1_sel_out_gpot, m1_sel_in_spike, m1_sel_out_spike)
        N1_gpot = SelectorMethods.count_ports(m1_sel_gpot)
        N1_spike = SelectorMethods.count_ports(m1_sel_spike)

        m2_sel_in_gpot = Selector('')
        m2_sel_out_gpot = Selector('')
        m2_sel_in_spike = Selector('/m2/in/spike[0:4]')
        m2_sel_out_spike = Selector('')
        m2_sel, m2_sel_in, m2_sel_out, m2_sel_gpot, m2_sel_spike = \
            make_sels(m2_sel_in_gpot, m2_sel_out_gpot, m2_sel_in_spike, m2_sel_out_spike)
        N2_gpot = SelectorMethods.count_ports(m2_sel_gpot)
        N2_spike = SelectorMethods.count_ports(m2_sel_spike)

        m1_id = 'm1'
        self.man.add(MyModule1, m1_id,
                     m1_sel, m1_sel_in, m1_sel_out,
                     m1_sel_gpot, m1_sel_spike,
                     np.zeros(N1_gpot, dtype=np.double),
                     np.zeros(N1_spike, dtype=int),
                     device=0, debug=debug, out_spike_data=[1, 0, 0, 0])

        f, out_file_name = tempfile.mkstemp()
        os.close(f)

        m2_id = 'm2'
        self.man.add(MyModule2, m2_id,
                     m2_sel, m2_sel_in, m2_sel_out,
                     m2_sel_gpot, m2_sel_spike,
                     np.zeros(N2_gpot, dtype=np.double),
                     np.zeros(N2_spike, dtype=int),
                     device=1, debug=debug, out_file_name=out_file_name)

        pat12 = Pattern(m1_sel, m2_sel)
        pat12.interface[m1_sel_out_gpot] = [0, 'in', 'gpot']
        pat12.interface[m1_sel_in_gpot] = [0, 'out', 'gpot']
        pat12.interface[m1_sel_out_spike] = [0, 'in', 'spike']
        pat12.interface[m1_sel_in_spike] = [0, 'out', 'spike']
        pat12.interface[m2_sel_in_gpot] = [1, 'out', 'gpot']
        pat12.interface[m2_sel_out_gpot] = [1, 'in', 'gpot']
        pat12.interface[m2_sel_in_spike] = [1, 'out', 'spike']
        pat12.interface[m2_sel_out_spike] = [1, 'in', 'spike']
        pat12['/m1/out/spike[0]', '/m2/in/spike[0]'] = 1
        pat12['/m1/out/spike[0]', '/m2/in/spike[1]'] = 1
        pat12['/m1/out/spike[0]', '/m2/in/spike[2]'] = 1
        pat12['/m1/out/spike[0]', '/m2/in/spike[3]'] = 1
        self.man.connect(m1_id, m2_id, pat12, 0, 1)

        # Run emulation for 2 steps:
        self.man.spawn()
        self.man.start(2)
        self.man.wait()

        # Get output of m2:
        with open(out_file_name, 'r') as f:
            output = pickle.load(f)

        os.remove(out_file_name)
        self.assertSequenceEqual(list(output), [1, 1, 1, 1])
开发者ID:neurokernel,项目名称:neurokernel,代码行数:66,代码来源:test_core_gpu.py

示例2: run_test

# 需要导入模块: from neurokernel.pattern import Pattern [as 别名]
# 或者: from neurokernel.pattern.Pattern import interface[m1_sel_out_gpot] [as 别名]
def run_test(m0_sel_in_gpot, m0_sel_in_spike,
             m0_sel_out_gpot, m0_sel_out_spike,
             m1_sel_in_gpot, m1_sel_in_spike,
             m1_sel_out_gpot, m1_sel_out_spike):

    # Create test module classes with a queue installed in the destination
    # module to check that data was correctly propagated:
    class TestModule0(TestModule):
        def __init__(self, *args, **kwargs):
            super(TestModule0, self).__init__(*args, **kwargs)
            self.q = Queue()

        def run_step(self):
            self.log_info('saving data to queue before run step')
            if self.steps > 0:
                self.q.put((self.pm['gpot'][self._out_port_dict['gpot']['m1']].copy(),
                            self.pm['spike'][self._out_port_dict['spike']['m1']].copy()))
            super(TestModule0, self).run_step()

    class TestModule1(TestModule):
        def __init__(self, *args, **kwargs):
            super(TestModule1, self).__init__(*args, **kwargs)
            self.q = Queue()

        def run_step(self):
            super(TestModule1, self).run_step()
            self.log_info('saving data to queue after run step')
            if self.steps > 0:
                self.q.put((self.pm['gpot'][self._in_port_dict['gpot']['m0']].copy(),
                            self.pm['spike'][self._in_port_dict['spike']['m0']].copy()))

    m0_sel_gpot = m0_sel_in_gpot+m0_sel_out_gpot
    m0_sel_spike = m0_sel_in_spike+m0_sel_out_spike
    m0_sel = m0_sel_in_gpot+m0_sel_in_spike+m0_sel_out_gpot+m0_sel_out_spike
    m0_data_gpot = np.ones(len(m0_sel_gpot), np.double)
    m0_data_spike = np.ones(len(m0_sel_spike), np.int32)

    m1_sel_gpot = m1_sel_in_gpot+m1_sel_out_gpot
    m1_sel_spike = m1_sel_in_spike+m1_sel_out_spike
    m1_sel = m1_sel_in_gpot+m1_sel_in_spike+m1_sel_out_gpot+m1_sel_out_spike
    m1_data_gpot = np.zeros(len(m1_sel_gpot), np.double)
    m1_data_spike = np.zeros(len(m1_sel_spike), np.int32)

    # Instantiate manager and broker:
    man = Manager(get_random_port(), get_random_port(), get_random_port())
    man.add_brok()

    # Add modules:
    m0 = TestModule0(m0_sel, m0_sel_in_gpot, m0_sel_in_spike,
                     m0_sel_out_gpot, m0_sel_out_spike, 
                     m0_data_gpot, m0_data_spike,
                     man.port_data, man.port_ctrl, man.port_time,
                     id='m0')
    man.add_mod(m0)
    m1 = TestModule1(m1_sel, m1_sel_in_gpot, m1_sel_in_spike,
                     m1_sel_out_gpot, m1_sel_out_spike,
                     m1_data_gpot, m1_data_spike,
                     man.port_data, man.port_ctrl, man.port_time,
                     id='m1')
    man.add_mod(m1)

    # Connect the modules:
    pat = Pattern(m0_sel, m1_sel)
    pat.interface[m0_sel_in_gpot] = [0, 'in', 'gpot']
    pat.interface[m0_sel_out_gpot] = [0, 'out', 'gpot']
    pat.interface[m0_sel_in_spike] = [0, 'in', 'spike']
    pat.interface[m0_sel_out_spike] = [0, 'out', 'spike']

    pat.interface[m1_sel_in_gpot] = [1, 'in', 'gpot']
    pat.interface[m1_sel_out_gpot] = [1, 'out', 'gpot']
    pat.interface[m1_sel_in_spike] = [1, 'in', 'spike']
    pat.interface[m1_sel_out_spike] = [1, 'out', 'spike']
    for sel_from, sel_to in zip(m0_sel_out_gpot,
                                m1_sel_in_gpot):
        if not (sel_from == ((),) or sel_to == ((),)):
            pat[sel_from, sel_to] = 1
    for sel_from, sel_to in zip(m0_sel_out_spike,
                                m1_sel_in_spike):
        if not (sel_from == ((),) or sel_to == ((),)):
            pat[sel_from, sel_to] = 1

    man.connect(m0, m1, pat, 0, 1)

    # Execute exactly two steps; m0 transmits data during the first step, which
    # should be received by m1 during the second step:
    man.start(steps=2)
    man.stop()

    # Forcibly terminate all processes that are still alive:
    if m0.is_alive():
        m0.terminate()
    if m1.is_alive():
        m1.terminate()
    for b in man.brokers.values():
        if b.is_alive():
            b.terminate()

    # Check that data was propagated correctly:
    m0_data_gpot_after, m0_data_spike_after = m0.q.get()
    m1_data_gpot_after, m1_data_spike_after = m1.q.get()
#.........这里部分代码省略.........
开发者ID:CEPBEP,项目名称:neurokernel,代码行数:103,代码来源:test_core.py


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