Skip to content

Commit

Permalink
revised the converter docstrings
Browse files Browse the repository at this point in the history
  • Loading branch information
KrissiHub committed Jan 25, 2024
1 parent 49e3249 commit d91f3dd
Show file tree
Hide file tree
Showing 5 changed files with 111 additions and 42 deletions.
4 changes: 2 additions & 2 deletions deepcave/runs/converters/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
## Modules
----------
bohb
This module is for managing and processing data concerning BOHB
(Bayesian Optimization and Hyperparameter Bandits).
This module provides utilities for managing and processing data concerning a BOHB
(Bayesian Optimization and Hyperparameter Bandits) run.
deepcave
This module defines the DeepCAVE run object.
smac3v1
Expand Down
42 changes: 26 additions & 16 deletions deepcave/runs/converters/bohb.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,9 @@
"""
# BOHBRun
This module is for managing and processing data concerning a BOHB
This module provides utilities for managing and processing data concerning a BOHB
(Bayesian Optimization and Hyperparameter Bandits) run.
Utilities provide getting a hash, as well as the latest change of a file.
## Classes
- BOHBRun: Create a BOHB Run.
"""
Expand All @@ -23,34 +21,46 @@

class BOHBRun(Run):
"""
Create a BOHB Run.
(Bayesian Optimization and Hyperparameter Bandits)
This class extends the Run class.
Utilities provide getting a hash, as well as the latest change of a file.
Create a BOHB (Bayesian Optimization and Hyperparameter Bandits) run.
Properties
----------
path : Path
The path to the "results.json" file.
The path to the run.
"""

prefix = "BOHB"
_initial_order = 2

@property
def hash(self) -> str:
"""Calculate a hash value of the json result file."""
"""
Get the hash of the current run.
If the hash changes, the cache has to be cleared.
This ensures that the cache always holds the latest results of the run.
Returns
-------
str
The hash of the run.
"""
if self.path is None:
return ""

print(self.path)
# Use hash of results.json as id
return file_to_hash(self.path / "results.json")

@property
def latest_change(self) -> Union[float, int]:
"""Get the timestamp of the latest change made to the results file."""
"""
Get the timestamp of the latest change.
Returns
-------
Union[float, int]
The latest change.
"""
if self.path is None:
return 0

Expand All @@ -59,12 +69,12 @@ def latest_change(self) -> Union[float, int]:
@classmethod
def from_path(cls, path: Union[Path, str]) -> "BOHBRun":
"""
Create a BOHB Run from a given path and add a new trial to it.
Create a new BOHB run from a given path and add a new trial to it.
Parameters
----------
path : Union[Path, str]
The pathname to create the Run from.
The pathname to base the run on.
Returns
-------
Expand Down
41 changes: 34 additions & 7 deletions deepcave/runs/converters/deepcave.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,9 @@
# DeepCAVE
This module defines the DeepCAVE run object.
It provides utilities to hash and get the DeepCAVE run object, as well as the latest change.
## Classes
- DeepCAVERun: Define the DeepCAVE run and provide handling utilities.
- DeepCAVERun: Create a DeepCAVE run and provide handling utilities.
"""

from typing import Union
Expand All @@ -19,20 +18,30 @@

class DeepCAVERun(Run):
"""
Define the DeepCAVE run and provide handling utilities.
Create a DeepCAVE run and provide handling utilities.
Properties
----------
path : Path
The path to the "history.jsonl" file.
The path the run.
"""

prefix = "DeepCAVE"
_initial_order = 1

@property
def hash(self) -> str:
"""Calculate a hash value of a jsonl history file to use as id."""
"""
Hash of the current run.
If the hash changes, the cache has to be cleared.
This ensures that the cache always holds the latest results of the run.
Returns
-------
str
The hash of the run.
"""
if self.path is None:
return ""

Expand All @@ -41,13 +50,31 @@ def hash(self) -> str:

@property
def latest_change(self) -> Union[float, int]:
"""Get the timestamp of the latest change made to the history file."""
"""
Get the timestamp of the latest change.
Returns
-------
Union[float, int]
The latest change.
"""
if self.path is None:
return 0

return Path(self.path / "history.jsonl").stat().st_mtime

@classmethod
def from_path(cls, path: Path) -> "DeepCAVERun":
"""Get a DeepCAVE run from a given path."""
"""
Get a DeepCAVE run from a given path.
Parameters
----------
path : Path
The path to base the run on.
Returns
-------
The DeepCAVE run.
"""
return DeepCAVERun(path.stem, path=Path(path))
34 changes: 25 additions & 9 deletions deepcave/runs/converters/smac3v1.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
This module provides utilities to create a SMAC3v1
(Sequential Model-based Algorithm Configuration) run.
It provides utilities to hash, as well a get the latest change of the object.
Version 1.4 is used.
## Classes
- SMAC3v1Run: Define a SMAC3v1 run object.
Expand All @@ -24,24 +25,32 @@

class SMAC3v1Run(Run):
"""
Define a SMAC3v1 run object.
(Sequential Model-based Algorithm Configuration)
Define a SMAC3v1 (Sequential Model-based Algorithm Configuration) run object.
It also provides utilities to hash it and get its latest change.
Version 1.4 is used.
Properties
----------
path : Path
The path to the "runhistory.json" file.
The path to the run.
"""

prefix = "SMAC3v1"
_initial_order = 2

@property
def hash(self) -> str:
"""Calculate a hash value of a json runhistory file to use as id."""
"""
Hash of the current run.
If the hash changes, the cache has to be cleared.
This ensures that the cache always holds the latest results of the run.
Returns
-------
str
The hash of the run.
"""
if self.path is None:
return ""

Expand All @@ -50,7 +59,14 @@ def hash(self) -> str:

@property
def latest_change(self) -> Union[float, int]:
"""Get the timestamp of the latest change of the runhistory file."""
"""
Get the timestamp of the latest change.
Returns
-------
Union[float, int]
The latest change.
"""
if self.path is None:
return 0

Expand All @@ -64,7 +80,7 @@ def from_path(cls, path: Union[Path, str]) -> "SMAC3v1Run":
Parameters
----------
path : Union[Path, str]
The path to base the trial object on.
The path to base the run on.
Returns
-------
Expand Down
32 changes: 24 additions & 8 deletions deepcave/runs/converters/smac3v2.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
This module provides utilities to create a SMAC3v2
(Sequential Model-based Algorithm Configuration) run.
It provides utilities to hash, as well a get the latest change of the object.
Version 2.0.0 is used.
## Classes
- SMAC3v2Run: Define a SMAC3v2 run object.
Expand All @@ -25,24 +26,32 @@

class SMAC3v2Run(Run):
"""
Define a SMAC3v2 run object.
(Sequential Model-based Algorithm Configuration)
Define a SMAC3v2 (Sequential Model-based Algorithm Configuration) run object.
It also provides utilities to hash it and get its latest change.
Version 2.0.0 is used.
Properties
----------
path : Path
The path to the "runhistory.json" file.
The path to the run.
"""

prefix = "SMAC3v2"
_initial_order = 2

@property
def hash(self) -> str:
"""Calculate a hash value of a json runhistory file to use as id."""
"""
Hash of the current run.
If the hash changes, the cache has to be cleared.
This ensures that the cache always holds the latest results of the run.
Returns
-------
str
The hash of the run.
"""
if self.path is None:
return ""

Expand All @@ -51,7 +60,14 @@ def hash(self) -> str:

@property
def latest_change(self) -> Union[float, int]:
"""Get the timestamp of the latest change of the runhistory file."""
"""
Get the timestamp of the latest change.
Returns
-------
Union[float, int]
The latest change.
"""
if self.path is None:
return 0

Expand Down

0 comments on commit d91f3dd

Please sign in to comment.