How to use the poap.strategy.PromiseStrategy function in POAP

To help you get started, we’ve selected a few POAP examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github dbindel / POAP / poap / strategy.py View on Github external
def blocking_evals(self, xs):
        "Request a list of function evaluations."
        promises = [self.promise_eval(x) for x in xs]
        return [p.value for p in promises]

    def terminate(self):
        "Request termination."
        logger.debug("PromiseStrategy queueing termination request")
        self.proposalq.put(self.propose_terminate())

    def _throw_terminate(self):
        logger.debug("Stop worker with RunTerminatedException")
        raise RunTerminatedException()


class ThreadStrategy(PromiseStrategy):
    """Event-driven to serial adapter using threads.

    The thread strategy runs a standard sequential optimization algorithm
    in a separate thread of control, with which the strategy communicates
    via promises.  The optimizer thread intercepts function evaluation requests
    and completion and turns them into proposals for the strategy, which
    it places in a proposal queue.  The optimizer then waits for the requested
    values (if any) to appear in the reply queue.

    Attributes:
        optimizer: Optimizer function (takes objective as an argument)
        proposalq: Queue of proposed actions caused by optimizer.
        valueq:    Queue of function values from proposed actions.
        thread:    Thread in which the optimizer runs.
        proposal:  Proposal that the strategy is currently requesting.
        rvalue:    Function mapping records to values