Skip to content

Reenable tests that were mostly good already #4830

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

Merged
merged 6 commits into from
Jul 2, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
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
19 changes: 18 additions & 1 deletion .github/workflows/pytest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,12 @@ jobs:
--ignore=pymc3/tests/test_model_graph.py
--ignore=pymc3/tests/test_modelcontext.py
--ignore=pymc3/tests/test_parallel_sampling.py
--ignore=pymc3/tests/test_posteriors.py
--ignore=pymc3/tests/test_sampling.py
--ignore=pymc3/tests/test_profile.py
--ignore=pymc3/tests/test_step.py
--ignore=pymc3/tests/test_tuning.py
--ignore=pymc3/tests/test_transforms.py
--ignore=pymc3/tests/test_types.py
--ignore=pymc3/tests/test_variational_inference.py
--ignore=pymc3/tests/test_sampling_jax.py
Expand All @@ -57,25 +60,35 @@ jobs:
--ignore=pymc3/tests/test_distributions_random.py
--ignore=pymc3/tests/test_idata_conversion.py

- pymc3/tests/test_distributions.py

- |
pymc3/tests/test_modelcontext.py
pymc3/tests/test_dist_math.py
pymc3/tests/test_minibatches.py
pymc3/tests/test_pickling.py
pymc3/tests/test_plots.py
pymc3/tests/test_updates.py
pymc3/tests/test_transforms.py

- |
pymc3/tests/test_parallel_sampling.py
pymc3/tests/test_sampling.py
pymc3/tests/test_tuning.py
pymc3/tests/test_posteriors.py

- |
pymc3/tests/test_idata_conversion.py
pymc3/tests/test_distributions.py
pymc3/tests/test_distributions_random.py
pymc3/tests/test_distributions_timeseries.py
pymc3/tests/test_examples.py
pymc3/tests/test_gp.py
pymc3/tests/test_model.py
pymc3/tests/test_model_func.py
pymc3/tests/test_model_graph.py
pymc3/tests/test_ode.py
pymc3/tests/test_posdef_sym.py
pymc3/tests/test_profile.py
pymc3/tests/test_quadpotential.py
pymc3/tests/test_shape_handling.py
pymc3/tests/test_step.py
Expand Down Expand Up @@ -140,8 +153,11 @@ jobs:
test-subset:
- |
pymc3/tests/test_distributions_random.py
pymc3/tests/test_distributions_timeseries.py
- |
pymc3/tests/test_parallel_sampling.py
pymc3/tests/test_sampling.py
pymc3/tests/test_tuning.py
pymc3/tests/test_shared.py
- |
pymc3/tests/test_gp.py
Expand All @@ -152,6 +168,7 @@ jobs:
pymc3/tests/test_modelcontext.py
pymc3/tests/test_model_graph.py
pymc3/tests/test_pickling.py
pymc3/tests/test_profile.py

fail-fast: false
runs-on: ${{ matrix.os }}
Expand Down
28 changes: 14 additions & 14 deletions pymc3/tests/test_distributions.py
Original file line number Diff line number Diff line change
Expand Up @@ -1056,7 +1056,7 @@ def test_chisquared_logp(self):
lambda value, nu: sp.chi2.logpdf(value, df=nu),
)

@pytest.mark.xfail(
@pytest.mark.skipif(
condition=(aesara.config.floatX == "float32"),
reason="Fails on float32 due to numerical issues",
)
Expand Down Expand Up @@ -1423,7 +1423,7 @@ def test_fun(value, mu, sigma):
test_fun,
)

@pytest.mark.xfail(
@pytest.mark.skipif(
condition=(aesara.config.floatX == "float32"),
reason="Fails on float32 due to numerical issues",
)
Expand All @@ -1449,7 +1449,7 @@ def test_inverse_gamma_logp(self):
# pymc-devs/aesara#224: skip_paramdomain_outside_edge_test has to be set
# True to avoid triggering a C-level assertion in the Aesara GammaQ function

@pytest.mark.xfail(
@pytest.mark.skipif(
condition=(aesara.config.floatX == "float32"),
reason="Fails on float32 due to numerical issues",
)
Expand All @@ -1465,7 +1465,7 @@ def test_inverse_gamma_logcdf(self):
skip_paramdomain_outside_edge_test=True,
)

@pytest.mark.xfail(
@pytest.mark.skipif(
condition=(aesara.config.floatX == "float32"),
reason="Fails on float32 due to scaling issues",
)
Expand Down Expand Up @@ -1496,7 +1496,7 @@ def test_pareto(self):
lambda value, alpha, m: sp.pareto.logcdf(value, alpha, scale=m),
)

@pytest.mark.xfail(
@pytest.mark.skipif(
condition=(aesara.config.floatX == "float32"),
reason="Fails on float32 due to numerical issues",
)
Expand All @@ -1508,7 +1508,7 @@ def test_weibull_logp(self):
lambda value, alpha, beta: sp.exponweib.logpdf(value, 1, alpha, scale=beta),
)

@pytest.mark.xfail(
@pytest.mark.skipif(
condition=(aesara.config.floatX == "float32"),
reason="Fails on float32 due to inf issues",
)
Expand Down Expand Up @@ -1560,7 +1560,7 @@ def test_binomial(self):
)

@pytest.mark.xfail(reason="checkd tests has not been refactored")
@pytest.mark.xfail(condition=(aesara.config.floatX == "float32"), reason="Fails on float32")
@pytest.mark.skipif(condition=(aesara.config.floatX == "float32"), reason="Fails on float32")
def test_beta_binomial_distribution(self):
self.checkd(
BetaBinomial,
Expand Down Expand Up @@ -1681,7 +1681,7 @@ def test_constantdist(self):
self.check_logp(Constant, I, {"c": I}, lambda value, c: np.log(c == value))

@pytest.mark.xfail(reason="Test has not been refactored")
@pytest.mark.xfail(
@pytest.mark.skipif(
condition=(aesara.config.floatX == "float32"),
reason="Fails on float32 due to inf issues",
)
Expand Down Expand Up @@ -1723,7 +1723,7 @@ def logcdf_fn(value, psi, theta):
)

@pytest.mark.xfail(reason="Test not refactored yet")
@pytest.mark.xfail(
@pytest.mark.skipif(
condition=(aesara.config.floatX == "float32"),
reason="Fails on float32 due to inf issues",
)
Expand Down Expand Up @@ -1860,7 +1860,7 @@ def test_mvnormal(self, n):
extra_args={"lower": False},
)

@pytest.mark.xfail(
@pytest.mark.skipif(
condition=(aesara.config.floatX == "float32"),
reason="Fails on float32 due to inf issues",
)
Expand Down Expand Up @@ -2521,7 +2521,7 @@ def test_ex_gaussian_cdf_outside_edges(self):
skip_paramdomain_inside_edge_test=True, # Valid values are tested above
)

@pytest.mark.xfail(condition=(aesara.config.floatX == "float32"), reason="Fails on float32")
@pytest.mark.skipif(condition=(aesara.config.floatX == "float32"), reason="Fails on float32")
def test_vonmises(self):
self.check_logp(
VonMises,
Expand Down Expand Up @@ -2571,7 +2571,7 @@ def test_logitnormal(self):
decimal=select_by_precision(float64=6, float32=1),
)

@pytest.mark.xfail(
@pytest.mark.skipif(
condition=(aesara.config.floatX == "float32"),
reason="Some combinations underflow to -inf in float32 in pymc version",
)
Expand Down Expand Up @@ -2603,7 +2603,7 @@ def test_moyal_logp(self):
lambda value, mu, sigma: floatX(sp.moyal.logpdf(value, mu, sigma)),
)

@pytest.mark.xfail(
@pytest.mark.skipif(
condition=(aesara.config.floatX == "float32"),
reason="Pymc3 underflows earlier than scipy on float32",
)
Expand All @@ -2617,7 +2617,7 @@ def test_moyal_logcdf(self):
if aesara.config.floatX == "float32":
raise Exception("Flaky test: It passed this time, but XPASS is not allowed.")

@pytest.mark.xfail(condition=(aesara.config.floatX == "float32"), reason="Fails on float32")
@pytest.mark.skipif(condition=(aesara.config.floatX == "float32"), reason="Fails on float32")
def test_interpolated(self):
for mu in R.vals:
for sigma in Rplus.vals:
Expand Down
68 changes: 44 additions & 24 deletions pymc3/tests/test_parallel_sampling.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,39 +89,51 @@ def test_remote_pipe_closed():
pm.sample(step=step, mp_ctx="spawn", tune=2, draws=2, cores=2, chains=2)


@pytest.mark.xfail(
reason="Possibly the same issue described in https://github.com/pymc-devs/pymc3/pull/4701"
)
def test_abort():
with pm.Model() as model:
a = pm.Normal("a", shape=1)
pm.HalfNormal("b")
step1 = pm.NUTS([a])
step2 = pm.Metropolis([model.b_log__])
step2 = pm.Metropolis([model["b_log__"]])

step = pm.CompoundStep([step1, step2])

ctx = multiprocessing.get_context()
proc = ps.ProcessAdapter(
10,
10,
step,
chain=3,
seed=1,
mp_ctx=ctx,
start={"a": 1.0, "b_log__": 2.0},
step_method_pickled=None,
pickle_backend="pickle",
)
proc.start()
proc.write_next()
proc.abort()
proc.join()


for abort in [False, True]:
ctx = multiprocessing.get_context()
proc = ps.ProcessAdapter(
10,
10,
step,
chain=3,
seed=1,
mp_ctx=ctx,
start={"a": np.array([1.0]), "b_log__": np.array(2.0)},
step_method_pickled=None,
pickle_backend="pickle",
)
proc.start()
while True:
proc.write_next()
out = ps.ProcessAdapter.recv_draw([proc])
if out[1]:
break
if abort:
proc.abort()
proc.join()


@pytest.mark.xfail(
reason="Possibly the same issue described in https://github.com/pymc-devs/pymc3/pull/4701"
)
def test_explicit_sample():
with pm.Model() as model:
a = pm.Normal("a", shape=1)
pm.HalfNormal("b")
step1 = pm.NUTS([a])
step2 = pm.Metropolis([model.b_log__])
step2 = pm.Metropolis([model["b_log__"]])

step = pm.CompoundStep([step1, step2])

Expand All @@ -133,7 +145,7 @@ def test_explicit_sample():
chain=3,
seed=1,
mp_ctx=ctx,
start={"a": 1.0, "b_log__": 2.0},
start={"a": np.array([1.0]), "b_log__": np.array(2.0)},
step_method_pickled=None,
pickle_backend="pickle",
)
Expand All @@ -149,22 +161,26 @@ def test_explicit_sample():
proc.join()


@pytest.mark.xfail(
reason="Possibly the same issue described in https://github.com/pymc-devs/pymc3/pull/4701"
)
def test_iterator():
with pm.Model() as model:
a = pm.Normal("a", shape=1)
pm.HalfNormal("b")
step1 = pm.NUTS([a])
step2 = pm.Metropolis([model.b_log__])
step2 = pm.Metropolis([model["b_log__"]])

step = pm.CompoundStep([step1, step2])

start = {"a": 1.0, "b_log__": 2.0}
start = {"a": np.array([1.0]), "b_log__": np.array(2.0)}
sampler = ps.ParallelSampler(10, 10, 3, 2, [2, 3, 4], [start] * 3, step, 0, False)
with sampler:
for draw in sampler:
pass


@pytest.mark.xfail(reason="DensityDist was not yet refactored for v4")
def test_spawn_densitydist_function():
with pm.Model() as model:
mu = pm.Normal("mu", 0, 1)
Expand All @@ -176,16 +192,19 @@ def func(x):
pm.sample(draws=10, tune=10, step=pm.Metropolis(), cores=2, mp_ctx="spawn")


@pytest.mark.xfail(reason="DensityDist was not yet refactored for v4")
def test_spawn_densitydist_bound_method():
with pm.Model() as model:
mu = pm.Normal("mu", 0, 1)
normal_dist = pm.Normal.dist(mu, 1)
obs = pm.DensityDist("density_dist", normal_dist.logp, observed=np.random.randn(100))
logp = lambda x: pm.logp(normal_dist, x, transformed=False)
obs = pm.DensityDist("density_dist", logp, observed=np.random.randn(100))
msg = "logp for DensityDist is a bound method, leading to RecursionError while serializing"
with pytest.raises(ValueError, match=msg):
pm.sample(draws=10, tune=10, step=pm.Metropolis(), cores=2, mp_ctx="spawn")


@pytest.mark.xfail(reason="DensityDist was not yet refactored for v4")
def test_spawn_densitydist_syswarning(monkeypatch):
monkeypatch.setattr("pymc3.distributions.distribution.PLATFORM", "win32")
with pm.Model() as model:
Expand All @@ -195,6 +214,7 @@ def test_spawn_densitydist_syswarning(monkeypatch):
obs = pm.DensityDist("density_dist", normal_dist.logp, observed=np.random.randn(100))


@pytest.mark.xfail(reason="DensityDist was not yet refactored for v4")
def test_spawn_densitydist_mpctxwarning(monkeypatch):
ctx = multiprocessing.get_context("spawn")
monkeypatch.setattr(multiprocessing, "get_context", lambda: ctx)
Expand Down
5 changes: 4 additions & 1 deletion pymc3/tests/test_profile.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
# See the License for the specific language governing permissions and
# limitations under the License.

import pymc3 as pm

from pymc3.tests.models import simple_model


Expand All @@ -23,7 +25,8 @@ def test_profile_model(self):
assert self.model.profile(self.model.logpt).fct_call_time > 0

def test_profile_variable(self):
assert self.model.profile(self.model.value_vars[0].logpt).fct_call_time > 0
rv = self.model.basic_RVs[0]
assert self.model.profile(pm.logpt(rv, self.model.rvs_to_values[rv])).fct_call_time

def test_profile_count(self):
count = 1005
Expand Down