How to use the pypet.pypetconstants function in pypet

To help you get started, we’ve selected a few pypet examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github SmokinCaterpillar / pypet / pypet / storageservice.py View on Github external
' %d. They should be equally long!'  %
                                               (full_name,array_length,len(traj)))

                class_constructor = traj._create_class(class_name)
                instance = class_constructor(name,comment=comment)

                parent_traj_node._nn_interface._add_from_leaf_instance(parent_traj_node,instance)

                if array_length:
                    traj._explored_parameters[instance.v_full_name]=instance

                self._ann_load_annotations(instance,node=hdf5group)



            if load_data in [pypetconstants.LOAD_DATA, pypetconstants.UPDATE_DATA]:
                self._prm_load_parameter_or_result(instance,_hdf5_group=hdf5group)
        else:

            if not name in parent_traj_node._children:
                new_traj_node = parent_traj_node._nn_interface._add_from_group_name(
                                                                            parent_traj_node, name)
                newly_created = True
            else:
                new_traj_node = parent_traj_node._children[name]
                newly_created=False

            if (load_data in [pypetconstants.LOAD_DATA, pypetconstants.LOAD_SKELETON] or
                                            newly_created):

                self._ann_load_annotations(new_traj_node,node=hdf5group)
github SmokinCaterpillar / pypet / pypet / storageservice.py View on Github external
self._trj_store_trajectory(stuff_to_store,*args,**kwargs)

            elif msg == pypetconstants.SINGLE_RUN:

                self._srn_store_single_run(stuff_to_store,*args,**kwargs)

            elif msg in (pypetconstants.LEAF, pypetconstants.UPDATE_LEAF):
                self._prm_store_parameter_or_result(msg,stuff_to_store,*args,**kwargs)

            elif msg == pypetconstants.REMOVE:
                self._all_remove_parameter_or_result_or_group(stuff_to_store,*args,**kwargs)

            elif msg == pypetconstants.GROUP:
                self._grp_store_group(stuff_to_store,*args,**kwargs)

            elif msg == pypetconstants.REMOVE_INCOMPLETE_RUNS:
                self._trj_remove_incomplete_runs(stuff_to_store,*args,**kwargs)

            elif msg == pypetconstants.TREE:
                self._tree_store_tree(stuff_to_store,*args,**kwargs)

            elif msg == pypetconstants.LIST:
                self._srvc_store_several_items(stuff_to_store,*args,**kwargs)

            else:
                raise pex.NoSuchServiceError('I do not know how to handle `%s`' % msg)

            self._srvc_closing_routine(opened)

        except:
            self._srvc_closing_routine(True)
            self._logger.error('Failed storing `%s`' % str(stuff_to_store))
github SmokinCaterpillar / pypet / pypet / parameter.py View on Github external
def f_supports(self, data):
        """Checks if input data is supported by the parameter."""
        dtype = type(data)
        if dtype is tuple:

            # Parameters cannot handle empty tuples
            if len(data) == 0:
                return False

            old_type = None

            # Check if the data in the tuple is homogeneous
            for item in data:
                if not type(item) in pypetconstants.PARAMETER_SUPPORTED_DATA:
                    return False
                if not old_type is None and old_type != type(item):
                    return False
                old_type = type(item)
            return True

        elif dtype is np.ndarray or dtype is np.matrix:

            if data.size == 0:
                return False # Parameters cannot handle empty arrays and matrices

            # Numpy has many string types that depend on the length of the string,
            # We allow all of them
            dtype = data.dtype
            if np.issubdtype(dtype, np.str):
                dtype = np.str
github SmokinCaterpillar / pypet / pypet / naturalnaming.py View on Github external
if result is None:
                            break
        elif not try_auto_load_directly:
            result = node
            for name in split_name:
                if name in result._children and (with_links or not name in result._links):
                    result = result._children[name]
                else:
                    raise AttributeError(
                        'You did not allow for shortcuts and `%s` was not directly '
                        'found  under node `%s`.' % (name, result.v_full_name))

        if result is None and auto_load:
            try:
                result = node.f_load_child('.'.join(split_name),
                                           load_data=pypetconstants.LOAD_DATA)
            except:
                self._logger.error('Error while auto-loading `%s` under `%s`.' %
                                   (name, node.v_full_name))
                raise

        if result is None:
            raise AttributeError('The node or param/result `%s`, cannot be found under `%s`' %
                                 (name, node.v_full_name))
        if result.v_is_leaf:
            if auto_load and result.f_is_empty():

                try:
                    self._root_instance.f_load_item(result)
                except:
                    self._logger.error('Error while auto-loading `%s` under `%s`. I found the '
                                       'item but I could not load the data.' %
github IGITUGraz / L2L / bin / ltl-lsm-ga.py View on Github external
print("All output can be found in file ", log_output_file)
    print("Change the values in logging.yaml to control log level and destination")
    print("e.g. change the handler to console for the loggers you're interesting in to get output to stdout")

    traj_file = os.path.join(paths.results_path, 'data.h5')

    # Create an environment that handles running our simulation

    env = Environment(trajectory=name, filename=traj_file, file_title='{} data'.format(name),
                      comment='{} data'.format(name),
                      add_time=True,
                      freeze_input=True,
                      multiproc=True,
                      use_scoop=True,
                      wrap_mode=pypetconstants.WRAP_MODE_LOCAL,
                      automatic_storing=True,
                      log_stdout=True,  # Sends stdout to logs
                      # only ok because output_dir_path is initialized by access of results_path
                      log_folder=os.path.join(paths.output_dir_path, 'logs')
                      )

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

    # NOTE: Innerloop simulator
    lsm = LSMOptimizee(traj, task=Tasks.XOR, n_NEST_threads=12)

    # NOTE: Outerloop optimizer initialization
    parameters = GeneticAlgorithmParameters(seed=42, popsize=8, CXPB=0.6, MUTPB=0.2, NGEN=5, indpb=0.05,
                                            tournsize=3, matepar=10., mutpar=10.)
    ga = GeneticAlgorithmOptimizer(traj, optimizee_create_individual=lsm.create_individual,
github SmokinCaterpillar / pypet / pypet / storageservice.py View on Github external
def _srn_add_explored_params(self, name, paramlist, add_table):
        ''' Stores the explored parameters as a Node in the HDF5File under the results nodes for easier comprehension of the hdf5file.
        '''

        paramdescriptiondict={'name': pt.StringCol(pypetconstants.HDF5_STRCOL_MAX_NAME_LENGTH),
                                'value' :pt.StringCol(pypetconstants.HDF5_STRCOL_MAX_VALUE_LENGTH)}

        where = 'results.'+name


        where = where.replace('.','/')
        add_table = add_table and where in self._trajectory_group

        if add_table:
            rungroup = getattr(self._trajectory_group,where)


            if not 'explored_parameters' in rungroup:
                try:
                    paramtable = self._hdf5file.create_table(where=rungroup,
                                                            name='explored_parameters',
github SmokinCaterpillar / pypet / pypet / storagedata_backup.py View on Github external
def _guess_type(self, kwargs):
        if 'description' in kwargs or 'first_row' in kwargs:
            self._type = pypetconstants.TABLE
        else:
            self._type = pypetconstants.CARRAY
github SmokinCaterpillar / pypet / pypet / utils / mpwrappers.py View on Github external
def _open_file(self):
        self._storage_service.store(pypetconstants.OPEN_FILE, None,
                                    trajectory_name=self._trajectory_name)
        self._logger.info('Opened the hdf5 file.')