graphtoolbox.utils.helper_functions¶
Functions
|
Converts a batch of data to a tensor, organizing elements by modulo num_nodes without detaching gradients. |
|
Converts a batch of data to a tensor, organizing elements by modulo num_nodes without detaching gradients. |
|
|
|
Change the current working directory to the specified directory by traversing up the directory tree until the target directory is found. |
|
Deletes and recreates a specified directory. |
|
|
|
Calculate the great circle distance (in km) between two points on the earth (specified in decimal degrees) |
|
Loads configuration dictionaries. |
|
Load keyword arguments. |
|
Parse a configuration string into a dictionary. |
|
Save new values to a specified dictionary in a module. |
|
Update a specified dictionary in a module with new configuration values. |
- graphtoolbox.utils.helper_functions.clean_dir(directory: str) None[source][source]¶
Deletes and recreates a specified directory.
- Parameters:
directory (str) – The path to the directory to clean.
- graphtoolbox.utils.helper_functions.batch_y_to_tensor(batch: Tensor, **kwargs) Tensor[source][source]¶
Converts a batch of data to a tensor, organizing elements by modulo num_nodes without detaching gradients.
- Parameters:
batch (torch.Tensor) – The batch of data containing the specified attribute.
**kwargs – num_nodes (int): Number of nodes in the graph. Defaults to 12.
- Returns:
A tensor where data is organized into num_nodes groups.
- Return type:
torch.Tensor
- graphtoolbox.utils.helper_functions.batch_x_to_tensor(batch: Tensor, **kwargs) Tensor[source][source]¶
Converts a batch of data to a tensor, organizing elements by modulo num_nodes without detaching gradients.
- Parameters:
batch (torch.Tensor) – The batch of data containing the specified attribute.
**kwargs – num_nodes (int): Number of nodes in the graph. Defaults to 12.
- Returns:
A tensor where data is organized into num_nodes groups.
- Return type:
torch.Tensor
- graphtoolbox.utils.helper_functions.load_config(folder_config: str)[source][source]¶
Loads configuration dictionaries.
- Parameters:
folder_config (str) – Path to the configuration file.
- Returns:
Configuration file.
- graphtoolbox.utils.helper_functions.load_kwargs(folder_config: str, kwargs: str) Dict[str, Any][source][source]¶
Load keyword arguments.
- Parameters:
kwargs (str) – The name of the attribute (dictionary) to retrieve from the module.
- Returns:
The dictionary retrieved from the module, or an empty dictionary if not found.
- Return type:
Dict[str, Any]
- graphtoolbox.utils.helper_functions.save_config(folder_config: str, kwargs: str, new_values: Dict[str, Any]) None[source][source]¶
Save new values to a specified dictionary in a module.
- Parameters:
kwargs (str) – The name of the dictionary to update in the module.
new_values (Dict[str, Any]) – The new key-value pairs to add to the dictionary.
- Raises:
ValueError – If the specified dictionary is not found in the module.
- graphtoolbox.utils.helper_functions.update_config(folder_config: str, kwargs: str, new_config: Dict[str, Any]) None[source][source]¶
Update a specified dictionary in a module with new configuration values.
- Parameters:
kwargs (str) – The name of the dictionary to update in the module.
new_config (Dict[str, Any]) – The new key-value pairs to update the dictionary with.
- Raises:
ValueError – If the specified dictionary is not found in the module.
- graphtoolbox.utils.helper_functions.parser_config(config: str) Dict[str, Any][source][source]¶
Parse a configuration string into a dictionary.
- Parameters:
config (str) – The configuration string, formatted as ‘{“key”: “value”, “key2”: “value2”,…}’.
- Returns:
The parsed dictionary.
- Return type:
Dict[str, Any]
Example
>>> parser_config('{"model_name": "GCN", "num_epochs": "100"}) {'model_name': 'GCN', 'num_epochs': 100}
- graphtoolbox.utils.helper_functions.change_cwd(target_directory: str | None = 'GraphToolbox', verbose: bool = False) None[source][source]¶
Change the current working directory to the specified directory by traversing up the directory tree until the target directory is found.
- Parameters:
target_directory (Optional[str]) – The target directory to change to. Defaults to “GraphToolbox”.
- Raises:
FileNotFoundError – If the target directory does not exist in the path hierarchy.
- graphtoolbox.utils.helper_functions.get_geodesic_distance(point_1, point_2) float[source][source]¶
Calculate the great circle distance (in km) between two points on the earth (specified in decimal degrees)