Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable deepcopy of bmb.Model #82

Open
lt-brs opened this issue Nov 2, 2022 · 1 comment
Open

Enable deepcopy of bmb.Model #82

lt-brs opened this issue Nov 2, 2022 · 1 comment

Comments

@lt-brs
Copy link

lt-brs commented Nov 2, 2022

Hello !

I tried to deepcopy a bmb.Model and find out that we face a cannot pickle '_thread.lock' object.
After investigation, this is due to saving of thread locked objects within formulae.Environment objects.

Indeed many, locked variables are fetched while calling Environment.capture().
My dummy workaround was to just replace the return cls([frame.f_locals, frame.f_globals])

        if isinstance(env, cls):
            return env
        elif isinstance(env, numbers.Integral):
            depth = env + reference
        else:
            raise TypeError("'env' must be either an integer or an instance of Environment.")
        frame = inspect.currentframe()
        try:
            for _ in range(depth + 1):
                if frame is None:
                    raise ValueError("call-stack is not that deep!")
                frame = frame.f_back
            # return cls([frame.f_locals, frame.f_globals])
            return cls([])
        finally:
            del frame

I'm not experienced enough on Bambi formulae, a good workaround would be to keep only what is necessary for formulae to work in output of the capture() function

I hope it would be helpful

@tomicapretto
Copy link
Collaborator

Just want to say this seems to be related bambinos/bambi#400

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants