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

Errors when copying or pickling models using the expectation_propagation.EP() class #1105

Open
olamarre opened this issue Nov 4, 2024 · 2 comments · May be fixed by #1108
Open

Errors when copying or pickling models using the expectation_propagation.EP() class #1105

olamarre opened this issue Nov 4, 2024 · 2 comments · May be fixed by #1108
Labels

Comments

@olamarre
Copy link

olamarre commented Nov 4, 2024

Problem

When I try to deep copy or pickle a binary classification model implementing the EP() inference method (from the GPy.inference.latent_function_inference.expectation_propagation module), I get the following error:

  File "[...]/site-packages/GPy/inference/latent_function_inference/expectation_propagation.py", line 238, in __getstate__
    return [super(EPBase, self).__getstate__() , [self.epsilon, self.eta, self.delta]]
AttributeError: 'super' object has no attribute '__getstate__'

Reproducible example

Ran with Python 3.9 and GPy version 1.13.1:

import GPy
import copy
import numpy as np
import pickle as pkl

# Dummy binary classification dataset
X = np.array([0, 1, 2, 3]).reshape(-1, 1)
Y = np.array([0, 0, 1, 1]).reshape(-1, 1)

# Model
m = GPy.core.GP(
    X=X,
    Y=Y, 
    kernel=GPy.kern.RBF(input_dim=1, variance=1.0, lengthscale=1.0), 
    inference_method = GPy.inference.latent_function_inference.expectation_propagation.EP(),
    likelihood=GPy.likelihoods.Bernoulli(),
    mean_function=None
)

copy.deepcopy(m)  # triggers error
pkl.dumps(m)  # also triggers same error

Suggested fix

I believe the issue is that the parent class EPBase only inherits the basic object class. Calling super(EPBase, self).__getstate__() will fail because the object class does not implement this method. In fact, some other method calls with super() in the EPBase class should also fail (such as super(EPBase, self).__setstate__(state[0]) and super(EPBase, self)._save_to_input_dict()).

As a fix, I think these super() method calls can simply be removed in the EPBase class.

@MartinBubel
Copy link
Contributor

Hi @olamarre

sorry for the late reply.
Thank you for the issue. Your suggested fix sounds promissing!
Could you help us by making a PR?

Best,
Martin

@olamarre
Copy link
Author

olamarre commented Jan 1, 2025

No worries! Yes, I'll put together a PR.

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

Successfully merging a pull request may close this issue.

2 participants