def launch_experiment(script, run_slot, affinity_code, log_dir, variant, run_ID, args): """Launches one learning run using ``subprocess.Popen()`` to call the python script. Calls the script as: ``python {script} {slot_affinity_code} {log_dir} {run_ID} {*args}`` If ``affinity_code["all_cpus"]`` is provided, then the call is prepended with ``tasket -c ..`` and the listed cpus (this is the most sure way to keep the run limited to these CPU cores). Also saves the `variant` file. Returns the process handle, which can be monitored. """ slot_affinity_code = prepend_run_slot(run_slot, affinity_code) affinity = affinity_from_code(slot_affinity_code) call_list = list() if isinstance(affinity, dict) and affinity.get("all_cpus", False): cpus = ",".join(str(c) for c in affinity["all_cpus"]) elif isinstance(affinity, list) and affinity[0].get("all_cpus", False): cpus = ",".join(str(c) for aff in affinity for c in aff["all_cpus"]) else: cpus = () if cpus: call_list += ["taskset", "-c", cpus] # PyTorch obeys better than just psutil. call_list += ["python", script, slot_affinity_code, log_dir, str(run_ID)] call_list += [str(a) for a in args] save_variant(variant, log_dir) print("\ncall string:\n", " ".join(call_list)) p = subprocess.Popen(call_list) return p
def launch_experiment( script, run_slot, affinity_code, log_dir, variant, run_ID, args, python_executable=None, set_egl_device=False, ): """Launches one learning run using ``subprocess.Popen()`` to call the python script. Calls the script as: ``python {script} {slot_affinity_code} {log_dir} {run_ID} {*args}`` If ``affinity_code["all_cpus"]`` is provided, then the call is prepended with ``tasket -c ..`` and the listed cpus (this is the most sure way to keep the run limited to these CPU cores). Also saves the `variant` file. Returns the process handle, which can be monitored. Use ``set_egl_device=True`` to set an environment variable ``EGL_DEVICE_ID`` equal to the same value as the cuda index for the algorithm. For example, can use with DMControl environment modified to look for this environment variable when selecting a GPU for headless rendering. """ slot_affinity_code = prepend_run_slot(run_slot, affinity_code) affinity = affinity_from_code(slot_affinity_code) call_list = list() if isinstance(affinity, dict) and affinity.get("all_cpus", False): cpus = ",".join(str(c) for c in affinity["all_cpus"]) elif isinstance(affinity, list) and affinity[0].get("all_cpus", False): cpus = ",".join(str(c) for aff in affinity for c in aff["all_cpus"]) else: cpus = () if cpus: call_list += ["taskset", "-c", cpus] # PyTorch obeys better than just psutil. py = python_executable if python_executable else sys.executable or "python" call_list += [py, script, slot_affinity_code, log_dir, str(run_ID)] call_list += [str(a) for a in args] save_variant(variant, log_dir) print("\ncall string:\n", " ".join(call_list)) print(os.getcwd()) if set_egl_device and affinity.get("cuda_idx", None) is not None: egl_device_id = str(affinity["cuda_idx"]) egl_env = os.environ.copy() egl_env["EGL_DEVICE_ID"] = egl_device_id print(f"Assigning EGL_DEVICE_ID={egl_device_id}") p = subprocess.Popen(call_list, env=egl_env) else: p = subprocess.Popen(call_list) return p
def launch_experiment(script, run_slot, affinity_code, log_dir, variant, run_ID, args): slot_affinity_code = prepend_run_slot(run_slot, affinity_code) affinity = affinity_from_code(slot_affinity_code) call_list = list() if isinstance(affinity, dict) and affinity.get("all_cpus", False): cpus = ",".join(str(c) for c in affinity["all_cpus"]) elif isinstance(affinity, list) and affinity[0].get("all_cpus", False): cpus = ",".join(str(c) for aff in affinity for c in aff["all_cpus"]) else: cpus = () if cpus: call_list += ["taskset", "-c", cpus] # PyTorch obeys better than just psutil. call_list += ["python", script, slot_affinity_code, log_dir, str(run_ID)] call_list += [str(a) for a in args] save_variant(variant, log_dir) print("\ncall string:\n", " ".join(call_list)) p = subprocess.Popen(call_list) return p