kmos icon indicating copy to clipboard operation
kmos copied to clipboard

Feed Parameters from Dictionaries

Open jmlorenzi opened this issue 11 years ago • 6 comments

I have a very short helper function that takes a KMC_Model instance and a dictionary and tries to set up the attributes of the KMC_Model.parameters. Would you be interested in including that in the Model_Parameters class, so as to be able to do something like model.parameters.set(dictionary) ?

jmlorenzi avatar Nov 07 '14 17:11 jmlorenzi

Sounds useful. What is the format of that dictionary? I am asking because there was a dictionary way before but it looks a bit clumsy because every dictionary needed the 'value' attribute, so it looked convoluted in many cases. However this method was also able to handle other attributes such as min, max. Is your method maybe able to handle both?

2014-11-07 9:13 GMT-08:00 Juan M. Lorenzi [email protected]:

I have a very short helper function that takes a KMC_Model instance and a dictionary and tries to set up the attributes of the KMC_Model.parameters. Would you be interested in including that in the Model_Parameters class, so as to be able to do something like model.parameters.set(dictionary) ?

— Reply to this email directly or view it on GitHub https://github.com/mhoffman/kmos/issues/12.

Dr. Max J. Hoffmann

Dept. of Chemical Engineering PHONE: +1 650 521 7187 Stanford University [email protected] Shriram Center 443 Via Ortega Room 315 Stanford, CA 94035-4300 (U.S.A.)

mhoffman avatar Nov 08 '14 16:11 mhoffman

The dictionary is just a dictionary {'param_name':value,...}. The method is just a loop over dict.keys() that uses setattr(model.parameters,key,dict[key]). So, it is not so powerful. This was intended for using kmos non interactively, and being able to skip hardcoding model.param.whatever = value. Does max and min affect the behavior of the model outside of live gui kmos? On Nov 8, 2014 5:51 PM, "Max Hoffmann" [email protected] wrote:

Sounds useful. What is the format of that dictionary? I am asking because there was a dictionary way before but it looks a bit clumsy because every dictionary needed the 'value' attribute, so it looked convoluted in many cases. However this method was also able to handle other attributes such as min, max. Is your method maybe able to handle both?

2014-11-07 9:13 GMT-08:00 Juan M. Lorenzi [email protected]:

I have a very short helper function that takes a KMC_Model instance and a dictionary and tries to set up the attributes of the KMC_Model.parameters. Would you be interested in including that in the Model_Parameters class, so as to be able to do something like model.parameters.set(dictionary) ?

— Reply to this email directly or view it on GitHub https://github.com/mhoffman/kmos/issues/12.

Dr. Max J. Hoffmann

Dept. of Chemical Engineering PHONE: +1 650 521 7187 Stanford University [email protected] Shriram Center 443 Via Ortega Room 315 Stanford, CA 94035-4300 (U.S.A.)

— Reply to this email directly or view it on GitHub https://github.com/mhoffman/kmos/issues/12#issuecomment-62264621.

jmlorenzi avatar Nov 08 '14 17:11 jmlorenzi

Does model.parameters.__dict__.update({ ... }) have the same effect as your function? The min/max is only important in the GUI. Maybe add a method like

def update(parameters): return self.__dict__.update(parameters)

would do?

mhoffman avatar Nov 12 '14 05:11 mhoffman

Well, I don't know. I think here I am hitting the limit of my knowledge of kmos and/or python, and I need to read more (kmos source code and python docs). However, I have questions right now... is model.parameters.dict.update calling model.parameters.set_attr ? Do I need to give the update method a complete dictionary (i.e. a dict of dicts which includes max, min, etc as in kmc_settings.py ? Will calling the update thing properly update the rate constants ?

jmlorenzi avatar Nov 12 '14 11:11 jmlorenzi

No. Probably yes. No.

So dict1.update(dict2) merges dict1 and dict2 into dict1 be overwriting the values in dict1 with the values in dict2 if they latter exist.[1] Object.dict is the internal dictionary to store the object methods and attributes. So it would update all the model parameters without hard-coding them as model.parameter. = <num_value>. Good point though that the rate-constants do not get updated. One could do

    self.**dict**.update(parameters)
    set_rate_constants(print_rates=self.print_rates)

...

Why don't you go ahead and send a pull-request with your actual method? I am sure it does the job just fine

Best, Max.

[1] https://docs.python.org/2/library/stdtypes.html#dict.update

2014-11-12 3:22 GMT-08:00 Juan M. Lorenzi [email protected]:

Well, I don't know. I think here I am hitting the limit of my knowledge of kmos and/or python, and I need to read more (kmos source code and python docs). However, I have questions right now... is model.parameters.dict.update calling model.parameters.set_attr ? Do I need to give the update method a complete dictionary (i.e. a dict of dicts which includes max, min, etc as in kmc_settings.py ? Will calling the update thing properly update the rate constants ?

— Reply to this email directly or view it on GitHub https://github.com/mhoffman/kmos/issues/12#issuecomment-62704358.

-- Dr. Max J. Hoffmann

Dept. of Chemical Engineering PHONE: +1 650 521 7187 Stanford University [email protected] Shriram Center 443 Via Ortega Room 315 Stanford, CA 94035-4300 (U.S.A.)

mhoffman avatar Nov 12 '14 15:11 mhoffman

OK. Tomorrow I will implement this and try to more elegantly include the parameter string for non interactive use from my previous pull request and send a more pretty pull request.

Best, Juan

jmlorenzi avatar Nov 12 '14 15:11 jmlorenzi