`petab_files_1to2` keeps a stale model file when converting into a non-empty output directory
维护者通常 1 天内回复
还没有人认领这个 Issue。
评估
调研方向
从 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:
- Require the output directory to be empty or non-existent (and create it), and raise a
ValueErrorotherwise. This makes the behaviour consistent, replaces the special case forexperiments.tsv, and avoids leftover files from earlier runs. It rules out converting in place (output directory = input directory), which thesamefilecheck seems meant to support, but converting in place overwrites the v1 files anyway. - Only fix
_copy_file, i.e., overwritedestunless it's the same file assrc. This is the minimal change, but leaves the inconsistency withexperiments.tsv.
I'd go with 1.
🤖 Generated with Claude Code
- 主要语言
- Python
- 星标
- 18
- 派生
- 9
- 平均合并
- 2 天 4 小时
- 30 天内合并 PR
- 30
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 没有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
PEtab-dev/libpetab-python 的其他 Issue
-
难度 2/5 1-3 小时 新手友好度 72/100
PEtab-dev/libpetab-python#549 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 72/100
PEtab-dev/libpetab-python#525 ·
维护者通常 1 天内回复
-
难度 4/5 3-5 天 新手友好度 55/100
PEtab-dev/libpetab-python#565 ·
维护者通常 1 天内回复
-
难度 3/5 1-2 天 新手友好度 48/100
PEtab-dev/libpetab-python#555 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 50/100
PEtab-dev/libpetab-python#553 ·
维护者通常 1 天内回复
查看 PEtab-dev/libpetab-python 的全部 Issue
相似的 Issue
-
lesson-submission pending-review
难度 2/5 1-3 小时 新手友好度 72/100
Ikalus1988/MisakaNet#3956 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 78/100
aws-samples/sample-per-model-bedrock#574 ·
维护者通常 1 天内回复
-
难度 1/5 1 小时以内 新手友好度 70/100
521xueweihan/HelloGitHub#4133 ·
-
plot_components fails for logistic models with minmax scaling and no floor可能已有人在做 @RaphaelFakhri 今天认领。 未关闭
难度 2/5 1-3 小时 新手友好度 72/100
维护者通常 4 天内回复
-
Update migen未关闭
难度 2/5 1-3 小时 新手友好度 70/100
YosysHQ/oss-cad-suite-build#220 ·