Hacktoberfest 2026:維護者為十月標記出來的 issue,仍然開放、適合新手。 瀏覽 Hacktoberfest issue

`petab_files_1to2` keeps a stale model file when converting into a non-empty output directory

未關閉 適合新手
#566 0 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視

維護者通常 1 天內回覆

還沒有人認領這個 Issue。

評估

難度
2/5
預估耗時
1-3 小時
新手友好度
73/100
Issue 類型
缺陷
描述清晰度
描述清楚
活躍度
活躍
技術堆疊
python
領域
backend

研究方向

從 petab/v2/petab1to2.py 中的 _copy_file 開始,追蹤 petab1to2 如何處理輸出目錄,包括現有的 experiments.tsv 情況。使用 issue 中的重現程式碼檢查重複轉換至非空目錄的情況。選定的行為保持一致即代表完成:以 ValueError 拒絕非空輸出目錄,或覆寫現有模型檔案,除非來源與目的地是同一個檔案。

由索引模型根據 Issue 內容生成。

描述

petab_files_1to2 (and petab1to2 with output_dir) doesn't overwrite an existing model file in the output directory. The other tables are overwritten, so the result mixes the new tables with the old model, without any warning.

The cause is _copy_file in petab/v2/petab1to2.py (since #328):

try:
    if dest.samefile(src):
        return
except FileNotFoundError:
    shutil.copy(str(src), str(dest))

If dest exists and is a different file, samefile returns False and nothing is copied.

Reproducer (two v1 problems that differ only in the model's value of k1, converted into the same directory):

import tempfile
from pathlib import Path

import pandas as pd

from petab import v1
from petab.v1.models.sbml_model import SbmlModel
from petab.v2 import Problem
from petab.v2.petab1to2 import petab1to2


def write_v1(path: Path, k1: float) -> Path:
    return v1.Problem(
        model=SbmlModel.from_antimony(f"A = 1; B = 0; k1 = {k1}; A -> B; k1 * A"),
        condition_df=v1.get_condition_df(pd.DataFrame({"conditionId": ["c1"]})),
        observable_df=v1.get_observable_df(
            pd.DataFrame(
                {"observableId": ["obs_B"], "observableFormula": ["B"], "noiseFormula": [0.1]}
            )
        ),
        measurement_df=v1.get_measurement_df(
            pd.DataFrame(
                {"observableId": ["obs_B"], "simulationConditionId": ["c1"], "time": [1.0], "measurement": [0.5]}
            )
        ),
        parameter_df=v1.get_parameter_df(
            pd.DataFrame(
                {"parameterId": ["k1"], "parameterScale": ["lin"], "lowerBound": [1e-3],
                 "upperBound": [1e3], "nominalValue": [0.5], "estimate": [1]}
            )
        ),
    ).to_files_generic(path)


with tempfile.TemporaryDirectory() as tmp:
    tmp = Path(tmp)
    out = tmp / "v2"
    out.mkdir()
    petab1to2(write_v1(tmp / "v1_a", k1=0.5), out)
    petab1to2(write_v1(tmp / "v1_b", k1=0.7), out)
    problem = Problem.from_yaml(out / "problem.yaml")
    print(problem.model.sbml_model.getParameter("k1").getValue())
    # 0.5, expected 0.7

With reparametrize="priors" or "all" (#539), converting the same problem twice into the same directory reparametrizes twice: the model left from the first run already contains log10_<id>, so the second run adds log10_<id>_1.

The behaviour for a non-empty output directory is inconsistent: if the problem has a non-empty condition table, the second conversion fails, because an existing experiments.tsv raises a ValueError. Without one, it silently succeeds as above.

Possible fixes:

  1. Require the output directory to be empty or non-existent (and create it), and raise a ValueError otherwise. This makes the behaviour consistent, replaces the special case for experiments.tsv, and avoids leftover files from earlier runs. It rules out converting in place (output directory = input directory), which the samefile check seems meant to support, but converting in place overwrites the v1 files anyway.
  2. Only fix _copy_file, i.e., overwrite dest unless it's the same file as src. This is the minimal change, but leaves the inconsistency with experiments.tsv.

I'd go with 1.

🤖 Generated with Claude Code

主要語言
Python
星號
18
分支
9
平均合併
1 天 8 小時
30 天內合併 PR
21

環境準備

  • 沒有 Dockerfile 或 Docker Compose 檔案
  • 沒有 Pull Request 範本
  • 閱讀貢獻指南

從這裡開始

  1. 先讀完整個 Issue,再讀專案的貢獻指南。
  2. 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
  3. Fork 儲存庫,在一個分支上完成修改。
  4. 送出 Pull Request,並在描述裡引用這個 Issue 編號。

PEtab-dev/libpetab-python 的其他 Issue

查看 PEtab-dev/libpetab-python 的全部 Issue

相似的 Issue

更多 Python Issue

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。