Example #1
0
    def next(self, state, **runopts):
        runopts.update(racing_context=True)
        futures = [
            branch.run(state.updated(), **runopts) for branch in self.branches
        ]

        # as soon as one is done, stop all others
        done, _ = concurrent.futures.wait(
            futures, return_when=concurrent.futures.FIRST_COMPLETED)

        logger.trace(
            "RacingBranches done set: {}. Stopping remaining.".format(done))
        self.stop()

        # debug info
        idx = futures.index(done.pop())
        branch = self.branches[idx]
        logger.debug("{name} won idx={idx} branch={branch!r}".format(
            name=self.name, idx=idx, branch=branch))

        # collect resolved states (in original order, not completion order!)
        states = States()
        for f in futures:
            states.append(f.result())

        return states
Example #2
0
    def next(self, state):
        """Execute one blocking iteration of an instantiated :class:`RacingBranches`."""

        futures = [branch.run(state.updated()) for branch in self.branches]

        states = States()
        if self.endomorphic:
            states.append(state)

        # as soon as one is done, stop all others
        done, _ = concurrent.futures.wait(
            futures,
            return_when=concurrent.futures.FIRST_COMPLETED)
        self.stop()

        # debug info
        idx = futures.index(done.pop())
        branch = self.branches[idx]
        logger.debug("{name} won idx={idx} branch={branch!r}".format(
            name=self.name, idx=idx, branch=branch))

        # collect resolved states (in original order, not completion order!)
        for f in futures:
            states.append(f.result())

        return states
Example #3
0
    def next(self, state):
        output = States()

        while True:
            try:
                state = self.runnable.run(state).result()
                output.append(state)
            except EndOfStream:
                break

        return output
Example #4
0
    def next(self, state, **runopts):
        samples = state.samples
        if not samples:
            raise ValueError("no input samples")

        states = States()
        n = len(samples)
        for start, stop in zip(range(n), range(1, n + 1)):
            sample = samples.slice(start, stop, sorted_by=None)
            states.append(state.updated(samples=sample))

        return states
Example #5
0
    def next(self, state, **runopts):
        output = States()
        runopts.update(executor=immediate_executor, silent_rewind=False)

        while True:
            try:
                state = self.runnable.run(state, **runopts).result()
                output.append(state)
            except EndOfStream:
                break

        return output
    def next(self, state, **runopts):
        futures = [
            branch.run(state.updated(), **runopts) for branch in self.branches
        ]

        # wait for all branches to finish
        concurrent.futures.wait(futures,
                                return_when=concurrent.futures.ALL_COMPLETED)

        # collect resolved states (in original order, not completion order)
        states = States()
        for f in futures:
            states.append(f.result())

        return states
Example #7
0
    def next(self, state, **runopts):
        output = States()
        runopts.update(executor=immediate_executor, silent_rewind=False)

        logger.debug("{} unwinding {!r}".format(self.name, self.runnable))

        while True:
            try:
                state = self.runnable.run(state, **runopts).result()
                output.append(state)
            except EndOfStream:
                break

        logger.debug("{} collected {} states".format(self.name, len(output)))

        return output
Example #8
0
    def next(self, states, **runopts):
        futures = [
            branch.run(state.updated(), **runopts)
            for branch, state in zip(self.branches, states)
        ]

        logger.debug("{} running {} branches in parallel".format(
            self.name, len(futures)))

        # wait for all branches to finish
        concurrent.futures.wait(futures,
                                return_when=concurrent.futures.ALL_COMPLETED)

        # collect resolved states (in original order, not completion order)
        states = States()
        for f in futures:
            states.append(f.result())

        return states