def test_remove_scan_op(): with pm.Model(): pm.Normal('n', 0, 1) inference = ADVI() buff = io.StringIO() inference.run_profiling(n=10).summary(buff) assert 'theano.scan_module.scan_op.Scan' not in buff.getvalue() buff.close()
def test_remove_scan_op(): with pm.Model(): pm.Normal("n", 0, 1) inference = ADVI() buff = io.StringIO() inference.run_profiling(n=10).summary(buff) assert "aesara.scan.op.Scan" not in buff.getvalue() buff.close()
def test_clear_cache(): pymc3.memoize.clear_cache() with pm.Model(): pm.Normal('n', 0, 1) inference = ADVI() inference.fit(n=10) assert len(pm.variational.opvi.Approximation.logp.fget.cache) == 1 del inference assert len(pm.variational.opvi.Approximation.logp.fget.cache) == 0 for c in pymc3.memoize.CACHE_REGISTRY: assert len(c) == 0
def test_clear_cache(): import pickle with pm.Model(): pm.Normal("n", 0, 1) inference = ADVI() inference.fit(n=10) assert any(len(c) != 0 for c in inference.approx._cache.values()) inference.approx._cache.clear() # should not be cleared at this call assert all(len(c) == 0 for c in inference.approx._cache.values()) new_a = pickle.loads(pickle.dumps(inference.approx)) assert not hasattr(new_a, "_cache") inference_new = pm.KLqp(new_a) inference_new.fit(n=10) assert any(len(c) != 0 for c in inference_new.approx._cache.values()) inference_new.approx._cache.clear() assert all(len(c) == 0 for c in inference_new.approx._cache.values())
def test_clear_cache(): import pickle pymc3.memoize.clear_cache() assert all(len(c) == 0 for c in pymc3.memoize.CACHE_REGISTRY) with pm.Model(): pm.Normal('n', 0, 1) inference = ADVI() inference.fit(n=10) assert any(len(c) != 0 for c in inference.approx._cache.values()) pymc3.memoize.clear_cache(inference.approx) # should not be cleared at this call assert all(len(c) == 0 for c in inference.approx._cache.values()) new_a = pickle.loads(pickle.dumps(inference.approx)) assert not hasattr(new_a, '_cache') inference_new = pm.KLqp(new_a) inference_new.fit(n=10) assert any(len(c) != 0 for c in inference_new.approx._cache.values()) pymc3.memoize.clear_cache(inference_new.approx) assert all(len(c) == 0 for c in inference_new.approx._cache.values())
def test_from_advi(self): with models.multidimensional_model()[1]: advi = ADVI() full_rank = FullRankADVI.from_advi(advi) full_rank.fit(20)
def test_from_mean_field(self): with models.multidimensional_model()[1]: advi = ADVI() full_rank = FullRankADVI.from_mean_field(advi.approx) full_rank.fit(20)