示例#1
0
    def test_without_proxy_coupling(self):
        connectivity, coupling, integrator, monitors, sim, result, result_all = self._reference_simulation(
        )
        # The modify model without proxy
        np.random.seed(42)
        init = np.concatenate((np.random.random_sample(
            (385, 1, 76, 1)), np.random.random_sample((385, 1, 76, 1))),
                              axis=1)
        model = ReducedWongWangProxy(tau_s=np.random.rand(76))
        synchronization_time = 1.0
        # Initialise a Simulator -- Model, Connectivity, Integrator, and Monitors.
        sim_6 = CoSimulator(
            voi=np.array([0]),
            synchronization_time=synchronization_time,
            cosim_monitors=(CosimCoupling(coupling=coupling), ),
            proxy_inds=np.asarray([0], dtype=np.int),
            model=model,
            connectivity=connectivity,
            coupling=coupling,
            integrator=integrator,
            monitors=(monitors, ),
            initial_conditions=init,
        )
        sim_6.configure()
        result_2_all = sim_6.run(
        )[0][1][:, 0, 0,
                0]  # run the first steps because the history is delayed

        sim_to_sync_time = int(SIMULATION_LENGTH / synchronization_time)
        sync_steps = int(synchronization_time / integrator.dt)

        with pytest.raises(ValueError):
            coupling_future = sim_6.loop_cosim_monitor_output(sync_steps, 1)

        coupling_future = sim_6.loop_cosim_monitor_output()

        for i in range(sim_to_sync_time):
            result_2 = sim_6.run()[0][1][:, 0, 0, 0]
            np.testing.assert_array_equal(
                result[i * sync_steps:(i + 1) * sync_steps] * np.NAN, result_2)
            assert np.sum(np.isnan(
                sim_6.loop_cosim_monitor_output()[0][1])) == 0
示例#2
0
    def test_monitor(self):
        connectivity, coupling, integrator, monitors, sim, result, result_all = self._reference_simulation(
            self._simulation_length)
        # New simulator with proxy
        np.random.seed(42)
        init = np.concatenate((np.random.random_sample(
            (385, 1, 76, 1)), np.random.random_sample((385, 1, 76, 1))),
                              axis=1)
        np.random.seed(42)
        model_1 = ReducedWongWangProxy(tau_s=np.random.rand(76))
        # Initialise a Simulator -- Model, Connectivity, Integrator, and Monitors.
        synchronization_time = 1.0
        sim_1 = CoSimulator(
            voi=np.array([0]),
            synchronization_time=synchronization_time,
            cosim_monitors=(RawCosim(),
                            RawVoiCosim(variables_of_interest=np.array([0])),
                            RawDelayed(),
                            RawVoiDelayed(variables_of_interest=np.array([0])),
                            CosimCoupling(coupling=coupling),
                            CosimCoupling(coupling=coupling,
                                          variables_of_interest=np.array([0
                                                                          ]))),
            proxy_inds=np.asarray([0], dtype=np.int),
            model=model_1,
            connectivity=connectivity,
            coupling=coupling,
            integrator=integrator,
            monitors=(monitors, ),
            initial_conditions=init,
        )
        sim_1.configure()

        sim_to_sync_time = int(self._simulation_length / synchronization_time)
        sync_steps = int(synchronization_time / integrator.dt)

        result_1_all = [np.empty((0, )), np.empty((sync_steps, 2, 76, 1))]
        result_cosim_monitors = []
        sim_1.run()  # run the first steps because the history is delayed

        for j in range(0, sim_to_sync_time):
            # This should fail for CosimCoupling that can only return FUTURE coupling values!!!
            result_cosim_monitors.append(
                sim_1.loop_cosim_monitor_output(sync_steps, 0))
            result_1_all_step = sim_1.run(cosim_updates=[
                np.array([
                    result_all[0][0][(sync_steps * j) + i]
                    for i in range(sync_steps)
                ]),
                np.array([
                    result_all[0][1][(sync_steps * j) + i][0][0]
                    for i in range(sync_steps)
                ]).reshape((sync_steps, 1, 1, 1))
            ])
            result_1_all[0] = np.concatenate(
                (result_1_all[0], result_1_all_step[0][0]))
            result_1_all[1] = np.concatenate(
                (result_1_all[1], result_1_all_step[0][1]))

        for i in range(int(self._simulation_length / integrator.dt)):
            np.testing.assert_array_equal(
                result_all[0][1][i][0][1:], result_1_all[1][i + sync_steps, 0,
                                                            1:])
            np.testing.assert_array_equal(
                result_all[0][1][i][0][:1], result_1_all[1][i + sync_steps,
                                                            0, :1])

        for i in range(sim_to_sync_time):
            result_step = result_cosim_monitors[i]
            # check the dimension of the monitors
            np.testing.assert_array_equal(result_step[0][1].shape,
                                          (sync_steps, 2, 76, 1))
            np.testing.assert_array_equal(result_step[1][1].shape,
                                          (sync_steps, 1, 76, 1))
            np.testing.assert_array_equal(result_step[3][1].shape,
                                          (sync_steps, 1, 76, 1))
            np.testing.assert_array_equal(result_step[4][1].shape,
                                          (sync_steps, 1, 76, 1))
            np.testing.assert_array_equal(result_step[5][1].shape,
                                          (sync_steps, 1, 76, 1))
            # compare the monitors between them
            np.testing.assert_array_equal(result_step[2][1], result_step[3][1])
            np.testing.assert_array_equal(result_step[4][1], result_step[5][1])
            np.testing.assert_array_equal(result_step[0][1][:, 0, :, :],
                                          result_step[1][1][:, 0, :, :])