Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions petab/schemas/petab_schema.v2.0.0.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,14 @@ properties:
- type: integer
description: Version of the PEtab format

id:
type: string
description: |
Identifier of the PEtab problem.

This is optional and has no effect on the PEtab problem itself.
pattern: "^[a-zA-Z_]\\w*|^$"

parameter_files:
type: array
description: |
Expand Down
16 changes: 16 additions & 0 deletions petab/v2/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -1630,6 +1630,18 @@ def mappings(self) -> list[Mapping]:
chain.from_iterable(mt.mappings for mt in self.mapping_tables)
)

@property
def id(self) -> str:
"""The ID of the PEtab problem if set, ``None`` otherwise."""
return self.config.id if self.config else None
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
@property
def id(self) -> str:
"""The ID of the PEtab problem if set, ``None`` otherwise."""
return self.config.id if self.config else None
@property
def id(self) -> str | None:
"""The ID of the PEtab problem if set, ``None`` otherwise."""
return self.config.id if self.config else None

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, yeah, I was undecided whether we should go for None or '' if no ID is set. I think always having a string could be more convenient. Any preference?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm, I think the Pythonic way would be to use None, because it's the absence of an ID. Also the "no ID" case is a special case that will always need to be handled, e.g. to avoid writing a file name .yaml to disc. Maybe using None then makes it easier to detect errors since the special case is more explicit. No strong opinion though.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Memo to self: The yaml schema may need updating. If we distinguish empty strings and null/None, the former should raise a validation error whereas the latter should not.


@id.setter
def id(self, value: str):
"""Set the ID of the PEtab problem."""
if self.config is None:
self.config = ProblemConfig(format_version="2.0.0")
self.config.id = value

def get_optimization_parameters(self) -> list[str]:
"""
Get the list of optimization parameter IDs from parameter table.
Expand Down Expand Up @@ -2327,6 +2339,10 @@ class ProblemConfig(BaseModel):
)
#: The PEtab format version.
format_version: str = "2.0.0"

#: The problem ID.
id: str = ""

#: The path to the parameter file, relative to ``base_path``.
# TODO https://github.com/PEtab-dev/PEtab/pull/641:
# rename to parameter_files in yaml for consistency with other files?
Expand Down
Loading