def METHOD_NAME(genNewPlanets=True, rewindPlanets=True, outpath="."):
    # wrap the run_sim in a try/except loop
    nbmax = 10
    for attempt in range(nbmax):
        try:
            # run one survey simulation
            SS.run_sim()
            DRM = SS.DRM[:]
            systems = SS.SimulatedUniverse.dump_systems()
            systems["MsTrue"] = SS.TargetList.MsTrue
            systems["MsEst"] = SS.TargetList.MsEst
            seed = SS.seed
        except Exception as e:
            # if anything goes wrong, log the error and reset simulation
            with open(os.path.join(outpath, "log.err"), "ab") as f:
                f.write(repr(e))
                f.write("\n")
                f.write(traceback.format_exc())
                f.write("\n\n")
            SS.reset_sim()
        else:
            break
    else:
        raise ValueError("Unsuccessful run_sim after %s reset_sim attempts" % nbmax)
    # reset simulation at the end of each simulation
    SS.reset_sim(genNewPlanets=genNewPlanets, rewindPlanets=rewindPlanets)
    pklname = (
        "run"
        + str(int(time.clock() * 100))
        + "".join(["%s" % random.randint(0, 9) for num in range(5)])
        + ".pkl"
    )
    pklpath = os.path.join(outpath, pklname)
    with open(pklpath, "wb") as f:
        pickle.dump({"DRM": DRM, "systems": systems, "seed": seed}, f)
    return 0