[docs]defevaluate_hessian_in_subprocess(free_betas_values,data,draws,rv,sum_function):""" Launch a subprocess to compute the Hessian using JAX autodiff. """importoswithTemporaryFile()astmp_file:hess_file=tmp_file.fullpathprint(f"[DEBUG] Created temporary file: {hess_file}")args=(free_betas_values,data,draws,rv,sum_function,hess_file)payload=pickle.dumps(args)cmd=[sys.executable,__file__]try:result=subprocess.run(cmd,input=payload,stderr=subprocess.PIPE,timeout=60)print(f"[DEBUG] Subprocess return code: {result.returncode}")ifresult.stderr:print(f"[DEBUG] Subprocess stderr:\n{result.stderr.decode()}")ifresult.returncode==0:ifnotos.path.exists(hess_file):print(f"[DEBUG] File does not exist: {hess_file}")returnNonetry:withopen(hess_file,"rb")asf:print(f"[DEBUG] Reading result from: {hess_file}")returnpickle.load(f)except(pickle.UnpicklingError,EOFError,AttributeError,FileNotFoundError,)ase:print(f"[DEBUG] Failed to unpickle result: {e}")returnNonefinally:try:os.remove(hess_file)print(f"[DEBUG] Deleted temporary file: {hess_file}")exceptFileNotFoundError:print(f"[DEBUG] Could not delete missing file: {hess_file}")returnNone