hvasbath / beat

Bayesian Earthquake Analysis Tool
GNU General Public License v3.0
132 stars 42 forks source link

Error when running beat sample Scenario II, regularization, ramps #24

Closed vic-chou closed 5 years ago

vic-chou commented 5 years ago

Hi, When I running "beat sample Laquila --hypers --mode=ffo" in Scenario II, I meet a error that beat sample Laquila --mode=ffo config - INFO All parameter-priors ok! config - INFO All hyper-parameters ok! config - INFO All hierarchical-parameters ok! models - INFO ... Initialising Distribution Optimizer ... models - INFO Analysing problem ... models - INFO --------------------- geodetic - INFO Number of geodetic datasets: 2 geodetic - INFO Number of geodetic data points: 419 geodetic - WARNING Covariance estimation not implemented (yet)! Using imported covariances! geodetic - INFO Fit residual ramp selected! Traceback (most recent call last): File "/beat/python35/lib/python3.5/site-packages/pymc3/model.py", line 179, in get_context return cls.get_contexts()[-1] IndexError: list index out of range

Can you help me solve this problem? Thank you!

hvasbath commented 5 years ago

Is this the full error traceback? There must be something missing. For now I unfrotunately have no clue - I have never seen this error before. You need to provide more details and for example also the logfile and config file etc.

vic-chou commented 5 years ago

I list the full error traceback as follows: config - INFO All parameter-priors ok! config - INFO All hyper-parameters ok! config - INFO All hierarchical-parameters ok! models - INFO ... Initialising Distribution Optimizer ...

models - INFO Analysing problem ... models - INFO ---------------------

geodetic - INFO Number of geodetic datasets: 2 geodetic - INFO Number of geodetic data points: 419 geodetic - WARNING Covariance estimation not implemented (yet)! Using imported covariances! geodetic - INFO Fit residual ramp selected! Traceback (most recent call last): File "/beat/python35/lib/python3.5/site-packages/pymc3/model.py", line 179, in get_context return cls.get_contexts()[-1] IndexError: list index out of range

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "/beat/python35/lib/python3.5/site-packages/pymc3/distributions/distribution.py", line 24, in new model = Model.get_context() File "/beat/python35/lib/python3.5/site-packages/pymc3/model.py", line 181, in get_context raise TypeError("No context on context stack") TypeError: No context on context stack

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "/.local/lib/python3.5/site-packages/beat-1.0rc1-py3.5-linux-x86_64.egg/beat/models/problems.py", line 339, in get_random_variables rvs[param.name] = Uniform(**kwargs) File "/beat/python35/lib/python3.5/site-packages/pymc3/distributions/distribution.py", line 26, in new raise TypeError("No model on context stack, which is needed to " TypeError: No model on context stack, which is needed to instantiate distributions. Add variable inside a 'with model:' block, or use the '.dist' syntax for a standalone distribution.

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "/beat/python35/bin/beat", line 11, in load_entry_point('beat==1.0rc1', 'console_scripts', 'beat')() File "/.local/lib/python3.5/site-packages/beat-1.0rc1-py3.5-linux-x8664.egg/beat/apps/beat.py", line 1588, in main globals()['command' + command](args) File "/.local/lib/python3.5/site-packages/beat-1.0rc1-py3.5-linux-x86_64.egg/beat/apps/beat.py", line 748, in command_sample project_dir, options.mode, options.hypers) File "/.local/lib/python3.5/site-packages/beat-1.0rc1-py3.5-linux-x86_64.egg/beat/models/problems.py", line 824, in load_model problem = problem_catalog[pc.mode](config, hypers) File "/.local/lib/python3.5/site-packages/beat-1.0rc1-py3.5-linux-x86_64.egg/beat/models/problems.py", line 697, in init composite.set_slip_varnames(self.varnames) File "/.local/lib/python3.5/site-packages/beat-1.0rc1-py3.5-linux-x86_64.egg/beat/models/problems.py", line 364, in varnames self._varnames = list(self.get_random_variables()[0].keys()) File "/.local/lib/python3.5/site-packages/beat-1.0rc1-py3.5-linux-x86_64.egg/beat/models/problems.py", line 343, in get_random_variables rvs[param.name] = Uniform.dist(kwargs) File "/beat/python35/lib/python3.5/site-packages/pymc3/distributions/distribution.py", line 47, in dist dist.init(*args, *kwargs) File "/beat/python35/lib/python3.5/site-packages/pymc3/distributions/continuous.py", line 162, in init super(Uniform, self).init(transform=transform, args, kwargs) File "/beat/python35/lib/python3.5/site-packages/pymc3/distributions/distribution.py", line 175, in init shape, dtype, defaults=defaults, *args, **kwargs) File "/beat/python35/lib/python3.5/site-packages/pymc3/distributions/distribution.py", line 53, in init if False in (np.floor(self.shape) == self.shape): AttributeError: 'NoneType' object has no attribute 'floor'

I noticed that the content of problem_config in my config_ffo.yaml is different from the content shown in the website "https://hvasbath.github.io/beat/examples/FFO_static.html". There is no "hierarchicals" in my problem_config, which is listed on the website as follows. Should I add this part to my problem_config? hierarchicals: Laquila_ascxn_offset: !beat.heart.Parameter name: Laquila_ascxn_offset form: Uniform lower: [-0.004496268249748271] upper: [-0.004496268249748271] testvalue: [-0.004496268249748271] Laquila_ascxn_ramp: !beat.heart.Parameter name: Laquila_ascxn_ramp form: Uniform lower: [-0.00043773457168120667, -0.00023808150002277328] upper: [-0.00043773457168120667, -0.00023808150002277328] testvalue: [-0.00043773457168120667, -0.00023808150002277328] Laquila_dscxn_offset: !beat.heart.Parameter name: Laquila_dscxn_offset form: Uniform lower: [-0.003754963750062188] upper: [-0.003754963750062188] testvalue: [-0.003754963750062188] Laquila_dscxn_ramp: !beat.heart.Parameter name: Laquila_dscxn_ramp form: Uniform lower: [4.978325480108451e-05, -0.00025072248953317104] upper: [4.978325480108451e-05, -0.00025072248953317104] testvalue: [4.978325480108451e-05, -0.00025072248953317104]

hvasbath commented 5 years ago

I guess you are following the tutorial? Did you run the "beat import Laquila ... " step? The hierarchicals should have been imported in this step from your previous geometry optimization.

vic-chou commented 5 years ago

I run the "beat import Laquila --results=Laquila --mode='geometry' --datatypes=geodetic" step, it traceback is beat - INFO Attempting to load results with mode geometry from directory: Laquila config - INFO All parameter-priors ok! config - INFO All hyper-parameters ok! config - INFO All hierarchical-parameters ok! config - INFO All parameter-priors ok! config - INFO All hyper-parameters ok! config - INFO All hierarchical-parameters ok! models - INFO ... Initialising Geometry Optimizer ...

models - INFO Analysing problem ... models - INFO ---------------------

heart - INFO Consistent number of datasets and targets in any_P_0 wavemap! heart - INFO Number of seismic datasets for wavemap: any_P_0: 35 geodetic - INFO Number of geodetic datasets: 2 geodetic - INFO Number of geodetic data points: 419 geodetic - WARNING Covariance estimation not implemented (yet)! Using imported covariances! geodetic - INFO Fit residual ramp selected! models - INFO ... Building model ...

models - INFO Optimization for 3 hyperparameters in total! seismic - INFO Seismic optimization on: depth, length, strike, rake, nucleation_x, east_shift, north_shift, nucleation_y, width, slip, time, dip seismic - INFO Retrieving seismic data-covariances with structure "non-toeplitz" for any_P_0 ... seismic - INFO Preparing data of "any_P_0" for optimization seismic - INFO Initializing synthesizer for "any_P_0" geodetic - INFO Geodetic optimization on: depth, length, strike, rake, east_shift, north_shift, width, slip, dip geodetic - INFO Estimating ramp for each dataset... geodetic - INFO Initialized 4 hierarchical parameters (ramps). models - INFO Model building was successful!

backend - INFO Loading multitrace from /data4/gyxu/beat/testbeat/Laquila/geometry/stage-1 beat - INFO Importing ramp parameters ... config - WARNING Prior for variable Laquila_dscxn_ramp does not exist! Bounds not updated! config - WARNING Prior for variable Laquila_ascxn_ramp does not exist! Bounds not updated! config - WARNING Prior for variable Laquila_dscxn_offset does not exist! Bounds not updated! config - WARNING Prior for variable Laquila_ascxn_offset does not exist! Bounds not updated! beat - INFO Importing non-linear source geometry results! config - WARNING Prior for variable time does not exist! Bounds not updated! beat - INFO Successfully updated config file!

I find that there is "hierarchicals" in my config_geometry.yaml file, but not in the config_ffo.yaml. I following the steps in the tutorial. Can you give me some suggestion?

hvasbath commented 5 years ago

Did you optimize for the orbital ramp parameters in your geometry step? Apparently there are no ramp results to be imported. If you did not run it simply put the fit_planes flag to false, update your config with beat update- as described on the webpage and your config file should be consistent again.

vic-chou commented 5 years ago

When I put the fit_planes flag to false, I can run the "beat sample Laquila --hypers --mode=ffo" successfully. But when I run "beat sample Laquila --mode=ffo", I meet the error config - INFO All parameter-priors ok! config - INFO All hyper-parameters ok! config - INFO All hierarchical-parameters ok! models - INFO ... Initialising Distribution Optimizer ...

models - INFO Analysing problem ... models - INFO ---------------------

geodetic - INFO Number of geodetic datasets: 2 geodetic - INFO Number of geodetic data points: 419 geodetic - WARNING Covariance estimation not implemented (yet)! Using imported covariances! models - INFO Using "none" regularization ... models - INFO ... Building model ...

models - INFO Optimization for 2 hyperparameters in total! geodetic - INFO Loading geodetic Green's Functions ffo - INFO Setting geodetic_uparr_static_0 GF Library to optimization mode. ffo - INFO Setting geodetic_uperp_static_0 GF Library to optimization mode. geodetic - INFO Initialized 0 hierarchical parameters (ramps). models - INFO Model building was successful!

models - INFO ... Initiate Sequential Monte Carlo ... n_chains=1000, tune_interval=50, n_jobs=1, proposal_distribution: MultivariateNormal,

models - INFO Compilation time: 4.386736 models.base - INFO Chain initialization with: models.base - INFO Random starting point.

models.base - INFO ... Starting SMC ...

backend - INFO Reloading existing results ... backend - INFO Loading multitrace from /beat/test_beat/Laquila/ffo/stage_0 backend - INFO Init new trace! smc - INFO Sample initial stage: ... smc - INFO Beta: 0.000000 Stage: 0 sampler - INFO Initialising 1000 chain traces ... sampler - INFO Serial time per sample: 0.000354 sampler - INFO Not using shared memory. sampler - INFO Sampling ... Traceback (most recent call last): File "/beat/python35/bin/beat", line 11, in load_entry_point('beat==1.0rc1', 'console_scripts', 'beat')() File "/.local/lib/python3.5/site-packages/beat-1.0rc1-py3.5-linux-x8664.egg/beat/apps/beat.py", line 1588, in main globals()['command' + command](args) File "/.local/lib/python3.5/site-packages/beat-1.0rc1-py3.5-linux-x86_64.egg/beat/apps/beat.py", line 755, in command_sample sample(step, problem) File "/.local/lib/python3.5/site-packages/beat-1.0rc1-py3.5-linux-x86_64.egg/beat/models/base.py", line 174, in sample rm_flag=pa.rm_flag) File "/.local/lib/python3.5/site-packages/beat-1.0rc1-py3.5-linux-x86_64.egg/beat/sampler/smc.py", line 461, in smc_sample mtrace = iter_parallel_chains(*sample_args) File "/.local/lib/python3.5/site-packages/beat-1.0rc1-py3.5-linux-x86_64.egg/beat/sampler/base.py", line 483, in iter_parallel_chains for res in p: File "/.local/lib/python3.5/site-packages/beat-1.0rc1-py3.5-linux-x86_64.egg/beat/parallel.py", line 224, in paripool yield [function(work)] File "/.local/lib/python3.5/site-packages/beat-1.0rc1-py3.5-linux-x86_64.egg/beat/sampler/base.py", line 263, in _sample parallel.borrow_all_memories(shared_params, parallel._shared_memory) File "/.local/lib/python3.5/site-packages/beat-1.0rc1-py3.5-linux-x86_64.egg/beat/parallel.py", line 422, in borrow_all_memories borrow_memory(sparam, *memshared_instances[sparam.name]) KeyError: 'geodetic_uparr_static_0'

And I noticed that in my updated config_ffo.yaml, there is no h_laplacian: !beat.heart.Parameter name: h_laplacian form: Uniform lower: [-5.0] upper: [5.0] testvalue: [0.5]

Can you give me some suggestion?

hvasbath commented 5 years ago

Please put the rm_flag under the SMC sampler config to true. At the moment it tries to load your previously failed sampling. Or please remove the stage_0 results.

Please read the regularization section in the tutorial...

vic-chou commented 5 years ago

Thanks for your help! I can run it successfully under your suggestion.

nanfang0422 commented 5 years ago

Hi Hannes, I meet the the same error. I have put the rm_flag under the SMC sampler config to true and also tried to remove the stage_0 results, but it still appears the error. I also set the fit_plane to false because I don't have hierarchical data. fangnandeMacBook-Pro:beat_learning NAN$ beat sample Laquila --mode=ffo config - INFO All parameter-priors ok! config - INFO All hyper-parameters ok! config - INFO All hierarchical-parameters ok! models - INFO ... Initialising Distribution Optimizer ...

models - INFO Analysing problem ... models - INFO ---------------------

geodetic - INFO Number of geodetic datasets: 2 geodetic - INFO Number of geodetic data points: 419 geodetic - WARNING Covariance estimation not implemented (yet)! Using imported covariances! models - INFO ... Building model ...

models - INFO Optimization for 3 hyperparameters in total! geodetic - INFO Loading geodetic Green's Functions ffo - INFO Setting geodetic_uparr_static_0 GF Library to optimization mode. ffo - INFO Setting geodetic_uperp_static_0 GF Library to optimization mode. geodetic - INFO Initialized 0 hierarchical parameters (ramps). ffo.laplacian - INFO Initialising Laplacian smoothing operator ... models - INFO Model building was successful!

models - INFO ... Initiate Sequential Monte Carlo ... n_chains=1000, tune_interval=50, n_jobs=1, proposal_distribution: MultivariateNormal,

models - INFO Compilation time: 14.379401 models.base - INFO Chain initialization with: models.base - INFO Random starting point.

models.base - INFO ... Starting SMC ...

backend - INFO Removing previous sampling results ... /Users/NAN/Documents/beat_learning/Laquila/ffo/stage_0 backend - INFO Init new trace! smc - INFO Sample initial stage: ... smc - INFO Beta: 0.000000 Stage: 0 sampler - INFO Initialising 1000 chain traces ... sampler - INFO Serial time per sample: 0.000364 sampler - INFO Not using shared memory. sampler - INFO Sampling ... Traceback (most recent call last): File "/anaconda3/bin/beat", line 11, in load_entry_point('beat==1.0rc1', 'console_scripts', 'beat')() File "/anaconda3/lib/python3.6/site-packages/beat-1.0rc1-py3.6-macosx-10.7-x8664.egg/beat/apps/beat.py", line 1588, in main globals()['command' + command](args) File "/anaconda3/lib/python3.6/site-packages/beat-1.0rc1-py3.6-macosx-10.7-x86_64.egg/beat/apps/beat.py", line 755, in command_sample sample(step, problem) File "/anaconda3/lib/python3.6/site-packages/beat-1.0rc1-py3.6-macosx-10.7-x86_64.egg/beat/models/base.py", line 174, in sample rm_flag=pa.rm_flag) File "/anaconda3/lib/python3.6/site-packages/beat-1.0rc1-py3.6-macosx-10.7-x86_64.egg/beat/sampler/smc.py", line 461, in smc_sample mtrace = iter_parallel_chains(*sample_args) File "/anaconda3/lib/python3.6/site-packages/beat-1.0rc1-py3.6-macosx-10.7-x86_64.egg/beat/sampler/base.py", line 483, in iter_parallel_chains for res in p: File "/anaconda3/lib/python3.6/site-packages/beat-1.0rc1-py3.6-macosx-10.7-x86_64.egg/beat/parallel.py", line 224, in paripool yield [function(work)] File "/anaconda3/lib/python3.6/site-packages/beat-1.0rc1-py3.6-macosx-10.7-x86_64.egg/beat/sampler/base.py", line 263, in _sample parallel.borrow_all_memories(shared_params, parallel._shared_memory) File "/anaconda3/lib/python3.6/site-packages/beat-1.0rc1-py3.6-macosx-10.7-x86_64.egg/beat/parallel.py", line 422, in borrow_all_memories borrow_memory(sparam, *memshared_instances[sparam.name]) KeyError: 'geodetic_uparr_static_0'

Can you give me some suggestions? Thank you very much.

hvasbath commented 5 years ago

Hi Nan! Thanks for noticing! I think this is related to a problem in the code. For you it is easy to fix. Can you please set the number of processors to use to higher than one,- I hope you have several CPUs? If you only use one core it will run quite a long time. It is the n_jobs parameter in the sampler_parameter config. Anyways I will have to fix it that it also runs for a single core ...

hvasbath commented 5 years ago

It should be working now with n_jobs = 1 as well after you update. It is fixed in this commit : https://github.com/hvasbath/beat/commit/10132e979b40f70bf37be0b90dc21fb3e30e5560

nanfang0422 commented 5 years ago

Hi Hannes, Thank you for your suggestions. After I set the n_jobs to 4, it's running well now.