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

Improve error log to json in run_sorter #3057

Merged

Conversation

h-mayorquin
Copy link
Collaborator

As in the title.

In the current PR:

{
    "sorter_name": "kilosort3",
    "sorter_version": "compiled",
    "datetime": "2024-06-20T19:08:55.934035",
    "runtime_trace": [
        "Warning: X does not support locale C.UTF-8",
        "Time   0s. Computing whitening matrix..",
        "Getting channel whitening matrix...",
        "Channel-whitening matrix computed.",
        "Time   2s. Loading raw data and applying filters...",
        "Time   2s. Finished preprocessing 4 batches.",
        "Drift correction ENABLED",
        "vertical pitch size is 20",
        "horizontal pitch size is 20",
        "0    10    20",
        "",
        "6",
        "",
        "----------------------------------------Index in position 1 exceeds array bounds. Index must not exceed 4."
    ],
    "error": true,
    "error_trace": [
        "Traceback (most recent call last):",
        "  File \"/root/.local/lib/python3.9/site-packages/spikeinterface/sorters/basesorter.py\", line 257, in run_from_folder",
        "    SorterClass._run_from_folder(sorter_output_folder, sorter_params, verbose)",
        "  File \"/root/.local/lib/python3.9/site-packages/spikeinterface/sorters/external/kilosortbase.py\", line 217, in _run_from_folder",
        "    raise Exception(f\"{cls.sorter_name} returned a non-zero exit code\")",
        "  Exception: kilosort3 returned a non-zero exit code"
    ],
    "run_time": null
}

Vs what is on main:

{
    "sorter_name": "kilosort3",
    "sorter_version": "compiled",
    "datetime": "2024-06-20T19:16:49.436576",
    "runtime_trace": [
        "Warning: X does not support locale C.UTF-8",
        "Time   0s. Computing whitening matrix..",
        "Getting channel whitening matrix...",
        "Channel-whitening matrix computed.",
        "Time   2s. Loading raw data and applying filters...",
        "Time   2s. Finished preprocessing 4 batches.",
        "Drift correction ENABLED",
        "vertical pitch size is 20",
        "horizontal pitch size is 20",
        "0    10    20",
        "",
        "6",
        "",
        "----------------------------------------Index in position 1 exceeds array bounds. Index must not exceed 4."
    ],
    "error": true,
    "error_trace": "Traceback (most recent call last):\n  File \"/root/.local/lib/python3.9/site-packages/spikeinterface/sorters/basesorter.py\", line 257, in run_from_folder\n    SorterClass._run_from_folder(sorter_output_folder, sorter_params, verbose)\n  File \"/root/.local/lib/python3.9/site-packages/spikeinterface/sorters/external/kilosortbase.py\", line 217, in _run_from_folder\n    raise Exception(f\"{cls.sorter_name} returned a non-zero exit code\")\nException: kilosort3 returned a non-zero exit code\n",
    "run_time": null
}

@h-mayorquin h-mayorquin self-assigned this Jun 20, 2024
error_log_to_display = traceback.format_exc()
trace_lines = error_log_to_display.strip().split("\n")
error_to_json = ["Traceback (most recent call last):"] + [
f" {line}" if not line.startswith(" ") else line for line in trace_lines[1:]
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is the space before {line} needed?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I don't think so. Removing it.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Oh no sorry I understand maybe it was to keep the left-alignment the same for lines that already start with a space vs. dont? In that case can leave, or maybe just .strip() all lines?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I feel it does not matter that much? The big gain is dividing the error trace in lines so it does not appear like a super-long-line in json I feel.

@JoeZiminski
Copy link
Collaborator

JoeZiminski commented Jun 21, 2024

Nice! This looks good to me and I appreciate it after doing lots of scrolling to read those error messages. My only thoughts are (I know nothing about how these stacktraces are generated) to be sure that the line f" {line}" if not line.startswith(" ") else line for line in trace_lines[1:] will work predictably against errors generated by all sorters.

@alejoe91 alejoe91 added the sorters Related to sorters module label Jun 21, 2024
@h-mayorquin
Copy link
Collaborator Author

Nice! This looks good to me and I appreciate it after doing lots of scrolling to read those error messages. My only thoughts are (I know nothing about how these stacktraces are generated) to be sure that the line f" {line}" if not line.startswith(" ") else line for line in trace_lines[1:] will work predictably against errors generated by all sorters.

This is the python trace that we get from the module:

https://docs.python.org/3/library/traceback.html

They are meant to be displayed in a terminal so they will be divided by lines.

My confidence is that it will generalize but of course can't know, we will have to wait and see.

@JoeZiminski
Copy link
Collaborator

I see it is just a generic traceback that makes sense, thanks LGTM!

@JoeZiminski JoeZiminski self-requested a review June 26, 2024 23:40
error_log_to_display = traceback.format_exc()
trace_lines = error_log_to_display.strip().split("\n")
error_to_json = ["Traceback (most recent call last):"] + [
f" {line}" if not line.startswith(" ") else line for line in trace_lines[1:]
Copy link
Collaborator

Choose a reason for hiding this comment

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

Oh no sorry I understand maybe it was to keep the left-alignment the same for lines that already start with a space vs. dont? In that case can leave, or maybe just .strip() all lines?

@alejoe91 alejoe91 added this to the 0.101.0 milestone Jun 27, 2024
@alejoe91 alejoe91 changed the title improve error log to json in run_sorter Improve error log to json in run_sorter Jun 27, 2024
@samuelgarcia
Copy link
Member

merci.

@samuelgarcia samuelgarcia merged commit c9d4511 into SpikeInterface:main Jun 28, 2024
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
sorters Related to sorters module
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants