brinckmann / montepython_public

Public repository for the Monte Python Code
MIT License
93 stars 80 forks source link

'Data' object has no attribute 'write_step' #207

Closed Sefa76 closed 3 years ago

Sefa76 commented 3 years ago

Hello everyone,

i am new here and i dont have much expieriance with the code and ive run into an error that i dont know how to resolve. When i try to run the code with my likelyhood i get this errormassage:

Traceback (most recent call last): File "montepython/MontePython.py", line 40, in sys.exit(run()) File "/mnt/c/Users/sefa7/Desktop/Bachlorarbeit/Code/montepython_public-3.4/montepython/run.py", line 45, in run sampler.run(cosmo, data, command_line) File "/mnt/c/Users/sefa7/Desktop/Bachlorarbeit/Code/montepython_public-3.4/montepython/sampler.py", line 46, in run mcmc.chain(cosmo, data, command_line) File "/mnt/c/Users/sefa7/Desktop/Bachlorarbeit/Code/montepython_public-3.4/montepython/mcmc.py", line 841, in chain if acc % data.write_step == 0: AttributeError: 'Data' object has no attribute 'write_step'

I dont really understand why this shows up, because i am able to run the code with the provided input/likelihoodmethod example.param so the error should be on my side, but there is no refference in the error to my code. Thank you for your time

with kind regards, Sefa

shan1525 commented 3 years ago

What param file you are using? How are you running your code? Which likelihood code you are using? Make an elaborate question so that we can figure out what's happening. I wanted to help but I couldn't understand the question properly.

Best, Shan.

Sefa76 commented 3 years ago

Hello Shan

im running the code with time python3 montepython/MontePython.py run -p input/hm_et.param -o chains/hm_et -N 10 i could run the example.param just fine with that

my .param is very simple

data.experiments=['fake_et'] data.parameters['H0'] = [68,60,80,3,1,'cosmo'] the 'fake_et' is a likelihood method i wrote myself, its very simple it just compares values for luminocity distance with values from a .csv

this is the init , the .data only has the path to the .csv ` import os from montepython.likelihood_class import Likelihood import pandas as pd import numpy as np

class fake_et(Likelihood):

    def __init__(self, path, data, command_line):
            #super
            Likelihood.__init__(self, path, data, command_line)
            #define array for values of z and dl and sigma
            dataframe = pd.read_csv(self.datapath).to_numpy()
            self.z = dataframe[0]
            self.d = dataframe[1]
            self.sigma = dataframe[2]

    def loglkl(self, cosmo, data):
            #cosmological model for dl(z)
            d=[]
            for i in range(len(self.z)):
                    d.append(cosmo.luminosity_distance(self.z[i]))
            d=np.array(d)
            #calculate chiq
            loglkl = -0.5 * (d - self.d) ** 2 / (self.sigma ** 2)
            return np.sum(loglkl) 

` thank you for your time with kind regards Sefa

lesgourg commented 3 years ago

Hi @Sefa, I think that I see the point. We forgot to ever define a default value of the variable data.write_step in montepython, because of the habit to end up all .param files with the usual lines (like in all the examples of input files):

#------ Mcmc parameters ----
# Number of steps taken, by default (overwritten by the -N command)
data.N=10
# Number of accepted steps before writing to file the chain. Larger means less
# access to disc, but this is not so much time consuming.
data.write_step=5

You did not have these lines at the end of your .param file, so the code complained. You just need to add them. But I agree that, on our side, we should implement a default value of write_step in the code, such that these lines could in principle be skipped in the .param !

Sefa76 commented 3 years ago

Hello everyone

thanks the code seems to be working now

with kind regards Sefa

brinckmann commented 3 years ago

Added default value for data.write_step in version 3.5 in case it's not specified in the param file.

Best, Thejs