# Copyright (c) 2022-2025, The Isaac Lab Project Developers.# All rights reserved.## SPDX-License-Identifier: BSD-3-Clause"""Utilities for file I/O with pickle."""importosimportpicklefromtypingimportAny
[docs]defload_pickle(filename:str)->Any:"""Loads an input PKL file safely. Args: filename: The path to pickled file. Raises: FileNotFoundError: When the specified file does not exist. Returns: The data read from the input file. """ifnotos.path.exists(filename):raiseFileNotFoundError(f"File not found: {filename}")withopen(filename,"rb")asf:data=pickle.load(f)returndata
[docs]defdump_pickle(filename:str,data:Any):"""Saves data into a pickle file safely. Note: The function creates any missing directory along the file's path. Args: filename: The path to save the file at. data: The data to save. """# check endingifnotfilename.endswith("pkl"):filename+=".pkl"# create directoryifnotos.path.exists(os.path.dirname(filename)):os.makedirs(os.path.dirname(filename),exist_ok=True)# save datawithopen(filename,"wb")asf:pickle.dump(data,f)