NCAR / ASAPPyTools

The ASAP Python Toolbox is a collection of stand-alone tools for doing simple tasks, from managing print messages with a set verbosity level, to keeping timing information, to managing simple MPI communication.
https://asappytools.readthedocs.io/en/latest
Apache License 2.0
9 stars 3 forks source link

Python3 error in vprinter.py #29

Open jedwards4b opened 3 years ago

jedwards4b commented 3 years ago
Traceback (most recent call last):
  File "./cesm_tseries_generator.py", line 7, in <module>
    exec(compile(f.read(), __file__, 'exec'))
  File "/glade/work/dbailey/CESM_postprocessing/timeseries/timeseries/cesm_tseries_generator.py", line 406, in <module>
    debugMsg('Running on {0} cores'.format(size), header=True)
  File "/glade/work/dbailey/CESM_postprocessing/cesm-env2/lib/python3.7/site-packages/asaptools/vprinter.py", line 110, in __call__
    if verbosity < self.verbosity:
TypeError: '<' not supported between instances of 'int' and 'list'
dabail10 commented 3 years ago

The fix is this:

    if verbosity < self.verbosity[0]:
        print(self.to_str(*args, **kwargs))

I'm not sure I can post a PR to this repo.

jedwards4b commented 3 years ago

@kmpaul this issue was opened in February and still hasn't been addressed.

kmpaul commented 3 years ago

@jedwards4b: Sorry. I missed this in the noise. Since the fix is so simple, I'd welcome a PR.

kmpaul commented 3 years ago

I also just made you a maintainer so you can advance these issues faster.

dabail10 commented 3 years ago

I'm not sure this fixes it entirely. There are some subtle aspects of the scripts as I recall where verbosity needs to be a list, and others where it is an integer. Can you test this out @kmpaul ?

kmpaul commented 3 years ago

@dabail10: I will. I agree that that doesn't seem like the right fix. I'm unsure why self.verbosity is a list and not an int. Can you provide a "minimal reproducible example" of the problem?

dabail10 commented 3 years ago

I'm not sure if I can. Let me try to dig up my post-process runs.

kmpaul commented 3 years ago

@jedwards4b @dabail10:

In lines 391-398 of NCAR/CESM_postprocessing/CESM_postprocessing/timeseries/timeseries/cesm_timeseries_generator.py:

https://github.com/NCAR/CESM_postprocessing/blob/67d1b1bb12e7ddb0d4d569f78fb09828f6f2120d/timeseries/timeseries/cesm_tseries_generator.py#L391-L398

It indicates that the VPrinter's verbosity is set from the debug value that is gathered in the commandline_options() function. The commandline_options() function defines the --debug option as:

https://github.com/NCAR/CESM_postprocessing/blob/67d1b1bb12e7ddb0d4d569f78fb09828f6f2120d/timeseries/timeseries/cesm_tseries_generator.py#L57-L58

And the debug variable returned by commandline_options() are shown in these two lines here:

https://github.com/NCAR/CESM_postprocessing/blob/67d1b1bb12e7ddb0d4d569f78fb09828f6f2120d/timeseries/timeseries/cesm_tseries_generator.py#L66

https://github.com/NCAR/CESM_postprocessing/blob/67d1b1bb12e7ddb0d4d569f78fb09828f6f2120d/timeseries/timeseries/cesm_tseries_generator.py#L73

According to the argparse documentation for nargs, setting nargs to 1 means that one argument will be "consumed" from the commandline and put into a list. Hence, the options.debug should be a list with 1 element. And the function is returning the [0] element from the list.

So, I don't understand how debug could be a list at all. It should just be an int.

I think we need a way of reproducing the error.