Package utilities#

exception pysolver_view.pysolver_utilities.DictionaryValidationError(message, key=None, value=None)[source]#

Bases: Exception

Exception raised for errors in the configuration options.

pysolver_view.pysolver_utilities.create_logger(name, path=None, use_datetime=True, to_console=False)[source]#

Creates and configures a logging object for recording logs during program execution.

Parameters:
namestr

Name of the log file. Allows for differentiation when analyzing logs from different components or runs of a program.

pathstr, optional

Specifies the directory where the log files will be saved. By default, a directory named “logs” will be created in the current working directory (cwd).

use_datetimebool, optional

Determines whether the log filename should have a unique datetime identifier appended. Default is True.

to_consolebool, optional

Whether to print log messages to the console. Default is True.

Returns:
loggerobject

Configured logger object.

Notes

  • By default, the function sets the log level to INFO, which means the logger will handle messages of level INFO and above (like ERROR, WARNING, etc.). The log entries will contain the timestamp, log level, and the actual log message.

  • When use_datetime=True, each log file will have a unique datetime identifier. This ensures traceability, avoids overwriting previous logs, allows chronological ordering of log files, and handles concurrency in multi-instance environments.

pysolver_view.pysolver_utilities.print_dict(data, indent=0, return_output=False)[source]#

Recursively prints nested dictionaries with indentation or returns the formatted string.

Parameters:
datadict

The dictionary to print.

indentint, optional

The initial level of indentation for the keys of the dictionary, by default 0.

return_outputbool, optional

If True, returns the formatted string instead of printing it.

Returns:
str or None

The formatted string representation of the dictionary if return_output is True, otherwise None.

pysolver_view.pysolver_utilities.print_installed_fonts()[source]#

Print the list of fonts installed on the system.

This function identifies and prints all available fonts for use in Matplotlib.

pysolver_view.pysolver_utilities.print_object(obj)[source]#

Prints all attributes and methods of an object, sorted alphabetically.

  • Methods are identified as callable and printed with the prefix ‘Method: ‘.

  • Attributes are identified as non-callable and printed with the prefix ‘Attribute: ‘.

Parameters:
objobject

The object whose attributes and methods are to be printed.

Returns:
None

This function does not return any value. It prints the attributes and methods of the given object.

pysolver_view.pysolver_utilities.print_rc_parameters(filename=None)[source]#

Print the current rcParams used by Matplotlib or write to file if provided.

This function provides a quick overview of the active configuration parameters within Matplotlib.

pysolver_view.pysolver_utilities.savefig_in_formats(fig, path_without_extension, formats=['.png', '.svg'], dpi=500)[source]#

Save a given Matplotlib figure in multiple file formats.

Parameters:
figmatplotlib.figure.Figure

The figure object to be saved.

path_without_extensionstr

The full path to save the figure excluding the file extension.

formatslist of str, optional

A list of string file extensions to specify which formats the figure should be saved in. Supported formats are [‘.png’, ‘.svg’, ‘.pdf’, ‘.eps’]. Default is [‘.png’, ‘.svg’].

dpiint, optional

The resolution in dots per inch with which to save the image. This parameter affects only PNG files. Default is 500.

Examples

>>> import matplotlib.pyplot as plt
>>> fig, ax = plt.subplots()
>>> ax.plot([0, 1], [0, 1])
>>> save_fig_in_formats(fig, "/path/to/figure/filename")

This will save the figure as “filename.png”, “filename.svg”, and “filename.pdf” in the “/path/to/figure/” directory.

pysolver_view.pysolver_utilities.set_plot_options(fontsize=13, grid=False, major_ticks=True, minor_ticks=True, margin=0.05, color_order='matlab', linewidth=1.25)[source]#

Set options for creating publication-quality figures using Matplotlib.

This function updates the internal Matplotlib settings to better align with standards for publication-quality figures. Features include improved font selections, tick marks, grid appearance, and color selections.

Parameters:
fontsizeint, optional

Font size for text elements in the plot. Default is 13.

gridbool, optional

Whether to show grid lines on the plot. Default is True.

major_ticksbool, optional

Whether to show major ticks. Default is True.

minor_ticksbool, optional

Whether to show minor ticks. Default is True.

marginfloat, optional

Margin size for axes. Default is 0.05.

color_orderstr, optional

Color order to be used for plot lines. Options include “python” and “matlab”. Default is “matlab”.

pysolver_view.pysolver_utilities.validate_keys(checked_dict, required_keys, allowed_keys=None)[source]#

Validate the presence of required keys and check for any unexpected keys in a dictionary.

Give required keys and allowed keys to have complete control Give required keys twice to check that the list of keys is necessary and sufficient Give only required keys to allow all extra additional key

Parameters:
checked_dictdict

The dictionary to be checked.

required_keysset

A set of keys that are required in the dictionary.

allowed_keysset

A set of keys that are allowed in the dictionary.

Raises:
ConfigurationError

If either required keys are missing or unexpected keys are found.