quvac.utils

Useful generic utilities.

Functions

read_yaml(yaml_file)

Read a YAML file and return its contents.

write_yaml(yaml_file, data)

Write data to a YAML file.

format_time(seconds)

Format time in seconds to a human-readable string.

format_memory(mem)

Format memory in kilobytes to a human-readable string.

save_wisdom(ini_file[, wisdom_file, add_host_name])

Save FFTW wisdom to a file.

load_wisdom(wisdom_file)

Load FFTW wisdom from a file.

get_maxrss()

Get the maximum resident set size used (in kilobytes).

zip_directory_shutil(directory_path, output_path)

Zip a directory using shutil.

find_classes_in_package(package_name)

Find all class names in a given package.

round_to_n(x, n)

Round up to n significant digits.

size_to_Gb(size)

Convert the size of float64 array to GBs.

estimate_max_required_memory(size[, memory_buffer])

Estimate max requred memory based on the grid size.

estimate_memory_usage(ini_file[, memory_buffer])

Estimate potential memory usage for a given ini file.

free_memory()

Module Contents

quvac.utils.read_yaml(yaml_file)[source]

Read a YAML file and return its contents.

Parameters:

yaml_file (str) – Path to the YAML file.

Returns:

Contents of the YAML file.

Return type:

dict

quvac.utils.write_yaml(yaml_file, data)[source]

Write data to a YAML file.

Parameters:
  • yaml_file (str) – Path to the YAML file.

  • data (dict) – Data to write to the YAML file.

quvac.utils.format_time(seconds)[source]

Format time in seconds to a human-readable string.

Parameters:

seconds (float) – Time in seconds.

Returns:

Formatted time string.

Return type:

str

quvac.utils.format_memory(mem)[source]

Format memory in kilobytes to a human-readable string.

Parameters:

mem (float) – Memory in kilobytes.

Returns:

Formatted memory string.

Return type:

str

quvac.utils.save_wisdom(ini_file, wisdom_file=None, add_host_name=False)[source]

Save FFTW wisdom to a file.

Parameters:
  • ini_file (str) – Path to the initialization file.

  • wisdom_file (str, optional) – Path to save the FFTW wisdom, by default None.

  • add_host_name (bool, optional) – Whether to add the host name to the wisdom file name, by default False.

quvac.utils.load_wisdom(wisdom_file)[source]

Load FFTW wisdom from a file.

Parameters:

wisdom_file (str) – Path to the FFTW wisdom file.

Returns:

FFTW wisdom.

Return type:

tuple

quvac.utils.get_maxrss()[source]

Get the maximum resident set size used (in kilobytes).

Returns:

Maximum resident set size used.

Return type:

int

quvac.utils.zip_directory_shutil(directory_path, output_path)[source]

Zip a directory using shutil.

Parameters:
  • directory_path (str) – Path to the directory to zip.

  • output_path (str) – Path to save the zipped directory.

quvac.utils.find_classes_in_package(package_name)[source]

Find all class names in a given package.

Parameters:

package_name (str) – Name of the package.

Returns:

List of class names in the package.

Return type:

list of str

quvac.utils.round_to_n(x, n)[source]

Round up to n significant digits.

Parameters:
  • x (int or float) – Number to round up.

  • n (int) – Number of digits to round up to.

Returns:

Rounded number.

Return type:

int or float

quvac.utils.size_to_Gb(size)[source]

Convert the size of float64 array to GBs.

quvac.utils.estimate_max_required_memory(size, memory_buffer=10)[source]

Estimate max requred memory based on the grid size.

quvac.utils.estimate_memory_usage(ini_file, memory_buffer=10)[source]

Estimate potential memory usage for a given ini file.

Parameters:

ini_file (str) – Path to the initialization file

Returns:

Required memory in format ‘<number>GB’.

Return type:

str

quvac.utils.free_memory()[source]