-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
127 changed files
with
3,257 additions
and
929 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
__version__ = "1.3.3" | ||
__version__ = "1.4.0" |
File renamed without changes.
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,75 @@ | ||
import os | ||
from collections import OrderedDict | ||
|
||
from pandas import DataFrame | ||
|
||
from cave.analyzer.base_analyzer import BaseAnalyzer | ||
from cave.utils.apt_helpers.apt_warning import apt_warning | ||
from cave.utils.exceptions import Deactivated | ||
|
||
|
||
class APTOverview(BaseAnalyzer): | ||
""" | ||
Overview of AutoPyTorch-Specific Configurations | ||
""" | ||
def __init__(self, runscontainer): | ||
super().__init__(runscontainer) | ||
self.output_dir = runscontainer.output_dir | ||
|
||
if self.runscontainer.file_format != "APT": | ||
raise Deactivated("{} deactivated, only designed for file-format APT (but detected {})".format( | ||
self.get_name(), self.runscontainer.file_format | ||
)) | ||
|
||
apt_warning(self.logger) | ||
|
||
html_table = self.run() | ||
self.result["General"] = {"table": html_table, | ||
"tooltip": "AutoPyTorch configuration."} | ||
|
||
def get_name(self): | ||
return "Auto-PyTorch Overview" | ||
|
||
def run(self): | ||
""" Generate tables. """ | ||
# Run-specific / budget specific infos | ||
runs = self.runscontainer.get_aggregated(keep_folders=True, keep_budgets=False) | ||
apt_config_dict = self._runspec_dict_apt_config(runs) | ||
results_fit_dict = self._runspec_dict_results_fit(runs) | ||
|
||
for k, runspec_dict in [("Auto-PyTorch Configuration", apt_config_dict), | ||
("Results of the fit()-call", results_fit_dict)]: | ||
order_spec = list(list(runspec_dict.values())[0].keys()) # Get keys of any sub-dict for order | ||
html_table_specific = DataFrame(runspec_dict) | ||
html_table_specific = html_table_specific.reindex(order_spec) | ||
html_table_specific = html_table_specific.to_html(escape=False, justify='left') | ||
|
||
self.result[k] = {"table": html_table_specific} | ||
|
||
def _runspec_dict_results_fit(self, runs): | ||
runspec = OrderedDict() | ||
|
||
for idx, run in enumerate(runs): | ||
self.logger.debug("Path to folder for run no. {}: {}".format(idx, str(run.path_to_folder))) | ||
name = os.path.basename(run.path_to_folder) | ||
runspec[name] = OrderedDict() | ||
for k, v in run.share_information['results_fit']['info'].items(): | ||
runspec[name]["Info: " + str(k)] = v | ||
for k, v in run.share_information['results_fit']['optimized_hyperparameter_config'].items(): | ||
runspec[name]["Parameter: " + str(k)] = v | ||
runspec[name]["Budget"] = run.share_information['results_fit']['budget'] | ||
runspec[name]["Loss"] = run.share_information['results_fit']['loss'] | ||
|
||
return runspec | ||
|
||
def _runspec_dict_apt_config(self, runs): | ||
runspec = OrderedDict() | ||
|
||
for idx, run in enumerate(runs): | ||
self.logger.debug("Path to folder for run no. {}: {}".format(idx, str(run.path_to_folder))) | ||
name = os.path.basename(run.path_to_folder) | ||
runspec[name] = OrderedDict() | ||
for k, v in run.share_information['apt_config'].items(): | ||
runspec[name][k] = v | ||
|
||
return runspec |
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,47 @@ | ||
import os | ||
|
||
from cave.analyzer.base_analyzer import BaseAnalyzer | ||
from cave.utils.apt_helpers.apt_warning import apt_warning | ||
from cave.utils.exceptions import Deactivated | ||
|
||
|
||
class APTTensorboard(BaseAnalyzer): | ||
""" | ||
Overview of AutoPyTorch-Specific Configurations | ||
""" | ||
def __init__(self, runscontainer): | ||
super().__init__(runscontainer) | ||
if self.runscontainer.file_format != "APT": | ||
raise Deactivated("{} deactivated, only designed for file-format APT (but detected {})".format( | ||
self.get_name(), self.runscontainer.file_format | ||
)) | ||
apt_warning(self.logger) | ||
self.run() | ||
|
||
def get_name(self): | ||
return "Auto-PyTorch Tensorboard" | ||
|
||
def run(self): | ||
try: | ||
from tensorboard import program | ||
except ModuleNotFoundError: | ||
raise Deactivated("Please install tensorboard to perform this analysis!") | ||
|
||
if len(self.runscontainer.get_folders()) != 1: | ||
raise ValueError("Undefined behaviour for multiple APT-outputs...") | ||
run = self.runscontainer.get_aggregated(keep_budgets=False, keep_folders=True)[0] | ||
|
||
# This line will need to be adapted | ||
single_tfevents_file = run.share_information['tfevents_paths'][0] | ||
tfevents_dir = os.path.split(single_tfevents_file)[0] | ||
self.logger.info("Tensorboard base dir: %s", tfevents_dir) | ||
print(tfevents_dir) | ||
|
||
#for config in traj['config']: | ||
# self.runscontainer.get_tensorboard_result(config['config']) | ||
|
||
tb = program.TensorBoard() | ||
tb.configure(argv=[None, '--logdir', tfevents_dir]) | ||
url = tb.launch() | ||
|
||
self.result["else"] = " <iframe src=" + url + " width=\"950\" height=\"700\"></iframe> " |
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,73 @@ | ||
import os | ||
from collections import namedtuple | ||
|
||
from bokeh.embed import components | ||
from bokeh.io import output_notebook | ||
from bokeh.plotting import show | ||
|
||
from cave.analyzer.apt.base_apt import BaseAPT | ||
from cave.reader.runs_container import RunsContainer | ||
from cave.utils.hpbandster_helpers import format_budgets | ||
|
||
Line = namedtuple('Line', ['name', 'time', 'mean', 'upper', 'lower', 'config']) | ||
|
||
class LossCurves(BaseAPT): | ||
""" | ||
Only works with AutoPyTorch-instance. | ||
Visualize loss-curves of multiple neural networks for comparison in interactive plot. | ||
""" | ||
|
||
def __init__(self, | ||
runscontainer: RunsContainer, | ||
incumbent_trajectory: str=None, | ||
): | ||
""" | ||
""" | ||
super().__init__(runscontainer, | ||
incumbent_trajectory=incumbent_trajectory, | ||
) | ||
|
||
self.rng = self.runscontainer.get_rng() | ||
|
||
self.scenario = self.runscontainer.scenario | ||
self.output_dir = os.path.join(self.runscontainer.output_dir, "tensorboard") | ||
self.rh = self.runscontainer.get_aggregated(False, False)[0].validated_runhistory | ||
# Run-specific / budget specific infos | ||
if len(self.runscontainer.get_budgets()) > 1: | ||
self.runs = self.runscontainer.get_aggregated(keep_folders=False, keep_budgets=True) | ||
else: | ||
self.runs = self.runscontainer.get_aggregated(keep_folders=True, keep_budgets=False) | ||
|
||
self.formatted_budgets = format_budgets(self.runscontainer.get_budgets()) | ||
|
||
# Will be set during execution: | ||
self.plots = [] # List with paths to '.png's | ||
|
||
def get_name(self): | ||
return "Loss Curves" | ||
|
||
def plot(self): | ||
""" | ||
Plot performance over time, using all trajectory entries. | ||
max_time denotes max(wallclock_limit, highest recorded time). | ||
""" | ||
#TODO Read in Tensorboard information | ||
#TODO interactive loss-plots | ||
raise NotImplementedError() | ||
|
||
def get_plots(self): | ||
return self.plots | ||
|
||
|
||
def get_html(self, d=None, tooltip=None): | ||
script, div = components(self.plot()) | ||
if d is not None: | ||
d[self.name] = { | ||
"bokeh" : (script, div), | ||
"tooltip" : self.__doc__, | ||
} | ||
return script, div | ||
|
||
def get_jupyter(self): | ||
output_notebook() | ||
show(self.plot()) |
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
Empty file.
Oops, something went wrong.