o  iB @sjddlmZddlZddlmZddlmZmZddlm Z gdZ ddddZ dddZ dddZ dS)) annotationsN) BundleAlgo)algo_from_picklealgo_to_pickle)AlgoKeys)import_bundle_algo_historyexport_bundle_algo_historyget_name_from_algo_id.T output_folderstr template_path str | None only_trainedboolreturnlistc Csg}tt|D]\}tj||}tj|sq tj|d}tj|s'q t||d\}}|t j d} | durJz| } Wn t yIYnw| du} |rR| sT|se| t j|t j|t j | t j| iq |S)a import the history of the bundleAlgo objects as a list of algo dicts. each algo_dict has keys name (folder name), algo (bundleAlgo), is_trained (bool), Args: output_folder: the root path of the algorithms templates. template_path: the algorithm_template. It must contain algo.py in the follow path: ``{algorithm_templates_dir}/{network}/scripts/algo.py``. only_trained: only read the algo history if the algo is trained. zalgo_object.pklr N)sortedoslistdirpathjoinisdirisfilergetrSCORE get_score BaseExceptionappendIDALGO IS_TRAINED) r r rhistorynameZ write_path obj_filenamealgoalgo_meta_data best_metric is_trainedr*\/home/dell461/cl/sdc2/last_ska_mid/HISourceFinder-master-l/src/monai/apps/auto3dseg/utils.pyrs.     rr#list[dict[str, BundleAlgo]]NonecCs&|D]}|tj}t||jdqdS)z Save all the BundleAlgo in the history to algo_object.pkl in each individual folder Args: history: a List of Bundle. Typically, the history can be obtained from BundleGen get_history method rN)rr!rr )r# algo_dictr&r*r*r+rDs ridcCs|ddS)z Get the name of Algo from the identifier of the Algo. Args: id: identifier which follows a convention of "name_fold_other". Returns: name of the Algo. _r)split)r/r*r*r+r Ps r )r NT)r r r rrrrr)r#r,rr-)r/r rr ) __future__rrmonai.apps.auto3dseg.bundle_genrmonai.auto3dsegrrmonai.utils.enumsr__all__rrr r*r*r*r+s    -