Repository navigation
Prepare library API and docs for PEtab v2 problems #328
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
dweindl
wants to merge
1
commit into
Benchmarking-Initiative:master
Choose a base branch
from
dweindl:prep-v2-groundwork
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
src/python/benchmark_models_petab/base.py → src/python/benchmark_models_petab/v1.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,65 @@ | ||
| """Get a PEtab v2 problem from the collection.""" | ||
|
|
||
| from pathlib import Path | ||
|
|
||
| import pandas as pd | ||
| import petab.v2 as petab | ||
|
|
||
| from .C import MODELS_DIR, PROBLEM_FILENAME, SIMULATIONS_FILENAME, V2_DIRNAME | ||
|
|
||
|
|
||
| def get_problem_yaml_path(id_: str) -> Path: | ||
| """Get the path to the PEtab v2 problem YAML file. | ||
|
|
||
| Parameters | ||
| ---------- | ||
| id_: Problem name, as in `benchmark_models_petab.MODELS`. | ||
|
|
||
| Returns | ||
| ------- | ||
| The path to the PEtab v2 problem YAML file. | ||
| """ | ||
| yaml_path = Path(MODELS_DIR, id_, V2_DIRNAME, PROBLEM_FILENAME) | ||
| if not yaml_path.exists(): | ||
| raise ValueError( | ||
| f"Could not find a v2 YAML for problem with ID `{id_}`. " | ||
| "Most problems in this collection do not have a v2 encoding " | ||
| "yet; see `benchmark_models_petab.v1` for the v1 problem." | ||
| ) | ||
| return yaml_path | ||
|
|
||
|
|
||
| def get_problem(id_: str) -> petab.Problem: | ||
| """Read the PEtab v2 problem from the benchmark collection by name. | ||
|
|
||
| Parameters | ||
| ---------- | ||
| id_: Problem name, as in `benchmark_models_petab.MODELS`. | ||
|
|
||
| Returns | ||
| ------- | ||
| The PEtab v2 problem. | ||
| """ | ||
| yaml_file = get_problem_yaml_path(id_) | ||
| return petab.Problem.from_yaml(yaml_file) | ||
|
|
||
|
|
||
| def get_simulation_df(id_: str) -> pd.DataFrame | None: | ||
| """Get the simulation dataframe for the v2 encoding of the benchmark | ||
| collection problem with the given name. | ||
|
|
||
| Parameters | ||
| ---------- | ||
| id_: Problem name, as in `benchmark_models_petab.MODELS`. | ||
|
|
||
| Returns | ||
| ------- | ||
| The simulation dataframe if it exists, else None. | ||
| """ | ||
| path = Path(MODELS_DIR, id_, V2_DIRNAME, SIMULATIONS_FILENAME) | ||
| if path.is_file(): | ||
| return pd.read_csv( | ||
| path, sep="\t", index_col=None, float_precision="round_trip" | ||
| ) | ||
|
|
||
| return None |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| """Tests for the v2 accessors. | ||
|
|
||
| No problem in the collection has a `v2/` encoding yet, so only the | ||
| "not found" error path can be tested here. Once real `problems/<id>/v2/` | ||
| directories exist, add a happy-path test (`get_problem`/`get_simulation_df` | ||
| on an actual v2 problem) alongside these. | ||
| """ | ||
|
|
||
| import pytest | ||
|
|
||
| import benchmark_models_petab as models | ||
|
|
||
|
|
||
| def test_get_problem_yaml_path_raises_for_missing_v2(): | ||
| with pytest.raises(ValueError, match="v2"): | ||
| models.v2.get_problem_yaml_path(models.MODELS[0]) | ||
|
|
||
|
|
||
| def test_get_problem_raises_for_missing_v2(): | ||
| with pytest.raises(ValueError, match="v2"): | ||
| models.v2.get_problem(models.MODELS[0]) | ||
|
|
||
|
|
||
| def test_get_simulation_df_returns_none_for_missing_v2(): | ||
| assert models.v2.get_simulation_df(models.MODELS[0]) is None |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will probably need some refinement. How do we want to deal with the whole parameter scaling topic? Encode it in the model or condition table, ignore it, ...?