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

Raise NotImplementedError on missing backend functionality #2055

Merged
merged 3 commits into from
Oct 5, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion pyro/generic/dispatch.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,10 @@ def __getattribute__(self, name):
except KeyError:
module = importlib.import_module(backend)
GenericModule._modules[backend] = module
return getattr(module, name)
try:
return getattr(module, name)
except AttributeError:
raise NotImplementedError(f'This Pyro backend does not implement {module_name}.{name}')


@contextmanager
Expand Down
16 changes: 13 additions & 3 deletions tests/test_generic.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import pytest
import torch

from pyro.generic import infer, pyro_backend, handlers
from pyro.generic import handlers, infer, pyro, pyro_backend
from pyro.generic.testing import MODELS


pytestmark = pytest.mark.stage('unit')


Expand All @@ -16,4 +16,14 @@ def test_mcmc_interface(model, backend):
nuts_kernel = infer.NUTS(model=model)
mcmc = infer.MCMC(nuts_kernel, num_samples=10, warmup_steps=10)
mcmc.run(*args, **kwargs)
mcmc.summary()
if torch.backends.mkl.is_available():
mcmc.summary()


@pytest.mark.parametrize('backend', ['pyro', 'minipyro'])
def test_not_implemented(backend):
with pyro_backend(backend):
pyro.sample # should be implemented
pyro.param # should be implemented
with pytest.raises(NotImplementedError):
pyro.nonexistant_primitive
neerajprad marked this conversation as resolved.
Show resolved Hide resolved