From 3f1ba4af070a71cd0927cb9e616ab5935fd23146 Mon Sep 17 00:00:00 2001 From: Yueqi Chen <245663479+ChenYueqi2024@users.noreply.github.com> Date: Thu, 19 Nov 2026 21:19:28 +0800 Subject: [PATCH 1/2] Replace stale model files when converting to PEtab v2 --- changelog.d/+refresh-converted-model.fix.md | 2 ++ petab/v2/petab1to2.py | 5 ++--- tests/v2/test_conversion.py | 22 ++++++++++++++++++++- 3 files changed, 25 insertions(+), 4 deletions(-) create mode 100644 changelog.d/+refresh-converted-model.fix.md diff --git a/changelog.d/+refresh-converted-model.fix.md b/changelog.d/+refresh-converted-model.fix.md new file mode 100644 index 00000000..6c973771 --- /dev/null +++ b/changelog.d/+refresh-converted-model.fix.md @@ -0,0 +1,2 @@ +Replace stale model files when converting to PEtab v2 in an existing output +directory. diff --git a/petab/v2/petab1to2.py b/petab/v2/petab1to2.py index cea4a73d..bf331950 100644 --- a/petab/v2/petab1to2.py +++ b/petab/v2/petab1to2.py @@ -439,11 +439,10 @@ def _copy_file(src: Path | str, dest: Path): dest_handle.write(src_handle.handle.read()) return - try: + with suppress(FileNotFoundError): if dest.samefile(src): return - except FileNotFoundError: - shutil.copy(str(src), str(dest)) + shutil.copy(src, dest) def v1v2_condition_df( diff --git a/tests/v2/test_conversion.py b/tests/v2/test_conversion.py index bb6c3628..88e79332 100644 --- a/tests/v2/test_conversion.py +++ b/tests/v2/test_conversion.py @@ -953,6 +953,8 @@ def _petab1to2_with_conditions( condition_df: pd.DataFrame, conditions: list[tuple[str, str]], output_dir: Path | None = None, + *, + model_parameter_value: float = 0.5, ) -> Problem: """Convert a minimal PEtab v1 problem with the given condition table. @@ -962,7 +964,7 @@ def _petab1to2_with_conditions( """ problem = v1.Problem( model=SbmlModel.from_antimony( - "A = 1; B = 0; k1 = 0.5; A -> B; k1 * A" + f"A = 1; B = 0; k1 = {model_parameter_value}; A -> B; k1 * A" ), condition_df=v1.get_condition_df(condition_df), observable_df=v1.get_observable_df( @@ -1009,6 +1011,24 @@ def _petab1to2_with_conditions( return Problem.from_yaml(output_dir / Path(yaml_file).name) +def test_petab1to2_replaces_stale_model_file(tmp_path): + """Reusing the output directory must copy the current input model.""" + conditions = pd.DataFrame({v1.C.CONDITION_ID: ["c1"]}) + output_dir = tmp_path / "v2" + output_dir.mkdir() + for value in (0.5, 0.7): + converted = _petab1to2_with_conditions( + tmp_path / f"source-{value}", + conditions, + [("", "c1")], + output_dir, + model_parameter_value=value, + ) + assert ( + converted.model.sbml_model.getParameter("k1").getValue() == value + ) + + def _measured_periods( problem: Problem, ) -> list[list[tuple[float, list[str]]] | None]: From 0405bde3bae954b227d3e395e2dd4b9b1cb4924e Mon Sep 17 00:00:00 2001 From: Yueqi Chen <245663479+ChenYueqi2024@users.noreply.github.com> Date: Thu, 19 Nov 2026 21:19:38 +0800 Subject: [PATCH 2/2] Link changelog entry to PR 618 --- changelog.d/+refresh-converted-model.fix.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/changelog.d/+refresh-converted-model.fix.md b/changelog.d/+refresh-converted-model.fix.md index 6c973771..1f5fe225 100644 --- a/changelog.d/+refresh-converted-model.fix.md +++ b/changelog.d/+refresh-converted-model.fix.md @@ -1,2 +1,3 @@ Replace stale model files when converting to PEtab v2 in an existing output -directory. +directory +([#618](https://github.com/PEtab-dev/libpetab-python/pull/618)).