B _@s~ddddddgZddlZddlmZGd ddeejZd dZGd ddeZ Gd dde Z e d dZ Gddde Z dS)ActionManagerError ActionHandleAsynchronousActionManager ActionStatusFailedActionHandlesolve_all_instancesN) itervaluesc@s(eZdZdZdZdZdZdZddZdS) rdoneerrorqueued executingunknowncCs|jS)N)value)selfr>/tmp/pip-unpacked-wheel-d4p3hk07/pyomo/opt/parallel/manager.py__str__szActionStatus.__str__N) __name__ __module__ __qualname__r r r r r rrrrrrs cKs|j||f|dS)zL A simple utility to apply a solver to a list of problem instances. N)Z solve_all)Zsolver_managerZsolverZ instanceskwdsrrrr sc@seZdZdZddZdS)rzI An exception used when an error occurs within an ActionManager. cOstj|f||dS)N) Exception__init__)rargsZkargsrrrr+szActionManagerError.__init__N)rrr__doc__rrrrrr&sc@sJeZdZdZdddZddZdd Zd d Zd d ZddZ ddZ dS)rrFcCs4|r d|_ntj|_tjd7_tj|_||_dS) ConstructorN)idr id_counterrr status explanation)rr r"rrrr2s zActionHandle.__init__cCs|j|_|j|_dS)z2 Update the contents of the provided ActionHandle N)rr!)rahrrrupdate<szActionHandle.updatecCs |j|jkS)N)r)rotherrrr__lt__AszActionHandle.__lt__cCs |jS)N)r__hash__)rrrrr'DszActionHandle.__hash__cCs*|j|jko(|j|ko(|j|jkS)N) __class__rr')rr%rrr__eq__Gs zActionHandle.__eq__cCs || S)N)r))rr%rrr__ne__LszActionHandle.__ne__cCs t|jS)N)strr)rrrrrOszActionHandle.__str__N)Fr) rrrr rr$r&r'r)r*rrrrrr.s T)r c@sxeZdZeddZddZddZddZd d Zd d Z d dZ ddZ ddZ ddZ ddZddZddZdS)rcGst}t|dkrx~|D]v}t|tkr4||qt|ttttfkr~xD|D]*}t|tk rntdt |||qNWqtdt |qW|S)NrzBad argument type %s) setlentyperaddlisttupledictrr+)rahsitemr#rrr_flattenWs      z"AsynchronousActionManager._flattencCs |dS)rN)clear)rrrrrgsz"AsynchronousActionManager.__init__cCsi|_i|_d|_dS)z% Clear manager state rN) event_handleresultsqueued_action_counter)rrrrr6kszAsynchronousActionManager.clearcOs*|j||}||}|dkr&td|S)z2 Synchronously execute an action. Nz6Problem executing an event. No results are available.)queuewait_forr)rrrr#r8rrrexecutess   z!AsynchronousActionManager.executecOs:t}||j|j<tj|_|jd7_|j|f||S)zD Queue an action, returning an ActionHandle object. r)rr7rrr r!r9_perform_queue)rrrr#rrrr:~s  zAsynchronousActionManager.queuecGs`t}t|dkr.|ddt|jDn |j|}x"t|dkrZ|}||q:WdS)a Wait for all actions to complete. The arguments to this method are expected to be ActionHandle objects or iterators that return ActionHandle objects. If no arguments are provided, then this method will terminate after all queued actions are rcss|]}|jtjkr|VqdS)N)r!rr ).0r#rrr sz5AsynchronousActionManager.wait_all..N)r,r-r$rr7r5wait_anydiscard)rrr3r#rrrwait_alls   z"AsynchronousActionManager.wait_allcGsd}t|r2|j|}d}x,||kr.|}qWnx|dkrF|}q4W|tkrT|S|jd8_|j|j||j|jS)z Wait for any action (or any of the specified actions) to complete, and return the corresponding ActionHandle. Nr)r-r5_perform_wait_anyrr9r7rr$)rrr#r3rrrr@s    z"AsynchronousActionManager.wait_anycCsB|}x.||kr6|}|tkr td||jfq W||S)z< Wait for the specified action to complete. zAction %s failed: %s)r@rrr" get_results)rr#tmprrrr;s z"AsynchronousActionManager.wait_forcCs|jS)z6 Return the number of queued actions. )r9)rrrr num_queuedsz$AsynchronousActionManager.num_queuedcCs|jS)z8 Return the status of the ActionHandle. )r!)rr#rrr get_statussz$AsynchronousActionManager.get_statuscCs*|j|jkr&|j|j}|j|j=|SdS)zc Return solver results. If solver results are not available, return None. N)rr8)rr#resultrrrrDs    z%AsynchronousActionManager.get_resultscOs tddS)z Perform the queue operation. This method returns the ActionHandle, and the ActionHandle status indicates whether the queue was successful. z(The _perform_queue method is not definedN)r)rr#rrrrrr=sz(AsynchronousActionManager._perform_queuecCs tddS)a@ Perform the wait_any operation. This method returns an ActionHandle with the results of waiting. If None is returned then the ActionManager assumes that it can call this method again. Note that an ActionHandle can be returned with a dummy value, to indicate an error. z+The _perform_wait_any method is not definedN)r)rrrrrCsz+AsynchronousActionManager._perform_wait_anyN)rrr staticmethodr5rr6r<r:rBr@r;rFrGrDr=rCrrrrrUs    )__all__enumsixrr+Enumrrrrobjectrrrrrrr s %