MCPcopy Index your code
hub / github.com/SkyworkAI/DeepResearchAgent / initialize

Method initialize

src/benchmark/leetcode.py:802–893  ·  view source on GitHub ↗

Initialize the benchmark by loading dataset, filtering finished tasks, and starting browser.

(self)

Source from the content-addressed store, hash-verified

800 self._queue_lock = asyncio.Lock() # 初始化队列锁
801
802 async def initialize(self):
803 """Initialize the benchmark by loading dataset, filtering finished tasks, and starting browser."""
804 try:
805 from src.data.leetcode import LeetCodeDataset
806 # 1. 加载数据集
807 dataset = LeetCodeDataset(
808 path=self.path,
809 split=self.split,
810 name=self.subset if self.subset else None
811 )
812 self._id_to_record_map = {}
813
814 # 获取原始数据记录
815 if hasattr(dataset, 'data'):
816 self._data_records = dataset.data.to_dict(orient="records")
817 else:
818 self._data_records = []
819
820 # ================= [新增逻辑:断点续跑过滤] =================
821
822 # A. 动态定位结果文件路径 (逻辑需与 CodeSubmitter 保持完全一致)
823 current_file_path = os.path.abspath(__file__)
824 project_root_name = "AgentWorld"
825
826 if project_root_name in current_file_path:
827 root_path = current_file_path.split(project_root_name)[0] + project_root_name
828 output_dir = os.path.join(
829 root_path,
830 "workdir", "tool_calling_agent", "benchmark", "leetcode"
831 )
832 else:
833 output_dir = os.path.join(os.getcwd(), "results")
834
835 # 固定文件名,不再带时间戳
836 result_file = os.path.join(output_dir, "results.jsonl")
837
838 # B. 读取已完成的任务 ID
839 finished_ids = set()
840 if os.path.exists(result_file):
841 logger.info(f"| 🔄 Found existing result file: {result_file}, checking for finished tasks...")
842 try:
843 with open(result_file, 'r', encoding='utf-8') as f:
844 for line in f:
845 line = line.strip()
846 if not line: continue
847 try:
848 record = json.loads(line)
849 if "task_id" in record:
850 finished_ids.add(str(record["task_id"]))
851 except json.JSONDecodeError:
852 continue
853 except Exception as e:
854 logger.warning(f"| ⚠️ Error reading result file for filtering: {e}")
855
856 # C. 过滤 self._data_records
857 original_count = len(self._data_records)
858 self._data_records = [
859 r for r in self._data_records

Callers

nothing calls this directly

Calls 11

LeetCodeDatasetClass · 0.90
setFunction · 0.85
joinMethod · 0.80
warningMethod · 0.80
to_dictMethod · 0.45
existsMethod · 0.45
infoMethod · 0.45
addMethod · 0.45
getMethod · 0.45
initializeMethod · 0.45
errorMethod · 0.45

Tested by

no test coverage detected