Utils Package¶
Class RootContext from the package pyzeal_util. This module defines a data container that holds the information necessary for a generic root finding algorithm to function.
Authors:
Philipp Schuette
- class pyzeal.utils.root_context.RootContext(f, df, container, precision, reRan=(-1.0, 1.0), imRan=(-1.0, 1.0), progress=None, task=None)[source]
Container for the data context of a root finding algorithm. The container is read-only.
- __delattr__(name)
Implement delattr(self, name).
- __eq__(other)
Return self==value.
- __hash__()
Return hash(self).
- __init__(f, df, container, precision, reRan=(-1.0, 1.0), imRan=(-1.0, 1.0), progress=None, task=None)
- __repr__()
Return repr(self).
- __setattr__(name, value)
Implement setattr(self, name, value).
- functionDataToString()[source]
Return a string describing the data stored by this object
- Returns:
str– Object data
- toFilterContext()[source]
Get a FilterContext object with the same parameters as this RootContext
- Returns:
FilterContext– FilterContext object with the same parameters as this RootContext
Class FilterContext from the package pyzeal_util. This module defines a data container that holds the information necessary for a generic root filter predicate to function.
Authors:
Philipp Schuette
- class pyzeal.utils.filter_context.FilterContext(f, reRan, imRan, precision, threshold=3)[source]
Container for the data context of a root filter predicate. The container is read-only.
- __delattr__(name)
Implement delattr(self, name).
- __eq__(other)
Return self==value.
- __hash__()
Return hash(self).
- __init__(f, reRan, imRan, precision, threshold=3)
- __repr__()
Return repr(self).
- __setattr__(name, value)
Implement setattr(self, name, value).
Protocol RootContainer from the package pyzeal_utils. This module defines an interface to container types which are meant to hold root data. The underlying strategy used in cases where e.g. almost identical roots are added or the precision of roots is changed between add operations is up to the concrete container implementation (and transparent to the user). Additional checks could also be implemented in subclasses, e.g. checking if a root is contained in a certain region.
Authors:
Philipp Schuette
- class pyzeal.utils.containers.root_container.RootContainer(*args, **kwargs)[source]
Structural interface for container classes meant to hold root data.
- addRoot(root, context)[source]
Add a root to the container.
- Parameters:
root (
Tuple[complex,int]) – the root to be added to the containercontext (
FilterContext) – the number of valid decimal places of root
- Return type:
None
- clear()[source]
Clear all data from the container.
- Return type:
None
- getRootOrders()[source]
Returns the orders of all roots currently held in this container as a vector which is parallel to the vector returned by getRoots.
- Returns:
ndarray[Any,dtype[int32]] – a vector of integer root orders (multiplicities)
- getRoots()[source]
Returns all roots currently held in this container as a vector.
- Returns:
ndarray[Any,dtype[complex128]] – a vector of complex roots
- registerFilter(filterPredicate, key)[source]
Add a new filter predicate to this container instance. The filtering applies to all roots added after the filter is registered. To guarantee a consistent set of roots any implementation should clear its internal root buffer before/after registering a filter.
- Parameters:
filterPredicate (
Callable[[Tuple[complex,int],FilterContext],bool]) – the predicate used to filter rootskey (
str) – a (unique) key under which the filter is registered
- Return type:
None
- removeRoot(root)[source]
Remove a root from the container and indicate whether or not a removal actually happened via the return value.
- Parameters:
root (
Tuple[complex,int]) – the root to be removed from the container- Returns:
bool– a boolean flag indicating if a removal happened
- unregisterFilter(key)[source]
Remove a previously registered filter by key.
- Parameters:
key (
str) – key value for the filter to remove- Return type:
None
Implementation RoundingContainer of the RootContainer protocol from the pyzeal_utils package. The concrete container class implemented here automatically rounds added roots to a fixed number of decimal places.
Authors:
Philipp Schuette
- class pyzeal.utils.containers.rounding_container.RoundingContainer(precision)[source]
This simple container implementation rounds every added root to a given number of decimal places and simple ignores any attempts to add additional roots which coincide with a previously added root after rounding. The multiplicity is not taken into account when comparing old and new roots. Changing the desired accuracy automatically removes all calculated roots to preserve consistency.
- __init__(precision)[source]
Initialize a rounding RootContainer. If no precision is given, default precision is used.
- Parameters:
precision (
Optional[Tuple[int,int]]) – expected accuracy of roots to be added
- addRoot(root, context)[source]
Add a new root with given accuracy to the container. If the accuracy differs from the accuracy of roots already added then all previous roots are removed.
- Parameters:
root (
Tuple[complex,int]) – the root to be added to the containercontext (
FilterContext) – the context of the new root, required for filtering
- Return type:
None
- clear()[source]
Clear the container by removing all roots.
- Return type:
None
- getRootOrders()[source]
Returns the orders of all roots currently held in this container as a vector which is parallel to the vector returned by getRoots.
- Returns:
ndarray[Any,dtype[int32]] – a vector of integer root orders (multiplicities)
- getRoots()[source]
Returns all roots currently held in this container as a vector.
- Returns:
ndarray[Any,dtype[complex128]] – a vector of complex roots
- registerFilter(filterPredicate, key)[source]
Register a new filter to check possible roots against
- Parameters:
filterPredicate (
Callable[[Tuple[complex,int],FilterContext],bool]) – New filter to registerkey (
str) – A key to identify this filter
- Return type:
None
- removeRoot(root)[source]
Remove a given root from the container. Return value indicates success.
- Parameters:
root (
Tuple[complex,int]) – the root to be removed from the container- Returns:
bool– a boolean flag indicating if a removal happened
- static roundRoot(root, precision)[source]
Round a given root to a given number of decimal places.
- Parameters:
root (
Tuple[complex,int]) – a root to be roundedprecision (
Tuple[int,int]) – the number of decimal places to round to
- Returns:
Tuple[complex,int] – the rounded root (multiplicity stays constant)
- unregisterFilter(key)[source]
Remove the filter identified by key.
- Parameters:
key (
str) – Filter key- Return type:
None
Implementation PlainContainer of the RootContainer protocol from the pyzeal_utils package. The concrete container class implemented here simply adds roots to an internal buffer without any further action. Its main use is the collection of potential roots in subprocesses during parallel calculations.
Authors:
Philipp Schuette
- class pyzeal.utils.containers.plain_container.PlainContainer(queue)[source]
Minimal container implementation. Simply adds roots to an internal buffer of type tQueue without any further action.
This class is mainly designed for application with a queue instance obtained from a multiprocessing.Manager. With this particular choice of root buffer it can serve as shared memory for several distinct processes each running their own instance of a FinderAlgorithm.
- __init__(queue)[source]
Initialize a new PlainContainer.
- Parameters:
queue (
Optional[tQueue]) – the internal buffer used for root storage
- addRoot(root, context)[source]
Add a new root to the internal buffer, ignoring the filter context.
- Parameters:
root (
Tuple[complex,int]) – the root to be added to the containercontext (
FilterContext) – the context of the new root, ignored
- Return type:
None
- clear()[source]
Plain containers cannot be cleared.
- Return type:
None
- getRootOrders()[source]
Returns the orders of all roots currently held in this container as a vector which is parallel to the vector returned by getRoots.
- Returns:
ndarray[Any,dtype[int32]] – a vector of integer root orders (multiplicities)
- getRoots()[source]
Returns all roots currently held in this container as a vector.
- Returns:
ndarray[Any,dtype[complex128]] – a vector of complex roots
- registerFilter(filterPredicate, key)[source]
Cannot register filters with an instance of PlainContainer.
- Parameters:
filterPredicate (
Callable[[Tuple[complex,int],FilterContext],bool]) – New filter to registerkey (
str) – A key to identify this filter
- Return type:
None
- removeRoot(root)[source]
Roots cannot be removed from a plain container.
- Parameters:
root (
Tuple[complex,int]) – the root to be removed from the container- Returns:
bool– always returns False
- unregisterFilter(key)[source]
Cannot unregister filters with an instance of PlainContainer.
- Parameters:
key (
str) – Filter key- Return type:
None
Module service_locator.py from the package PyZEAL. This module provides a way to register and locate services used throughout the project, to enable loading additional services for the plugin system.
Authors:
Philipp Schuette
- class pyzeal.utils.service_locator.ServiceLocator[source]
Static locator class used to add and resolve services.
- static clearConfigurations()[source]
Clear all service locator configurations, unsealing the locator in the process.
- Return type:
None
- static isSealed()[source]
Return True if the service locator is sealed.
- Returns:
bool– True if the service locator is sealed.
- static registerAsSingleton(serviceType, instance)[source]
Register service instance as a singleton service, meaning only one instance exists.
- Parameters:
serviceType (
Type[TypeVar(T)]) – Type of serviceinstance (
TypeVar(T)) – Service instance
- Raises:
ValueError – If the service locator is sealed, no new services can be registered.
InvalidServiceConfiguration – Given instance must implement the given type
- Returns:
Type[ServiceLocator] – Return the static ServiceLocator for method chaining
- static registerAsTransient(serviceType, factory)[source]
Register a transient service. Note that you MUST implement a (dummy) default constructor if you want to register a class without constructor as an instance factory and that class inherits from typing.Protocol.
- Parameters:
serviceType (
Type[TypeVar(T)]) – Type of service to register.factory (
Callable[...,TypeVar(T)]) – Factory for the given service
- Raises:
ValueError – If the service locator is sealed, no new services can be registered.
- Returns:
Type[ServiceLocator] – Return the static ServiceLocator for method chaining
- static seal()[source]
Seal the service locator to prevent additional services from being registered.
- Raises:
ValueError – Raises an exception if the service locator has already been sealed.
- Return type:
None
- static tryResolve(serviceType, **kwargs)[source]
Try to resolve the requested service type by first searching registered singleton and then registered transient configurations.
- Parameters:
serviceType (
Type[TypeVar(T)]) – Type of service to resolve- Raises:
InvalidServiceConfiguration – If the given serviceType can not be resolved, an exception is raised
- Returns:
TypeVar(T) – An instance of the given service. If the service is transient, the factory is called with the parameters given by **kwargs.
Class FinderProgressBar from the package pyzeal_utils. This module defines a progress bar used for command line display of the progress a running root finding algorithm has made.
Authors:
Philipp Schuette
- class pyzeal.utils.finder_progress.FinderProgressBar[source]
This class is a very specialized subtype of the general rich.Progress type representing a very customizable command line displayed progress bar.
- __init__()[source]
Initialize a root finder specific progress bar with fixed defaults.
- addTask(total)[source]
Override the add_task() method of generic progress bars by allowing only the total amount of work to be adjusted and prescribing a default task description.
- Parameters:
total (
float) – the total amount of work contained in the added task- Return type:
NewType(TaskID,int)