Deltares / Wflow.jl

Hydrological modeling
https://deltares.github.io/Wflow.jl/dev/
MIT License
108 stars 17 forks source link

log.txt not updated after changing parameter through change in config=Wflow.config(wflwow_sbm.toml) #234

Open ahweerts opened 1 year ago

ahweerts commented 1 year ago
    "-e"
   "using Wflow;
    config = Wflow.Config(\"model/{{inputs.parameters.uuid}}/wflow_sbm.toml\");
    config.input.lateral.subsurface.ksathorfrac.value=({{workflow.parameters.ksathorfrac}});
    Wflow.run(config);

log.txt keeps default value and not the the value assigned ({{workflow.parameters.ksathorfrac}});

this is de default in the toml

[input.lateral.subsurface] ksathorfrac.value = 100

visr commented 1 year ago

That is strange, this should work. I tried, but cannot reproduce:

using Wflow

# modified TOML to have
# [input.lateral.subsurface]
# ksathorfrac.value = 1.0
config = Wflow.Config("test/sbm_simple.toml")

config.input.lateral.subsurface.ksathorfrac.value  # 1.0
config.input.lateral.subsurface.ksathorfrac.value = 2.0
config.input.lateral.subsurface.ksathorfrac.value  # 2.0

Wflow.run(config)  # logs: Info: Set `lateral.subsurface.ksathorfrac` using default value `2.0`.

Perhaps you could add println(config.input.lateral.subsurface.ksathorfrac.value); before and after your change to make sure it is working as intended?

ahweerts commented 1 year ago

thx, i see that the log.txt file is not created at all, hence they are all the same. I also see the value is properly being picked up. However, I don't understand why the log.txt file is not being created.

visr commented 1 year ago

Oh yes if you use Wflow.run with a config object rather than a path to a TOML file it doesn't create the logging file.

This is mentioned in the docstring

https://github.com/Deltares/Wflow.jl/blob/d1dcbfefa4f7937cceaf6c22feae3e1e0c14dd14/src/Wflow.jl#L137-L138

But would be good to mention in the logging docs as well.

Probably we can also fix that, right now it's done like that do avoid creating the file twice since one method calls the other.

verseve commented 1 year ago

I have added a small sentence to the logging docs about this: https://github.com/Deltares/Wflow.jl/commit/a41dc5317747e1ee12119116c9d99d22c95e8428.

We could indeed fix this. On the other hand, since this is in most cases run from a custom Julia file, I guess it is probably easier to just implement the logging at that level.

pauwiersma commented 9 months ago

I'm running wflow through the pywflow wrapper, which uses Wflow.run with a config object, so I'm having the same problem. It would be very helpful to be able to set the silent=True setting in the toml file. Has there been any development on this bug, and if not, is there perhaps a quick patch that I can apply locally where I hardcode the option to not print everything to the terminal? I could try it myself but I doubt that I'll find a solution quickly

verseve commented 9 months ago

It would be very helpful to be able to set the silent=True setting in the toml file.

It is possible to set silent=true in the TOML file. Would that help in your case?

If logging to a file is in your case important, you could follow the logic in the Wflow.run function with a TOML path for the logging part, and use that in a custom run function.

pauwiersma commented 9 months ago

I have added silent=True to the TOML file, along with loglevel and pathlog but none of them are read. I found out that bmi.initialize() actually doesn't call any of the run() functions in Wflow.jl but goes directly to initialize_sbm_model() in sbm_model.jl. Copy-pasting the logging lines from run(tomlpath::AbstractString) to this function does the silencing job for now. Somehow if I set silent=False and loglevel=warn it still prints all the info statements and nothing is written to the logfile but I'm not really concerned about this for the moment.