a
    ƹDf)                     @   s0   d Z ddgZG dd deZG dd deZdS )a}  
This module contains the base classes for pathos pool and pipe objects,
and describes the map and pipe interfaces.  A pipe is defined as a
connection between two 'nodes', where a node is something that does
work.  A pipe may be a one-way or two-way connection.  A map is defined
as a one-to-many connection between nodes.  In both map and pipe
connections, results from the connected nodes can be returned to the
calling node.  There are several variants of pipe and map, such as
whether the connection is blocking, or ordered, or asynchronous.  For
pipes, derived methods must overwrite the 'pipe' method, while maps
must overwrite the 'map' method.  Pipes and maps are available from
worker pool objects, where the work is done by any of the workers
in the pool.  For more specific point-to-point connections (such as
a pipe between two specific compute nodes), use the pipe object
directly.


Usage
=====

A typical call to a pathos map will roughly follow this example:

    >>> # instantiate and configure the worker pool
    >>> from pathos.pools import ProcessPool
    >>> pool = ProcessPool(nodes=4)
    >>>
    >>> # do a blocking map on the chosen function
    >>> results = pool.map(pow, [1,2,3,4], [5,6,7,8])
    >>>
    >>> # do a non-blocking map, then extract the results from the iterator
    >>> results = pool.imap(pow, [1,2,3,4], [5,6,7,8])
    >>> print("...")
    >>> results = list(results)
    >>>
    >>> # do an asynchronous map, then get the results
    >>> results = pool.amap(pow, [1,2,3,4], [5,6,7,8])
    >>> while not results.ready():
    ...     time.sleep(5); print(".", end=' ')
    ...
    >>> results = results.get()


Notes
=====

Each of the pathos worker pools rely on a different transport protocol
(e.g. threads, multiprocessing, etc), where the use of each pool comes
with a few caveats.  See the usage documentation and examples for each
worker pool for more information.

AbstractPipeConnectionAbstractWorkerPoolc                   @   s    e Zd ZdZdd Zdd ZdS )r   z9
AbstractPipeConnection base class for pathos pipes.
    c                 O   s   t |  dS )z}
Required input:
    ???

Additional inputs:
    ???

Important class members:
    ???

Other class members:
    ???
        N)object__init__selfargskwds r	   e/nfs/NAS7/SABIOD/METHODE/ermites/ermites_venv/lib/python3.9/site-packages/pathos/abstract_launcher.pyr   A   s    
zAbstractPipeConnection.__init__c                 C   s   d| j j S )Nz	<pipe %s>	__class____name__r   r	   r	   r
   __repr__Q   s    zAbstractPipeConnection.__repr__N)r   
__module____qualname____doc__r   r   r	   r	   r	   r
   r   =   s   c                   @   s   e Zd ZdZdZdd Zdd Zdd Zd	d
 Zdd Z	dd Z
dd Zdd Zdd Zdd Zdd Zdd Zdd Zdd Zdd  Zd!d" Zd#d$ Zd%d& Zd'S )(r   z5
AbstractWorkerPool base class for pathos pools.
       c                 O   s,   t |  | j|i | |dd| _dS )a  
Important class members:
    nodes	- number (and potentially description) of workers
    ncpus       - number of worker processors
    servers     - list of worker servers
    scheduler   - the associated scheduler
    workdir     - associated $WORKDIR for scratch calculations/files

Other class members:
    scatter     - True, if uses 'scatter-gather' (instead of 'worker-pool')
    source      - False, if minimal use of TemporaryFiles is desired
    timeout	- number of seconds to wait for return value from scheduler
        idN)r   r   _AbstractWorkerPool__initgetZ_idr   r	   r	   r
   r   \   s    
zAbstractWorkerPool.__init__c                 C   s   | S Nr	   r   r	   r	   r
   	__enter__n   s    zAbstractWorkerPool.__enter__c                 G   s   d S r   r	   )r   r   r	   r	   r
   __exit__p   s    zAbstractWorkerPool.__exit__c                 O   sn   t |r>z|d }d}t|W qL ty:   |d }Y qL0 n|d| j}z
|| _W n tyh   Y n0 dS )z+default filter for __init__ inputs
        nodesz0got multiple values for keyword argument 'nodes'    N)len	TypeErrorKeyErrorr   _AbstractWorkerPool__nodesr   )r   r   r   r   msgr	   r	   r
   Z__inits   s    zAbstractWorkerPool.__initc                 O   s2   |rz|d g}W n t y,   tdY n0 dS )z&default filter for map inputs
        r   z map() requires at least two argsN
IndexErrorr   r   fr   r   Zargzr	   r	   r
   Z__map   s    zAbstractWorkerPool.__mapc                 O   s2   |rz|d g}W n t y,   tdY n0 dS )z'default filter for imap inputs
        r   z'imap() must have at least two argumentsNr!   r#   r	   r	   r
   Z__imap   s    zAbstractWorkerPool.__imapc                 O   s   |rz|j j}t|j}t|}|| }||krX||krXtd| t|t|f nV||krtd| t|t|f n.||| k rtd| t|| t|f W n   Y n0 dS )z'default filter for pipe inputs
        z-%s() takes at exactly %s arguments (%s given)z*%s() takes at most %s arguments (%s given)z+%s() takes at least %s arguments (%s given)N)__code__co_argcountr   __defaults__r   r   str)r   r$   r   r   varsZdefsZarglenZminlenr	   r	   r
   Z__pipe   s    
  &zAbstractWorkerPool.__pipec                 O   s   t dS )z4Create a new server if one isn't already initializedNNotImplementedErrorr   r	   r	   r
   _serve   s    zAbstractWorkerPool._servec                 C   s   t dS )z!Remove server with matching stateNr*   r   r	   r	   r
   clear   s    zAbstractWorkerPool.clearc                 O   s   t dS )a  run a batch of jobs with a blocking and ordered map

Returns a list of results of applying the function f to the items of
the argument sequence(s). If more than one sequence is given, the
function is called with an argument list consisting of the corresponding
item of each sequence. Some maps accept the `chunksize` keyword, which
causes the sequence to be split into tasks of approximately the given size.
        Nr*   r   r$   r   r   r	   r	   r
   map   s    
zAbstractWorkerPool.mapc                 O   s   t dS )a  run a batch of jobs with a non-blocking and ordered map

Returns a list iterator of results of applying the function f to the items
of the argument sequence(s). If more than one sequence is given, the
function is called with an argument list consisting of the corresponding
item of each sequence. Some maps accept the `chunksize` keyword, which
causes the sequence to be split into tasks of approximately the given size.
        Nr*   r.   r	   r	   r
   imap   s    
zAbstractWorkerPool.imapc                 O   s   t dS )a  run a batch of jobs with a non-blocking and unordered map

Returns a list iterator of results of applying the function f to the items
of the argument sequence(s). If more than one sequence is given, the
function is called with an argument list consisting of the corresponding
item of each sequence. The order of the resulting sequence is not guaranteed.
Some maps accept the `chunksize` keyword, which causes the sequence to be
split into tasks of approximately the given size.
        Nr*   r.   r	   r	   r
   uimap   s    zAbstractWorkerPool.uimapc                 O   s   t dS )a  run a batch of jobs with an asynchronous map

Returns a results object which containts the results of applying the
function f to the items of the argument sequence(s). If more than one
sequence is given, the function is called with an argument list consisting
of the corresponding item of each sequence. To retrieve the results, call
the get() method on the returned results object. The call to get() is
blocking, until all results are retrieved. Use the ready() method on the
result object to check if all results are ready. Some maps accept the
`chunksize` keyword, which causes the sequence to be split into tasks of
approximately the given size.
        Nr*   r.   r	   r	   r
   amap   s    zAbstractWorkerPool.amapc                 O   s   t dS )zsubmit a job and block until results are available

Returns result of calling the function f on a selected worker.  This function
will block until results are available.
        Nr*   r.   r	   r	   r
   pipe   s    zAbstractWorkerPool.pipec                 O   s   t dS )ao  submit a job asynchronously to a queue

Returns a results object which containts the result of calling the
function f on a selected worker. To retrieve the results, call the
get() method on the returned results object. The call to get() is
blocking, until the result is available. Use the ready() method on the
results object to check if the result is ready.
        Nr*   r.   r	   r	   r
   apipe   s    
zAbstractWorkerPool.apipec                 C   s   d| j j S )Nz<pool %s()>r   r   r	   r	   r
   r     s    zAbstractWorkerPool.__repr__c                 C   s   | j S )z#get the number of nodes in the pool)r   r   r	   r	   r
   Z__get_nodes  s    zAbstractWorkerPool.__get_nodesc                 C   s   t ddS )z#set the number of nodes in the poolznodes is a read-only attributeN)r   )r   r   r	   r	   r
   Z__set_nodes
  s    zAbstractWorkerPool.__set_nodesN)r   r   r   r   r   r   r   r   r   Z_AbstractWorkerPool__mapZ_AbstractWorkerPool__imapZ_AbstractWorkerPool__piper,   r-   r/   r0   r1   r2   r3   r4   r   Z_AbstractWorkerPool__get_nodesZ_AbstractWorkerPool__set_nodesr	   r	   r	   r
   r   W   s*   N)r   __all__r   r   r   r	   r	   r	   r
   <module>   s   3