def getProgsAndUnkSortWithUniqueNames(self, progs):
        res = []
        for prog in progs:
            assert (not ASTUtils.isOpen(prog))

            unkSortMap = {}
            if ASTUtils.hasUnk(prog):
                prog = self._giveUniqueNamesToUnks(prog)
                unkSortMap = ASTUtils.getUnkNameSortMap(prog)

            res.append((prog, unkSortMap))

        return res
示例#2
0
 def update_library(self, lib: FnLibrary,
                    task_result_single: TaskResultSingle, taskid):
     if self.seq_settings.update_library:
         # Add learned modules to the library
         top_solution = task_result_single.get_top_solution_details()
         if top_solution is not None:
             prog, resDict = top_solution
             unk_sort_map: Dict[str,
                                PPSort] = ASTUtils.getUnkNameSortMap(prog)
             lib_items = [
                 PPLibItem(unk, unk_sort, resDict['new_fns_dict'][unk])
                 for unk, unk_sort in unk_sort_map.items()
             ]
             if lib_items.__len__() > 0:
                 lib.addItems(lib_items)
             # Save the library.
             lib.save1(self.getLibLocation(), taskid)
示例#3
0
    def genProgs(self) -> Iterable[Tuple[PPTerm, Dict[str, PPSort]]]:
        for prog in self.genTerms():
            if self.isOpen(prog):
                continue

            if self.concreteTypes:
                maxSortVarsToBeInstantiated = 2
                eprogs = instantiateSortVar(prog, self.concreteTypes,
                                            maxSortVarsToBeInstantiated)
            else:
                eprogs = [prog]

            for eprog in eprogs:
                unkSortMap = {}
                if self.hasUnk(eprog):
                    eprog = self._giveUniqueNamesToUnks(eprog)
                    unkSortMap = ASTUtils.getUnkNameSortMap(eprog)

                yield eprog, unkSortMap