Skip to content

Commit

Permalink
Add functionality to select all jobs that are finished
Browse files Browse the repository at this point in the history
Fixes #250
  • Loading branch information
mpvanderschelling committed Dec 11, 2023
1 parent 7f96e7e commit 69dbb8b
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 0 deletions.
18 changes: 18 additions & 0 deletions src/f3dasm/_src/experimentdata/_jobqueue.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,24 @@ def reset(self) -> None:
"""Resets the job queue."""
self.jobs = pd.Series(dtype='string')

# Select
# =========================================================================

def select_all(self, status: str) -> _JobQueue:
"""Selects all jobs with a certain status.
Parameters
----------
status : str
Status of the jobs to select
Returns
-------
JobQueue
JobQueue object containing the selected jobs.
"""
return _JobQueue(self.jobs[self.jobs == status])

# Export
# =========================================================================

Expand Down
28 changes: 28 additions & 0 deletions src/f3dasm/_src/experimentdata/experimentdata.py
Original file line number Diff line number Diff line change
Expand Up @@ -377,6 +377,34 @@ def select(self, indices: int | Iterable[int]) -> ExperimentData:
jobs=self._jobs[indices],
domain=self.domain, project_dir=self.project_dir)

def select_with_status(self, status: Literal['open', 'in progress',
'finished', 'error']
) -> ExperimentData:
"""Select a subset of the ExperimentData object with a given status
Parameters
----------
status : Literal['open', 'in progress', 'finished', 'error']
The status to select.
Returns
-------
ExperimentData
The selected ExperimentData object with only the selected status.
Raises
------
ValueError
Raised when invalid status is specified
"""
if status not in [s.value for s in Status]:
raise ValueError(f"Invalid status {status} given. "
f"\nChoose from values: "
f"{', '.join([s.value for s in Status])}")

_indices = self._jobs.select_all(status).indices
return self.select(_indices)

def get_input_data(self,
parameter_names: Optional[str | Iterable[str]] = None
) -> ExperimentData:
Expand Down

0 comments on commit 69dbb8b

Please sign in to comment.