-
-
Notifications
You must be signed in to change notification settings - Fork 150
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
Feature/fix long output prints #1513
Feature/fix long output prints #1513
Conversation
ersilia/cli/commands/run.py
Outdated
@@ -10,6 +10,42 @@ | |||
from . import ersilia_cli | |||
|
|||
|
|||
def truncate_output(output, max_items=10, max_chars=500): |
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.
Can we move this function to ersilia/utils/terminal.py
?
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.
okay. please what is the logic behind that for learning purpose?
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.
The function you have created is terminal utility, right? So putting it in its own module makes the code clean and managable.
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 @Abellegese that is indeed the case, @OlawumiSalaam
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.
@Abellegese Thank you very much for this. I am still learning.
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.
Thats very much appreciated @OlawumiSalaam. Keep learning.
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.
@DhanshreeA
I have moved the truncate_output
function to ersilia/utils/terminal.py
as suggested and updated the imports.
ersilia/cli/commands/run.py
Outdated
else: | ||
echo("Something went wrong", fg="red") | ||
else: | ||
if as_table: | ||
print_result_table(result) | ||
if isinstance(result, dict): |
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.
Why do we do this? I wouldn't touch this functionality just yet, we need to deal with print_result_table
separately.
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.
@DhanshreeA
This is explanation of my logic, if it helps. Let me know if you want me to modify anything
if isinstance(result, types.GeneratorType):
for result in mdl.run(input=input, output=output, batch_size=batch_size):
if result is not None:
truncated = truncate_output(result) # Truncate the output
if as_table:
print_result_table(truncated) # Print truncated result as table
else:
echo(truncated) # Print truncated raw output
else:
echo("Something went wrong", fg="red") # Print error if result is None
else:
#truncated = truncate_output(result) # Optional: Truncate non-generator output
if as_table:
print_result_table(result) # Print the entire result as a table
else:
try:
echo(truncated) # Print truncated result
except Exception as e:
echo(f"Error: {e}", fg="red") # Print error if echo fails
print_result_table(truncated) # Fallback: Print truncated result as table
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.
Hi @OlawumiSalaam I mean just try to understand, in this PR you have changed 1 file, run command. I am only seeing you trunctated results in per generator, the other case is not addressed. The print output as table (specifically fixed in my PR) handle printing results from three file types, csv, json and hdf5 also a normal json displayed in the terminal. Maybe you need to create a more general trunctor to handle truncating this files output so that the print table function can display them.
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.
@DhanshreeA @Abellegese
If I understand properly, your suggestion is to extend the functionality of the truncate to handle the other three file types, csv, json and hdf5 so the print table function can display them to?
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 @OlawumiSalaam. But the files shouldn't be modified because users want them.
@OlawumiSalaam can we write a small unit test for the truncate_output method in a |
I have written the unit test. Please review and Please let me know if there is anything else to adjust. Thanks |
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.
This is also not clear what the code is testing. So currently you applied truncation for the case the mdl.run
returns generator. This generator always returns a json based output from the conventional runner, given as below:
[
{
"input": {
"key": "NQQBNZBOOHHVQP-UHFFFAOYSA-N",
"input": "C1=C(SC(=N1)SC2=NN=C(S2)N)[N+](=O)[O-]",
"text": "C1=C(SC(=N1)SC2=NN=C(S2)N)[N+](=O)[O-]"
},
"output": {
"outcome": [
261.313
]
}
}
{
"input": {
"key": "HEFNNWSXXWATRW-UHFFFAOYSA-N",
"input": "CC(C)CC1=CC=C(C=C1)C(C)C(=O)O",
"text": "CC(C)CC1=CC=C(C=C1)C(C)C(=O)O"
},
"output": {
"outcome": [
206.28499999999997
]
}
}
]
In the output: { outcome
section there are several datastructure currently supported by Ersilia such as given below. In the above output case, the datastructure is Single
.
{
"Single": lambda x: isinstance(x, list) and len(x) == 1,
"List": lambda x: isinstance(x, list)
and len(x) > 1
and all(isinstance(item, (str, int, float)) for item in x),
"Flexible List": lambda x: isinstance(x, list)
and all(isinstance(item, (str, int, float)) for item in x),
"Matrix": lambda x: isinstance(x, list)
and all(
isinstance(row, list)
and all(isinstance(item, (str, int, float)) for item in row)
for row in x
),
"Serializable Object": lambda x: isinstance(x, dict),
}
So I believe you should somehow make the truncation function to be able to work with them. Also in the unittest
it there should be a test to test this structures based output.
ersilia/utils/terminal.py
Outdated
elif isinstance(output, str): | ||
if len(output) > max_chars: | ||
suffix = " ... (truncated)" | ||
truncated = output[ | ||
: max_chars - len(suffix) - 1 | ||
].rstrip() # Adjust for space | ||
return f"{truncated} {suffix}" | ||
return output |
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.
Hi @OlawumiSalaam can you explain the case this code truncates or gets used?
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.
@Abellegese
Thank you for your detailed feedback.
This is my first task where I am diving deeper into the Ersilia codebase, and I am still in the process of fully understanding the purpose and structure of each part of the code. Initially, I wasn’t certain whether all models produced the same type of output, so I aimed to create a generic truncation function that could handle common data structures.
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 I understand you clearly now, i should modify the function to handle the supported data structures (e.g., Single, List, Matrix, Serializable Object) as shared from the feedback.
@OlawumiSalaam This test is failing on your branch: Traceback (most recent call last):
|
@DhanshreeA I will push the updated changes |
@DhanshreeA @Abellegese |
Hi @DhanshreeA |
@OlawumiSalaam I think the confusion should resolve once I merge @Abellegese's PR since both of you are working on terminal utilities, specifically those that go within the |
@OlawumiSalaam could you look into the conflicts on this PR? I would first recommend checking out the master branch, seeing how the code works especially with the
|
@DhanshreeA |
Hi @DhanshreeA and @OlawumiSalaam I think there is a misunderstanding here. This is not what I meant by fixing the long output printing. I do not want to modify anything on the CLI, only the logger.DEBUG |
@GemmaTuron |
Closing this PR as we were working on the wrong thing all along. @OlawumiSalaam will create a new PR. |
Thank you for taking your time to contribute to Ersilia, just a few checks before we proceed
Description
This PR addresses an issue where large outputs clutter the terminal, making it difficult to interpret results effectively. Specifically, some models, such as descriptors, produce outputs with thousands of columns which floods the terminal and reduce readability.
Changes to be made
Added
truncate_output
Function:Handles truncation for large outputs, summarizing them with ellipses (...) and providing context about omitted parts.
Ensures clarity and concise representation of outputs.
Modified Output Handling:
Applied
truncate_output
to both regular and generator outputs.Ensured the truncated version is passed to
echo
orprint_result_table
as applicable.Steps taken to implement the fix
Created a utility function,
truncate_output
, within the output handling module.Updated the generator loop and regular output sections to conditionally truncate results based on size.
Verified that truncated outputs integrate seamlessly with echo and
print_result_table
functions.Status
eos4wt0
,eos4u6p
,eos7w6n
,eos4avb
,eos3b5e
, andeos69p9
.To do
Review and address feedback
Is this pull request related to any open issue? If yes, replace issueID below with the issue ID
fixes #1455