Closed cpwnd closed 1 year ago
Hi @cpwnd , super nice, thank you for this cool contribution! I tested it and it runs smothely on my PC.
Three minor things:
I will work on you PR and implement different levels of the logging. Indeed some of the stuff from the algorithms can be seen as --debug
@philippkraft what do you think about the cli option, logging format and having a logging file?
Hey @thouska, you can now set logfile, logdir and verbosity as "quiet" via cli parameters. I tested it via your suggested way:
from spotpy.cli import main
from spotpy.examples.spot_setup_rosenbrock import spot_setup
setup = spot_setup()
main(setup)
And then start it via command line e.g. $ python script.py --logfile test.log --quiet
The path for the logfile should be possible to set (I assume this can/will be done when working on the cli option).
I think we implemented now all remaining points.
EDIT: See the help message for an explanation on the cli options
-q, --quiet Suppress any logging messages to stdout
during computation
--logfile FILE Logging messages will be written to this
file. If already exists, contents are
appended. A default filename is created with
a current timestamp
--logdir DIRECTORY Logging files will be written to this
directory. Default is "."
Is this line important? Thats the last print statement remaining. https://github.com/thouska/spotpy/blob/6be2dcfa17e34e65dd43bf9f369da39c597d5760/spotpy/database/__init__.py#L21
Maybe it can be replaced by the logger. If yes, then the database/__init__
also needs a logger object.
Changes Missing Coverage | Covered Lines | Changed/Added Lines | % | ||
---|---|---|---|---|---|
spotpy/algorithms/mle.py | 3 | 4 | 75.0% | ||
spotpy/algorithms/sa.py | 1 | 2 | 50.0% | ||
spotpy/database/hdf5.py | 0 | 1 | 0.0% | ||
spotpy/objectivefunctions.py | 19 | 20 | 95.0% | ||
spotpy/algorithms/_algorithm.py | 26 | 28 | 92.86% | ||
spotpy/algorithms/demcz.py | 9 | 11 | 81.82% | ||
spotpy/algorithms/fast.py | 5 | 7 | 71.43% | ||
spotpy/algorithms/rope.py | 6 | 8 | 75.0% | ||
spotpy/analyser.py | 31 | 33 | 93.94% | ||
spotpy/algorithms/abc.py | 10 | 13 | 76.92% | ||
<!-- | Total: | 216 | 254 | 85.04% | --> |
Files with Coverage Reduction | New Missed Lines | % | ||
---|---|---|---|---|
spotpy/algorithms/abc.py | 1 | 84.87% | ||
<!-- | Total: | 1 | --> |
Totals | |
---|---|
Change from base Build 910: | 0.2% |
Covered Lines: | 4155 |
Relevant Lines: | 4901 |
With the last two commits, at least for me, this is finished. Can be merged into master now.
Hi @cpwnd,
thx for pushing this new feature. I tested it on my device and it works almost perfect. However, there is one strange error: Everytime it is started for the frst time in an interactive console, any of the example errors with:
Traceback (most recent call last): File "...\spotpy\examples\tutorial_parallel_computing_hymod.py", line 44, in
sampler=spotpy.algorithms.mc(spot_setup, dbname='Parallel_hymod', dbformat='csv', File "...\spotpy\algorithms\mc.py", line 53, in init super(mc, self).init(*args, **kwargs) File "...\spotpy\algorithms_algorithm.py", line 221, in init self.logger = spotpylogging.instantiate_logger(self.class.name, quiet, logfile, logdir) File "...\spotpy\spotpylogging.py", line 49, in instantiate_logger handler_file = logging.FileHandler(path_to_logfile) File "...\anaconda3\lib\logging__init.py", line 1143, in init StreamHandler.init__(self, self._open()) File "...\anaconda3\lib\logging__init__.py", line 1172, in _open return open(self.baseFilename, self.mode, encoding=self.encoding) OSError: [Errno 22] Invalid argument: '...\spotpy\examples\2021-06-15-spotpy.log'`
If I restated the code from there, it works without any error. Do you have any idea what could cause that behavior?
I don't have an anaconda installation at the moment. But when I start it in an interactive console (ipython) it works. Also I'm using Ubuntu instead of Windows.
How do you start the scripts in anaconda?
Am 15.06.21 um 16:07 schrieb thouska:
Hi @cpwnd https://github.com/cpwnd,
thx for pushing this new feature. I tested it on my device and it works almost perfect. However, there is one strange error: Everytime it is started for the frst time in an interactive console, any of the example errors with:
Traceback (most recent call last): File "...\spotpy\examples\tutorial_parallel_computing_hymod.py", line 44, in sampler=spotpy.algorithms.mc(spot_setup, dbname='Parallel_hymod', dbformat='csv', File "...\spotpy\algorithms\mc.py", line 53, in *init* super(mc, self).*init*(*args, **kwargs) File "...\spotpy\algorithms_algorithm.py", line 221, in *init* self.logger = spotpylogging.instantiate_logger(self.*class*.*name*, quiet, logfile, logdir) File "...\spotpy\spotpylogging.py", line 49, in instantiate_logger handler_file = logging.FileHandler(path_to_logfile) File "...\anaconda3\lib\logging_/init/_.py", line 1143, in *init* StreamHandler.*init*(self, self./open()) File "...\anaconda3\lib\logging_/init//.py", line 1172, in _open return open(self.baseFilename, self.mode, encoding=self.encoding) OSError: [Errno 22] Invalid argument: '...\spotpy\examples\2021-06-15-spotpy.log'`
If I restated the code from there, it works without any error. Do you have any idea what could cause that behavior?
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/thouska/spotpy/pull/244#issuecomment-861530178, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAMTH7ISCMPDF6RVPATK3P3TS5NDDANCNFSM4L2LP2MA.
I start the scripts in Anaconda's spyder editor. I will try, how it works outside of spyer and keep you posted.
@thouska please check the branch again for your Windwos Anaconda setup. I replaced the logging paths now with pathlib.PurePath
s, which are OS agnostic and should work everywhere.
Closing this in favor of #293
Hey I followed your discussion in #239 and went ahead to implement the standard logging library. If you wan't to use the code, I'm happy to contribute.
What is already done
All print calls are replaced with a
logging.info
call. I don't know if the info level is always appropriate. I changed your logging code in analyser.py (EDIT i mean objectivefunctions.py) to use the new main logger. There is one print call in the database package. I don't know if its really necessary.What has to be done
--verbose/debug/quiet
or something like that, to toggle the standard behavior. So we can met the requirements of the issue. I wasn't quite sure how to add a new cli option that. If you point me to the right direction I can add code for e.g. (1)--quiet
=> no console output/everything is printed to the file (2) default (no option) => info level and (3)--debug
which then prints all.debug(...)
messages as well. Also printing to the file can be disabled too.https://github.com/cpwnd/spotpy/blob/15e219692f6d7d8a9553264a5830a92b481cde82/spotpy/spotpylogging.py#L16
Not implemented in this pr
In my opinion would be possible next steps, that can be adressed with future pull requests:
At the moment I tested only with different tutorials from the examples folder.
Hope to hear from you soon :)