Skip to content

Commit

Permalink
Unified tuner and tree_tuner as well as Evaluation and TreeEvaluation…
Browse files Browse the repository at this point in the history
…. Removed evaluation_binding.
  • Loading branch information
Kerilk committed May 9, 2024
1 parent 8220442 commit f080e5e
Show file tree
Hide file tree
Showing 94 changed files with 1,331 additions and 4,431 deletions.
3 changes: 0 additions & 3 deletions bindings/python/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,14 @@ EXTRA_DIST = \
cconfigspace/configuration_space.py \
cconfigspace/distribution_space.py \
cconfigspace/tree_configuration.py \
cconfigspace/tree_tuner.py \
cconfigspace/features.py \
cconfigspace/interval.py \
cconfigspace/objective_space.py \
cconfigspace/features_evaluation.py \
cconfigspace/tree_evaluation.py \
cconfigspace/binding.py \
cconfigspace/features_tuner.py \
cconfigspace/tuner.py \
cconfigspace/base.py \
cconfigspace/evaluation_binding.py \
cconfigspace/evaluation.py \
test/test_distribution.py \
test/test_tree_tuner.py \
Expand Down
3 changes: 0 additions & 3 deletions bindings/python/cconfigspace/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,10 @@
from .feature_space import *
from .features import *
from .objective_space import *
from .evaluation_binding import *
from .evaluation import *
from .features_evaluation import *
from .tuner import *
from .features_tuner import *
from .tree import *
from .tree_space import *
from .tree_configuration import *
from .tree_evaluation import *
from .tree_tuner import *
62 changes: 26 additions & 36 deletions bindings/python/cconfigspace/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,31 +22,29 @@ def __str__(self):
ccs_object = ct.c_void_p

# Objects
ccs_rng = ccs_object
ccs_distribution = ccs_object
ccs_parameter = ccs_object
ccs_expression = ccs_object
ccs_context = ccs_object
ccs_distribution_space = ccs_object
ccs_search_space = ccs_object
ccs_configuration_space = ccs_object
ccs_binding = ccs_object
ccs_configuration = ccs_object
ccs_feature_space = ccs_object
ccs_features = ccs_object
ccs_objective_space = ccs_object
ccs_evaluation_binding = ccs_object
ccs_evaluation = ccs_object
ccs_features_evaluation = ccs_object
ccs_tuner = ccs_object
ccs_features_tuner = ccs_object
ccs_map = ccs_object
ccs_error_stack = ccs_object
ccs_tree = ccs_object
ccs_tree_space = ccs_object
ccs_tree_configuration = ccs_object
ccs_tree_evaluation = ccs_object
ccs_tree_tuner = ccs_object
ccs_rng = ccs_object
ccs_distribution = ccs_object
ccs_parameter = ccs_object
ccs_expression = ccs_object
ccs_context = ccs_object
ccs_distribution_space = ccs_object
ccs_search_space = ccs_object
ccs_configuration_space = ccs_object
ccs_binding = ccs_object
ccs_search_configuration = ccs_object
ccs_configuration = ccs_object
ccs_feature_space = ccs_object
ccs_features = ccs_object
ccs_objective_space = ccs_object
ccs_evaluation = ccs_object
ccs_features_evaluation = ccs_object
ccs_tuner = ccs_object
ccs_features_tuner = ccs_object
ccs_map = ccs_object
ccs_error_stack = ccs_object
ccs_tree = ccs_object
ccs_tree_space = ccs_object
ccs_tree_configuration = ccs_object

ccs_false = 0
ccs_true = 1
Expand Down Expand Up @@ -156,8 +154,6 @@ class ObjectType(CEnumeration):
'TREE',
'TREE_SPACE',
'TREE_CONFIGURATION',
'TREE_EVALUATION',
'TREE_TUNER',
'DISTRIBUTION_SPACE' ]

class Result(CEnumeration):
Expand Down Expand Up @@ -193,8 +189,7 @@ class Result(CEnumeration):
('ERROR_EXTERNAL', -27),
('ERROR_INVALID_TREE', -28),
('ERROR_INVALID_TREE_SPACE', -29),
('ERROR_INVALID_TREE_TUNER', -30),
('ERROR_INVALID_DISTRIBUTION_SPACE', -31) ]
('ERROR_INVALID_DISTRIBUTION_SPACE', -30) ]

class DataType(CEnumeration):
_members_ = [
Expand Down Expand Up @@ -518,7 +513,7 @@ def _from_handle(cls, h, retain, auto_release):
return klass.from_handle(h, retain = retain, auto_release = auto_release)

@classmethod
def from_handle(cls, h):
def from_handle(cls, h, retain = True):
r = ct.c_int(0)
res = ccs_object_get_refcount(h, ct.byref(r))
Error.check(res)
Expand All @@ -527,7 +522,6 @@ def from_handle(cls, h):
retain = False
auto_release = False
else:
retain = True
auto_release = True
return cls._from_handle(h, retain, auto_release)

Expand Down Expand Up @@ -755,7 +749,6 @@ def _ccs_get_id():
from .parameter import Parameter
from .expression import Expression
from .configuration_space import ConfigurationSpace
from .distribution_space import DistributionSpace
from .configuration import Configuration
from .feature_space import FeatureSpace
from .features import Features
Expand All @@ -769,8 +762,7 @@ def _ccs_get_id():
from .tree import Tree
from .tree_space import TreeSpace
from .tree_configuration import TreeConfiguration
from .tree_evaluation import TreeEvaluation
from .tree_tuner import TreeTuner
from .distribution_space import DistributionSpace

setattr(Object, 'CLASS_MAP', {
ObjectType.RNG: Rng,
Expand All @@ -791,8 +783,6 @@ def _ccs_get_id():
ObjectType.TREE: Tree,
ObjectType.TREE_SPACE: TreeSpace,
ObjectType.TREE_CONFIGURATION: TreeConfiguration,
ObjectType.TREE_EVALUATION: TreeEvaluation,
ObjectType.TREE_TUNER: TreeTuner,
ObjectType.DISTRIBUTION_SPACE: DistributionSpace
})

Expand Down
81 changes: 73 additions & 8 deletions bindings/python/cconfigspace/evaluation.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,24 @@
import ctypes as ct
from .base import Error, Datum, Result, _ccs_get_function, ccs_configuration, ccs_evaluation, ccs_objective_space, ccs_evaluation_result
from .evaluation_binding import EvaluationBinding
from .configuration import Configuration
from .base import Object, Error, CEnumeration, Datum, Result, _ccs_get_function, ccs_search_configuration, ccs_evaluation, ccs_objective_space, ccs_evaluation_result, ccs_bool
from .objective_space import ObjectiveSpace
from .binding import Binding

ccs_create_evaluation = _ccs_get_function("ccs_create_evaluation", [ccs_objective_space, ccs_configuration, ccs_evaluation_result, ct.c_size_t, ct.POINTER(Datum), ct.POINTER(ccs_evaluation)])
ccs_evaluation_get_configuration = _ccs_get_function("ccs_evaluation_get_configuration", [ccs_evaluation, ct.POINTER(ccs_configuration)])
class Comparison(CEnumeration):
_members_ = [
('BETTER', -1),
('EQUIVALENT', 0),
('WORSE', 1),
('NOT_COMPARABLE', 2) ]

class Evaluation(EvaluationBinding):
ccs_create_evaluation = _ccs_get_function("ccs_create_evaluation", [ccs_objective_space, ccs_search_configuration, ccs_evaluation_result, ct.c_size_t, ct.POINTER(Datum), ct.POINTER(ccs_evaluation)])
ccs_evaluation_get_objective_space = _ccs_get_function("ccs_evaluation_get_objective_space", [ccs_evaluation, ct.POINTER(ccs_objective_space)])
ccs_evaluation_get_objective_values = _ccs_get_function("ccs_evaluation_get_objective_values", [ccs_evaluation, ct.c_size_t, ct.POINTER(Datum), ct.POINTER(ct.c_size_t)])
ccs_evaluation_get_result = _ccs_get_function("ccs_evaluation_get_result", [ccs_evaluation, ct.POINTER(ccs_evaluation_result)])
ccs_evaluation_compare = _ccs_get_function("ccs_evaluation_compare", [ccs_evaluation, ccs_evaluation, ct.POINTER(Comparison)])
ccs_evaluation_check = _ccs_get_function("ccs_evaluation_check", [ccs_evaluation, ct.POINTER(ccs_bool)])
ccs_evaluation_get_configuration = _ccs_get_function("ccs_evaluation_get_configuration", [ccs_evaluation, ct.POINTER(ccs_search_configuration)])

class Evaluation(Binding):
def __init__(self, handle = None, retain = False, auto_release = True,
objective_space = None, configuration = None, result = Result.SUCCESS, values = None):
if handle is None:
Expand All @@ -30,12 +42,65 @@ def __init__(self, handle = None, retain = False, auto_release = True,
def from_handle(cls, handle, retain = True, auto_release = True):
return cls(handle = handle, retain = retain, auto_release = auto_release)

@property
def objective_space(self):
if hasattr(self, "_objective_space"):
return self._objective_space
v = ccs_objective_space()
res = ccs_evaluation_get_objective_space(self.handle, ct.byref(v))
Error.check(res)
self._objective_space = ObjectiveSpace.from_handle(v)
return self._objective_space

@property
def result(self):
if hasattr(self, "_result"):
return self._result
v = ccs_evaluation_result()
res = ccs_evaluation_get_result(self.handle, ct.byref(v))
Error.check(res)
self._result = v.value
return self._result

@property
def num_objective_values(self):
if hasattr(self, "_num_objective_values"):
return self._num_objective_values
v = ct.c_size_t()
res = ccs_evaluation_get_objective_values(self.handle, 0, None, ct.byref(v))
Error.check(res)
self._num_objective_values = v.value
return self._num_objective_values

@property
def objective_values(self):
if hasattr(self, "_objective_values"):
return self._objective_values
sz = self.num_objective_values
v = (Datum * sz)()
res = ccs_evaluation_get_objective_values(self.handle, sz, v, None)
Error.check(res)
self._objective_values = tuple(x.value for x in v)
return self._objective_values

def compare(self, other):
v = Comparison(0)
res = ccs_evaluation_compare(self.handle, other.handle, ct.byref(v))
Error.check(res)
return v.value

def check(self):
valid = ccs_bool()
res = ccs_evaluation_check(self.handle, ct.byref(valid))
Error.check(res)
return False if valid.value == 0 else True

@property
def configuration(self):
if hasattr(self, "_configuration"):
return self._configuration
v = ccs_configuration()
v = ccs_search_configuration()
res = ccs_evaluation_get_configuration(self.handle, ct.byref(v))
Error.check(res)
self._configuration = Configuration.from_handle(v)
self._configuration = Object.from_handle(v)
return self._configuration
72 changes: 0 additions & 72 deletions bindings/python/cconfigspace/evaluation_binding.py

This file was deleted.

20 changes: 4 additions & 16 deletions bindings/python/cconfigspace/features_evaluation.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
import ctypes as ct
from .base import Error, Datum, Result, _ccs_get_function, ccs_configuration, ccs_features, ccs_features_evaluation, ccs_objective_space, ccs_evaluation_result
from .evaluation_binding import EvaluationBinding
from .configuration import Configuration
from .base import Error, Datum, Result, _ccs_get_function, ccs_search_configuration, ccs_features, ccs_features_evaluation, ccs_objective_space, ccs_evaluation_result
from .evaluation import Evaluation
from .features import Features

ccs_create_features_evaluation = _ccs_get_function("ccs_create_features_evaluation", [ccs_objective_space, ccs_configuration, ccs_features, ccs_evaluation_result, ct.c_size_t, ct.POINTER(Datum), ct.POINTER(ccs_features_evaluation)])
ccs_features_evaluation_get_configuration = _ccs_get_function("ccs_features_evaluation_get_configuration", [ccs_features_evaluation, ct.POINTER(ccs_configuration)])
ccs_create_features_evaluation = _ccs_get_function("ccs_create_features_evaluation", [ccs_objective_space, ccs_search_configuration, ccs_features, ccs_evaluation_result, ct.c_size_t, ct.POINTER(Datum), ct.POINTER(ccs_features_evaluation)])
ccs_features_evaluation_get_features = _ccs_get_function("ccs_features_evaluation_get_features", [ccs_features_evaluation, ct.POINTER(ccs_features)])

class FeaturesEvaluation(EvaluationBinding):
class FeaturesEvaluation(Evaluation):
def __init__(self, handle = None, retain = False, auto_release = True,
objective_space = None, configuration = None, features = None, result = Result.SUCCESS, values = None):
if handle is None:
Expand All @@ -32,16 +30,6 @@ def __init__(self, handle = None, retain = False, auto_release = True,
def from_handle(cls, handle, retain = True, auto_release = True):
return cls(handle = handle, retain = retain, auto_release = auto_release)

@property
def configuration(self):
if hasattr(self, "_configuration"):
return self._configuration
v = ccs_configuration()
res = ccs_features_evaluation_get_configuration(self.handle, ct.byref(v))
Error.check(res)
self._configuration = Configuration.from_handle(v)
return self._configuration

@property
def features(self):
if hasattr(self, "_features"):
Expand Down
Loading

0 comments on commit f080e5e

Please sign in to comment.