Skip to content
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

Merged
merged 10 commits into from
Dec 18, 2023

Conversation

SimonDold
Copy link
Contributor

No description provided.

Copy link
Contributor

@jendrikseipp jendrikseipp left a 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".

@SimonDold SimonDold changed the title [trivial] restrict format changes to Duration. [trivial] restrict format changes to Logging. Dec 3, 2023
@@ -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) {

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?

Copy link
Contributor

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.

@@ -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) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
void Log::prepend_header(ostream &stream) {
void Log::add_prefix(ostream &stream) {

Copy link
Contributor

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 << ", "
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove line break.

Copy link
Contributor

@maltehelmert maltehelmert Dec 4, 2023

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.

Copy link
Contributor

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?

Copy link
Contributor Author

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.

Copy link
Contributor Author

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                    │
└──────────┴────────────┴──────────────────────────┘```

Copy link
Contributor

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.

@@ -34,7 +34,9 @@ enum class Verbosity {
class Log {
std::ostream &stream;
const Verbosity verbosity;
static const int output_precision = 6;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
static const int output_precision = 6;
static const int TIMER_PRECISION = 6;


stream << ", "
<< get_peak_memory_in_kb() << " KB] ";
}
Copy link
Contributor

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.

@@ -34,7 +34,9 @@ enum class Verbosity {
class Log {
std::ostream &stream;
const Verbosity verbosity;
static const int output_precision = 6;
Copy link
Contributor

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.

@maltehelmert
Copy link
Contributor

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".

Where do you see 1.010000s? I thought we used the high-precision timer everywhere in the C++ code these days.

@SimonDold SimonDold merged commit 9c5107f into aibasel:main Dec 18, 2023
6 of 11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants