`run_sorter_jobs(engine='slurm')` writes an invalid Python script for a preprocessed recording
メンテナーはふだん 2 日以内に返信
まだ誰も着手していません。
評価
調査の方向性
sorters/launcher.pyの183~192行付近にあるSlurmスクリプト生成処理から始め、記録のシリアライズがどのように処理されるかを調べます。未処理、フィルタ済み、スライス済みの記録それぞれについて生成されたスクリプトをコンパイルし、問題を再現してください。報告には実行可能な例が含まれています。3つすべてのスクリプトがコンパイルでき、引用符やバックスラッシュを含む文字列およびパスの引数が安全に処理されれば完了です。
索引モデルが issue の本文から書いたものです。
説明
I found this while reading sorters/launcher.py, not in my own analyses, so this is a "for the sake of improvement" report.
With engine="slurm", the recording is written into the generated script as kwargs["recording"].to_dict() (line 192). Without recursive=True, the parent of a preprocessed or sliced recording is written as its repr, so the script is not valid Python. As sbatch does not parse the script, this would only show up when the job starts.
I have no slurm here, so the example mocks subprocess.run (no sbatch call) and compiles the generated script:
import contextlib
import io
import os
import subprocess
import tempfile
from pathlib import Path
from unittest import mock
from spikeinterface.core import generate_recording
from spikeinterface.preprocessing import bandpass_filter
from spikeinterface.sorters import run_sorter_jobs
if not hasattr(os, "fchmod"): # only needed on Windows with Python < 3.13
os.fchmod = lambda fd, mode: None
def slurm_script(recording, folder):
# sbatch is not called: only the generated script is kept and compiled
job = dict(sorter_name="simple", recording=recording, folder=(folder / "out").as_posix())
done = subprocess.CompletedProcess(args=[], returncode=0, stdout="", stderr="")
with mock.patch("subprocess.run", return_value=done), contextlib.redirect_stdout(io.StringIO()):
run_sorter_jobs([job], engine="slurm", engine_kwargs=dict(tmp_script_folder=folder))
script = folder / "si_script_0.py"
try:
compile(script.read_text(), str(script), "exec")
return "compiles"
except SyntaxError as e:
return f"SyntaxError: {e.msg} (line {e.lineno})"
if __name__ == "__main__":
recording = generate_recording(num_channels=4, durations=[5.0], seed=0)
with tempfile.TemporaryDirectory() as tmp:
print("raw: ", slurm_script(recording, Path(tmp) / "raw"))
print("filtered:", slurm_script(bandpass_filter(recording), Path(tmp) / "filtered"))
print("sliced: ", slurm_script(recording.select_channels(recording.channel_ids[:2]), Path(tmp) / "sliced"))
# Output:
# raw: compiles
# filtered: SyntaxError: invalid decimal literal (line 6)
# sliced: SyntaxError: invalid decimal literal (line 6)
# Expected: the script compiles in all three cases.
A string or path argument containing a quote or a backslash also breaks the script (lines 183-186).
Fix: write the recording to a JSON or pickle file next to the script and load it from there.
I can open a PR with a test if you agree.
- 主要言語
- Python
- スター
- 883
- フォーク
- 291
- 平均マージ
- 3日 17時間
- マージ済み PR(30日)
- 40
環境構築
このプロジェクトには開発コンテナ、Dockerfile、コントリビューションガイドがありません。まず README を読み、一般的な手順ははじめてのコントリビューションガイドを参照してください。
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
SpikeInterface/spikeinterface のほかの issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 83/100
SpikeInterface/spikeinterface#5008 ·
メンテナーはふだん 2 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 74/100
SpikeInterface/spikeinterface#5007 ·
メンテナーはふだん 2 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 82/100
SpikeInterface/spikeinterface#5006 ·
メンテナーはふだん 2 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 83/100
SpikeInterface/spikeinterface#5005 ·
メンテナーはふだん 2 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 76/100
SpikeInterface/spikeinterface#5004 ·
メンテナーはふだん 2 日以内に返信
SpikeInterface/spikeinterface の issue をすべて見る
似ている issue
-
bug
難易度 2/5 1〜3時間 初心者へのやさしさ 69/100
daniel-ospina/tortoise#15308 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 66/100
メンテナーはふだん 1 日以内に返信
-
difficulty:easy prio:low type:bug
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
NatronGitHub/Natron#2405 ·
メンテナーはふだん 1 日以内に返信
-
bug
難易度 2/5 1〜3時間 初心者へのやさしさ 76/100
Jstar269/nakagawa-recomp#3746 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
メンテナーはふだん 1 日以内に返信