Comments (2)
Daphne can provide a code example of how this can be integrated.
from deepcave.
Example Code:
import json
from pathlib import Path
import numpy as np
from deepcave.runs import Status
from deepcave.runs.objective import Objective
from deepcave.runs.run import Run
from deepcave.utils.hash import file_to_hash
class SMAC3v2Run(Run):
prefix = "SMAC3v2_MO"
_initial_order = 2
@property
def hash(self):
if self.path is None:
return ""
# Use hash of history.json as id
return file_to_hash(self.path / "runhistory.json")
@property
def latest_change(self):
if self.path is None:
return 0
return Path(self.path / "runhistory.json").stat().st_mtime
@classmethod
def from_path(cls, path):
"""
Based on working_dir/run_name/*, return a new trials object.
"""
path = Path(path)
# Read configspace
from ConfigSpace.read_and_write import json as cs_json
with (path / "configspace.json").open("r") as f:
configspace = cs_json.read(f.read())
# Read objectives
# We have to define it ourselves, because we don't know the type of the objective
# Only lock lower
with (path / "scenario.json").open() as json_file:
all_data = json.load(json_file)
objectives = all_data["objectives"]
# objective1 = Objective("Cost", lower=0)
# objective2 = Objective("Time", lower=0)
obj_list = list()
if not isinstance(objectives, list):
objectives = [objectives]
for obj in objectives:
obj_list.append(Objective(obj, lower=0))
obj_list.append(Objective("Time", lower=0))
# Read meta
with (path / "scenario.json").open() as json_file:
meta = json.load(json_file)
meta["run_objectives"] = meta.pop("objectives")
# Let's create a new run object
run = SMAC3v2Run(
name=path.stem, configspace=configspace, objectives=obj_list, meta=meta
)
# We have to set the path manually
run._path = path
# Iterate over the runhistory
with (path / "runhistory.json").open() as json_file:
all_data = json.load(json_file)
data = all_data["data"]
config_origins = all_data["config_origins"]
configs = all_data["configs"]
instance_ids = []
first_starttime = None
seeds = []
for (
config_id,
instance_id,
seed,
budget,
cost,
time,
status,
starttime,
endtime,
additional_info,
) in data:
if instance_id not in instance_ids:
instance_ids += [instance_id]
if len(instance_ids) > 1:
raise RuntimeError("Instances are not supported.")
config_id = str(config_id)
config = configs[config_id]
if seed not in seeds:
seeds.append(seed)
if len(seeds) > 1:
raise RuntimeError("Multiple seeds are not supported.")
if first_starttime is None:
first_starttime = starttime
starttime = starttime - first_starttime
endtime = endtime - first_starttime
if status == 0:
# still running
continue
elif status == 1:
status = Status.SUCCESS
elif status == 3:
status = Status.TIMEOUT
elif status == 4:
status = Status.MEMORYOUT
else:
status = Status.CRASHED
if status != Status.SUCCESS:
# We don't want cost included which are failed
cost = [None]*len(cost) if isinstance(cost, list) else None
time = None
else:
time = endtime - starttime
# Round budget
if budget:
budget = np.round(budget, 2)
else:
budget = 0.0
origin = None
if config_id in config_origins:
origin = config_origins[config_id]
run.add(
costs=cost + [time] if isinstance(cost, list) else [cost, time],
config=config,
budget=budget,
start_time=starttime,
end_time=endtime,
status=status,
origin=origin,
additional=additional_info,
)
return run
from deepcave.
Related Issues (20)
- Varying configspace index order in PDP and symbolic explanations HOT 1
- Remove disabling of existing loggers and deactivate redis-logs
- Check and update documentation
- Add a teaser video
- [Feature] Use of DeepCave API with data loaded in memory
- [Doc] Plugin API usage
- [Possible Minor Bug] Encoding of NaN's in run encoding
- Seemingly random server unresponsiveness
- [Minor Bug] Order of Hyperparameters in Parallel Coordinates should be switched
- Building Documentation Raises non Breaking Errors
- Add new paper & authors in Readme and Docs
- Python 3.11 support
- Random forest surrogate test is not actually executed
- Check and possibly fix record examples
- Make clear that DeepCAVE assumes objectives to be minimized
- Add support for general tabular input format
- Run names in logs are not really distinguishable
- Move Configuration Cube and Parallel Coordinates to Hyperparameter Analysis
- Reading several Runs as Group does not work
- Partial Dependencies shows only vertical line for certain cases
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from deepcave.