-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Visualizations (with more comments) (#248)
* Revert "Revert "Sweep Visualizations" (#247)" This reverts commit 9324f82. * Clarifying comments and docstrings * Additional comments on utils * add sweeps dir * Actually use self.sweeps * Very basic support for multiple sweeps * Remove unittest on test * Annotated command dataclass, added comments, trivial refactor * Make multiplots actually correct * Dataclasses are good * Always use relative imports when possible * Remove unnecessary utils file * Simplify everything by dropping support for plotting multiple sweeps together; deaggregate datasets in the table * Use the layer with the best average AUROC across datasets --------- Co-authored-by: Walter Laurito <[email protected]> Co-authored-by: Nora Belrose <[email protected]>
- Loading branch information
1 parent
1b60b3b
commit 5abcd7d
Showing
9 changed files
with
594 additions
and
34 deletions.
There are no files selected for viewing
This file contains 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 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 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 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,50 @@ | ||
import shutil | ||
from dataclasses import dataclass | ||
from pathlib import Path | ||
|
||
from simple_parsing import field | ||
|
||
from ..files import sweeps_dir | ||
from ..utils import colorize | ||
from .visualize import visualize_sweep | ||
|
||
|
||
def pretty_error(msg): | ||
"""Prints a pretty error message.""" | ||
print(colorize("Error", "red") + f": {msg}") | ||
|
||
|
||
@dataclass | ||
class Plot: | ||
sweeps: list[Path] = field(positional=True, default_factory=list) | ||
"""Names of the sweeps to plot. If empty, the most recent sweep is used.""" | ||
|
||
overwrite: bool = False | ||
"""Whether to overwrite existing plots.""" | ||
|
||
def execute(self): | ||
root_dir = sweeps_dir() | ||
|
||
# If sweep is nonempty, get the paths to the specified sweeps. | ||
# If no sweep is specified, use the most recent one. | ||
if not self.sweeps: | ||
sweep_paths = [max(root_dir.iterdir(), key=lambda f: f.stat().st_ctime)] | ||
print( | ||
f"Reading most recent sweep from \033[1m{sweep_paths[0]}\033[0m" | ||
) # bold | ||
else: | ||
sweep_paths = [root_dir / sweep for sweep in self.sweeps] | ||
|
||
for sweep_path in sweep_paths: | ||
if not sweep_path.exists(): | ||
pretty_error(f"No sweep with name {{{sweep_path}}} found in {root_dir}") | ||
elif (sweep_path / "viz").exists() and not self.overwrite: | ||
pretty_error( | ||
f"[blue]{sweep_path / 'viz'}[/blue] already exists. " | ||
f"Use --overwrite to overwrite." | ||
) | ||
else: | ||
if self.overwrite: | ||
shutil.rmtree(sweep_path / "viz") | ||
|
||
visualize_sweep(sweep_path) |
Oops, something went wrong.