Skip to content

Add logging variables to the config file#121

Open
ischeider wants to merge 1 commit into4C-multiphysics:mainfrom
ischeider:add_logging_flag
Open

Add logging variables to the config file#121
ischeider wants to merge 1 commit into4C-multiphysics:mainfrom
ischeider:add_logging_flag

Conversation

@ischeider
Copy link
Copy Markdown
Contributor

Description

The 4Cipp code has a logging option, which is explicitly disabled in the code. I thought it is a good idea to have a flag in the config file or a command line switch to enable logging (to screen or to a file). This is what I propose in this PR.
Please tell me whether you think it's useful.

The problem I see is that the config file is part of the repo itself, and as such might be overwritten if there is a merge conflict (which could happen in this PR...)

The change in yaml_io.py is included because I got an error message when running 4Cipp, and the copilot told me this is caused by a misinterpretation of specific values for floats, which are now converted to none.

also add command line switches
Comment on lines +52 to +61
# rapidyaml may emit non-standard JSON tokens for special float values
# such as 'inf', '-inf' or 'nan' (sometimes lowercase). The standard
# json.loads() will raise JSONDecodeError for these. Replace those
# literal tokens with null so the JSON parser can load the document.
# We only replace standalone tokens that appear as values (followed by
# a comma, closing bracket or closing brace).
json_str = regex.sub(
r"(?<=:\s)(?:-?inf|nan)(?=[,\]\}])", "null", json_str, flags=regex.IGNORECASE
)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This should not be necessary anymore with the last release of rapidyaml.

See biojppm/rapidyaml#574, biojppm/rapidyaml#535 and biojppm/rapidyaml#312

I suspect that you do not have the latest rapidyaml version installed? Otherwise also our pipeline should fail.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

FYI that was the old way we had it implemented #119

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I have ryml 0.10.0 installed, and I get the error without it. What should I do?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Yes that was fixed in 0.11.0 ;)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

okay, but the requirements.txt in the root directory says 0.10.0.
Anyway, with 0.11, the error is indeed gone.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

@ischeider I am sorry, I forgot to update that file in the last PR. In the upstream repos we always compile this file new that's why it did not come up anywhere else.

You can just update the requirements.txt file with

pip-compile --all-extras --output-file=requirements.txt --upgrade requirements.in

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

@ischeider @davidrudlstorfer

We should add rapidyaml>=0.11 in the requirements.in to ensure even in the case we don't do a safe install that it still works :)

Comment on lines +8 to +9
log_output_flag: false
log_output_path: null
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I don't see why we should have this in the config. The config is related to the specific 4C input version, which, if I understand correctly, is not the case for these options.

Comment on lines +166 to +173
# Determine whether logging should be enabled. Precedence:
# 1. CLI --log-file (explicit path)
# 2. CLI --enable-log
# 3. CONFIG.log_output_flag
# When enabled, if a file path is provided (CLI or CONFIG.log_output_path) use it
# and open with mode='w' (replace any existing file). Otherwise log to stdout.
try:
log_file_arg = getattr(parsed_args, "log_file", None)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Tbh, this feels a bit overengineered 😅

IMO, logging is something case-specific and not part of the project config. A log-file path in the config does not make sense to me 🤔

What if we keep the arguments you've added, with the defaults that seem sensible to you (for example: default logging enabled, default file something like fourcipp.log in the current directory?) and drop the config part? I think you are the power user of this feature as well as a motivated contributor, so I think it's fair for you to decide the defaults :)

Is there a particular reason for you to want this in the config?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Actually, the particular reason was the error due to the "old" ryml version. And I did not understand, why there is a logging capability which has to be switched on in the code by deleting the disable.

Anyway, I am not sure whether the proposed feature is really needed, so if you feel it's not, I am perfectly fine with closing the PR without merging.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

My 'beef' was only with the config part of the feature, if you enjoy having the flag in the CLI, I support it :) I'll leave it up to you :)

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.

3 participants