`petab_files_1to2` keeps a stale model file when converting into a non-empty output directory
Mantenedores costumam responder em até 1 dia
Ninguém assumiu esta issue ainda.
Avaliação
- Dificuldade
- 2/5
- Tempo estimado
- 1-3 horas
- Facilidade para iniciantes
- 73/100
Direção de pesquisa
Comece por _copy_file em petab/v2/petab1to2.py e acompanhe como petab1to2 lida com diretórios de saída, incluindo o caso existente de experiments.tsv. Use o reprodutor da issue para verificar conversões repetidas em um diretório não vazio. O trabalho está concluído quando o comportamento escolhido for consistente: rejeitar um diretório de saída não vazio com um ValueError ou sobrescrever um arquivo de modelo existente, a menos que a origem e o destino sejam o mesmo arquivo.
Escrita pelo modelo de indexação a partir do texto da issue.
Descrição
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
- Linguagem predominante
- Python
- Estrelas
- 18
- Forks
- 9
- Merge médio
- 1d 8h
- PRs com merge (30d)
- 21
Preparar o ambiente
- Sem Dockerfile nem arquivo Docker Compose
- Sem modelo de pull request
- Ler o guia de contribuição
Primeiros passos
- Leia a issue inteira e depois o guia de contribuição do projeto.
- Comente na issue dizendo que vai assumir — evita que duas pessoas façam o mesmo trabalho.
- Faça um fork do repositório e trabalhe em uma branch.
- Abra um pull request que referencie o número da issue.
Mais de PEtab-dev/libpetab-python
-
`petab1to2`: random column name for pre-existing `experimentId` columnTalvez já em andamento Um pull request vinculado a esta issue está aberto ou já foi mesclado. Aberta
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 82/100
PEtab-dev/libpetab-python#568 ·
Mantenedores costumam responder em até 1 dia
-
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 72/100
PEtab-dev/libpetab-python#549 ·
Mantenedores costumam responder em até 1 dia
-
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 72/100
PEtab-dev/libpetab-python#525 ·
Mantenedores costumam responder em até 1 dia
-
Deprecation warnings with pandas 3.1 (`inplace`, `read_csv(float_precision=...)`)Talvez já em andamento @dweindl assumiu há 3 dias. Aberta
PEtab-dev/libpetab-python#570 · 1 responsável ·
Mantenedores costumam responder em até 1 dia
-
`petablint` fails for PEtab v2 problems with only warningsTalvez já em andamento @dweindl assumiu há 4 dias. Aberta
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 35/100
PEtab-dev/libpetab-python#567 ·
Mantenedores costumam responder em até 1 dia
Todas as issues de PEtab-dev/libpetab-python
Issues semelhantes
-
bug
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 84/100
GoogleCloudPlatform/gce-rescue#195 ·
Mantenedores costumam responder em até 2 dias
-
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 83/100
Mantenedores costumam responder em até 1 dia
-
intake mcp-intake needs-ac needs-human-review priority:medium
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 67/100
Ikalus1988/MisakaNet#3848 · 2 comentários ·
Mantenedores costumam responder em até 1 dia
-
Dificuldade 1/5 Menos de uma hora Facilidade para iniciantes 75/100
521xueweihan/HelloGitHub#4105 ·
-
bug size:XS
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 83/100
Mantenedores costumam responder em até 1 dia