Created
May 16, 2023 17:42
-
-
Save davipatti/3e9de14255869bf9f52120ded93ba288 to your computer and use it in GitHub Desktop.
Try to load a pymc trace from a path. If the path doesn't exist then generate the trace by calling fun.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import arviz as az | |
def make_trace(path: str, fun: Callable, *args, **kwargs): | |
""" | |
Try to load a pymc trace from a path. If the path doesn't exist then generate | |
the trace by calling fun. | |
Args: | |
path: Path to Netcdf file. | |
fun: Callable that returns a PyMC trace. | |
*args, **kwargs: Passed to fun. | |
""" | |
try: | |
trace = az.from_netcdf(path) | |
except FileNotFoundError: | |
trace = fun(*args, **kwargs) | |
trace.to_netcdf(path) | |
return trace |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment