def main():
    # Let's be very verbose!
    logging.basicConfig(level=logging.INFO)

    # Let's do multiprocessing this time with a lock (which is default)
    filename = os.path.join('hdf5', 'example_23.hdf5')
    env = Environment(
        trajectory='Example_23_BRIAN2',
        filename=filename,
        file_title='Example_23_Brian2',
        comment='Go Brian2!',
        dynamically_imported_classes=[Brian2MonitorResult, Brian2Parameter])

    traj = env.trajectory

    # 1st a) add the parameters
    add_params(traj)

    # 1st b) prepare, we want to explore the different network sizes and different tauw time scales
    traj.f_explore(
        cartesian_product({
            traj.f_get('N').v_full_name: [50, 60],
            traj.f_get('tauw').v_full_name: [30 * ms, 40 * ms]
        }))

    # 2nd let's run our experiment
    env.run(run_net)

    # You can take a look at the results in the hdf5 file if you want!

    # Finally disable logging and close all log-files
    env.disable_logging()
def main():
    # Let's be very verbose!
    logging.basicConfig(level = logging.INFO)


    # Let's do multiprocessing this time with a lock (which is default)
    filename = os.path.join('hdf5', 'example_07.hdf5')
    env = Environment(trajectory='Example_07_BRIAN',
                      filename=filename,
                      file_title='Example_07_Brian',
                      comment = 'Go Brian!',
                      dynamically_imported_classes=[BrianMonitorResult, BrianParameter],
                      multiproc=True,
                      wrap_mode='QUEUE',
                      ncores=2)

    traj = env.trajectory

    # 1st a) add the parameters
    add_params(traj)

    # 1st b) prepare, we want to explore the different network sizes and different tauw time scales
    traj.f_explore(cartesian_product({traj.f_get('N').v_full_name:[50,60],
                           traj.f_get('tauw').v_full_name:[30*ms,40*ms]}))

    # 2nd let's run our experiment
    env.run(run_net)

    # You can take a look at the results in the hdf5 file if you want!

    # Finally disable logging and close all log-files
    env.disable_logging()
def main():
    # Let's be very verbose!
    logging.basicConfig(level = logging.INFO)


    # Let's do multiprocessing this time with a lock (which is default)
    env = Environment(trajectory='Example_07_BRIAN',
                      filename='experiments/example_07/HDF5/example_07.hdf5',
                      file_title='Example_07_Euler_Integration',
                      log_folder='experiments/example_07/LOGS/',
                      comment = 'Go Brian!',
                      dynamically_imported_classes=[BrianMonitorResult, BrianParameter],
                      multiproc=True,
                      wrap_mode='QUEUE',
                      ncores=2)

    traj = env.v_trajectory

    # 1st a) add the parameters
    add_params(traj)

    # 1st b) prepare, we want to explore the different network sizes and different tauw time scales
    traj.f_explore(cartesian_product({traj.f_get('N').v_full_name:[50,60],
                           traj.f_get('tauw').v_full_name:[30*ms,40*ms]}))

    # 2nd let's run our experiment
    env.f_run(run_net)
Beispiel #4
0
    def explore_mp(self, traj):
        self.explored = {
            'x': [0.0, 1.0, 2.0, 3.0, 4.0],
            'y': [0.1, 2.2, 3.3, 4.4, 5.5]
        }

        traj.f_explore(cartesian_product(self.explored))
Beispiel #5
0
def main():
    try:
        # Create an environment that handles running
        env = Environment(trajectory='Example1_Quick_And_Not_So_Dirty',filename='experiments/example_01/HDF5/',
                          file_title='Example1_Quick_And_Not_So_Dirty', log_folder='experiments/example_01/LOGS/',
                          comment='The first example!',
                          complib='blosc',
                          small_overview_tables=False,
                          git_repository='./', git_message='Im a message!',
                          sumatra_project='./', sumatra_reason='Testing!')

        # Get the trajectory from the environment
        traj = env.v_trajectory

        # Add both parameters
        traj.f_add_parameter('x', 1, comment='Im the first dimension!')
        traj.f_add_parameter('y', 1, comment='Im the second dimension!')

        # Explore the parameters with a cartesian product:
        traj.f_explore(cartesian_product({'x':[1,2,3], 'y':[6,7,8]}))

        # Run the simulation
        env.f_run(multiply)

        print("Python git test successful")

        # traj.f_expand({'x':[3,3],'y':[42,43]})
        #
        # env.f_run(multiply)
    except Exception as e:
        print(repr(e))
        sys.exit(1)
Beispiel #6
0
    def explore(self):

        matrices = []

        for irun in range(3):

            spsparse_lil = spsp.lil_matrix((111, 111))
            spsparse_lil[3, 2] = 44.5 * irun

            matrices.append(spsparse_lil)

        self.explore_dict = cartesian_product(
            {
                'npstr': [
                    np.array(['Uno', 'Dos', 'Tres']),
                    np.array(['Cinco', 'Seis', 'Siette']),
                    np.array(['Ocho', 'Nueve', 'Diez'])
                ],
                'val0': [1, 2, 3],
                'spsparse_lil':
                matrices
            }, (('npstr', 'val0'), 'spsparse_lil'))

        ## Explore the parameter:
        for key, vallist in self.explore_dict.items():
            self.param[key]._explore(vallist)
    def explore(self):

        matrices = []


        for irun in range(3):

            spsparse_lil = spsp.lil_matrix((111,111))
            spsparse_lil[3,2] = 44.5*irun

            matrices.append(spsparse_lil)


        self.explore_dict=cartesian_product({'npstr':[np.array(['Uno', 'Dos', 'Tres']),
                               np.array(['Cinco', 'Seis', 'Siette']),
                            np.array(['Ocho', 'Nueve', 'Diez'])],
                           'val0':[1,2,3],
                           'spsparse_lil' : matrices}, (('npstr','val0'),'spsparse_lil'))




        ## Explore the parameter:
        for key, vallist in self.explore_dict.items():
            self.param[key]._explore(vallist)
Beispiel #8
0
def main():
    # pypet environment
    env = Environment(trajectory=SIM_NAME,
                      comment="Experiment on density with binary covariates",
                      log_config=None,
                      multiproc=False,
                      ncores=1,
                      filename=SIM_PATH + "/results/",
                      overwrite_file=True)
    traj = env.trajectory

    # parameters (data generation)

    traj.f_add_parameter("data.N", np.int64(500), "Number of nodes")
    traj.f_add_parameter("data.K", np.int64(5),
                         "True number of latent components")
    traj.f_add_parameter("data.p_cts", np.int64(0),
                         "Number of continuous covariates")
    traj.f_add_parameter("data.p_bin", np.int64(0),
                         "Number of binary covariates")
    traj.f_add_parameter("data.var_adj", np.float64(1.),
                         "True variance in the link Probit model")
    traj.f_add_parameter("data.var_cov", np.float64(1.),
                         "True variance in the covariate model (cts and bin)")
    traj.f_add_parameter("data.missing_rate", np.float64(0.1), "Missing rate")
    traj.f_add_parameter("data.seed", np.int64(1), "Random seed")
    traj.f_add_parameter("data.alpha_mean", np.float64(-1.85),
                         "Mean of the heterogeneity parameter")

    # parameters (model)
    traj.f_add_parameter("model.K", np.int64(5),
                         "Number of latent components in the model")
    traj.f_add_parameter("model.adj_model", "Logistic", "Adjacency model")
    traj.f_add_parameter("model.bin_model", "Logistic",
                         "Binary covariate model")

    # parameters (fit)
    traj.f_add_parameter("fit.n_iter", np.int64(20),
                         "Number of VEM iterations")
    traj.f_add_parameter("fit.n_vmp", np.int64(5),
                         "Number of VMP iterations per E-step")
    traj.f_add_parameter("fit.n_gd", np.int64(5),
                         "Number of GD iterations per M-step")
    traj.f_add_parameter("fit.step_size", np.float64(0.01), "GD Step size")

    # experiment
    explore_dict = {
        "data.alpha_mean":
        np.array([-3.2, -2.8, -2.4, -2., -1.6, -1.2, -0.8, -0.4, 0.0, 0.4]),
        "data.p_bin":
        np.array([10, 100, 500]),
        "data.seed":
        np.arange(0, 100, 1)
    }
    experiment = cartesian_product(explore_dict, tuple(explore_dict.keys()))
    traj.f_explore(experiment)

    env.add_postprocessing(post_processing)
    env.run(run)
    env.disable_logging()
    def setUp(self):
        env = Environment(trajectory='Test_'+repr(time.time()).replace('.','_'),
                          filename=make_temp_dir(os.path.join(
                              'experiments',
                              'tests',
                              'briantests',
                              'HDF5',
                               'briantest.hdf5')),
                          file_title='test',
                          log_config=get_log_config(),
                          dynamic_imports=['pypet.brian.parameter.BrianParameter',
                                                        BrianMonitorResult],
                          multiproc=False)

        traj = env.v_trajectory

        #env._set_standard_storage()
        #env._hdf5_queue_writer._hdf5storageservice = LazyStorageService()
        traj = env.v_trajectory
        #traj.set_storage_service(LazyStorageService())

        add_params(traj)
        #traj.mode='Parallel'


        traj.f_explore(cartesian_product({traj.f_get('N').v_full_name:[50,60],
                               traj.f_get('tauw').v_full_name:[30*ms,40*ms]}))

        self.traj = traj

        self.env = env
        self.traj = traj
    def setUp(self):
        logging.basicConfig(level = logging.DEBUG)


        env = Environment(trajectory='Test_'+repr(time.time()).replace('.','_'),
                          filename=make_temp_file('experiments/tests/briantests/HDF5/briantest.hdf5'),
                          file_title='test',
                          log_folder=make_temp_file('experiments/tests/briantests/log'),
                          dynamically_imported_classes=['pypet.brian.parameter.BrianParameter',
                                                        BrianMonitorResult],
                          multiproc=True,
                          use_pool=True,
                          complib='blosc',
                          wrap_mode='QUEUE',
                          ncores=2)

        traj = env.v_trajectory

        #env._set_standard_storage()
        #env._hdf5_queue_writer._hdf5storageservice = LazyStorageService()
        traj = env.v_trajectory
        #traj.set_storage_service(LazyStorageService())

        add_params(traj)
        #traj.mode='Parallel'


        traj.f_explore(cartesian_product({traj.f_get('N').v_full_name:[50,60],
                               traj.f_get('tauw').v_full_name:[30*ms,40*ms]}))

        self.traj = traj

        self.env = env
        self.traj = traj
Beispiel #11
0
    def setUp(self):
        env = Environment(
            trajectory='Test_' + repr(time.time()).replace('.', '_'),
            filename=make_temp_dir(
                os.path.join('experiments', 'tests', 'briantests', 'HDF5',
                             'briantest.hdf5')),
            file_title='test',
            log_config=get_log_config(),
            dynamic_imports=[
                'pypet.brian.parameter.BrianParameter', BrianMonitorResult
            ],
            multiproc=False)

        traj = env.v_trajectory

        #env._set_standard_storage()
        #env._hdf5_queue_writer._hdf5storageservice = LazyStorageService()
        traj = env.v_trajectory
        #traj.set_storage_service(LazyStorageService())

        add_params(traj)
        #traj.mode='Parallel'

        traj.f_explore(
            cartesian_product({
                traj.f_get('N').v_full_name: [50, 60],
                traj.f_get('tauw').v_full_name: [30 * ms, 40 * ms]
            }))

        self.traj = traj

        self.env = env
        self.traj = traj
Beispiel #12
0
    def test_cartesian_product(self):

        cartesian_dict=cartesian_product({'param1':[1,2,3], 'param2':[42.0, 52.5]},
                                          ('param1','param2'))
        result_dict = {'param1':[1,1,2,2,3,3],'param2': [42.0,52.5,42.0,52.5,42.0,52.5]}

        self.assertTrue(nested_equal(cartesian_dict,result_dict), '%s != %s' %
                                                        (str(cartesian_dict),str(result_dict)))
Beispiel #13
0
    def explore(self):
        self.explore_dict=cartesian_product({'npstr':[np.array(['Uno', 'Dos', 'Tres']),
                               np.array(['Cinco', 'Seis', 'Siette']),
                            np.array(['Ocho', 'Nueve', 'Diez'])],
                           'val0':[1,2,3]})

        ## Explore the parameter:
        for key, vallist in self.explore_dict.items():
            self.param[key]._explore(vallist)
Beispiel #14
0
    def test_cartesian_product_combined_params(self):
        cartesian_dict=cartesian_product( {'param1': [42.0, 52.5], 'param2':['a', 'b'],\
            'param3' : [1,2,3]}, (('param3',),('param1', 'param2')))

        result_dict={'param3':[1,1,2,2,3,3],'param1' : [42.0,52.5,42.0,52.5,42.0,52.5],
                      'param2':['a','b','a','b','a','b']}

        self.assertTrue(nested_equal(cartesian_dict,result_dict), '%s != %s' %
                                                    (str(cartesian_dict),str(result_dict)))
Beispiel #15
0
    def expand(self):
        self.expanded ={'Normal.trial': [1],
            'Numpy.double': [np.array([1.0,2.0,3.0,4.0]), np.array([-1.0,3.0,5.0,7.0])],
            'csr_mat' :[spsp.csr_matrix((2222,22)), spsp.csr_matrix((2222,22))]}

        self.expanded['csr_mat'][0][1,2]=44.0
        self.expanded['csr_mat'][1][2,2]=33

        self.traj.f_expand(cartesian_product(self.expanded))
Beispiel #16
0
    def explore(self):

        matrices_csr = []
        for irun in range(3):

            spsparse_csr = spsp.csr_matrix((111, 111))
            spsparse_csr[3, 2 + irun] = 44.5 * irun

            matrices_csr.append(spsparse_csr)

        matrices_csc = []
        for irun in range(3):

            spsparse_csc = spsp.csc_matrix((111, 111))
            spsparse_csc[3, 2 + irun] = 44.5 * irun

            matrices_csc.append(spsparse_csc)

        matrices_bsr = []
        for irun in range(3):

            spsparse_bsr = spsp.csr_matrix((111, 111))
            spsparse_bsr[3, 2 + irun] = 44.5 * irun

            matrices_bsr.append(spsparse_bsr.tobsr())

        matrices_dia = []
        for irun in range(3):

            spsparse_dia = spsp.csr_matrix((111, 111))
            spsparse_dia[3, 2 + irun] = 44.5 * irun

            matrices_dia.append(spsparse_dia.todia())

        self.explore_dict = cartesian_product(
            {
                'npstr': [
                    np.array(['Uno', 'Dos', 'Tres']),
                    np.array(['Cinco', 'Seis', 'Siette']),
                    np.array(['Ocho', 'Nueve', 'Diez'])
                ],
                'val0': [1, 2, 3],
                'spsparse_csr':
                matrices_csr,
                'spsparse_csc':
                matrices_csc,
                'spsparse_bsr':
                matrices_bsr,
                'spsparse_dia':
                matrices_dia
            },
            (('npstr', 'val0'),
             ('spsparse_csr', 'spsparse_csc', 'spsparse_bsr', 'spsparse_dia')))

        ## Explore the parameter:
        for key, vallist in self.explore_dict.items():
            self.param[key]._explore(vallist)
Beispiel #17
0
    def explore(self, traj):
        self.explored = cartesian_product({
            'Normal.trial': [0, 1],
            'Numpy.double':
            [np.array([1.0, 2.0, 3.0, 4.0]),
             np.array([-1.0, 3.0, 5.0, 7.0])]
        })

        traj.f_explore(self.explored)
Beispiel #18
0
    def test_cartesian_product_combined_params(self):
        cartesian_dict=cartesian_product( {'param1': [42.0, 52.5], 'param2':['a', 'b'],\
            'param3' : [1,2,3]}, (('param3',),('param1', 'param2')))

        result_dict = {
            'param3': [1, 1, 2, 2, 3, 3],
            'param1': [42.0, 52.5, 42.0, 52.5, 42.0, 52.5],
            'param2': ['a', 'b', 'a', 'b', 'a', 'b']
        }

        self.assertTrue(nested_equal(cartesian_dict, result_dict),
                        '%s != %s' % (str(cartesian_dict), str(result_dict)))
Beispiel #19
0
    def explore(self):
        self.explore_dict = cartesian_product({#'brian2_array_a': [np.array([1., 2.]) * mV],
                                               # 'brian2_array_b': [2 * mV],
                                               # Arrays need to be of the same size!
                                               'brian2_array_c': [np.array([5., 8.]) * mV, np.array([7., 8.]) * mV],
                                               })


        ## Explore the parameter:
        for key, vallist in self.explore_dict.items():
            self.param[key]._explore(vallist)
            self.assertTrue(self.param[key].v_explored and self.param[key].f_has_range())
Beispiel #20
0
    def expand(self):
        self.expanded ={'Normal.trial': [1],
            'Numpy.double': [np.array([1.0,2.0,3.0,4.0]), np.array([-1.0,3.0,5.0,7.0])],
            'csr_mat' :[spsp.lil_matrix((2222,22)), spsp.lil_matrix((2222,22))]}

        self.expanded['csr_mat'][0][1,2]=44.0
        self.expanded['csr_mat'][1][2,2]=33
        self.expanded['csr_mat'][0]=self.expanded['csr_mat'][0].tocsr()
        self.expanded['csr_mat'][1]=self.expanded['csr_mat'][1].tocsr()

        self.traj.f_expand(cartesian_product(self.expanded))
        self.traj.f_store()
    def explore(self):
        self.explore_dict = cartesian_product({#'brian2_array_a': [np.array([1., 2.]) * mV],
                                               # 'brian2_array_b': [2 * mV],
                                               # Arrays need to be of the same size!
                                               'brian2_array_c': [np.array([5., 8.]) * mV, np.array([7., 8.]) * mV],
                                               })


        ## Explore the parameter:
        for key, vallist in self.explore_dict.items():
            self.param[key]._explore(vallist)
            self.assertTrue(self.param[key].v_explored and self.param[key].f_has_range())
Beispiel #22
0
    def explore(self, traj):
        self.explored ={'Normal.trial': [0],
            'Numpy.double': [np.array([1.0,2.0,3.0,4.0]), np.array([-1.0,3.0,5.0,7.0])],
            'csr_mat' :[spsp.lil_matrix((2222,22)), spsp.lil_matrix((2222,22))]}

        self.explored['csr_mat'][0][1,2]=44.0
        self.explored['csr_mat'][1][2,2]=33

        self.explored['csr_mat'][0] = self.explored['csr_mat'][0].tocsr()
        self.explored['csr_mat'][1] = self.explored['csr_mat'][0].tocsr()

        traj.f_explore(cartesian_product(self.explored))
    def explore(self):

        matrices_csr = []
        for irun in range(3):

            spsparse_csr = spsp.csr_matrix((111,111))
            spsparse_csr[3,2+irun] = 44.5*irun

            matrices_csr.append(spsparse_csr)

        matrices_csc = []
        for irun in range(3):

            spsparse_csc = spsp.csc_matrix((111,111))
            spsparse_csc[3,2+irun] = 44.5*irun

            matrices_csc.append(spsparse_csc)

        matrices_bsr = []
        for irun in range(3):

            spsparse_bsr = spsp.csr_matrix((111,111))
            spsparse_bsr[3,2+irun] = 44.5*irun

            matrices_bsr.append(spsparse_bsr.tobsr())

        matrices_dia = []
        for irun in range(3):

            spsparse_dia = spsp.csr_matrix((111,111))
            spsparse_dia[3,2+irun] = 44.5*irun

            matrices_dia.append(spsparse_dia.todia())


        self.explore_dict=cartesian_product({'npstr':[np.array(['Uno', 'Dos', 'Tres']),
                               np.array(['Cinco', 'Seis', 'Siette']),
                            np.array(['Ocho', 'Nueve', 'Diez'])],
                           'val0':[1,2,3],
                           'spsparse_csr' : matrices_csr,
                           'spsparse_csc' : matrices_csc,
                           'spsparse_bsr' : matrices_bsr,
                           'spsparse_dia' : matrices_dia},
                            (('npstr','val0'),('spsparse_csr',
                            'spsparse_csc', 'spsparse_bsr','spsparse_dia')) )




        ## Explore the parameter:
        for key, vallist in self.explore_dict.items():
            self.param[key]._explore(vallist)
Beispiel #24
0
    def explore(self):
        self.explore_dict=cartesian_product({'npstr':[np.array(['Uno', 'Dos', 'Tres']),
                               np.array(['Cinco', 'Seis', 'Siette']),
                            np.array(['Ocho', 'Nueve', 'Diez'])],
                           'val0':[1,2,3], 'alist':[[1,2,3,4],[3,4,5,6]]})

        ## Explore the parameter:
        for key, vallist in self.explore_dict.items():
            old_data = self.param[key]._data
            self.param[key]._data = None
            with self.assertRaises(TypeError):
                self.param[key]._explore(vallist)
            self.param[key]._data = old_data
            self.param[key]._explore(vallist)
    def explore(self):
        self.explore_dict = cartesian_product({
                                            #'npstr': [np.array(['Uno', 'Dos', 'Tres']),
                                            #           np.array(['Cinco', 'Seis', 'Siette']),
                                            #           np.array(['Ocho', 'Nueve', 'Diez'])],
                                            'ampere1': [1*mA],
                                             #'val0': [1, 2, 3],
                                             'mV1': [42.0*mV, 3*mV, 4*mV],
                                             'b2a': [np.array([1., 2.]) * mV]})

        ## Explore the parameter:
        for key, vallist in self.explore_dict.items():
            self.param[key]._explore(vallist)
            self.assertTrue(self.param[key].v_explored and self.param[key].f_has_range())
    def explore(self):
        self.explore_dict=cartesian_product({'npstr':[np.array(['Uno', 'Dos', 'Tres']),
                               np.array(['Cinco', 'Seis', 'Siette']),
                            np.array(['Ocho', 'Nueve', 'Diez'])],
                           'val0':[1,2,3], 'alist':[[1,2,3,4],[3,4,5,6]]})

        ## Explore the parameter:
        for key, vallist in self.explore_dict.items():
            old_data = self.param[key]._data
            self.param[key]._data = None
            with self.assertRaises(TypeError):
                self.param[key]._explore(vallist)
            self.param[key]._data = old_data
            self.param[key]._explore(vallist)
Beispiel #27
0
def main(path, name, explore_dict):
    comment = "\n".join(
        ["{}: {}".format(k, v) for k, v in explore_dict.items()])
    # pypet environment
    env = Environment(trajectory=name,
                      comment=comment,
                      log_config=None,
                      multiproc=False,
                      ncores=1,
                      filename=path + name + "/results/",
                      overwrite_file=True)
    traj = env.trajectory
    traj.f_add_parameter("path", path + name, "Path")

    # parameters (data generation)
    traj.f_add_parameter("data.N", np.int64(500), "Number of nodes")
    traj.f_add_parameter("data.K", np.int64(5),
                         "True number of latent components")
    traj.f_add_parameter("data.p_cts", np.int64(0),
                         "Number of continuous covariates")
    traj.f_add_parameter("data.p_bin", np.int64(0),
                         "Number of binary covariates")
    traj.f_add_parameter("data.var_cov", np.float64(1.),
                         "True variance in the covariate model (cts and bin)")
    traj.f_add_parameter("data.missing_rate", np.float64(0.1), "Missing rate")
    traj.f_add_parameter("data.seed", np.int64(1), "Random seed")
    traj.f_add_parameter("data.center", np.int64(1), "Ego-network center")
    traj.f_add_parameter("data.alpha_mean", np.float64(-1.85),
                         "Mean of the heterogeneity parameter")

    # parameters (model)
    traj.f_add_parameter("model.K", np.int64(5),
                         "Number of latent components in the model")

    # parameters (fit)
    traj.f_add_parameter("fit.algo", "MLE", "Inference algorithm")
    traj.f_add_parameter("fit.max_iter", np.int64(500),
                         "Number of VEM iterations")
    traj.f_add_parameter("fit.n_sample", np.int64(1),
                         "Number of samples for VIMC")
    traj.f_add_parameter("fit.eps", np.float64(1.0e-6),
                         "convergence threshold")
    traj.f_add_parameter("fit.lr", np.float64(0.01), "GD Step size")

    # experiment
    experiment = cartesian_product(explore_dict, tuple(explore_dict.keys()))
    traj.f_explore(experiment)
    env.add_postprocessing(post_processing)
    env.run(run)
    env.disable_logging()
Beispiel #28
0
    def explore(self):
        self.explore_dict = cartesian_product({
                                            #'npstr': [np.array(['Uno', 'Dos', 'Tres']),
                                            #           np.array(['Cinco', 'Seis', 'Siette']),
                                            #           np.array(['Ocho', 'Nueve', 'Diez'])],
                                            'ampere1': [1*mA],
                                             #'val0': [1, 2, 3],
                                             'mV1': [42.0*mV, 3*mV, 4*mV],
                                             'b2a': [np.array([1., 2.]) * mV]})

        ## Explore the parameter:
        for key, vallist in self.explore_dict.items():
            self.param[key]._explore(vallist)
            self.assertTrue(self.param[key].v_explored and self.param[key].f_has_range())
Beispiel #29
0
    def test_cartesian_product(self):

        cartesian_dict = cartesian_product(
            {
                'param1': [1, 2, 3],
                'param2': [42.0, 52.5]
            }, ('param1', 'param2'))
        result_dict = {
            'param1': [1, 1, 2, 2, 3, 3],
            'param2': [42.0, 52.5, 42.0, 52.5, 42.0, 52.5]
        }

        self.assertTrue(nested_equal(cartesian_dict, result_dict),
                        '%s != %s' % (str(cartesian_dict), str(result_dict)))
Beispiel #30
0
    def explore(self):

        matrices = []


        self.explore_dict=cartesian_product({'npstr':[np.array(['Uno', 'Dos', 'Tres']),
                               np.array(['Cinco', 'Seis', 'Siette']),
                            np.array(['Ocho', 'Nueve', 'Diez'])],
                           'val0':[1,2,3],
                           'myinttuple':[(1,2,1),(4,5,6),(5,6,7)]} ,(('npstr','val0'),'myinttuple'))

        ### Convert the explored stuff into numpy arrays
        #for idx, val in enumerate(self.explore_dict['myinttuple']):
         #   self.explore_dict['myinttuple'][idx] = np.array(val)


        ## Explore the parameter:
        for key, vallist in self.explore_dict.items():
            self.param[key]._explore(vallist)
Beispiel #31
0
def main(inputargs=None):
    if inputargs is None:
        inputargs = sys.argv[1:] if len(sys.argv) > 1 else ""
    args = docopt(__doc__, argv=inputargs)
    wavpath = path.join(modulePath, "resources", "tone_in_noise")
    stimuli = [path.join(wavpath, i) for i in glob.glob(path.join(wavpath, "*.wav"))]
    outfile = path.realpath(path.expanduser(args["--out"]))
    env = Environment(trajectory='tone-in-noise',
                      filename=outfile,
                      overwrite_file=True,
                      file_title="Tone in noise at different SNR",
                      comment="some comment",
                      large_overview_tables="False",
                      # freeze_input=True,
                      # use_pool=True,
                      multiproc=True,
                      ncores=3,
                      graceful_exit=True,
                      #wrap_mode=pypetconstants.WRAP_MODE_QUEUE,
                      )

    traj = env.trajectory
    traj.f_add_parameter('periphery', 'verhulst', comment="which periphery was used")
    traj.f_add_parameter('brainstem', 'nelsoncarney04', comment="which brainstem model was used")
    traj.f_add_parameter('weighting', "--no-cf-weighting ", comment="weighted CFs")
    traj.f_add_parameter('wavfile', '', comment="Which wav file to run")
    traj.f_add_parameter('level', 80, comment="stimulus level, spl")
    traj.f_add_parameter('neuropathy', "none", comment="")

    parameter_dict = {
        "periphery" : ['verhulst', 'zilany'],
        "brainstem" : ['nelsoncarney04', 'carney2015'],
        "weighting" : [cf_weighting, ""],
        "wavfile"   : stimuli,
        "level"     : [80],
        "neuropathy": ["none", "moderate", "severe", "ls-moderate", "ls-severe"]
    }

    traj.f_explore(cartesian_product(parameter_dict))
    env.run(tone_in_noise)
    return 0
def main():
    # Create an environment that handles running
    filename = os.path.join('hdf5','example_18.hdf5')
    env = Environment(trajectory='Multiplication',
                      filename=filename,
                      file_title='Example_18_Many_Runs',
                      overwrite_file=True,
                      comment='Contains many runs',
                      multiproc=True,
                      use_pool=True,
                      freeze_input=True,
                      ncores=2,
                      wrap_mode='QUEUE')

    # The environment has created a trajectory container for us
    traj = env.trajectory

    # Add both parameters
    traj.f_add_parameter('x', 1, comment='I am the first dimension!')
    traj.f_add_parameter('y', 1, comment='I am the second dimension!')

    # Explore the parameters with a cartesian product, yielding 2500 runs
    traj.f_explore(cartesian_product({'x': range(50), 'y': range(50)}))

    # Run the simulation
    env.run(multiply)

    # Disable logging
    env.disable_logging()

    # turn auto loading on, since results have not been loaded, yet
    traj.v_auto_load = True
    # Use the `v_idx` functionality
    traj.v_idx = 2042
    print('The result of run %d is: ' % traj.v_idx)
    # Now we can rely on the wildcards
    print(traj.res.crunset.crun.z)
    traj.v_idx = -1
    # Or we can use the shortcuts `rts_X` (run to set) and `r_X` to get particular results
    print('The result of run %d is: ' % 2044)
    print(traj.res.rts_2044.r_2044.z)
Beispiel #33
0
    def explore(self):

        matrices = []


        self.explore_dict=cartesian_product({'npstr':[np.array(['Uno', 'Dos', 'Tres']),
                               np.array(['Cinco', 'Seis', 'Siette']),
                            np.array(['Ocho', 'Nueve', 'Diez'])],
                           'val0':[1,2,3],
                           'myinttuple':[(1,2,1),(4,5,6),(5,6,7)],
                            'alist':[[1,2,3,4],['wooot']]} ,
                                            (('npstr','val0'),'myinttuple', 'alist'))

        ### Convert the explored stuff into numpy arrays
        #for idx, val in enumerate(self.explore_dict['myinttuple']):
         #   self.explore_dict['myinttuple'][idx] = np.array(val)


        ## Explore the parameter:
        for key, vallist in self.explore_dict.items():
            self.param[key]._explore(vallist)
Beispiel #34
0
def main(inputargs):
    args = docopt(__doc__, argv=inputargs)
    wavpath = path.join(modulePath, "resources", "tone_in_noise")
    stimuli = [path.join(wavpath, i) for i in glob.glob(path.join(wavpath, "*.wav"))]
    outfile = path.realpath(path.expanduser(args["--out"]))
    env = Environment(trajectory='tone-in-noise',
                      filename=outfile,
                      overwrite_file=True,
                      file_title="Tone in noise at different SNR",
                      comment="some comment",
                      large_overview_tables="False",
                      # freeze_input=True,
                      # use_pool=True,
                      multiproc=True,
                      ncores=3,
                      graceful_exit=True,
                      #wrap_mode=pypetconstants.WRAP_MODE_QUEUE,
                      )

    traj = env.trajectory
    traj.f_add_parameter('periphery', 'verhulst', comment="which periphery was used")
    traj.f_add_parameter('brainstem', 'nelsoncarney04', comment="which brainstem model was used")
    traj.f_add_parameter('weighting', "--no-cf-weighting ", comment="weighted CFs")
    traj.f_add_parameter('wavfile', '', comment="Which wav file to run")
    traj.f_add_parameter('level', 80, comment="stimulus level, spl")
    traj.f_add_parameter('neuropathy', "none", comment="")

    parameter_dict = {
        "periphery" : ['verhulst', 'zilany'],
        "brainstem" : ['nelsoncarney04', 'carney2015'],
        "weighting" : [cf_weighting, ""],
        "wavfile"   : stimuli,
        "level"     : [80],
        "neuropathy": ["none", "moderate", "severe", "ls-moderate", "ls-severe"]
    }

    traj.f_explore(cartesian_product(parameter_dict))
    env.run(tone_in_noise)
    return 0
    """Sophisticated simulation of multiplication"""
    z=traj.x*traj.y
    traj.f_add_result('z',z=z, comment='I am the product of two reals!')



# Create an environment that handles running.
# Let's enable multiprocessing with 2 workers.
env = Environment(trajectory='Example_04_MP',
                  filename='experiments/example_04/HDF5/example_04.hdf5',
                  file_title='Example_04_MP',
                  log_folder='experiments/example_04/LOGS/',
                  comment = 'Multiprocessing example!',
                  multiproc=True,
                  ncores=2,
                  use_pool=True,
                  wrap_mode=pypetconstants.WRAP_MODE_LOCK)

# Get the trajectory from the environment
traj = env.v_trajectory

# Add both parameters
traj.f_add_parameter('x', 1.0, comment='I am the first dimension!')
traj.f_add_parameter('y', 1.0, comment='I am the second dimension!')

# Explore the parameters with a cartesian product, but we want to explore a bit more
traj.f_explore(cartesian_product({'x':[float(x) for x in range(15)],
                                  'y':[float(y) for y in range(15)]}))

# Run the simulation
env.f_run(multiply)
Beispiel #36
0
def main():
    """Main function to protect the *entry point* of the program.

    If you want to use multiprocessing with SCOOP you need to wrap your
    main code creating an environment into a function. Otherwise
    the newly started child processes will re-execute the code and throw
    errors (also see http://scoop.readthedocs.org/en/latest/usage.html#pitfalls).

    """

    # Load settings from file
    settings_file = 'pypet_settings.pkl'
    settings = load_obj(settings_file)
    # Print settings dictionary
    print('\nSettings dictionary:')
    for key, value in settings.items():
        print(key, ' : ', value)
    print('\nParameters to explore:')
    for key, value in settings.items():
        if isinstance(value, list):
            print(key, ' : ', value)

    # Create new folder to store results
    traj_dir = os.getcwd()
    # Read output path (if provided)
    if len(sys.argv) > 1:
        # Only use specified folder if it exists
        if os.path.isdir(sys.argv[1]):
            # Get name of directory
            traj_dir = os.path.dirname(sys.argv[1])
            # Convert to full path
            traj_dir = os.path.abspath(traj_dir)
    # Add time stamp (final '' is to make sure there is a trailing slash)
    traj_dir = os.path.join(traj_dir,
                            datetime.now().strftime("%Y_%m_%d_%Hh%Mm%Ss"), '')
    # Create directory with time stamp
    os.makedirs(traj_dir)
    # Change current directory to the one containing the trajectory files
    os.chdir(traj_dir)
    print('Trajectory and results will be stored in: {0}'.format(traj_dir))

    # Create an environment that handles running.
    # Let's enable multiprocessing with scoop:
    env = Environment(
        trajectory='traj',
        comment='',
        add_time=False,
        log_config='DEFAULT',
        log_stdout=
        True,  # log everything that is printed, will make the log file HUGE
        filename=
        traj_dir,  # filename or just folder (name will be automatic in this case)
        multiproc=False,
        #use_pool=True,
        #ncores=10,
        #freeze_input=True,
        use_scoop=False,
        #wrap_mode=pypetconstants.WRAP_MODE_LOCAL,
        memory_cap=1,
        swap_cap=1
        #cpu_cap=30

        #,git_repository='' #path to the root git folder. The commit code will be added in the trajectory
        #,git_fail=True #no automatic commits
        #,sumatra_project='' #path to sumatra root folder,
        #graceful_exit=True
    )

    traj = env.trajectory

    # Add config parameters (those that DO NOT influence the final result of the experiment)
    traj.f_add_config('parallel_target_analysis', True)
    #traj.f_add_config('debug', False)
    #traj.f_add_config('max_mem_frac', 0.7)

    # Set up trajectory parameters
    param_to_explore = {}
    for key, val in settings.items():
        if isinstance(val, list):
            param_to_explore[key] = val
            traj.f_add_parameter(key, val[0])
        else:
            traj.f_add_parameter(key, val)

    # Define parameter combinations to explore (a trajectory in
    # the parameter space). The second argument, the tuple, specifies the order
    #  of the cartesian product.
    # The variable on the right most side changes fastest and defines the
    # 'inner for-loop' of the cartesian product
    explore_dict = cartesian_product(param_to_explore,
                                     tuple(param_to_explore.keys()))
    # explore_dict = cartesian_product(
    #     {
    #         'network_inference.algorithm': ['bMI_greedy', 'bTE_greedy', 'mTE_greedy'],
    #         #'node_coupling.initial.weight_distribution': ['fixed'],
    #         'repetition_i': np.arange(0, 5, 1).tolist(),
    #         'topology.initial.nodes_n': np.arange(50, 50+1, 300).tolist(),
    #         'node_dynamics.samples_n': np.array([1000, 10000]).tolist(),
    #         'network_inference.p_value': np.array([0.001]).tolist(),
    #         #'node_coupling.initial.self_coupling': np.arange(-0.5, 0.5 + 0.001, 0.1).tolist(),
    #         #'node_coupling.initial.total_cross_coupling': np.arange(-1., 1 + 0.001, 0.2).tolist(),
    #         #'topology.initial.WS_p': np.around(np.logspace(-2.2, 0, 10), decimals=4).tolist(),
    #     },
    #     (
    #         'network_inference.algorithm',
    #         #'node_coupling.initial.weight_distribution',
    #         'network_inference.p_value',
    #         'node_dynamics.samples_n',
    #         'topology.initial.nodes_n',
    #         #'topology.initial.WS_p',
    #         #'node_coupling.initial.self_coupling',
    #         #'node_coupling.initial.total_cross_coupling',
    #         'repetition_i',
    #     )
    # )
    traj.f_explore(explore_dict)

    # Store trajectory parameters to disk
    pypet_utils.print_traj_leaves(traj, 'parameters', 'traj_parameters.txt')

    # Run the experiment
    env.run(information_network_inference)
    # env.run(bTE_on_existing_links)

    # Check that all runs are completed
    assert traj.f_is_completed()

    # Finally disable logging and close all log-files
    env.disable_logging()
Beispiel #37
0
    def explore2(self, traj):
        self.explored2 ={'Normal.trial': [0,1],
            'Normal.int': [44, 45]}

        traj.f_explore(cartesian_product(self.explored2,  ('Normal.int','Normal.trial') ))
Beispiel #38
0
 def explore_large(self, traj):
     self.explored ={'Normal.trial': [0,1]}
     traj.f_explore(cartesian_product(self.explored))
                  file_title='Example_01_First_Steps',
                  comment='The first example!',
                  large_overview_tables=True,  # To see a nice overview of all
                  # computed `z` values in the resulting HDF5 file.
                  # Per default disabled for more compact HDF5 files.
                  )

# The environment has created a trajectory container for us
traj = env.trajectory

# Add both parameters
traj.f_add_parameter('x', 1, comment='I am the first dimension!')
traj.f_add_parameter('y', 1, comment='I am the second dimension!')

# Explore the parameters with a cartesian product
traj.f_explore(cartesian_product({'x':[1,2,3,4], 'y':[6,7,8]}))

# Run the simulation
env.run(multiply)



# Now let's see how we can reload the stored data from above.
# We do not need an environment for that, just a trajectory.
from pypet.trajectory import Trajectory

# So, first let's create a new trajectory and pass it the path and name of the HDF5 file.
# Yet, to be very clear let's delete all the old stuff.
del traj
# Before deleting the environment let's disable logging and close all log-files
env.disable_logging()
Beispiel #40
0
 def explore_cartesian(self,traj):
     self.explore_dict=cartesian_product({'x':[-1,1,2,3,4, 5, 6],'y':[1,1,2,2,3,4,4]})
     traj.f_explore(self.explore_dict)
Beispiel #41
0
def main():
    # pypet environment
    env = Environment(
        trajectory="missing_rate",
        comment="Test experiment with varying missing rate",
        log_config=None,
        multiproc=False,
        ncores=1,
        # use_pool=True,
        # freeze_input=True,
        # wrap_mode=pypetconstants.WRAP_MODE_QUEUE,
        # graceful_exit=True,
        filename="./simulations/results/test/",
        overwrite_file=True
    )
    traj = env.trajectory

    # parameters (data generation)

    traj.f_add_parameter(
        "data.N", np.int64(500), "Number of nodes"
    )
    traj.f_add_parameter(
        "data.K", np.int64(5), "True number of latent components"
    )
    traj.f_add_parameter(
        "data.p_cts", np.int64(10), "Number of continuous covariates"
    )
    traj.f_add_parameter(
        "data.p_bin", np.int64(0), "Number of binary covariates"
    )
    traj.f_add_parameter(
        "data.var_adj", np.float64(1.), "True variance in the link Probit model"
    )
    traj.f_add_parameter(
        "data.var_cov", np.float64(1.), "True variance in the covariate model (cts and bin)"
    )
    traj.f_add_parameter(
        "data.missing_rate", np.float64(0.2), "Missing rate"
    )
    traj.f_add_parameter(
        "data.seed", np.int64(1), "Random seed"
    )
    traj.f_add_parameter(
        "data.alpha_mean", np.float64(-1.85), "Mean of the heterogeneity parameter"
    )

    # parameters (model)
    traj.f_add_parameter(
        "model.K", np.int64(3), "Number of latent components in the model"
    )
    traj.f_add_parameter(
        "model.adj_model", "Logistic", "Adjacency model"
    )
    traj.f_add_parameter(
        "model.bin_model", "Logistic", "Binary covariate model"
    )

    # parameters (fit)
    traj.f_add_parameter(
        "fit.n_iter", np.int64(10), "Number of VEM iterations"
    )
    traj.f_add_parameter(
        "fit.n_vmp", np.int64(10), "Number of VMP iterations per E-step"
    )
    traj.f_add_parameter(
        "fit.n_gd", np.int64(10), "Number of GD iterations per M-step"
    )
    traj.f_add_parameter(
        "fit.step_size", np.float64(0.01), "GD Step size"
    )

    # experiment
    explore_dict = {
        "data.missing_rate": np.array([0.05]),
        "data.p_cts": np.array([10]),
        "data.seed": np.array([1])
    }
    experiment = cartesian_product(explore_dict, ('data.missing_rate', "data.p_cts", "data.seed"))
    traj.f_explore(experiment)

    env.add_postprocessing(post_processing)
    env.run(run)
    env.disable_logging()
env2 = Environment(trajectory='Traj2',filename='experiments/example_03/HDF5/example_03.hdf5',
                  file_title='Example_03', log_folder='experiments/example_03/LOGS/',
                  comment = 'I am going to be merged into some other trajectory!')

# Get the trajectories from the environment
traj1 = env1.v_trajectory
traj2 = env2.v_trajectory

# Add both parameters
traj1.f_add_parameter('x', 1.0, comment='I am the first dimension!')
traj1.f_add_parameter('y', 1.0, comment='I am the second dimension!')
traj2.f_add_parameter('x', 1.0, comment='I am the first dimension!')
traj2.f_add_parameter('y', 1.0, comment='I am the second dimension!')

# Explore the parameters with a cartesian product for the first trajectory:
traj1.f_explore(cartesian_product({'x':[1.0,2.0,3.0,4.0], 'y':[6.0,7.0,8.0]}))
# Let's explore slightly differently for the second:
traj2.f_explore(cartesian_product({'x':[3.0,4.0,5.0,6.0], 'y':[7.0,8.0,9.0]}))


# Run the simulations with all parameter combinations
env1.f_run(multiply)
env2.f_run(multiply)

# Now we merge them together into traj1
# We want to remove duplicate entries
# like the parameter space point x=3.0, y=7.0.
# Several points have been explored by both trajectories and we need them only once.
# Therefore, we set remove_duplicates=True (Note this takes O(N1*N2)!).
# We also want to backup both trajectories, but we let the system choose the filename.
# Accordingly we choose backup_filename=True instead of providing a filename.
                  file_title='Example_01_First_Steps',
                  comment='The first example!',
                  large_overview_tables=True,  # To see a nice overview of all
                  # computed `z` values in the resulting HDF5 file.
                  # Per default disabled for more compact HDF5 files.
                  )

# The environment has created a trajectory container for us
traj = env.v_trajectory

# Add both parameters
traj.f_add_parameter('x', 1, comment='I am the first dimension!')
traj.f_add_parameter('y', 1, comment='I am the second dimension!')

# Explore the parameters with a cartesian product
traj.f_explore(cartesian_product({'x':[1,2,3,4], 'y':[6,7,8]}))

# Run the simulation
env.f_run(multiply)



# Now let's see how we can reload the stored data from above.
# We do not need an environment for that, just a trajectory.
from pypet.trajectory import Trajectory

# So, first let's create a new trajectory and pass it the path and name of the HDF5 file.
# Yet, to be very clear let's delete all the old stuff.
del traj
# Before deleting the environment let's disable logging and close all log-files
env.f_disable_logging()
    def explore_mp(self, traj):
        self.explored={'x':[0.0, 1.0, 2.0, 3.0, 4.0], 'y':[0.1, 2.2, 3.3, 4.4, 5.5]}

        traj.f_explore(cartesian_product(self.explored))
    def explore(self, traj):
        self.explored =cartesian_product({'Normal.trial': [0,1],
            'Numpy.double': [np.array([1.0,2.0,3.0,4.0]), np.array([-1.0,3.0,5.0,7.0])]})


        traj.f_explore(self.explored)
Beispiel #46
0
def main():
    """Main function to protect the *entry point* of the program."""

    # Load settings from file
    settings_file = 'pypet_settings.pkl'
    settings = load_obj(settings_file)
    # Print settings dictionary
    print('\nSettings dictionary:')
    for key, value in settings.items():
        print(key, ' : ', value)
    print('\nParameters to explore:')
    for key, value in settings.items():
        if isinstance(value, list):
            print(key, ' : ', value)

    # Create new folder to store results
    traj_dir = os.getcwd()
    # Read output path (if provided)
    if len(sys.argv) > 1:
        # Add trailing slash if missing
        dir_provided = os.path.join(sys.argv[1], '')
        # Check if provided directory exists
        if os.path.isdir(dir_provided):
            # Convert to full path
            traj_dir = os.path.abspath(dir_provided)
        else:
            print(
                'WARNING: Output path not found, current directory will be used instead'
            )
    else:
        print(
            'WARNING: Output path not provided, current directory will be used instead'
        )
    # Add time stamp (the final '' is to make sure there is a trailing slash)
    traj_dir = os.path.join(traj_dir,
                            datetime.now().strftime("%Y_%m_%d_%Hh%Mm%Ss"), '')
    # Create directory with time stamp
    os.makedirs(traj_dir)
    # Change current directory to the one containing the trajectory files
    os.chdir(traj_dir)
    print('Trajectory and results will be stored in: {0}'.format(traj_dir))

    # Create new pypet Trajectory object
    traj_filename = 'traj.hdf5'
    traj_fullpath = os.path.join(traj_dir, traj_filename)
    traj = Trajectory(filename=traj_fullpath)

    # -------------------------------------------------------------------
    # Add config parameters (those that DO NOT influence the final result of the experiment)
    traj.f_add_config('debug', False, comment='Activate debug mode')
    #    #traj.f_add_config('max_mem_frac', 0.7, comment='Fraction of global GPU memory to use')

    # Set up trajectory parameters
    param_to_explore = {}
    for key, val in settings.items():
        if isinstance(val, list):
            param_to_explore[key] = val
            traj.f_add_parameter(key, val[0])
        else:
            traj.f_add_parameter(key, val)

    # Define parameter combinations to explore (a trajectory in
    # the parameter space). The second argument, the tuple, specifies the order
    #  of the cartesian product.
    # The variable on the right most side changes fastest and defines the
    # 'inner for-loop' of the cartesian product
    explore_dict = cartesian_product(param_to_explore,
                                     tuple(param_to_explore.keys()))

    print(explore_dict)
    traj.f_explore(explore_dict)

    # Store trajectory parameters to disk
    pypet_utils.print_traj_leaves(traj,
                                  'parameters',
                                  file=os.path.join(traj_dir,
                                                    'traj_parameters.txt'))

    # Store trajectory
    traj.f_store()

    # Define PBS script
    bash_lines = '\n'.join([
        '#! /bin/bash',
        '#PBS -P InfoDynFuncStruct',
        '#PBS -l select=1:ncpus=1:mem=1GB',
        #'#PBS -l select=1:ncpus=1:ngpus=1:mem=1GB',
        '#PBS -M [email protected]',
        '#PBS -m abe',
        'module load java',
        'module load python/3.5.1',
        'module load cuda/8.0.44',
        'source /project/RDS-FEI-InfoDynFuncStruct-RW/Leo/idtxl_env/bin/activate',
        'cd ${traj_dir}',
        'python ${python_script_path} ${traj_dir} ${traj_filename} ${file_prefix} $PBS_ARRAY_INDEX'
    ])

    # Save PBS script file (automatically generated)
    bash_script_name = 'run_python_script.pbs'
    job_script_path = os.path.join(traj_dir, bash_script_name)
    with open(job_script_path, 'w', newline='\n') as bash_file:
        bash_file.writelines(bash_lines)

    # Run job array
    job_walltime_hours = 0
    job_walltime_minutes = 5
    #after_job_array_ends = 1573895
    job_settings = {
        'N': 'run_traj',
        'l': 'walltime={0}:{1}:00'.format(job_walltime_hours,
                                          job_walltime_minutes),
        #'W': 'depend=afteranyarray:{0}[]'.format(after_job_array_ends),
        'q': 'defaultQ'
    }
    if len(traj.f_get_run_names()) > 1:
        job_settings['J'] = '{0}-{1}'.format(0,
                                             len(traj.f_get_run_names()) - 1)

    job_args = {
        'python_script_path':
        '/project/RDS-FEI-InfoDynFuncStruct-RW/Leo/inference/hpc_pypet_single_run.py',
        'traj_dir': traj_dir,
        'traj_filename': traj_filename,
        'file_prefix': 'none'
    }
    run_job_array(job_script_path, job_settings, job_args)
def main():
    # Get current directory
    traj_dir = os.getcwd()
    # Read output path (if provided)
    if len(sys.argv) > 1:
        # Only use specified folder if it exists
        if os.path.isdir(sys.argv[1]):
            # Get name of directory
            traj_dir = os.path.dirname(sys.argv[1])
            # Convert to full path
            traj_dir = os.path.abspath(traj_dir)
    # Add time stamp (final '' is to make sure there is a trailing slash)
    traj_dir = os.path.join(traj_dir,
                            datetime.now().strftime("%Y_%m_%d_%Hh%Mm%Ss"), '')
    # Create directory with time stamp
    os.makedirs(traj_dir)
    # Change current directory to the one containing the trajectory files
    os.chdir(traj_dir)
    print('Trajectory and results will be stored to: {0}'.format(traj_dir))

    # Create an environment that handles running.
    # Let's enable multiprocessing with scoop:
    env = Environment(
        trajectory='traj',
        comment='',
        add_time=False,
        log_config='DEFAULT',
        log_stdout=
        True,  # log everything that is printed, will make the log file HUGE
        filename=
        traj_dir,  # filename or just folder (name will be automatic in this case)
        multiproc=True,
        use_scoop=True,
        wrap_mode=pypetconstants.WRAP_MODE_LOCAL,
        memory_cap=10,
        swap_cap=1)
    traj = env.trajectory

    # -------------------------------------------------------------------
    # Add config parameters (those that DO NOT influence the final result of the experiment)
    traj.f_add_config('parallel_target_analysis',
                      False,
                      comment='Analyse targets in parallel')
    # -------------------------------------------------------------------
    # Parameters characterizing the initial topology of the network
    traj.f_add_parameter('topology.initial.model', 'BA')
    #traj.f_add_parameter('topology.initial.model', 'WS')
    traj.f_add_parameter('topology.initial.nodes_n',
                         5,
                         comment='Number of nodes')
    #traj.f_add_parameter('topology.initial.WS_k', 4, comment='Number of neighbours (and mean degree) in the Watts-Strogatz model')
    #traj.f_add_parameter('topology.initial.WS_p', 0.0, comment='Rewiring probability in the Watts-Strogatz model')
    traj.f_add_parameter(
        'topology.initial.BA_m',
        1,
        comment=
        'Number of edges to attach from a new node to existing nodes in the Barabási–Albert model'
    )

    # -------------------------------------------------------------------
    # Parameters characterizing the coupling between the nodes
    traj.f_add_parameter(
        'node_coupling.initial.model',
        'linear',
        comment=
        'Linear coupling model: the input to each target node is the weighted sum of the outputs of its source nodes'
    )
    traj.f_add_parameter('node_coupling.initial.weight_distribution', 'fixed')
    traj.f_add_parameter('node_coupling.initial.fixed_coupling', 0.1)

    # -------------------------------------------------------------------
    # Parameters characterizing the delay
    traj.f_add_parameter('delay.initial.distribution', 'uniform')
    traj.f_add_parameter('delay.initial.delay_links_n_max',
                         1,
                         comment='Maximum number of delay links')
    traj.f_add_parameter('delay.initial.delay_min', 1, comment='')
    traj.f_add_parameter('delay.initial.delay_max', 1, comment='')
    traj.f_add_parameter('delay.initial.delay_self', 1, comment='')

    # -------------------------------------------------------------------
    # Parameters characterizing the estimator
    traj.f_add_parameter('estimation.history_source',
                         1,
                         comment='Embedding length for the source')
    traj.f_add_parameter('estimation.history_target',
                         14,
                         comment='Embedding length for the target')

    # -------------------------------------------------------------------
    # Parameters characterizing the dynamics of the nodes
    traj.f_add_parameter('node_dynamics.model', 'AR_gaussian_discrete')
    #traj.f_add_parameter('node_dynamics.model', 'boolean_random')
    traj.f_add_parameter('node_dynamics.samples_n',
                         100,
                         comment='Number of samples (observations) to record')
    traj.f_add_parameter(
        'node_dynamics.samples_transient_n',
        1000 * traj.topology.initial.nodes_n,
        comment=
        'Number of initial samples (observations) to skip to leave out the transient'
    )
    traj.f_add_parameter('node_dynamics.replications',
                         1,
                         comment='Number of replications (trials) to record')
    traj.f_add_parameter('node_dynamics.noise_std',
                         1,
                         comment='Standard deviation of Gaussian noise')
    #traj.f_add_parameter('node_dynamics.RBN_r', 0.5, comment='Activity level (i.e. probability of state "1") in Boolean dynamics')
    #traj.f_add_parameter('node_dynamics.noise_flip_p', 0.005, comment='Probability of flipping bit in Boolean dynamics')

    # -------------------------------------------------------------------
    # Parameters characterizing the repetitions of the same run
    traj.f_add_parameter(
        'repetition_i', 0,
        comment='Index of the current repetition')  # Normally starts from 0

    # -------------------------------------------------------------------
    # Define parameter combinations to explore (a trajectory in
    # the parameter space)
    # The second argument, the tuple, specifies the order of the cartesian product,
    # The variable on the right most side changes fastest and defines the
    # 'inner for-loop' of the cartesian product
    explore_dict = cartesian_product(
        {
            'node_coupling.initial.weight_distribution': ['fixed'],
            'repetition_i': np.arange(0, 10000, 1).tolist(),
            'topology.initial.nodes_n': np.arange(100, 100 + 1, 30).tolist(),
            'node_dynamics.samples_n': np.array([100]).tolist(),
            #'topology.initial.WS_p': np.around(np.logspace(-2.2, 0, 10), decimals=4).tolist(),
        },
        (
            'node_coupling.initial.weight_distribution',
            'node_dynamics.samples_n',
            'topology.initial.nodes_n',
            #'topology.initial.WS_p',
            'repetition_i',
        ))
    print(explore_dict)
    traj.f_explore(explore_dict)
    # Run the experiment
    env.run(compute_bTE_all_pairs)
    # Check that all runs are completed
    assert traj.f_is_completed()
    # Finally disable logging and close all log-files
    env.disable_logging()
Beispiel #48
0
    def explore_trials_differently(self, traj):
        self.explored ={'Normal.trial': [0,1],
            'Numpy.double': [np.array([-1.0,2.0,3.0,5.0]), np.array([-1.0,3.0,5.0,7.0])]}

        traj.f_explore(cartesian_product(self.explored, ('Numpy.double','Normal.trial')))
Beispiel #49
0
traj.f_add_parameter('dThetha', np.float64(0))
traj.f_add_parameter('dPhi', np.float64(0))
traj.f_add_parameter('ux', np.float64(1))
traj.f_add_parameter('uy', np.float64(1))
traj.f_add_parameter('uz', np.float64(1))
traj.f_add_parameter('uThetha', np.float64(0))
traj.f_add_parameter('uPhi', np.float64(0))

# Explore the parameters with a cartesian product
space_range = np.arange(-2, 2, 0.5)
dx_range = 2.5 + space_range
dy_range = 0.8 + space_range
dz_range = [0]

trajectory = {
    'dx': dx_range,
    'dy': dx_range,
    'dz': dx_range,
    'dThetha': [np.float64(0.006)],
    'dPhi': [np.float64(0.1)],
    'ux': [np.float64(0)],
    'uy': [np.float64(0)],
    'uz': [np.float64(0)],
    'uThetha': [np.float64(-0.001)],
    'uPhi': [np.float64(-0.003)]
}

traj.f_explore(cartesian_product(trajectory))

# Run the simulation
env.run(cross_tune)
Beispiel #50
0
    def explore2(self, traj):
        self.explored2 ={'Normal.trial': [0,1],
            'Normal.int': [44, 45]}

        traj.f_explore(cartesian_product(self.explored2,  ('Normal.int','Normal.trial') ))
# Create an environment that handles running
env = Environment(trajectory='Example10',filename='experiments/example_08/HDF5/example_10.hdf5',
                  file_title='Example10', log_folder='experiments/example_08/LOGS/',
                  comment='Another example!')

# Get the trajectory from the environment
traj = env.v_trajectory

# Add both parameters
traj.f_add_parameter('x', 1, comment='I am the first dimension!')
traj.f_add_parameter('y', 1, comment='I am the second dimension!')

# Explore the parameters with a cartesian product:
x_length = 15
y_length = 15
traj.f_explore(cartesian_product({'x':range(x_length), 'y':range(y_length)}))

# Run the simulation
env.f_run(multiply)

# We load all results
traj.f_load(load_results=pypetconstants.LOAD_DATA)

# We access the ranges for plotting
xs = traj.f_get('x').f_get_range()
ys = traj.f_get('y').f_get_range()

# Now we want to directly get all numbers z from all runs
# for plotting.
# We use `fast_access=True` to directly get access to
# the values.
Beispiel #52
0
    def explore_trials_differently(self, traj):
        self.explored ={'Normal.trial': [0,1],
            'Numpy.double': [np.array([-1.0,2.0,3.0,5.0]), np.array([-1.0,3.0,5.0,7.0])]}

        traj.f_explore(cartesian_product(self.explored, ('Numpy.double','Normal.trial')))
Beispiel #53
0
 def explore_large(self, traj):
     self.explored ={'Normal.trial': [0,1]}
     traj.f_explore(cartesian_product(self.explored))
Beispiel #54
0
 def explore_cartesian(self,traj):
     self.explore_dict=cartesian_product({'x':[-1,1,2,3,4, 5, 6],'y':[1,1,2,2,3,4,4]})
     traj.f_explore(self.explore_dict)