<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def flush(self):
 """Force the queue of Primitives to compile, execute on the Controller, and fulfill promises with the data returned."""

        self.stages = []
        self.stagenames = []

        if not self.queue:
            return

        if self.print_statistics:#pragma: no cover
            print("LEN OF QUENE", len(self))
            t = time()

        if self._chain._collect_compiler_artifacts:
            self._compile(debug=True, stages=self.stages,
                          stagenames=self.stagenames)
        else:
            self._compile()

        if self.debug:
            print("ABOUT TO EXEC", self.queue)#pragma: no cover

        if self.print_statistics:#pragma: no cover
            print("COMPILE TIME", time()-t)
            print("TOTAL BITS OF ALL PRIMS", sum(
                (p.count for p in self.queue if hasattr(p, 'count'))))
            t = time()

        self._chain._controller._execute_primitives(self.queue)

        if self.print_statistics:
            print("EXECUTE TIME", time()-t)#pragma: no cover

        self.queue = []
        self._chain._sm.state = self._fsm.state