Search is not available for this dataset
text
stringlengths
75
104k
def _srvc_closing_routine(self, closing): """Routine to close an hdf5 file The file is closed only when `closing=True`. `closing=True` means that the file was opened in the current highest recursion level. This prevents re-opening and closing of the file if `store` or `load` are called ...
def _srvc_extract_file_information(self, kwargs): """Extracts file information from kwargs. Note that `kwargs` is not passed as `**kwargs` in order to also `pop` the elements on the level of the function calling `_srvc_extract_file_information`. """ if 'filename' in kwargs: ...
def _trj_backup_trajectory(self, traj, backup_filename=None): """Backs up a trajectory. :param traj: Trajectory that should be backed up :param backup_filename: Path and filename of backup file. If None is specified the storage service defaults to `path_to_trajectory_h...
def _trj_read_out_row(colnames, row): """Reads out a row and returns a dictionary containing the row content. :param colnames: List of column names :param row: A pytables table row :return: A dictionary with colnames as keys and content as values """ result_dict = {} ...
def _trj_merge_trajectories(self, other_trajectory_name, rename_dict, move_nodes=False, delete_trajectory=False, other_filename=None): """Merges another trajectory into the current trajectory (as in self._trajectory_name). :param other_trajectory_name: Name of other traj...
def _trj_prepare_merge(self, traj, changed_parameters, old_length): """Prepares a trajectory for merging. This function will already store extended parameters. :param traj: Target of merge :param changed_parameters: List of extended parameters (i.e. their names). """ ...
def _trj_load_trajectory(self, traj, as_new, load_parameters, load_derived_parameters, load_results, load_other_data, recursive, max_depth, with_run_information, with_meta_data, force): """Loads a single trajectory from a given file. :param tra...
def _trj_load_meta_data(self, traj, load_data, as_new, with_run_information, force): """Loads meta information about the trajectory Checks if the version number does not differ from current pypet version Loads, comment, timestamp, name, version from disk in case trajectory is not loaded ...
def _tree_load_sub_branch(self, traj_node, branch_name, load_data=pypetconstants.LOAD_DATA, with_links=True, recursive=False, max_depth=None, _trajectory=None, _as_new=False, _hdf5_group=None): ...
def _trj_check_version(self, version, python, force): """Checks for version mismatch Raises a VersionMismatchError if version of loaded trajectory and current pypet version do not match. In case of `force=True` error is not raised only a warning is emitted. """ curr_python = py...
def _trj_fill_run_table(self, traj, start, stop): """Fills the `run` overview table with information. Will also update new information. """ def _make_row(info_dict): row = (info_dict['idx'], info_dict['name'], info_dict['time'], ...
def _trj_store_meta_data(self, traj): """ Stores general information about the trajectory in the hdf5file. The `info` table will contain the name of the trajectory, it's timestamp, a comment, the length (aka the number of single runs), and the current version number of pypet. Also prep...
def _trj_load_exploration(self, traj): """Recalls names of all explored parameters""" if hasattr(self._overview_group, 'explorations'): explorations_table = self._overview_group._f_get_child( 'explorations') for row in explorations_table.iterrows(): param_name = r...
def _trj_store_explorations(self, traj): """Stores a all explored parameter names for internal recall""" nexplored = len(traj._explored_parameters) if nexplored > 0: if hasattr(self._overview_group, 'explorations'): explorations_table = self._overview_group._f_get_chi...
def _srvc_make_overview_tables(self, tables_to_make, traj=None): """Creates the overview tables in overview group""" for table_name in tables_to_make: # Prepare the tables desciptions, depending on which overview table we create # we need different columns paramdescri...
def _trj_store_trajectory(self, traj, only_init=False, store_data=pypetconstants.STORE_DATA, max_depth=None): """ Stores a trajectory to an hdf5 file Stores all groups, parameters and results """ if not only_init: self._logger.info('Start stori...
def _tree_store_sub_branch(self, traj_node, branch_name, store_data=pypetconstants.STORE_DATA, with_links=True, recursive=False, max_depth=None, hdf5_group=None): ...
def _tree_create_leaf(self, name, trajectory, hdf5_group): """ Creates a new pypet leaf instance. Returns the leaf and if it is an explored parameter the length of the range. """ class_name = self._all_get_from_attrs(hdf5_group, HDF5StorageService.CLASS_NAME) # Create the inst...
def _tree_load_nodes_dfs(self, parent_traj_node, load_data, with_links, recursive, max_depth, current_depth, trajectory, as_new, hdf5_group): """Loads a node from hdf5 file and if desired recursively everything below :param parent_traj_node: The parent node whose child should b...
def _tree_load_link(self, new_traj_node, load_data, traj, as_new, hdf5_soft_link): """ Loads a link :param new_traj_node: Node in traj containing link :param load_data: How to load data in the linked node :param traj: The trajectory :param as_new: If data in linked node...
def _tree_store_nodes_dfs(self, parent_traj_node, name, store_data, with_links, recursive, max_depth, current_depth, parent_hdf5_group): """Stores a node to hdf5 and if desired stores recursively everything below it. :param parent_traj_node: The paren...
def _tree_store_link(self, node_in_traj, link, hdf5_group): """Creates a soft link. :param node_in_traj: parental node :param store_data: how to store data :param link: name of link :param hdf5_group: current parental hdf5 group """ if hasattr(hdf5_group...
def _srn_store_single_run(self, traj, recursive=True, store_data=pypetconstants.STORE_DATA, max_depth=None): """ Stores a single run instance to disk (only meta data)""" if store_data != pypetconstants.STORE_NOTHI...
def _srn_summarize_explored_parameters(self, paramlist): """Summarizes the parameter settings. :param run_name: Name of the single run :param paramlist: List of explored parameters :param add_table: Whether to add the overview table :param create_run_group: If a ...
def _all_store_param_or_result_table_entry(self, instance, table, flags, additional_info=None): """Stores a single row into an overview table :param instance: A parameter or result instance :param table: Table where row will be inserted :...
def _all_get_or_create_table(self, where, tablename, description, expectedrows=None): """Creates a new table, or if the table already exists, returns it.""" where_node = self._hdf5file.get_node(where) if not tablename in where_node: if not expectedrows is None: table...
def _all_get_node_by_name(self, name): """Returns an HDF5 node by the path specified in `name`""" path_name = name.replace('.', '/') where = '/%s/%s' % (self._trajectory_name, path_name) return self._hdf5file.get_node(where=where)
def _all_set_attributes_to_recall_natives(data, ptitem, prefix): """Stores original data type to hdf5 node attributes for preserving the data type. :param data: Data to be stored :param ptitem: HDF5 node to store data types as attributes. Can also be just a PTItemMock...
def _all_recall_native_type(self, data, ptitem, prefix): """Checks if loaded data has the type it was stored in. If not converts it. :param data: Data item to be checked and converted :param ptitem: HDf5 Node or Leaf from where data was loaded :param prefix: Prefix for recalling the dat...
def _all_add_or_modify_row(self, item_name, insert_dict, table, index=None, condition=None, condvars=None, flags=(ADD_ROW, MODIFY_ROW,)): """Adds or changes a row in a pytable. :param item_name: Name of item, the row is about, only important...
def _all_insert_into_row(self, row, insert_dict): """Copies data from `insert_dict` into a pytables `row`.""" for key, val in insert_dict.items(): try: row[key] = val except KeyError as ke: self._logger.warning('Could not write `%s` into a table, '...
def _all_extract_insert_dict(self, item, colnames, additional_info=None): """Extracts information from a given item to be stored into a pytable row. Items can be a variety of things here, trajectories, single runs, group node, parameters, results. :param item: Item from which data shou...
def _all_cut_string(string, max_length, logger): """Cuts string data to the maximum length allowed in a pytables column if string is too long. :param string: String to be cut :param max_length: Maximum allowed string length :param logger: Logger where messages about truncating s...
def _all_create_or_get_group(self, name, parent_hdf5_group=None): """Creates or returns a group""" if not name in parent_hdf5_group: new_hdf5_group = self._hdf5file.create_group(where=parent_hdf5_group, name=name, ...
def _all_create_or_get_groups(self, key, start_hdf5_group=None): """Creates new or follows existing group nodes along a given colon separated `key`. :param key: Colon separated path along hdf5 file, e.g. `parameters.mobiles.cars`. :param start_hdf5_group: HDF5 group f...
def _ann_store_annotations(self, item_with_annotations, node, overwrite=False): """Stores annotations into an hdf5 file.""" # If we overwrite delete all annotations first if overwrite is True or overwrite == 'v_annotations': annotated = self._all_get_from_attrs(node, HDF5StorageServ...
def _ann_load_annotations(self, item_with_annotations, node): """Loads annotations from disk.""" annotated = self._all_get_from_attrs(node, HDF5StorageService.ANNOTATED) if annotated: annotations = item_with_annotations.v_annotations # You can only load into non-empty...
def _grp_store_group(self, traj_group, store_data=pypetconstants.STORE_DATA, with_links=True, recursive=False, max_depth=None, _hdf5_group=None, _newly_created=False): """Stores a group node. For group nodes only annotations and comments need to be stor...
def _grp_load_group(self, traj_group, load_data=pypetconstants.LOAD_DATA, with_links=True, recursive=False, max_depth=None, _traj=None, _as_new=False, _hdf5_group=None): """Loads a group node and potentially everything recursively below""" if _hdf5_group i...
def _all_load_skeleton(self, traj_node, hdf5_group): """Reloads skeleton data of a tree node""" if traj_node.v_annotations.f_is_empty(): self._ann_load_annotations(traj_node, hdf5_group) if traj_node.v_comment == '': comment = self._all_get_from_attrs(hdf5_group, HDF5Stor...
def _prm_extract_missing_flags(data_dict, flags_dict): """Extracts storage flags for data in `data_dict` if they were not specified in `flags_dict`. See :const:`~pypet.storageservice.HDF5StorageService.TYPE_FLAG_MAPPING` for how to store different types of data per default. """...
def _prm_meta_add_summary(self, instance): """Adds data to the summary tables and returns if `instance`s comment has to be stored. Also moves comments upwards in the hierarchy if purge_duplicate_comments is true and a lower index run has completed. Only necessary for *multiprocessing*. ...
def _prm_add_meta_info(self, instance, group, overwrite=False): """Adds information to overview tables and meta information to the `instance`s hdf5 `group`. :param instance: Instance to store meta info about :param group: HDF5 group of instance :param overwrite: If data should b...
def _prm_store_from_dict(self, fullname, store_dict, hdf5_group, store_flags, kwargs): """Stores a `store_dict`""" for key, data_to_store in store_dict.items(): # self._logger.log(1, 'SUB-Storing %s [%s]', key, str(store_dict[key])) original_hdf5_group = None flag = ...
def _prm_store_parameter_or_result(self, instance, store_data=pypetconstants.STORE_DATA, store_flags=None, overwrite=None, wi...
def _prm_select_shared_pandas_data(self, pd_node, full_name, **kwargs): """Reads a DataFrame from dis. :param pd_node: hdf5 node storing the pandas DataFrame :param full_name: Full name of the parameter or result whose data is to be loaded :param kwargs: ...
def _prm_write_shared_array(self, key, data, hdf5_group, full_name, flag, **kwargs): """Creates and array that can be used with an HDF5 array object""" if flag == HDF5StorageService.ARRAY: self._prm_write_into_array(key, data, hdf5_group, full_name, **kwargs) elif flag in (HDF5Stora...
def _prm_write_shared_table(self, key, hdf5_group, fullname, **kwargs): """Creates a new empty table""" first_row = None description = None if 'first_row' in kwargs: first_row = kwargs.pop('first_row') if not 'description' in kwargs: description = ...
def _prm_write_dict_as_table(self, key, data_to_store, group, fullname, **kwargs): """Stores a python dictionary as pytable :param key: Name of data item to store :param data_to_store: Dictionary to store :param group: Group node where to store d...
def _prm_write_pandas_data(self, key, data, group, fullname, flag, **kwargs): """Stores a pandas DataFrame into hdf5. :param key: Name of data item to store :param data: Pandas Data to Store :param group: Group node where to store data in hdf5 fi...
def _prm_write_into_other_array(self, key, data, group, fullname, flag, **kwargs): """Stores data as carray, earray or vlarray depending on `flag`. :param key: Name of data item to store :param data: Data to store :param gr...
def _prm_write_into_array(self, key, data, group, fullname, **kwargs): """Stores data as array. :param key: Name of data item to store :param data: Data to store :param group: Group node where to store data in hdf5 file :param fullname: ...
def _lnk_delete_link(self, link_name): """Removes a link from disk""" translated_name = '/' + self._trajectory_name + '/' + link_name.replace('.','/') link = self._hdf5file.get_node(where=translated_name) link._f_remove()
def _all_delete_parameter_or_result_or_group(self, instance, delete_only=None, remove_from_item=False, recursive=False, _hdf...
def _prm_write_into_pytable(self, tablename, data, hdf5_group, fullname, **kwargs): """Stores data as pytable. :param tablename: Name of the data table :param data: Data to store :param hdf5_group: Group node where to store data in hdf5 file ...
def _prm_make_description(self, data, fullname): """ Returns a description dictionary for pytables table creation""" def _convert_lists_and_tuples(series_of_data): """Converts lists and tuples to numpy arrays""" if isinstance(series_of_data[0], (list, t...
def _all_get_table_col(self, key, column, fullname): """ Creates a pytables column instance. The type of column depends on the type of `column[0]`. Note that data in `column` must be homogeneous! """ val = column[0] try: # # We do not want to loose int_ ...
def _prm_get_longest_stringsize(string_list): """ Returns the longest string size for a string entry across data.""" maxlength = 1 for stringar in string_list: if isinstance(stringar, np.ndarray): if stringar.ndim > 0: for string in stringar.ravel...
def _prm_load_into_dict(self, full_name, load_dict, hdf5_group, instance, load_only, load_except, load_flags, _prefix = ''): """Loads into dictionary""" for node in hdf5_group: load_type = self._all_get_from_attrs(node, HDF5StorageService.STORAGE_TYPE) ...
def _prm_load_parameter_or_result(self, instance, load_data=pypetconstants.LOAD_DATA, load_only=None, load_except=None, load_flags=None, ...
def _prm_read_dictionary(self, leaf, full_name): """Loads data that was originally a dictionary when stored :param leaf: PyTables table containing the dictionary data :param full_name: Full name of the parameter or result whose data is to be loaded :return: ...
def _prm_read_shared_data(self, shared_node, instance): """Reads shared data and constructs the appropraite class. :param shared_node: hdf5 node storing the pandas DataFrame :param full_name: Full name of the parameter or result whose data is to be loaded :re...
def _prm_read_pandas(self, pd_node, full_name): """Reads a DataFrame from dis. :param pd_node: hdf5 node storing the pandas DataFrame :param full_name: Full name of the parameter or result whose data is to be loaded :return: Data to load ...
def _prm_read_table(self, table_or_group, full_name): """Reads a non-nested PyTables table column by column and created a new ObjectTable for the loaded data. :param table_or_group: PyTables table to read from or a group containing subtables. :param full_name: ...
def _prm_read_array(self, array, full_name): """Reads data from an array or carray :param array: PyTables array or carray to read from :param full_name: Full name of the parameter or result whose data is to be loaded :return: Data to load ...
def load_trajectory(name=None, index=None, as_new=False, load_parameters=pypetconstants.LOAD_DATA, load_derived_parameters=pypetconstants.LOAD_SKELETON, load_results=pypetconstants.LOAD_SKELETON, load...
def make_set_name(idx): """Creates a run set name based on ``idx``""" GROUPSIZE = 1000 set_idx = idx // GROUPSIZE if set_idx >= 0: return pypetconstants.FORMATTED_SET_NAME % set_idx else: return pypetconstants.SET_NAME_DUMMY
def f_add_wildcard_functions(self, func_dict): """#TODO""" for wildcards, function in func_dict.items(): if not isinstance(wildcards, tuple): wildcards = (wildcards,) for wildcard in wildcards: if wildcard in self._wildcard_keys: ...
def f_wildcard(self, wildcard='$', run_idx=None): """#TODO""" if run_idx is None: run_idx = self.v_idx wildcards = self._wildcard_keys[wildcard] try: return self._wildcard_cache[(wildcards, run_idx)] except KeyError: translation = self._wildcar...
def v_full_copy(self, val): """ Sets full copy mode of trajectory and (!) ALL explored parameters!""" self._full_copy = bool(val) for param in self._explored_parameters.values(): if param is not None: param.v_full_copy = bool(val)
def f_set_properties(self, **kwargs): """Sets properties like ``v_fast_access``. For example: ``traj.f_set_properties(v_fast_access=True, v_auto_load=False)`` """ for name in kwargs: val = kwargs[name] if not name.startswith('v_'): name = 'v_' + ...
def f_add_to_dynamic_imports(self, dynamic_imports): """Adds classes or paths to classes to the trajectory to create custom parameters. :param dynamic_imports: If you've written custom parameter that needs to be loaded dynamically during runtime, this needs to be specified here...
def f_set_crun(self, name_or_idx): """Can make the trajectory behave as during a particular single run. It allows easier data analysis. Has the following effects: * `v_idx` and `v_crun` are set to the appropriate index and run name * All explored para...
def f_iter_runs(self, start=0, stop=None, step=1, yields='name'): """Makes the trajectory iterate over all runs. :param start: Start index of run :param stop: Stop index, leave ``None`` for length of trajectory :param step: Stepsize :param yields: What should be ...
def f_shrink(self, force=False): """ Shrinks the trajectory and removes all exploration ranges from the parameters. Only possible if the trajectory has not been stored to disk before or was loaded as new. :param force: Usually you cannot shrink the trajectory if it has been stored ...
def _preset(self, name, args, kwargs): """Generic preset function, marks a parameter or config for presetting.""" if self.f_contains(name, shortcuts=False): raise ValueError('Parameter `%s` is already part of your trajectory, use the normal' 'accessing routine to...
def f_preset_config(self, config_name, *args, **kwargs): """Similar to func:`~pypet.trajectory.Trajectory.f_preset_parameter`""" if not config_name.startswith('config.'): config_name = 'config.' + config_name self._preset(config_name, args, kwargs)
def f_preset_parameter(self, param_name, *args, **kwargs): """Presets parameter value before a parameter is added. Can be called before parameters are added to the Trajectory in order to change the values that are stored into the parameter on creation. After creation of a parameter, th...
def _prepare_experiment(self): """Called by the environment to make some initial configurations before performing the individual runs. Checks if all parameters marked for presetting were preset. If not raises a DefaultReplacementError. Locks all parameters. Removal of ...
def f_get_from_runs(self, name, include_default_run=True, use_indices=False, fast_access=False, with_links = True, shortcuts=True, max_depth=None, auto_load=False): """Searches for all occurrences of `name` in each run. Generates an ordered dictionary wit...
def _is_completed(self, name_or_id=None): """Private function such that it can still be called by the environment during a single run""" if name_or_id is None: return all( (runinfo['completed'] for runinfo in self._run_information.values())) else: ...
def f_expand(self, build_dict, fail_safe=True): """Similar to :func:`~pypet.trajectory.Trajectory.f_explore`, but can be used to enlarge already completed trajectories. Please ensure before usage, that all explored parameters are loaded! :param build_dict: Dictionary conta...
def _remove_exploration(self): """ Called if trajectory is expanded, deletes all explored parameters from disk """ for param in self._explored_parameters.values(): if param._stored: try: self.f_delete_item(param) except Exception: ...
def f_copy(self, copy_leaves=True, with_links=True): """Returns a *shallow* copy of a trajectory. :param copy_leaves: If leaves should be **shallow** copied or simply referred to by both trees. **Shallow** copying is established using the copy module. ...
def _copy_from(self, node, copy_leaves=True, overwrite=False, with_links=True): """Pass a ``node`` to insert the full tree to the trajectory. Considers all links in the given node! Ignored nodes already found in the c...
def f_explore(self, build_dict): """Prepares the trajectory to explore the parameter space. To explore the parameter space you need to provide a dictionary with the names of the parameters to explore as keys and iterables specifying the exploration ranges as values. All iterables need...
def _update_run_information(self, run_information_dict): """Overwrites the run information of a particular run""" idx = run_information_dict['idx'] name = run_information_dict['name'] self._run_information[name] = run_information_dict self._updated_run_information.add(idx)
def _add_run_info(self, idx, name='', timestamp=42.0, finish_timestamp=1.337, runtime='forever and ever', time='>>Maybe time`s gone on strike', completed=0, parameter_summary='Not yet my friend!', short_environment_hexsha='N/A'): """Adds a new ru...
def f_lock_parameters(self): """Locks all non-empty parameters""" for par in self._parameters.values(): if not par.f_is_empty(): par.f_lock()
def f_lock_derived_parameters(self): """Locks all non-empty derived parameters""" for par in self._derived_parameters.values(): if not par.f_is_empty(): par.f_lock()
def _finalize(self, store_meta_data=True): """Final rollback initiated by the environment Restores the trajectory as root of the tree, and stores meta data to disk. This updates the trajectory's information about single runs, i.e. if they've been completed, when they were started, etc. ...
def f_load_skeleton(self): """Loads the full skeleton from the storage service. This needs to be done after a successful exploration in order to update the trajectory tree with all results and derived parameters from the individual single runs. This will only add empty results and deriv...
def f_load(self, name=None, index=None, as_new=False, load_parameters=pypetconstants.LOAD_DATA, load_derived_parameters=pypetconstants.LOAD_SKELETON, load_results=pypetconstants.LOAD_SKELETON, load_other_data=pypetconstants.LOAD_SKELETON, recursive=True, ...
def _check_if_both_have_same_parameters(self, other_trajectory, ignore_data, consecutive_merge): """ Checks if two trajectories live in the same space and can be merged. """ if not isinstance(other_trajectory, Trajectory): raise TypeError('Can onl...
def f_backup(self, **kwargs): """Backs up the trajectory with the given storage service. Arguments of ``kwargs`` are directly passed to the storage service, for the HDF5StorageService you can provide the following argument: :param backup_filename: Name of file where to sto...
def _make_reversed_wildcards(self, old_length=-1): """Creates a full mapping from all wildcard translations to the corresponding wildcards""" if len(self._reversed_wildcards) > 0: # We already created reversed wildcards, so we don't need to do all of them # again star...
def f_merge_many(self, other_trajectories, ignore_data=(), move_data=False, delete_other_trajectory=False, keep_info=True, keep_other_trajectory_info=True, merge_config=True, backup=True): """Can be u...
def f_merge(self, other_trajectory, trial_parameter=None, remove_duplicates=False, ignore_data=(), backup=True, move_data=False, delete_other_trajectory=False, keep_info=True, keep_other_trajectory_info=True, ...
def _merge_single_runs(self, other_trajectory, used_runs): """ Updates the `run_information` of the current trajectory.""" count = len(self) # Variable to count the increasing new run indices and create # new run names run_indices = range(len(other_trajectory)) run_name_dict ...
def _rename_full_name(self, full_name, other_trajectory, used_runs=None, new_run_idx=None): """Renames a full name based on the wildcards and a particular run""" split_name = full_name.split('.') for idx, name in enumerate(split_name): if name in other_trajectory._reversed_wildcards:...