MCPcopy Create free account
hub / github.com/InternScience/InternAgent / run_experiment

Function run_experiment

internagent/experiments_utils_claude.py:147–304  ·  view source on GitHub ↗

Run experiment with the code in the folder Args: folder_name: The folder containing the code run_num: The run number timeout: Maximum execution time in seconds gpu_ids: GPU IDs to use (string like "0,1" or None for CPU) log_file: Optional file object

(folder_name, run_num, timeout=None, gpu_ids=None, log_file=None, task_type='auto')

Source from the content-addressed store, hash-verified

145 return result.stdout
146
147def run_experiment(folder_name, run_num, timeout=None, gpu_ids=None, log_file=None, task_type='auto'):
148 """
149 Run experiment with the code in the folder
150
151 Args:
152 folder_name: The folder containing the code
153 run_num: The run number
154 timeout: Maximum execution time in seconds
155 gpu_ids: GPU IDs to use (string like "0,1" or None for CPU)
156 log_file: Optional file object to write logs to
157
158 Returns:
159 Tuple of (return_code, next_prompt, traceback, message)
160 """
161 def log_message(msg):
162 """Write message to both stdout and log file"""
163 print(msg)
164 sys.stdout.flush()
165 if log_file:
166 try:
167 log_file.write(msg + "\n")
168 log_file.flush()
169 except (ValueError, OSError):
170 pass
171
172 timestamp = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
173 logger.info(f"[{timestamp}] Starting experiment run {run_num} in {folder_name}")
174
175 cwd = osp.abspath(folder_name)
176 # Create run directory
177 run_dir = osp.join(cwd, f"run_{run_num}")
178 if not osp.exists(run_dir):
179 os.makedirs(run_dir, exist_ok=True)
180
181 # Copy all files from the main folder to the run directory
182 logger.info(f"Copying files to run directory: {run_dir}")
183 for item in os.listdir(cwd):
184 if item.startswith("run_") or item == ".git":
185 continue
186 src = osp.join(cwd, item)
187 dst = osp.join(run_dir, item)
188 if osp.isdir(src):
189 if task_type == 'sci' and item in SCI_SYMLINK_DIRS:
190 if osp.exists(dst) or osp.islink(dst):
191 os.remove(dst) if osp.islink(dst) else shutil.rmtree(dst)
192 os.symlink(osp.abspath(src), dst)
193 else:
194 if osp.exists(dst):
195 shutil.rmtree(dst)
196 shutil.copytree(src, dst)
197 else:
198 shutil.copy2(src, dst)
199
200 # LAUNCH COMMAND
201 command = ["bash", f"launcher.sh"]
202 logger.info(f"Running command: {command} in {run_dir}")
203
204 # Prepare environment variables (thread-safe copy)

Callers 3

_draftMethod · 0.90
_improveMethod · 0.90
perform_experimentsFunction · 0.70

Calls 8

formatMethod · 0.80
log_messageFunction · 0.70
info_tracebackFunction · 0.70
removeMethod · 0.45
copyMethod · 0.45
startMethod · 0.45
waitMethod · 0.45
loadMethod · 0.45

Tested by

no test coverage detected