EnzymeML / PyEnzyme

🧬 - Data management and modeling framework based on EnzymeML.
BSD 2-Clause "Simplified" License
21 stars 9 forks source link

Changes in KineticParameter are not logged correctly in Thin Layers #25

Closed JR-1991 closed 2 years ago

JR-1991 commented 2 years ago

According to the EnzymeMLBase class every change should be logged to the objects log-attribute, but in the case of Thin Layers, when writing out, these are written to stdout. In addition, the resulting document lacks these logs, although changes have been applied.

copasi_doc = tl_copasi.write()
copasi_doc.toFile(".", name="EnzymeML_Lagerman_M4_COPASI_Modeled")

Out:

DEBUG:pyenzyme:KineticParameter 'K_si' - value was set from '16.12556695' to '16.114987233151997'
DEBUG:pyenzyme:KineticParameter 'K_n' - value was set from '14.16013538' to '14.168483907055077'
DEBUG:pyenzyme:KineticParameter 'K_s' - value was set from '0.9517666749' to '0.9507535476900487'
DEBUG:pyenzyme:KineticParameter 'k_2' - value was set from '32894.518' to '32862.95620531188'
DEBUG:pyenzyme:KineticParameter 'k_6' - value was set from '1364.827977' to '1364.4033354617336'
DEBUG:pyenzyme:KineticParameter 'k_3' - value was set from '999911.3271' to '999219.6373831154'
DEBUG:pyenzyme:KineticParameter 'K_pg' - value was set from '163.4985656' to '163.46716926999855'
DEBUG:pyenzyme:KineticParameter 'k_5' - value was set from '438.2508805' to '438.2888429562448'
DEBUG:pyenzyme:KineticParameter 'k_4' - value was set from '13120.92495' to '13114.702442929261'
DEBUG:pyenzyme:KineticParameter 'k_4b' - value was set from '572987.5006' to '572414.2215109317'
DEBUG:pyenzyme:KineticParameter 'v_r' - value was set from '10000.0' to '9970.771396002263'
DEBUG:pyenzyme:KineticParameter 'K_p' - value was set from '102.3138715' to '102.18118247102849'
DEBUG:pyenzyme:KineticParameter 'k_d' - value was set from '0.3011902176' to '0.3009933934631488'
fbergmann commented 2 years ago

I think this might have to be handled differently. currently, whenever the log attribute is modified there will be new StreamHandlers added to the pyenzyme logger. Especially already during initialization, the 2 handlers will be added already :

        enzmldoc = EnzymeMLDocument(  ## <-- here the log will be initialized with '' (calling start_logger)
            name=model.getName(), level=model.getLevel(), version=model.getVersion()
        )

        # Add logs to the document
        enzmldoc.log = log ## <--- here another set of handlers is added

so at the very least we need to start, by setting the log already in the construction of the document.

However, with this setup, since the pyenzyme logger class is being used. if we have two documents instantiated side by side, log changes on one document would also materialize in the other one.

fbergmann commented 2 years ago

to prevent the changes to be written out, you might want to set the pyenzyme logger, to set the propagate attribute to False. What is happening, is that after logging on pyenzyme, the record is passed to the root logger, where it is written out, thats why we see it in the notebook.

So maybe add this to your setup_custom_logger function.