pycbc icon indicating copy to clipboard operation
pycbc copied to clipboard

The prior distribution is from an external file

Open YanqingQi opened this issue 1 year ago • 2 comments

[prior-srcmchirp] name = external_func_fromfile module = pycbc.distributions.external file_path = /home/QiYanQing/GWTC_reweight/Bayesian_inference_20230203/CE/GW190421_213856/prob_chirp_mass_source.txt column_index = 1 logpdf = _logpdf cdfinv = _cdfinv

An error occurred when I added the external file for prior distribution. The error content is as follows:

Exception while calling prior_transform function: params: [0.84038099 0.4933855 0.8026766 0.59142185 0.83061054 0.79597841 0.25080969 0.44994178 0.37936985 0.43277318 0.71048502 0.59450103 0.67310086 0.42945355 0.11565985 0.14913514 0.9938903 0.24068312 0.15047841 0.12633541 0.53773862 0.82638099 0.5791036 0.94994042 0.52760596 0.9099858 0.29087171 0.42707169 0.0184765 0.95325992 0.95652605 0.87521508 0.05293357 0.72265498 0.61398852 0.45729437 0.12369397 0.13525217 0.10249336 0.52767358 0.40559351 0.99125834 0.6069971 0.6301132 0.35665295 0.53264742 0.84110584 0.01857072 0.94779999 0.01961378 0.48009919 0.62480051 0.91169068 0.09506492 0.52875516] args: [] kwargs: {} exception: Traceback (most recent call last): File "/home/QiYanQing/.conda/envs/GWTC-3-population/lib/python3.8/site-packages/dynesty/dynesty.py", line 939, in call return self.func(x, *self.args, **self.kwargs) File "/home/QiYanQing/.conda/envs/GWTC-3-population/lib/python3.8/site-packages/pycbc/inference/sampler/base_cube.py", line 38, in call_global_logprior return models._global_instance.prior_transform(cube) File "/home/QiYanQing/.conda/envs/GWTC-3-population/lib/python3.8/site-packages/pycbc/inference/sampler/base_cube.py", line 95, in prior_transform cube[i] = inv[param] KeyError: 'srcmchirp'

YanqingQi avatar Apr 10 '23 03:04 YanqingQi

Then I use parallel tempering sampler emcee_pt instead, the error content is as follows:

2023-04-09T21:58:12.454+08:00 Setting up sampler 2023-04-09T21:58:12.773+08:00 Setting max samples per chain to 1000 2023-04-09T21:58:12.774+08:00 Looking for checkpoint file 2023-04-09T21:58:12.774+08:00 Checkpoint not found or not valid 2023-04-09T21:58:12.774+08:00 Creating file GW190421_213856_inference.hdf.checkpoint 2023-04-09T21:58:36.561+08:00 Running sampler for 0 to 2000 iterations multiprocessing.pool.RemoteTraceback: """ Traceback (most recent call last): File "/home/QiYanQing/.conda/envs/pycbc/lib/python3.8/site-packages/pycbc/inference/models/base.py", line 502, in _trytoget return getattr(self._current_stats, statname) AttributeError: 'ModelStats' object has no attribute 'logprior'

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "/home/QiYanQing/.conda/envs/pycbc/lib/python3.8/multiprocessing/pool.py", line 125, in worker result = (True, func(*args, **kwds)) File "/home/QiYanQing/.conda/envs/pycbc/lib/python3.8/multiprocessing/pool.py", line 48, in mapstar return list(map(*args)) File "/home/QiYanQing/.conda/envs/pycbc/lib/python3.8/site-packages/emcee/ptsampler.py", line 91, in call lp = self.logp(x, *self.logpargs, **self.logpkwargs) File "/home/QiYanQing/.conda/envs/pycbc/lib/python3.8/site-packages/pycbc/inference/models/init.py", line 58, in _call_global_model_logprior return _global_instance(*args, callstat='logprior', **kwds) File "/home/QiYanQing/.conda/envs/pycbc/lib/python3.8/site-packages/pycbc/inference/models/init.py", line 157, in call val = getattr(self.model, callstat) File "/home/QiYanQing/.conda/envs/pycbc/lib/python3.8/site-packages/pycbc/inference/models/base.py", line 561, in logprior return self._trytoget('logprior', self._logprior) File "/home/QiYanQing/.conda/envs/pycbc/lib/python3.8/site-packages/pycbc/inference/models/base.py", line 509, in _trytoget val = fallback(**kwargs) File "/home/QiYanQing/.conda/envs/pycbc/lib/python3.8/site-packages/pycbc/inference/models/base.py", line 566, in _logprior logp = self.prior_distribution(**self.current_params) + logj File "/home/QiYanQing/.conda/envs/pycbc/lib/python3.8/site-packages/pycbc/distributions/joint.py", line 294, in call logps = numpy.array([d(**params) for d in self.distributions]) File "/home/QiYanQing/.conda/envs/pycbc/lib/python3.8/site-packages/pycbc/distributions/joint.py", line 294, in logps = numpy.array([d(**params) for d in self.distributions]) File "/home/QiYanQing/.conda/envs/pycbc/lib/python3.8/site-packages/pycbc/distributions/external.py", line 105, in call return self.logpdf(**kwds) TypeError: 'NoneType' object is not callable """

The above exception was the direct cause of the following exception:

Traceback (most recent call last): File "/home/QiYanQing/.conda/envs/pycbc/bin/pycbc_inference", line 148, in sampler.run() File "/home/QiYanQing/.conda/envs/pycbc/lib/python3.8/site-packages/pycbc/inference/sampler/base_mcmc.py", line 491, in run self.run_mcmc(iterinterval) File "/home/QiYanQing/.conda/envs/pycbc/lib/python3.8/site-packages/pycbc/inference/sampler/emcee_pt.py", line 333, in run_mcmc res = self._sampler.run_mcmc(pos, niterations) File "/home/QiYanQing/.conda/envs/pycbc/lib/python3.8/site-packages/emcee/sampler.py", line 171, in run_mcmc for results in self.sample(pos0, lnprob0, rstate0, iterations=N, File "/home/QiYanQing/.conda/envs/pycbc/lib/python3.8/site-packages/emcee/ptsampler.py", line 259, in sample results = list(self.pool.map(fn, p.reshape((-1, self.dim)))) File "/home/QiYanQing/.conda/envs/pycbc/lib/python3.8/site-packages/pycbc/pool.py", line 106, in map return results.get(1800) File "/home/QiYanQing/.conda/envs/pycbc/lib/python3.8/multiprocessing/pool.py", line 771, in get raise self._value TypeError: 'NoneType' object is not callable

This error occurred during the running of a sampling program. The error message mentions both AttributeError and TypeError.

Specifically, multiple processes are running the sampling program, and within one of the processes a function called an attribute named logprior that does not exist in the ModelStats object, leading to the AttributeError. Furthermore, in another process, a function called a NoneType object that should have been a function earlier, leading to the TypeError.

YanqingQi avatar Apr 10 '23 03:04 YanqingQi