-
Notifications
You must be signed in to change notification settings - Fork 148
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[trivial] restrict format changes to Logging. #199
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for taking care of this! I would even go one step further and only set the fixed precision for when a timer is printed by a logger, because only there do we want a fixed length of the output. In other places in the code, at least I would prefer a timer output of e.g., "1.01s" to "1.010000s".
src/search/utils/logging.cc
Outdated
@@ -133,4 +133,18 @@ static plugins::TypedEnumPlugin<Verbosity> _enum_plugin({ | |||
{"verbose", "full output"}, | |||
{"debug", "like verbose with additional debug output"} | |||
}); | |||
|
|||
void Log::prepend_header(ostream &stream) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
With saving, changing and undoing the precision flags, this method does a lot of work for what used to be a simple printing. Could this possibly slow down the overall runtime to an extent we don't want?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I hope that the runtime for this is negligible compared to measuring the time and the peak memory usage. But we should run an experiment with blind search that confirms this.
src/search/utils/logging.cc
Outdated
@@ -133,4 +133,18 @@ static plugins::TypedEnumPlugin<Verbosity> _enum_plugin({ | |||
{"verbose", "full output"}, | |||
{"debug", "like verbose with additional debug output"} | |||
}); | |||
|
|||
void Log::prepend_header(ostream &stream) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
void Log::prepend_header(ostream &stream) { | |
void Log::add_prefix(ostream &stream) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Getting a setting precision should have trivial runtime compared to the actual output. The output has to do a floating-point division for every digit. Getting/setting precision is just returning/setting some ints. I would not run an experiment.
|
||
stream.flags(previous_flags); // undo format flag changes | ||
|
||
stream << ", " |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove line break.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If it's just for precision, I think a much more idiomatic way to do this is something like (untested):
streamsize old_precision = stream.precision(new_precision);
// do output
stream.precision(old_precision);
Regarding use of fixed
, do we not want this throughout the planner anyway and perhaps should do it in initialization? I'm not so clear what it does exactly and which other kinds of outputs we do that may/may not want it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't this be a const
function?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes this should be const, and have a signature without parameter, because the stream is already a field of this object.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I do not think that we want fixed
throughout the planner. It would change things like
[t=0.XXXXXXs, 45080 KB] Int hash set load factor: 108/128 = 0.84375
to
[t=0.XXXXXXs, 45080 KB] Int hash set load factor: 108/128 = 0.843750
for blocks/probBLOCKS-4-0.pddl --search "astar(blind())"
(adding tailing zeros).
https://cplusplus.com/reference/ios/fixed/ :
"Notice that the treatment of the precision field differs between the default floating-point notation and the fixed and scientific notations (see precision). On the default floating-point notation, the precision field specifies the maximum number of meaningful digits to display both before and after the decimal point, while in both the fixed and scientific notations, the precision field specifies exactly how many digits to display after the decimal point, even if they are trailing decimal zeros."
https://en.cppreference.com/w/cpp/io/manip/fixed :
│ number │ iomanip │ representation │
├──────────┼────────────┼──────────────────────────┤
│ 0.0 │ fixed │ 0.000000 │
│ 0.0 │ scientific │ 0.000000e+00 │
│ 0.0 │ hexfloat │ 0x0p+0 │
│ 0.0 │ default │ 0 │
├──────────┼────────────┼──────────────────────────┤
│ 0.01 │ fixed │ 0.010000 │
│ 0.01 │ scientific │ 1.000000e-02 │
│ 0.01 │ hexfloat │ 0x1.47ae147ae147bp-7 │
│ 0.01 │ default │ 0.01 │
├──────────┼────────────┼──────────────────────────┤
│ 0.00001 │ fixed │ 0.000010 │
│ 0.00001 │ scientific │ 1.000000e-05 │
│ 0.00001 │ hexfloat │ 0x1.4f8b588e368f1p-17 │
│ 0.00001 │ default │ 1e-05 │
└──────────┴────────────┴──────────────────────────┘```
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! Somehow, none of the four options for 0.00001 looks good to me (for example for the hash table output you mention). All of them other than "fixed" are likely to break at least some tools that parse the output, and the trailing zeros for fixed are ugly. I guess the only reason this doesn't currently break is because these are either not commonly parsed, or the numbers are never so close to 0. It's a bit funny that they write it as "0.00001" in the first column of the table, but none of the available options would allow actually displaying it as "0.00001". ;-)
In any case, if we don't want to invest too much time into this, the less invasive way to do this indeed would be to store and restore all flags including "fixed", like the patch currently does. Not because I think the default is better than fixed for things like the hash table example but because it's a less invasive change. Whether or not we want to eventually change these outputs is then perhaps a concern for another time.
src/search/utils/logging.h
Outdated
@@ -34,7 +34,9 @@ enum class Verbosity { | |||
class Log { | |||
std::ostream &stream; | |||
const Verbosity verbosity; | |||
static const int output_precision = 6; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
static const int output_precision = 6; | |
static const int TIMER_PRECISION = 6; |
|
||
stream << ", " | ||
<< get_peak_memory_in_kb() << " KB] "; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd remove the empty lines and the comments since they don't add info IMO.
src/search/utils/logging.h
Outdated
@@ -34,7 +34,9 @@ enum class Verbosity { | |||
class Log { | |||
std::ostream &stream; | |||
const Verbosity verbosity; | |||
static const int output_precision = 6; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Move the static member above all instance members.
Where do you see 1.010000s? I thought we used the high-precision timer everywhere in the C++ code these days. |
No description provided.