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

Function run_experiment

internagent/experiments_utils_iflow.py:146–307  ·  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 log_file: Optional file object to write logs to Returns: Tuple of (return_code, next_

(folder_name, run_num, timeout=180000, log_file=None)

Source from the content-addressed store, hash-verified

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

Callers 3

_draftMethod · 0.90
_improveMethod · 0.90
perform_experimentsFunction · 0.70

Calls 6

formatMethod · 0.80
log_messageFunction · 0.70
info_tracebackFunction · 0.70
waitMethod · 0.45
loadMethod · 0.45
itemsMethod · 0.45

Tested by

no test coverage detected