-
Notifications
You must be signed in to change notification settings - Fork 7
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
Update/use ProblemConfig #353
base: develop
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -11,7 +11,7 @@ | |||||||||||||
from warnings import warn | ||||||||||||||
|
||||||||||||||
import pandas as pd | ||||||||||||||
from pydantic import AnyUrl, BaseModel, Field, RootModel | ||||||||||||||
from pydantic import AnyUrl, BaseModel, Field | ||||||||||||||
|
||||||||||||||
from ..versions import get_major_version | ||||||||||||||
from . import ( | ||||||||||||||
|
@@ -1185,33 +1185,14 @@ def add_measurement( | |||||||||||||
) | ||||||||||||||
|
||||||||||||||
|
||||||||||||||
class VersionNumber(RootModel): | ||||||||||||||
root: str | int | ||||||||||||||
|
||||||||||||||
|
||||||||||||||
class ListOfFiles(RootModel): | ||||||||||||||
"""List of files.""" | ||||||||||||||
|
||||||||||||||
root: list[str | AnyUrl] = Field(..., description="List of files.") | ||||||||||||||
|
||||||||||||||
def __iter__(self): | ||||||||||||||
return iter(self.root) | ||||||||||||||
|
||||||||||||||
def __len__(self): | ||||||||||||||
return len(self.root) | ||||||||||||||
|
||||||||||||||
def __getitem__(self, index): | ||||||||||||||
return self.root[index] | ||||||||||||||
|
||||||||||||||
|
||||||||||||||
class SubProblem(BaseModel): | ||||||||||||||
"""A `problems` object in the PEtab problem configuration.""" | ||||||||||||||
|
||||||||||||||
sbml_files: ListOfFiles = [] | ||||||||||||||
measurement_files: ListOfFiles = [] | ||||||||||||||
condition_files: ListOfFiles = [] | ||||||||||||||
observable_files: ListOfFiles = [] | ||||||||||||||
visualization_files: ListOfFiles = [] | ||||||||||||||
sbml_files: list[str | AnyUrl] = [] | ||||||||||||||
measurement_files: list[str | AnyUrl] = [] | ||||||||||||||
condition_files: list[str | AnyUrl] = [] | ||||||||||||||
observable_files: list[str | AnyUrl] = [] | ||||||||||||||
visualization_files: list[str | AnyUrl] = [] | ||||||||||||||
|
||||||||||||||
|
||||||||||||||
class ProblemConfig(BaseModel): | ||||||||||||||
|
@@ -1227,6 +1208,16 @@ class ProblemConfig(BaseModel): | |||||||||||||
description="The base path to resolve relative paths.", | ||||||||||||||
exclude=True, | ||||||||||||||
) | ||||||||||||||
format_version: VersionNumber = 1 | ||||||||||||||
format_version: str | int = 1 | ||||||||||||||
parameter_file: str | AnyUrl | None = None | ||||||||||||||
problems: list[SubProblem] = [] | ||||||||||||||
|
||||||||||||||
def to_yaml(self, filename: str | Path): | ||||||||||||||
"""Write the configuration to a YAML file. | ||||||||||||||
|
||||||||||||||
filename: Destination file name. The parent directory will be created | ||||||||||||||
if necessary. | ||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not in
Suggested change
.. I think. In the files touched by this PR alone, I see
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, it would make sense to start a style guide.... I'd prefer There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Agreed, but no preference for the specific style |
||||||||||||||
""" | ||||||||||||||
from .yaml import write_yaml | ||||||||||||||
|
||||||||||||||
write_yaml(self.model_dump(), filename) |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,7 +25,6 @@ | |
yaml, | ||
) | ||
from ..v1.models.model import Model, model_factory | ||
from ..v1.problem import ListOfFiles, VersionNumber | ||
from ..v1.yaml import get_path_prefix | ||
from ..v2.C import * # noqa: F403 | ||
from ..versions import parse_version | ||
|
@@ -995,12 +994,12 @@ class SubProblem(BaseModel): | |
"""A `problems` object in the PEtab problem configuration.""" | ||
|
||
model_files: dict[str, ModelFile] | None = {} | ||
measurement_files: ListOfFiles = [] | ||
condition_files: ListOfFiles = [] | ||
experiment_files: ListOfFiles = [] | ||
observable_files: ListOfFiles = [] | ||
visualization_files: ListOfFiles = [] | ||
mapping_files: ListOfFiles = [] | ||
measurement_files: list[str | AnyUrl] = [] | ||
condition_files: list[str | AnyUrl] = [] | ||
experiment_files: list[str | AnyUrl] = [] | ||
observable_files: list[str | AnyUrl] = [] | ||
visualization_files: list[str | AnyUrl] = [] | ||
mapping_files: list[str | AnyUrl] = [] | ||
|
||
|
||
class ExtensionConfig(BaseModel): | ||
|
@@ -1024,7 +1023,17 @@ class ProblemConfig(BaseModel): | |
description="The base path to resolve relative paths.", | ||
exclude=True, | ||
) | ||
format_version: VersionNumber = "2.0.0" | ||
format_version: str = "2.0.0" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That's how it is in the current schema draft. Although not strictly enforced so far, I think it would make sense to always require major.minor. But that's probably a separate discussion. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since there is no benefit to keeping Requiring a full version string is fine for me, but then we need to provide schemas for each minor version. Makes sense to support minor updates to the format, so I'm also in favor of expecting a full There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Agreed, but I'll keep that for a future update. |
||
parameter_file: str | AnyUrl | None = None | ||
problems: list[SubProblem] = [] | ||
extensions: list[ExtensionConfig] = [] | ||
|
||
def to_yaml(self, filename: str | Path): | ||
"""Write the configuration to a YAML file. | ||
|
||
filename: Destination file name. The parent directory will be created | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same doc comment re: |
||
if necessary. | ||
""" | ||
from ..v1.yaml import write_yaml | ||
|
||
write_yaml(self.model_dump(), filename) |
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 can be
list[Path | AnyUrl]
, since pydantic has native support forpathlib.Path
IIRC. But then you might need to make a custom path object that serializes to string https://github.com/dilpath/mkstd/blob/fb4ebfda629b0fb9eedb1def5ab05438ab85696e/mkstd/types/path.pyFine as is, just noting in case it becomes useful later