From f080e5ed051880f0b5799a8f960fee80728acbef Mon Sep 17 00:00:00 2001 From: Brice Videau Date: Thu, 9 May 2024 14:11:03 -0500 Subject: [PATCH] Unified tuner and tree_tuner as well as Evaluation and TreeEvaluation. Removed evaluation_binding. --- bindings/python/Makefile.am | 3 - bindings/python/cconfigspace/__init__.py | 3 - bindings/python/cconfigspace/base.py | 62 ++- bindings/python/cconfigspace/evaluation.py | 81 +++- .../python/cconfigspace/evaluation_binding.py | 72 --- .../cconfigspace/features_evaluation.py | 20 +- .../python/cconfigspace/features_tuner.py | 38 +- .../python/cconfigspace/tree_evaluation.py | 41 -- bindings/python/cconfigspace/tree_space.py | 35 +- bindings/python/cconfigspace/tree_tuner.py | 421 ------------------ bindings/python/cconfigspace/tuner.py | 36 +- bindings/python/test/test_features_tuner.py | 4 +- bindings/python/test/test_tree_evaluation.py | 10 +- bindings/python/test/test_tree_space.py | 3 +- bindings/python/test/test_tree_tuner.py | 20 +- bindings/python/test/test_tuner.py | 4 +- bindings/ruby/Makefile.am | 3 - bindings/ruby/lib/cconfigspace.rb | 3 - bindings/ruby/lib/cconfigspace/base.rb | 26 +- bindings/ruby/lib/cconfigspace/evaluation.rb | 57 ++- .../lib/cconfigspace/evaluation_binding.rb | 60 --- .../lib/cconfigspace/features_evaluation.rb | 5 +- .../ruby/lib/cconfigspace/features_tuner.rb | 12 +- .../ruby/lib/cconfigspace/tree_evaluation.rb | 39 -- bindings/ruby/lib/cconfigspace/tree_space.rb | 32 +- bindings/ruby/lib/cconfigspace/tree_tuner.rb | 313 ------------- bindings/ruby/lib/cconfigspace/tuner.rb | 12 +- bindings/ruby/test/test_features_tuner.rb | 2 +- bindings/ruby/test/test_tree_evaluation.rb | 10 +- bindings/ruby/test/test_tree_space.rb | 5 +- bindings/ruby/test/test_tree_tuner.rb | 22 +- bindings/ruby/test/test_tuner.rb | 4 +- connectors/kokkos/ccs-kokkos-connector.cpp | 16 +- include/Makefile.am | 5 +- include/cconfigspace.h | 3 - include/cconfigspace/base.h | 68 ++- include/cconfigspace/evaluation.h | 188 +++++++- include/cconfigspace/evaluation_binding.h | 178 -------- include/cconfigspace/features_evaluation.h | 31 +- include/cconfigspace/features_tuner.h | 60 ++- include/cconfigspace/objective_space.h | 10 +- include/cconfigspace/tree_evaluation.h | 69 --- include/cconfigspace/tree_space.h | 29 +- include/cconfigspace/tree_tuner.h | 386 ---------------- include/cconfigspace/tuner.h | 45 +- samples/test_python.c | 12 +- samples/test_python.py | 4 +- samples/test_ruby.c | 12 +- samples/test_ruby.rb | 2 +- src/Makefile.am | 13 +- src/cconfigspace.c | 1 - src/cconfigspace_deserialize.h | 12 - src/cconfigspace_internal.h | 45 +- src/evaluation.c | 192 +++++--- src/evaluation_binding.c | 122 ----- src/evaluation_binding_internal.h | 92 ---- src/evaluation_deserialize.h | 12 +- src/evaluation_internal.h | 106 ++++- src/features_evaluation.c | 25 +- src/features_evaluation_deserialize.h | 14 +- src/features_evaluation_internal.h | 12 +- src/features_tuner.c | 26 +- src/features_tuner_internal.h | 18 +- src/features_tuner_random.c | 81 ++-- src/features_tuner_user_defined.c | 38 +- src/objective_space.c | 16 +- src/search_configuration_internal.h | 53 +++ src/tree_configuration.c | 53 ++- src/tree_configuration_internal.h | 9 + src/tree_evaluation.c | 253 ----------- src/tree_evaluation_deserialize.h | 122 ----- src/tree_evaluation_internal.h | 40 -- src/tree_space.c | 28 +- src/tree_space_deserialize.h | 11 +- src/tree_space_dynamic.c | 9 +- src/tree_space_static.c | 9 +- src/tree_tuner.c | 139 ------ src/tree_tuner_deserialize.h | 321 ------------- src/tree_tuner_internal.h | 86 ---- src/tree_tuner_random.c | 414 ----------------- src/tree_tuner_user_defined.c | 376 ---------------- src/tuner.c | 20 +- src/tuner_deserialize.h | 2 - src/tuner_internal.h | 20 +- src/tuner_random.c | 71 +-- src/tuner_user_defined.c | 32 +- tests/test_dynamic_tree_space.c | 15 +- tests/test_random_features_tuner.c | 32 +- tests/test_random_tree_tuner.c | 59 ++- tests/test_random_tuner.c | 34 +- tests/test_static_tree_space.c | 15 +- tests/test_user_defined_features_tuner.c | 28 +- tests/test_user_defined_tree_tuner.c | 91 ++-- tests/test_user_defined_tuner.c | 19 +- 94 files changed, 1331 insertions(+), 4431 deletions(-) delete mode 100644 bindings/python/cconfigspace/evaluation_binding.py delete mode 100644 bindings/python/cconfigspace/tree_evaluation.py delete mode 100644 bindings/python/cconfigspace/tree_tuner.py delete mode 100644 bindings/ruby/lib/cconfigspace/evaluation_binding.rb delete mode 100644 bindings/ruby/lib/cconfigspace/tree_evaluation.rb delete mode 100644 bindings/ruby/lib/cconfigspace/tree_tuner.rb delete mode 100644 include/cconfigspace/evaluation_binding.h delete mode 100644 include/cconfigspace/tree_evaluation.h delete mode 100644 include/cconfigspace/tree_tuner.h delete mode 100644 src/evaluation_binding.c delete mode 100644 src/evaluation_binding_internal.h create mode 100644 src/search_configuration_internal.h delete mode 100644 src/tree_evaluation.c delete mode 100644 src/tree_evaluation_deserialize.h delete mode 100644 src/tree_evaluation_internal.h delete mode 100644 src/tree_tuner.c delete mode 100644 src/tree_tuner_deserialize.h delete mode 100644 src/tree_tuner_internal.h delete mode 100644 src/tree_tuner_random.c delete mode 100644 src/tree_tuner_user_defined.c diff --git a/bindings/python/Makefile.am b/bindings/python/Makefile.am index c0ceeff8..c48d5e29 100644 --- a/bindings/python/Makefile.am +++ b/bindings/python/Makefile.am @@ -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 \ diff --git a/bindings/python/cconfigspace/__init__.py b/bindings/python/cconfigspace/__init__.py index 00540633..c630210d 100644 --- a/bindings/python/cconfigspace/__init__.py +++ b/bindings/python/cconfigspace/__init__.py @@ -26,7 +26,6 @@ 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 * @@ -34,5 +33,3 @@ from .tree import * from .tree_space import * from .tree_configuration import * -from .tree_evaluation import * -from .tree_tuner import * diff --git a/bindings/python/cconfigspace/base.py b/bindings/python/cconfigspace/base.py index e8f6f6bf..e4f28831 100644 --- a/bindings/python/cconfigspace/base.py +++ b/bindings/python/cconfigspace/base.py @@ -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 @@ -156,8 +154,6 @@ class ObjectType(CEnumeration): 'TREE', 'TREE_SPACE', 'TREE_CONFIGURATION', - 'TREE_EVALUATION', - 'TREE_TUNER', 'DISTRIBUTION_SPACE' ] class Result(CEnumeration): @@ -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_ = [ @@ -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) @@ -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) @@ -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 @@ -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, @@ -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 }) diff --git a/bindings/python/cconfigspace/evaluation.py b/bindings/python/cconfigspace/evaluation.py index 0a79c038..b542c345 100644 --- a/bindings/python/cconfigspace/evaluation.py +++ b/bindings/python/cconfigspace/evaluation.py @@ -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: @@ -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 diff --git a/bindings/python/cconfigspace/evaluation_binding.py b/bindings/python/cconfigspace/evaluation_binding.py deleted file mode 100644 index 0a635367..00000000 --- a/bindings/python/cconfigspace/evaluation_binding.py +++ /dev/null @@ -1,72 +0,0 @@ -import ctypes as ct -from .base import Error, CEnumeration, Result, ccs_evaluation_result, _ccs_get_function, Datum, DatumFix, ccs_evaluation_binding, ccs_objective_space, ccs_bool -from .binding import Binding -from .objective_space import ObjectiveSpace - -class Comparison(CEnumeration): - _members_ = [ - ('BETTER', -1), - ('EQUIVALENT', 0), - ('WORSE', 1), - ('NOT_COMPARABLE', 2) ] - -ccs_evaluation_binding_get_objective_space = _ccs_get_function("ccs_evaluation_binding_get_objective_space", [ccs_evaluation_binding, ct.POINTER(ccs_objective_space)]) -ccs_evaluation_binding_get_result = _ccs_get_function("ccs_evaluation_binding_get_result", [ccs_evaluation_binding, ct.POINTER(ccs_evaluation_result)]) -ccs_evaluation_binding_get_objective_values = _ccs_get_function("ccs_evaluation_binding_get_objective_values", [ccs_evaluation_binding, ct.c_size_t, ct.POINTER(Datum), ct.POINTER(ct.c_size_t)]) -ccs_evaluation_binding_compare = _ccs_get_function("ccs_evaluation_binding_compare", [ccs_evaluation_binding, ccs_evaluation_binding, ct.POINTER(Comparison)]) -ccs_evaluation_binding_check = _ccs_get_function("ccs_evaluation_binding_check", [ccs_evaluation_binding, ct.POINTER(ccs_bool)]) - -class EvaluationBinding(Binding): - - @property - def objective_space(self): - if hasattr(self, "_objective_space"): - return self._objective_space - v = ccs_objective_space() - res = ccs_evaluation_binding_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_binding_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_binding_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_binding_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_binding_compare(self.handle, other.handle, ct.byref(v)) - Error.check(res) - return v.value - - def check(self): - valid = ccs_bool() - res = ccs_evaluation_binding_check(self.handle, ct.byref(valid)) - Error.check(res) - return False if valid.value == 0 else True diff --git a/bindings/python/cconfigspace/features_evaluation.py b/bindings/python/cconfigspace/features_evaluation.py index f5c08439..851dc6b4 100644 --- a/bindings/python/cconfigspace/features_evaluation.py +++ b/bindings/python/cconfigspace/features_evaluation.py @@ -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: @@ -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"): diff --git a/bindings/python/cconfigspace/features_tuner.py b/bindings/python/cconfigspace/features_tuner.py index 67e97548..651d7b2a 100644 --- a/bindings/python/cconfigspace/features_tuner.py +++ b/bindings/python/cconfigspace/features_tuner.py @@ -1,11 +1,9 @@ import ctypes as ct -from .base import Object, Error, CEnumeration, Result, _ccs_get_function, ccs_context, ccs_parameter, ccs_configuration_space, ccs_configuration, ccs_feature_space, ccs_features, Datum, ccs_objective_space, ccs_features_evaluation, ccs_features_tuner, ccs_retain_object, _register_vector, _unregister_vector +from .base import Object, Error, CEnumeration, Result, _ccs_get_function, ccs_context, ccs_parameter, ccs_search_space, ccs_search_configuration, ccs_feature_space, ccs_features, Datum, ccs_objective_space, ccs_features_evaluation, ccs_features_tuner, ccs_retain_object, _register_vector, _unregister_vector from .context import Context from .parameter import Parameter -from .configuration_space import ConfigurationSpace -from .configuration import Configuration -from .feature_space import FeatureSpace from .features import Features +from .feature_space import FeatureSpace from .objective_space import ObjectiveSpace from .features_evaluation import FeaturesEvaluation @@ -16,14 +14,14 @@ class FeaturesTunerType(CEnumeration): ccs_features_tuner_get_type = _ccs_get_function("ccs_features_tuner_get_type", [ccs_features_tuner, ct.POINTER(FeaturesTunerType)]) ccs_features_tuner_get_name = _ccs_get_function("ccs_features_tuner_get_name", [ccs_features_tuner, ct.POINTER(ct.c_char_p)]) -ccs_features_tuner_get_configuration_space = _ccs_get_function("ccs_features_tuner_get_configuration_space", [ccs_features_tuner, ct.POINTER(ccs_configuration_space)]) +ccs_features_tuner_get_search_space = _ccs_get_function("ccs_features_tuner_get_search_space", [ccs_features_tuner, ct.POINTER(ccs_search_space)]) ccs_features_tuner_get_objective_space = _ccs_get_function("ccs_features_tuner_get_objective_space", [ccs_features_tuner, ct.POINTER(ccs_objective_space)]) ccs_features_tuner_get_feature_space = _ccs_get_function("ccs_features_tuner_get_feature_space", [ccs_features_tuner, ct.POINTER(ccs_feature_space)]) -ccs_features_tuner_ask = _ccs_get_function("ccs_features_tuner_ask", [ccs_features_tuner, ccs_features, ct.c_size_t, ct.POINTER(ccs_configuration), ct.POINTER(ct.c_size_t)]) +ccs_features_tuner_ask = _ccs_get_function("ccs_features_tuner_ask", [ccs_features_tuner, ccs_features, ct.c_size_t, ct.POINTER(ccs_search_configuration), ct.POINTER(ct.c_size_t)]) ccs_features_tuner_tell = _ccs_get_function("ccs_features_tuner_tell", [ccs_features_tuner, ct.c_size_t, ct.POINTER(ccs_features_evaluation)]) ccs_features_tuner_get_optima = _ccs_get_function("ccs_features_tuner_get_optima", [ccs_features_tuner, ccs_features, ct.c_size_t, ct.POINTER(ccs_features_evaluation), ct.POINTER(ct.c_size_t)]) ccs_features_tuner_get_history = _ccs_get_function("ccs_features_tuner_get_history", [ccs_features_tuner, ccs_features, ct.c_size_t, ct.POINTER(ccs_features_evaluation), ct.POINTER(ct.c_size_t)]) -ccs_features_tuner_suggest = _ccs_get_function("ccs_features_tuner_suggest", [ccs_features_tuner, ccs_features, ct.POINTER(ccs_configuration)]) +ccs_features_tuner_suggest = _ccs_get_function("ccs_features_tuner_suggest", [ccs_features_tuner, ccs_features, ct.POINTER(ccs_search_configuration)]) class FeaturesTuner(Object): @classmethod @@ -80,22 +78,22 @@ def feature_space(self): return self._feature_space @property - def configuration_space(self): - if hasattr(self, "_configuration_space"): - return self._configuration_space - v = ccs_configuration_space() - res = ccs_features_tuner_get_configuration_space(self.handle, ct.byref(v)) + def search_space(self): + if hasattr(self, "_search_space"): + return self._search_space + v = ccs_search_space() + res = ccs_features_tuner_get_search_space(self.handle, ct.byref(v)) Error.check(res) - self._configuration_space = ConfigurationSpace.from_handle(v) - return self._configuration_space + self._search_space = Object.from_handle(v) + return self._search_space def ask(self, features, count = 1): - v = (ccs_configuration * count)() + v = (ccs_search_configuration * count)() c = ct.c_size_t() res = ccs_features_tuner_ask(self.handle, features.handle, count, v, ct.byref(c)) Error.check(res) count = c.value - return [Configuration(handle = ccs_configuration(v[x]), retain = False) for x in range(count)] + return [Object.from_handle(ccs_search_configuration(v[x]), retain = False) for x in range(count)] def tell(self, evaluations): count = len(evaluations) @@ -138,10 +136,10 @@ def optima(self, features = None): return [FeaturesEvaluation.from_handle(ccs_features_evaluation(x)) for x in v] def suggest(self, features): - config = ccs_configuration() + config = ccs_search_configuration() res = ccs_features_tuner_suggest(self.handle, features.handle, ct.byref(config)) Error.check(res) - return Configuration(handle = config, retain = False) + return Object.from_handle(config, retain = False) ccs_create_random_features_tuner = _ccs_get_function("ccs_create_random_features_tuner", [ct.c_char_p, ccs_feature_space, ccs_objective_space, ct.POINTER(ccs_features_tuner)]) @@ -159,11 +157,11 @@ def __init__(self, handle = None, retain = False, auto_release = True, FeaturesTuner.Random = RandomFeaturesTuner ccs_user_defined_features_tuner_del_type = ct.CFUNCTYPE(Result, ccs_features_tuner) -ccs_user_defined_features_tuner_ask_type = ct.CFUNCTYPE(Result, ccs_features_tuner, ccs_features, ct.c_size_t, ct.POINTER(ccs_configuration), ct.POINTER(ct.c_size_t)) +ccs_user_defined_features_tuner_ask_type = ct.CFUNCTYPE(Result, ccs_features_tuner, ccs_features, ct.c_size_t, ct.POINTER(ccs_search_configuration), ct.POINTER(ct.c_size_t)) ccs_user_defined_features_tuner_tell_type = ct.CFUNCTYPE(Result, ccs_features_tuner, ct.c_size_t, ct.POINTER(ccs_features_evaluation)) ccs_user_defined_features_tuner_get_optima_type = ct.CFUNCTYPE(Result, ccs_features_tuner, ccs_features, ct.c_size_t, ct.POINTER(ccs_features_evaluation), ct.POINTER(ct.c_size_t)) ccs_user_defined_features_tuner_get_history_type = ct.CFUNCTYPE(Result, ccs_features_tuner, ccs_features, ct.c_size_t, ct.POINTER(ccs_features_evaluation), ct.POINTER(ct.c_size_t)) -ccs_user_defined_features_tuner_suggest_type = ct.CFUNCTYPE(Result, ccs_features_tuner, ccs_features, ct.POINTER(ccs_configuration)) +ccs_user_defined_features_tuner_suggest_type = ct.CFUNCTYPE(Result, ccs_features_tuner, ccs_features, ct.POINTER(ccs_search_configuration)) ccs_user_defined_features_tuner_serialize_type = ct.CFUNCTYPE(Result, ccs_features_tuner, ct.c_size_t, ct.c_void_p, ct.POINTER(ct.c_size_t)) ccs_user_defined_features_tuner_deserialize_type = ct.CFUNCTYPE(Result, ccs_features_tuner, ct.c_size_t, ct.POINTER(ccs_features_evaluation), ct.c_size_t, ct.POINTER(ccs_features_evaluation), ct.c_size_t, ct.c_void_p) diff --git a/bindings/python/cconfigspace/tree_evaluation.py b/bindings/python/cconfigspace/tree_evaluation.py deleted file mode 100644 index 6c6c8bf0..00000000 --- a/bindings/python/cconfigspace/tree_evaluation.py +++ /dev/null @@ -1,41 +0,0 @@ -import ctypes as ct -from .base import Error, Datum, Result, _ccs_get_function, ccs_tree_configuration, ccs_tree_evaluation, ccs_objective_space, ccs_evaluation_result -from .evaluation_binding import EvaluationBinding -from .tree_configuration import TreeConfiguration - -ccs_create_tree_evaluation = _ccs_get_function("ccs_create_tree_evaluation", [ccs_objective_space, ccs_tree_configuration, ccs_evaluation_result, ct.c_size_t, ct.POINTER(Datum), ct.POINTER(ccs_tree_evaluation)]) -ccs_tree_evaluation_get_configuration = _ccs_get_function("ccs_tree_evaluation_get_configuration", [ccs_tree_evaluation, ct.POINTER(ccs_tree_configuration)]) - -class TreeEvaluation(EvaluationBinding): - def __init__(self, handle = None, retain = False, auto_release = True, - objective_space = None, configuration = None, result = Result.SUCCESS, values = None): - if handle is None: - count = 0 - if values: - count = len(values) - vals = (Datum * count)() - ss = [] - for i in range(count): - vals[i].set_value(values[i], string_store = ss) - else: - vals = None - handle = ccs_tree_evaluation() - res = ccs_create_tree_evaluation(objective_space.handle, configuration.handle, result, count, vals, ct.byref(handle)) - Error.check(res) - super().__init__(handle = handle, retain = False) - else: - super().__init__(handle = handle, retain = retain, auto_release = auto_release) - - @classmethod - 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_tree_configuration() - res = ccs_tree_evaluation_get_configuration(self.handle, ct.byref(v)) - Error.check(res) - self._configuration = TreeConfiguration.from_handle(v) - return self._configuration diff --git a/bindings/python/cconfigspace/tree_space.py b/bindings/python/cconfigspace/tree_space.py index 49e9346c..b6a181e7 100644 --- a/bindings/python/cconfigspace/tree_space.py +++ b/bindings/python/cconfigspace/tree_space.py @@ -11,15 +11,14 @@ class TreeSpaceType(CEnumeration): ccs_tree_space_get_type = _ccs_get_function("ccs_tree_space_get_type", [ccs_tree_space, ct.POINTER(TreeSpaceType)]) ccs_tree_space_get_name = _ccs_get_function("ccs_tree_space_get_name", [ccs_tree_space, ct.POINTER(ct.c_char_p)]) -ccs_tree_space_set_rng = _ccs_get_function("ccs_tree_space_set_rng", [ccs_tree_space, ccs_rng]) ccs_tree_space_get_rng = _ccs_get_function("ccs_tree_space_get_rng", [ccs_tree_space, ct.POINTER(ccs_rng)]) ccs_tree_space_get_tree = _ccs_get_function("ccs_tree_space_get_tree", [ccs_tree_space, ct.POINTER(ccs_tree)]) ccs_tree_space_get_node_at_position = _ccs_get_function("ccs_tree_space_get_node_at_position", [ccs_tree_space, ct.c_size_t, ct.POINTER(ct.c_size_t), ct.POINTER(ccs_tree)]) ccs_tree_space_get_values_at_position = _ccs_get_function("ccs_tree_space_get_values_at_position", [ccs_tree_space, ct.c_size_t, ct.POINTER(ct.c_size_t), ct.c_size_t, ct.POINTER(Datum)]) ccs_tree_space_check_position = _ccs_get_function("ccs_tree_space_check_position", [ccs_tree_space, ct.c_size_t, ct.POINTER(ct.c_size_t), ct.POINTER(ccs_bool)]) ccs_tree_space_check_configuration = _ccs_get_function("ccs_tree_space_check_configuration", [ccs_tree_space, ccs_tree_configuration, ct.POINTER(ccs_bool)]) -ccs_tree_space_sample = _ccs_get_function("ccs_tree_space_sample", [ccs_tree_space, ct.POINTER(ccs_tree_configuration)]) -ccs_tree_space_samples = _ccs_get_function("ccs_tree_space_samples", [ccs_tree_space, ct.c_size_t, ct.POINTER(ccs_tree_configuration)]) +ccs_tree_space_sample = _ccs_get_function("ccs_tree_space_sample", [ccs_tree_space, ccs_rng, ct.POINTER(ccs_tree_configuration)]) +ccs_tree_space_samples = _ccs_get_function("ccs_tree_space_samples", [ccs_tree_space, ccs_rng, ct.c_size_t, ct.POINTER(ccs_tree_configuration)]) class TreeSpace(Object): @@ -58,15 +57,13 @@ def name(self): @property def rng(self): + if hasattr(self, "_rng"): + return self._rng v = ccs_rng() res = ccs_tree_space_get_rng(self.handle, ct.byref(v)) Error.check(res) - return Rng.from_handle(v) - - @rng.setter - def rng(self, r): - res = ccs_tree_space_set_rng(self.handle, r.handle) - Error.check(res) + self._rng = Rng.from_handle(v) + return self._rng @property def tree(self): @@ -108,30 +105,30 @@ def check_configuration(self, configuration): Error.check(res) return not (b.value == 0) - def sample(self): + def sample(self, rng = None): v = ccs_tree_configuration() - res = ccs_tree_space_sample(self.handle, ct.byref(v)) + res = ccs_tree_space_sample(self.handle, rng.handle if rng is not None else None, ct.byref(v)) Error.check(res) return TreeConfiguration(handle = v, retain = False) - def samples(self, count): + def samples(self, count, rng = None): if count == 0: return [] v = (ccs_tree_configuration * count)() - res = ccs_tree_space_samples(self.handle, count, v) + res = ccs_tree_space_samples(self.handle, rng.handle if rng is not None else None, count, v) Error.check(res) return [TreeConfiguration(handle = ccs_tree_configuration(x), retain = False) for x in v] -ccs_create_static_tree_space = _ccs_get_function("ccs_create_static_tree_space", [ct.c_char_p, ccs_tree, ct.POINTER(ccs_tree_space)]) +ccs_create_static_tree_space = _ccs_get_function("ccs_create_static_tree_space", [ct.c_char_p, ccs_tree, ccs_rng, ct.POINTER(ccs_tree_space)]) class StaticTreeSpace(TreeSpace): def __init__(self, handle = None, retain = False, auto_release = True, - name = "", tree = None): + name = "", tree = None, rng = None): if handle is None: handle = ccs_tree_space() - res = ccs_create_static_tree_space(str.encode(name), tree.handle, ct.byref(handle)) + res = ccs_create_static_tree_space(str.encode(name), tree.handle, rng.handle if rng is not None else None, ct.byref(handle)) Error.check(res) super().__init__(handle = handle, retain = False) else: @@ -151,7 +148,7 @@ class DynamicTreeSpaceVector(ct.Structure): ('serialize', ccs_dynamic_tree_space_serialize_type), ('deserialize', ccs_dynamic_tree_space_deserialize_type) ] -ccs_create_dynamic_tree_space = _ccs_get_function("ccs_create_dynamic_tree_space", [ct.c_char_p, ccs_tree, ct.POINTER(DynamicTreeSpaceVector), ct.py_object, ct.POINTER(ccs_tree_space)]) +ccs_create_dynamic_tree_space = _ccs_get_function("ccs_create_dynamic_tree_space", [ct.c_char_p, ccs_tree, ccs_rng, ct.POINTER(DynamicTreeSpaceVector), ct.py_object, ct.POINTER(ccs_tree_space)]) ccs_dynamic_tree_space_get_tree_space_data = _ccs_get_function("ccs_dynamic_tree_space_get_tree_space_data", [ccs_tree_space, ct.POINTER(ct.c_void_p)]) def _wrap_user_defined_callbacks(delete, get_child, serialize, deserialize): @@ -224,7 +221,7 @@ def deserialize_wrapper(ts, state_size, p_state): class DynamicTreeSpace(TreeSpace): def __init__(self, handle = None, retain = False, auto_release = True, - name = "", tree = None, delete = None, get_child = None, serialize = None, deserialize = None, tree_space_data = None): + name = "", tree = None, rng = None, delete = None, get_child = None, serialize = None, deserialize = None, tree_space_data = None): if handle is None: if get_child is None: raise Error(Result(Result.ERROR_INVALID_VALUE)) @@ -247,7 +244,7 @@ def __init__(self, handle = None, retain = False, auto_release = True, c_tree_space_data = ct.py_object(tree_space_data) else: c_tree_space_data = None - res = ccs_create_dynamic_tree_space(str.encode(name), tree.handle, ct.byref(vec), c_tree_space_data, ct.byref(handle)) + res = ccs_create_dynamic_tree_space(str.encode(name), tree.handle, rng.handle if rng is not None else None, ct.byref(vec), c_tree_space_data, ct.byref(handle)) Error.check(res) super().__init__(handle = handle, retain = False) _register_vector(handle, [delete_wrapper, get_child_wrapper, serialize_wrapper, deserialize_wrapper, delete_wrapper_func, get_child_wrapper_func, serialize_wrapper_func, deserialize_wrapper_func, tree_space_data]) diff --git a/bindings/python/cconfigspace/tree_tuner.py b/bindings/python/cconfigspace/tree_tuner.py deleted file mode 100644 index 32bf48c2..00000000 --- a/bindings/python/cconfigspace/tree_tuner.py +++ /dev/null @@ -1,421 +0,0 @@ -import ctypes as ct -from .base import Object, Error, CEnumeration, Result, _ccs_get_function, ccs_context, ccs_parameter, ccs_tree_space, ccs_tree_configuration, Datum, ccs_objective_space, ccs_tree_evaluation, ccs_tree_tuner, ccs_retain_object, _register_vector, _unregister_vector -from .context import Context -from .parameter import Parameter -from .tree_space import TreeSpace -from .tree_configuration import TreeConfiguration -from .objective_space import ObjectiveSpace -from .tree_evaluation import TreeEvaluation - -class TreeTunerType(CEnumeration): - _members_ = [ - ('RANDOM',0), - 'USER_DEFINED' ] - -ccs_tree_tuner_get_type = _ccs_get_function("ccs_tree_tuner_get_type", [ccs_tree_tuner, ct.POINTER(TreeTunerType)]) -ccs_tree_tuner_get_name = _ccs_get_function("ccs_tree_tuner_get_name", [ccs_tree_tuner, ct.POINTER(ct.c_char_p)]) -ccs_tree_tuner_get_tree_space = _ccs_get_function("ccs_tree_tuner_get_tree_space", [ccs_tree_tuner, ct.POINTER(ccs_tree_space)]) -ccs_tree_tuner_get_objective_space = _ccs_get_function("ccs_tree_tuner_get_objective_space", [ccs_tree_tuner, ct.POINTER(ccs_objective_space)]) -ccs_tree_tuner_ask = _ccs_get_function("ccs_tree_tuner_ask", [ccs_tree_tuner, ct.c_size_t, ct.POINTER(ccs_tree_configuration), ct.POINTER(ct.c_size_t)]) -ccs_tree_tuner_tell = _ccs_get_function("ccs_tree_tuner_tell", [ccs_tree_tuner, ct.c_size_t, ct.POINTER(ccs_tree_evaluation)]) -ccs_tree_tuner_get_optima = _ccs_get_function("ccs_tree_tuner_get_optima", [ccs_tree_tuner, ct.c_size_t, ct.POINTER(ccs_tree_evaluation), ct.POINTER(ct.c_size_t)]) -ccs_tree_tuner_get_history = _ccs_get_function("ccs_tree_tuner_get_history", [ccs_tree_tuner, ct.c_size_t, ct.POINTER(ccs_tree_evaluation), ct.POINTER(ct.c_size_t)]) -ccs_tree_tuner_suggest = _ccs_get_function("ccs_tree_tuner_suggest", [ccs_tree_tuner, ct.POINTER(ccs_tree_configuration)]) - -class TreeTuner(Object): - @classmethod - def from_handle(cls, handle, retain = True, auto_release = True): - v = TreeTunerType(0) - res = ccs_tree_tuner_get_type(handle, ct.byref(v)) - Error.check(res) - v = v.value - if v == TreeTunerType.RANDOM: - return RandomTreeTuner(handle = handle, retain = retain, auto_release = auto_release) - elif v == TreeTunerType.USER_DEFINED: - return UserDefinedTreeTuner(handle = handle, retain = retain, auto_release = auto_release) - else: - raise Error(Result(Result.ERROR_INVALID_TREE_TUNER)) - - @property - def type(self): - if hasattr(self, "_type"): - return self._type - v = TreeTunerType(0) - res = ccs_tree_tuner_get_type(self.handle, ct.byref(v)) - Error.check(res) - self._type = v.value - return self._type - - @property - def name(self): - if hasattr(self, "_name"): - return self._name - v = ct.c_char_p() - res = ccs_tree_tuner_get_name(self.handle, ct.byref(v)) - Error.check(res) - self._name = v.value.decode() - return self._name - - @property - def objective_space(self): - if hasattr(self, "_objective_space"): - return self._objective_space - v = ccs_objective_space() - res = ccs_tree_tuner_get_objective_space(self.handle, ct.byref(v)) - Error.check(res) - self._objective_space = ObjectiveSpace.from_handle(v) - return self._objective_space - - @property - def tree_space(self): - if hasattr(self, "_tree_space"): - return self._tree_space - v = ccs_tree_space() - res = ccs_tree_tuner_get_tree_space(self.handle, ct.byref(v)) - Error.check(res) - self._tree_space = TreeSpace.from_handle(v) - return self._tree_space - - def ask(self, count = 1): - v = (ccs_tree_configuration * count)() - c = ct.c_size_t() - res = ccs_tree_tuner_ask(self.handle, count, v, ct.byref(c)) - Error.check(res) - count = c.value - return [TreeConfiguration(handle = ccs_tree_configuration(v[x]), retain = False) for x in range(count)] - - def tell(self, evaluations): - count = len(evaluations) - v = (ccs_tree_evaluation * count)(*[x.handle.value for x in evaluations]) - res = ccs_tree_tuner_tell(self.handle, count, v) - Error.check(res) - - @property - def history_size(self): - v = ct.c_size_t() - res = ccs_tree_tuner_get_history(self.handle, 0, None, ct.byref(v)) - Error.check(res) - return v.value - - @property - def history(self): - count = self.history_size - v = (ccs_tree_evaluation * count)() - res = ccs_tree_tuner_get_history(self.handle, count, v, None) - Error.check(res) - return [TreeEvaluation.from_handle(ccs_tree_evaluation(x)) for x in v] - - @property - def num_optima(self): - v = ct.c_size_t() - res = ccs_tree_tuner_get_optima(self.handle, 0, None, ct.byref(v)) - Error.check(res) - return v.value - - @property - def optima(self): - count = self.num_optima - v = (ccs_tree_evaluation * count)() - res = ccs_tree_tuner_get_optima(self.handle, count, v, None) - Error.check(res) - return [TreeEvaluation.from_handle(ccs_tree_evaluation(x)) for x in v] - - @property - def suggest(self): - config = ccs_tree_configuration() - res = ccs_tree_tuner_suggest(self.handle, ct.byref(config)) - Error.check(res) - return TreeConfiguration(handle = config, retain = False) - -ccs_create_random_tree_tuner = _ccs_get_function("ccs_create_random_tree_tuner", [ct.c_char_p, ccs_objective_space, ct.POINTER(ccs_tree_tuner)]) - -class RandomTreeTuner(TreeTuner): - def __init__(self, handle = None, retain = False, auto_release = True, - name = "", objective_space = None): - if handle is None: - handle = ccs_tree_tuner() - res = ccs_create_random_tree_tuner(str.encode(name), objective_space.handle, ct.byref(handle)) - Error.check(res) - super().__init__(handle = handle, retain = False) - else: - super().__init__(handle = handle, retain = retain, auto_release = auto_release) - -TreeTuner.Random = RandomTreeTuner - -ccs_user_defined_tree_tuner_del_type = ct.CFUNCTYPE(Result, ccs_tree_tuner) -ccs_user_defined_tree_tuner_ask_type = ct.CFUNCTYPE(Result, ccs_tree_tuner, ct.c_size_t, ct.POINTER(ccs_tree_configuration), ct.POINTER(ct.c_size_t)) -ccs_user_defined_tree_tuner_tell_type = ct.CFUNCTYPE(Result, ccs_tree_tuner, ct.c_size_t, ct.POINTER(ccs_tree_evaluation)) -ccs_user_defined_tree_tuner_get_optima_type = ct.CFUNCTYPE(Result, ccs_tree_tuner, ct.c_size_t, ct.POINTER(ccs_tree_evaluation), ct.POINTER(ct.c_size_t)) -ccs_user_defined_tree_tuner_get_history_type = ct.CFUNCTYPE(Result, ccs_tree_tuner, ct.c_size_t, ct.POINTER(ccs_tree_evaluation), ct.POINTER(ct.c_size_t)) -ccs_user_defined_tree_tuner_suggest_type = ct.CFUNCTYPE(Result, ccs_tree_tuner, ct.POINTER(ccs_tree_configuration)) -ccs_user_defined_tree_tuner_serialize_type = ct.CFUNCTYPE(Result, ccs_tree_tuner, ct.c_size_t, ct.c_void_p, ct.POINTER(ct.c_size_t)) -ccs_user_defined_tree_tuner_deserialize_type = ct.CFUNCTYPE(Result, ccs_tree_tuner, ct.c_size_t, ct.POINTER(ccs_tree_evaluation), ct.c_size_t, ct.POINTER(ccs_tree_evaluation), ct.c_size_t, ct.c_void_p) - -class UserDefinedTreeTunerVector(ct.Structure): - _fields_ = [ - ('delete', ccs_user_defined_tree_tuner_del_type), - ('ask', ccs_user_defined_tree_tuner_ask_type), - ('tell', ccs_user_defined_tree_tuner_tell_type), - ('get_optima', ccs_user_defined_tree_tuner_get_optima_type), - ('get_history', ccs_user_defined_tree_tuner_get_history_type), - ('suggest', ccs_user_defined_tree_tuner_suggest_type), - ('serialize', ccs_user_defined_tree_tuner_serialize_type), - ('deserialize', ccs_user_defined_tree_tuner_deserialize_type) ] - -ccs_create_user_defined_tree_tuner = _ccs_get_function("ccs_create_user_defined_tree_tuner", [ct.c_char_p, ccs_objective_space, ct.POINTER(UserDefinedTreeTunerVector), ct.py_object, ct.POINTER(ccs_tree_tuner)]) -ccs_user_defined_tree_tuner_get_tuner_data = _ccs_get_function("ccs_user_defined_tree_tuner_get_tuner_data", [ccs_tree_tuner, ct.POINTER(ct.c_void_p)]) - -def _wrap_user_defined_tree_tuner_callbacks(delete, ask, tell, get_optima, get_history, suggest, serialize, deserialize): - def delete_wrapper(tun): - try: - tun = ct.cast(tun, ccs_tree_tuner) - if delete is not None: - delete(Object.from_handle(tun)) - _unregister_vector(tun) - return Result.SUCCESS - except Exception as e: - return Error.set_error(e) - - def ask_wrapper(tun, count, p_configurations, p_count): - try: - tun = ct.cast(tun, ccs_tree_tuner) - p_confs = ct.cast(p_configurations, ct.c_void_p) - p_c = ct.cast(p_count, ct.c_void_p) - (configurations, count_ret) = ask(TreeTuner.from_handle(tun), count if p_confs.value else None) - if p_confs.value is not None and count < count_ret: - raise Error(Result(Result.ERROR_INVALID_VALUE)) - if p_confs.value is not None: - for i in range(len(configurations)): - res = ccs_retain_object(configurations[i].handle) - Error.check(res) - p_configurations[i] = configurations[i].handle.value - for i in range(len(configurations), count): - p_configurations[i] = None - if p_c.value is not None: - p_count[0] = count_ret - return Result.SUCCESS - except Exception as e: - return Error.set_error(e) - - def tell_wrapper(tun, count, p_evaluations): - try: - tun = ct.cast(tun, ccs_tree_tuner) - if count == 0: - return Result.SUCCESS - p_evals = ct.cast(p_evaluations, ct.c_void_p) - if p_evals.value is None: - raise Error(Result(Result.ERROR_INVALID_VALUE)) - evals = [TreeEvaluation.from_handle(ccs_tree_evaluation(p_evaluations[i])) for i in range(count)] - tell(TreeTuner.from_handle(tun), evals) - return Result.SUCCESS - except Exception as e: - return Error.set_error(e) - - def get_optima_wrapper(tun, count, p_evaluations, p_count): - try: - tun = ct.cast(tun, ccs_tree_tuner) - p_evals = ct.cast(p_evaluations, ct.c_void_p) - p_c = ct.cast(p_count, ct.c_void_p) - optima = get_optima(TreeTuner.from_handle(tun)) - count_ret = len(optima) - if p_evals.value is not None and count < count_ret: - raise Error(Result(Result.ERROR_INVALID_VALUE)) - if p_evals.value is not None: - for i in range(count_ret): - p_evaluations[i] = optima[i].handle.value - for i in range(count_ret, count): - p_evaluations[i] = None - if p_c.value is not None: - p_count[0] = count_ret - return Result.SUCCESS - except Exception as e: - return Error.set_error(e) - - def get_history_wrapper(tun, count, p_evaluations, p_count): - try: - tun = ct.cast(tun, ccs_tree_tuner) - p_evals = ct.cast(p_evaluations, ct.c_void_p) - p_c = ct.cast(p_count, ct.c_void_p) - history = get_history(TreeTuner.from_handle(tun)) - count_ret = len(history) - if p_evals.value is not None and count < count_ret: - raise Error(Result(Result.ERROR_INVALID_VALUE)) - if p_evals.value is not None: - for i in range(count_ret): - p_evaluations[i] = history[i].handle.value - for i in range(count_ret, count): - p_evaluations[i] = None - if p_c.value is not None: - p_count[0] = count_ret - return Result.SUCCESS - except Exception as e: - return Error.set_error(e) - - if suggest is not None: - def suggest_wrapper(tun, p_configuration): - try: - tun = ct.cast(tun, ccs_tree_tuner) - configuration = suggest(TreeTuner.from_handle(tun)) - res = ccs_retain_object(configuration.handle) - Error.check(res) - p_configuration[0] = configuration.handle.value - return Result.SUCCESS - except Exception as e: - return Error.set_error(e) - else: - suggest_wrapper = 0 - - if serialize is not None: - def serialize_wrapper(tun, state_size, p_state, p_state_size): - try: - tun = ct.cast(tun, ccs_tree_tuner) - p_s = ct.cast(p_state, ct.c_void_p) - p_sz = ct.cast(p_state_size, ct.c_void_p) - state = serialize(TreeTuner.from_handle(tun), True if state_size == 0 else False) - if p_s.value is not None and state_size < ct.sizeof(state): - raise Error(Result(Result.ERROR_INVALID_VALUE)) - if p_s.value is not None: - ct.memmove(p_s, ct.byref(state), ct.sizeof(state)) - if p_sz.value is not None: - p_state_size[0] = ct.sizeof(state) - return Result.SUCCESS - except Exception as e: - return Error.set_error(e) - else: - serialize_wrapper = 0 - - if deserialize is not None: - def deserialize_wrapper(tun, size_history, p_history, num_optima, p_optima, state_size, p_state): - try: - tun = ct.cast(tun, ccs_tree_tuner) - p_h = ct.cast(p_history, ct.c_void_p) - p_o = ct.cast(p_optima, ct.c_void_p) - p_s = ct.cast(p_state, ct.c_void_p) - if p_h.value is None: - history = [] - else: - history = [TreeEvaluation.from_handle(ccs_tree_evaluation(p_h[i])) for i in range(size_history)] - if p_o.value is None: - optima = [] - else: - optima = [TreeEvaluation.from_handle(ccs_tree_evaluation(p_o[i])) for i in range(num_optima)] - if p_s.value is None: - state = None - else: - state = ct.cast(p_s, POINTER(c_byte * state_size)) - deserialize(TreeTuner.from_handle(tun), history, optima, state) - return Result.SUCCESS - except Exception as e: - return Error.set_error(e) - else: - deserialize_wrapper = 0 - - return (delete_wrapper, - ask_wrapper, - tell_wrapper, - get_optima_wrapper, - get_history_wrapper, - suggest_wrapper, - serialize_wrapper, - deserialize_wrapper, - ccs_user_defined_tree_tuner_del_type(delete_wrapper), - ccs_user_defined_tree_tuner_ask_type(ask_wrapper), - ccs_user_defined_tree_tuner_tell_type(tell_wrapper), - ccs_user_defined_tree_tuner_get_optima_type(get_optima_wrapper), - ccs_user_defined_tree_tuner_get_history_type(get_history_wrapper), - ccs_user_defined_tree_tuner_suggest_type(suggest_wrapper), - ccs_user_defined_tree_tuner_serialize_type(serialize_wrapper), - ccs_user_defined_tree_tuner_deserialize_type(deserialize_wrapper)) - - -class UserDefinedTreeTuner(TreeTuner): - def __init__(self, handle = None, retain = False, auto_release = True, - name = "", objective_space = None, delete = None, ask = None, tell = None, get_optima = None, get_history = None, suggest = None, serialize = None, deserialize = None, tuner_data = None ): - if handle is None: - if ask is None or tell is None or get_optima is None or get_history is None: - raise Error(Result(Result.ERROR_INVALID_VALUE)) - - (delete_wrapper, - ask_wrapper, - tell_wrapper, - get_optima_wrapper, - get_history_wrapper, - suggest_wrapper, - serialize_wrapper, - deserialize_wrapper, - delete_wrapper_func, - ask_wrapper_func, - tell_wrapper_func, - get_optima_wrapper_func, - get_history_wrapper_func, - suggest_wrapper_func, - serialize_wrapper_func, - deserialize_wrapper_func) = _wrap_user_defined_tree_tuner_callbacks(delete, ask, tell, get_optima, get_history, suggest, serialize, deserialize) - handle = ccs_tree_tuner() - vec = UserDefinedTreeTunerVector() - vec.delete = delete_wrapper_func - vec.ask = ask_wrapper_func - vec.tell = tell_wrapper_func - vec.get_optima = get_optima_wrapper_func - vec.get_history = get_history_wrapper_func - vec.suggest = suggest_wrapper_func - vec.serialize = serialize_wrapper_func - vec.deserialize = deserialize_wrapper_func - if tuner_data is not None: - c_tuner_data = ct.py_object(tuner_data) - else: - c_tuner_data = None - res = ccs_create_user_defined_tree_tuner(str.encode(name), objective_space.handle, ct.byref(vec), c_tuner_data, ct.byref(handle)) - Error.check(res) - super().__init__(handle = handle, retain = False) - _register_vector(handle, [delete_wrapper, ask_wrapper, tell_wrapper, get_optima_wrapper, get_history_wrapper, suggest_wrapper, serialize_wrapper, deserialize_wrapper, delete_wrapper_func, ask_wrapper_func, tell_wrapper_func, get_optima_wrapper_func, get_history_wrapper_func, suggest_wrapper_func, serialize_wrapper_func, deserialize_wrapper_func, tuner_data]) - else: - super().__init__(handle = handle, retain = retain, auto_release = auto_release) - - @classmethod - def deserialize(cls, delete, ask, tell, get_optima, get_history, suggest = None, serialize = None, deserialize = None, tuner_data = None, format = 'binary', handle_map = None, path = None, buffer = None, file_descriptor = None, callback = None, callback_data = None): - if ask is None or tell is None or get_optima is None or get_history is None: - raise Error(Result(Result.ERROR_INVALID_VALUE)) - (delete_wrapper, - ask_wrapper, - tell_wrapper, - get_optima_wrapper, - get_history_wrapper, - suggest_wrapper, - serialize_wrapper, - deserialize_wrapper, - delete_wrapper_func, - ask_wrapper_func, - tell_wrapper_func, - get_optima_wrapper_func, - get_history_wrapper_func, - suggest_wrapper_func, - serialize_wrapper_func, - deserialize_wrapper_func) = _wrap_user_defined_tree_tuner_callbacks(delete, ask, tell, get_optima, get_history, suggest, serialize, deserialize) - vector = UserDefinedTreeTunerVector() - vector.delete = delete_wrapper_func - vector.ask = ask_wrapper_func - vector.tell = tell_wrapper_func - vector.get_optima = get_optima_wrapper_func - vector.get_history = get_history_wrapper_func - vector.suggest = suggest_wrapper_func - vector.serialize = serialize_wrapper_func - vector.deserialize = deserialize_wrapper_func - res = Object.deserialize(format = format, handle_map = handle_map, vector = vector, data = tuner_data, path = path, buffer = buffer, file_descriptor = file_descriptor, callback = callback, callback_data = callback_data) - _register_vector(res.handle, [delete_wrapper, ask_wrapper, tell_wrapper, get_optima_wrapper, get_history_wrapper, suggest_wrapper, serialize_wrapper, deserialize_wrapper, delete_wrapper_func, ask_wrapper_func, tell_wrapper_func, get_optima_wrapper_func, get_history_wrapper_func, suggest_wrapper_func, serialize_wrapper_func, deserialize_wrapper_func, tuner_data]) - return res - - @property - def tuner_data(self): - if hasattr(self, "_tuner_data"): - return self._tuner_data - v = ct.c_void_p() - res = ccs_user_defined_tree_tuner_get_tuner_data(self.handle, ct.byref(v)) - Error.check(res) - if v: - self._tuner_data = ct.cast(v, ct.py_object).value - else: - self._tuner_data = None - return self._tuner_data - -TreeTuner.UserDefined = UserDefinedTreeTuner diff --git a/bindings/python/cconfigspace/tuner.py b/bindings/python/cconfigspace/tuner.py index 3359ae38..1d92a2b9 100644 --- a/bindings/python/cconfigspace/tuner.py +++ b/bindings/python/cconfigspace/tuner.py @@ -1,9 +1,7 @@ import ctypes as ct -from .base import Object, Error, CEnumeration, Result, _ccs_get_function, ccs_context, ccs_parameter, ccs_configuration_space, ccs_configuration, Datum, ccs_objective_space, ccs_evaluation, ccs_tuner, ccs_retain_object, _register_vector, _unregister_vector +from .base import Object, Error, CEnumeration, Result, _ccs_get_function, ccs_context, ccs_parameter, ccs_search_space, ccs_search_configuration, Datum, ccs_objective_space, ccs_evaluation, ccs_tuner, ccs_retain_object, _register_vector, _unregister_vector from .context import Context from .parameter import Parameter -from .configuration_space import ConfigurationSpace -from .configuration import Configuration from .objective_space import ObjectiveSpace from .evaluation import Evaluation @@ -14,13 +12,13 @@ class TunerType(CEnumeration): ccs_tuner_get_type = _ccs_get_function("ccs_tuner_get_type", [ccs_tuner, ct.POINTER(TunerType)]) ccs_tuner_get_name = _ccs_get_function("ccs_tuner_get_name", [ccs_tuner, ct.POINTER(ct.c_char_p)]) -ccs_tuner_get_configuration_space = _ccs_get_function("ccs_tuner_get_configuration_space", [ccs_tuner, ct.POINTER(ccs_configuration_space)]) +ccs_tuner_get_search_space = _ccs_get_function("ccs_tuner_get_search_space", [ccs_tuner, ct.POINTER(ccs_search_space)]) ccs_tuner_get_objective_space = _ccs_get_function("ccs_tuner_get_objective_space", [ccs_tuner, ct.POINTER(ccs_objective_space)]) -ccs_tuner_ask = _ccs_get_function("ccs_tuner_ask", [ccs_tuner, ct.c_size_t, ct.POINTER(ccs_configuration), ct.POINTER(ct.c_size_t)]) +ccs_tuner_ask = _ccs_get_function("ccs_tuner_ask", [ccs_tuner, ct.c_size_t, ct.POINTER(ccs_search_configuration), ct.POINTER(ct.c_size_t)]) ccs_tuner_tell = _ccs_get_function("ccs_tuner_tell", [ccs_tuner, ct.c_size_t, ct.POINTER(ccs_evaluation)]) ccs_tuner_get_optima = _ccs_get_function("ccs_tuner_get_optima", [ccs_tuner, ct.c_size_t, ct.POINTER(ccs_evaluation), ct.POINTER(ct.c_size_t)]) ccs_tuner_get_history = _ccs_get_function("ccs_tuner_get_history", [ccs_tuner, ct.c_size_t, ct.POINTER(ccs_evaluation), ct.POINTER(ct.c_size_t)]) -ccs_tuner_suggest = _ccs_get_function("ccs_tuner_suggest", [ccs_tuner, ct.POINTER(ccs_configuration)]) +ccs_tuner_suggest = _ccs_get_function("ccs_tuner_suggest", [ccs_tuner, ct.POINTER(ccs_search_configuration)]) class Tuner(Object): @classmethod @@ -67,22 +65,22 @@ def objective_space(self): return self._objective_space @property - def configuration_space(self): - if hasattr(self, "_configuration_space"): - return self._configuration_space - v = ccs_configuration_space() - res = ccs_tuner_get_configuration_space(self.handle, ct.byref(v)) + def search_space(self): + if hasattr(self, "_search_space"): + return self._search_space + v = ccs_search_space() + res = ccs_tuner_get_search_space(self.handle, ct.byref(v)) Error.check(res) - self._configuration_space = ConfigurationSpace.from_handle(v) - return self._configuration_space + self._search_space = Object.from_handle(v) + return self._search_space def ask(self, count = 1): - v = (ccs_configuration * count)() + v = (ccs_search_configuration * count)() c = ct.c_size_t() res = ccs_tuner_ask(self.handle, count, v, ct.byref(c)) Error.check(res) count = c.value - return [Configuration(handle = ccs_configuration(v[x]), retain = False) for x in range(count)] + return [Object.from_handle(ccs_search_configuration(v[x]), retain = False) for x in range(count)] def tell(self, evaluations): count = len(evaluations) @@ -122,10 +120,10 @@ def optima(self): @property def suggest(self): - config = ccs_configuration() + config = ccs_search_configuration() res = ccs_tuner_suggest(self.handle, ct.byref(config)) Error.check(res) - return Configuration(handle = config, retain = False) + return Object.from_handle(config, retain = False) ccs_create_random_tuner = _ccs_get_function("ccs_create_random_tuner", [ct.c_char_p, ccs_objective_space, ct.POINTER(ccs_tuner)]) @@ -143,11 +141,11 @@ def __init__(self, handle = None, retain = False, auto_release = True, Tuner.Random = RandomTuner ccs_user_defined_tuner_del_type = ct.CFUNCTYPE(Result, ccs_tuner) -ccs_user_defined_tuner_ask_type = ct.CFUNCTYPE(Result, ccs_tuner, ct.c_size_t, ct.POINTER(ccs_configuration), ct.POINTER(ct.c_size_t)) +ccs_user_defined_tuner_ask_type = ct.CFUNCTYPE(Result, ccs_tuner, ct.c_size_t, ct.POINTER(ccs_search_configuration), ct.POINTER(ct.c_size_t)) ccs_user_defined_tuner_tell_type = ct.CFUNCTYPE(Result, ccs_tuner, ct.c_size_t, ct.POINTER(ccs_evaluation)) ccs_user_defined_tuner_get_optima_type = ct.CFUNCTYPE(Result, ccs_tuner, ct.c_size_t, ct.POINTER(ccs_evaluation), ct.POINTER(ct.c_size_t)) ccs_user_defined_tuner_get_history_type = ct.CFUNCTYPE(Result, ccs_tuner, ct.c_size_t, ct.POINTER(ccs_evaluation), ct.POINTER(ct.c_size_t)) -ccs_user_defined_tuner_suggest_type = ct.CFUNCTYPE(Result, ccs_tuner, ct.POINTER(ccs_configuration)) +ccs_user_defined_tuner_suggest_type = ct.CFUNCTYPE(Result, ccs_tuner, ct.POINTER(ccs_search_configuration)) ccs_user_defined_tuner_serialize_type = ct.CFUNCTYPE(Result, ccs_tuner, ct.c_size_t, ct.c_void_p, ct.POINTER(ct.c_size_t)) ccs_user_defined_tuner_deserialize_type = ct.CFUNCTYPE(Result, ccs_tuner, ct.c_size_t, ct.POINTER(ccs_evaluation), ct.c_size_t, ct.POINTER(ccs_evaluation), ct.c_size_t, ct.c_void_p) diff --git a/bindings/python/test/test_features_tuner.py b/bindings/python/test/test_features_tuner.py index 94ecc40e..e5d875a1 100644 --- a/bindings/python/test/test_features_tuner.py +++ b/bindings/python/test/test_features_tuner.py @@ -76,7 +76,7 @@ def ask(tuner, features, count): if count is None: return (None, 1) else: - cs = tuner.configuration_space + cs = tuner.search_space return (cs.samples(count), count) def tell(tuner, evaluations): @@ -125,7 +125,7 @@ def suggest(tuner, features): self.assertEqual(ccs.FeaturesTunerType.USER_DEFINED, t.type) self.assertEqual(fs.handle.value, t.feature_space.handle.value) self.assertEqual(os.handle.value, t.objective_space.handle.value) - self.assertEqual(os.search_space.handle.value, t.configuration_space.handle.value) + self.assertEqual(os.search_space.handle.value, t.search_space.handle.value) func = lambda x, y, z: [(x-2)*(x-2), sin(z+y)] features_on = ccs.Features(feature_space = fs, values = [True]) features_off = ccs.Features(feature_space = fs, values = [False]) diff --git a/bindings/python/test/test_tree_evaluation.py b/bindings/python/test/test_tree_evaluation.py index c2a0774f..6511efdf 100644 --- a/bindings/python/test/test_tree_evaluation.py +++ b/bindings/python/test/test_tree_evaluation.py @@ -23,20 +23,20 @@ def test_create(self): e1 = ccs.Expression.Variable(parameter = v1) e2 = ccs.Expression.Variable(parameter = v2) os = ccs.ObjectiveSpace(name = "ospace", search_space = ts, parameters = [v1, v2], objectives = { e1: ccs.ObjectiveType.MAXIMIZE, e2: ccs.ObjectiveType.MINIMIZE }) - ev1 = ccs.TreeEvaluation(objective_space = os, configuration = ts.sample(), values = [0.5, 0.6]) + ev1 = ccs.Evaluation(objective_space = os, configuration = ts.sample(), values = [0.5, 0.6]) self.assertEqual( (0.5, 0.6), ev1.values ) self.assertEqual( (0.5, 0.6), ev1.objective_values ) self.assertTrue( ev1.check ) self.assertTrue( os.check(ev1) ) - ev2 = ccs.TreeEvaluation(objective_space = os, configuration = ts.sample(), values = [0.5, 0.6]) + ev2 = ccs.Evaluation(objective_space = os, configuration = ts.sample(), values = [0.5, 0.6]) self.assertEqual( (0.5, 0.6), ev2.values ) self.assertEqual( (0.5, 0.6), ev2.objective_values ) self.assertEqual( ccs.Comparison.EQUIVALENT, ev1.compare(ev2) ) - ev3 = ccs.TreeEvaluation(objective_space = os, configuration = ts.sample(), values = [0.6, 0.5]) + ev3 = ccs.Evaluation(objective_space = os, configuration = ts.sample(), values = [0.6, 0.5]) self.assertEqual( (0.6, 0.5), ev3.objective_values ) self.assertEqual( ccs.Comparison.WORSE, ev1.compare(ev3) ) self.assertEqual( ccs.Comparison.BETTER, ev3.compare(ev1) ) - ev4 = ccs.TreeEvaluation(objective_space = os, configuration = ts.sample(), values = [0.6, 0.7]) + ev4 = ccs.Evaluation(objective_space = os, configuration = ts.sample(), values = [0.6, 0.7]) self.assertEqual( (0.6, 0.7), ev4.objective_values ) self.assertEqual( ccs.Comparison.NOT_COMPARABLE, ev1.compare(ev4) ) self.assertEqual( ccs.Comparison.NOT_COMPARABLE, ev4.compare(ev1) ) @@ -49,7 +49,7 @@ def test_serialize(self): e1 = ccs.Expression.Variable(parameter = v1) e2 = ccs.Expression.Variable(parameter = v2) os = ccs.ObjectiveSpace(name = "ospace", search_space = ts, parameters = [v1, v2], objectives = { e1: ccs.ObjectiveType.MAXIMIZE, e2: ccs.ObjectiveType.MINIMIZE }) - evref = ccs.TreeEvaluation(objective_space = os, configuration = ts.sample(), values = [0.5, 0.6]) + evref = ccs.Evaluation(objective_space = os, configuration = ts.sample(), values = [0.5, 0.6]) buff = evref.serialize() handle_map = ccs.Map() handle_map[ts] = ts diff --git a/bindings/python/test/test_tree_space.py b/bindings/python/test/test_tree_space.py index 3072cc00..39f1ef4e 100644 --- a/bindings/python/test/test_tree_space.py +++ b/bindings/python/test/test_tree_space.py @@ -19,12 +19,11 @@ class TestTreeSpace(unittest.TestCase): def test_static_tree_space(self): rng = ccs.Rng() tree = generate_tree(4, 0) - ts = ccs.StaticTreeSpace(name = 'space', tree = tree) + ts = ccs.StaticTreeSpace(name = 'space', tree = tree, rng = rng) self.assertEqual( ccs.ObjectType.TREE_SPACE, ts.object_type ) self.assertEqual( "space", ts.name ) self.assertIsInstance( ts.rng, ccs.Rng ) self.assertEqual( ccs.TreeSpaceType.STATIC, ts.type ) - ts.rng = rng self.assertEqual( rng.handle.value, ts.rng.handle.value ) self.assertEqual( tree.handle.value, ts.tree.handle.value ) self.assertEqual( tree.handle.value, ts.get_node_at_position([]).handle.value ) diff --git a/bindings/python/test/test_tree_tuner.py b/bindings/python/test/test_tree_tuner.py index bc5f59c4..0d81e937 100644 --- a/bindings/python/test/test_tree_tuner.py +++ b/bindings/python/test/test_tree_tuner.py @@ -32,14 +32,14 @@ def create_tuning_problem(self): def test_create_random(self): os = self.create_tuning_problem() - t = ccs.RandomTreeTuner(name = "tuner", objective_space = os) + t = ccs.RandomTuner(name = "tuner", objective_space = os) t2 = ccs.Object.from_handle(t.handle) self.assertEqual("tuner", t.name) - self.assertEqual(ccs.TreeTunerType.RANDOM, t.type) - evals = [ccs.TreeEvaluation(objective_space = os, configuration = c, values = [reduce(c.values)]) for c in t.ask(100)] + self.assertEqual(ccs.TunerType.RANDOM, t.type) + evals = [ccs.Evaluation(objective_space = os, configuration = c, values = [reduce(c.values)]) for c in t.ask(100)] t.tell(evals) hist = t.history - evals = [ccs.TreeEvaluation(objective_space = os, configuration = c, values = [reduce(c.values)]) for c in t.ask(100)] + evals = [ccs.Evaluation(objective_space = os, configuration = c, values = [reduce(c.values)]) for c in t.ask(100)] t.tell(evals) hist = t.history self.assertEqual(200, len(hist)) @@ -72,7 +72,7 @@ def ask(tuner, count): if count is None: return (None, 1) else: - ts = tuner.tree_space + ts = tuner.search_space return (ts.samples(count), count) def tell(tuner, evaluations): @@ -108,14 +108,14 @@ def suggest(tuner): return choice(tuner.tuner_data.optima).configuration os = self.create_tuning_problem() - t = ccs.UserDefinedTreeTuner(name = "tuner", objective_space = os, delete = delete, ask = ask, tell = tell, get_optima = get_optima, get_history = get_history, suggest = suggest, tuner_data = TunerData()) + t = ccs.UserDefinedTuner(name = "tuner", objective_space = os, delete = delete, ask = ask, tell = tell, get_optima = get_optima, get_history = get_history, suggest = suggest, tuner_data = TunerData()) t2 = ccs.Object.from_handle(t.handle) self.assertEqual("tuner", t.name) - self.assertEqual(ccs.TreeTunerType.USER_DEFINED, t.type) - evals = [ccs.TreeEvaluation(objective_space = os, configuration = c, values = [reduce(c.values)]) for c in t.ask(100)] + self.assertEqual(ccs.TunerType.USER_DEFINED, t.type) + evals = [ccs.Evaluation(objective_space = os, configuration = c, values = [reduce(c.values)]) for c in t.ask(100)] t.tell(evals) hist = t.history - evals = [ccs.TreeEvaluation(objective_space = os, configuration = c, values = [reduce(c.values)]) for c in t.ask(100)] + evals = [ccs.Evaluation(objective_space = os, configuration = c, values = [reduce(c.values)]) for c in t.ask(100)] t.tell(evals) hist = t.history self.assertEqual(200, len(hist)) @@ -125,7 +125,7 @@ def suggest(tuner): self.assertTrue(all(best >= x.objective_values[0] for x in hist)) self.assertTrue(t.suggest in [x.configuration for x in optims]) buff = t.serialize() - t_copy = ccs.UserDefinedTreeTuner.deserialize(buffer = buff, delete = delete, ask = ask, tell = tell, get_optima = get_optima, get_history = get_history, suggest = suggest, tuner_data = TunerData()) + t_copy = ccs.UserDefinedTuner.deserialize(buffer = buff, delete = delete, ask = ask, tell = tell, get_optima = get_optima, get_history = get_history, suggest = suggest, tuner_data = TunerData()) hist = t_copy.history self.assertEqual(200, len(hist)) optims_2 = t_copy.optima diff --git a/bindings/python/test/test_tuner.py b/bindings/python/test/test_tuner.py index 946d1360..07a2f323 100644 --- a/bindings/python/test/test_tuner.py +++ b/bindings/python/test/test_tuner.py @@ -66,7 +66,7 @@ def ask(tuner, count): if count is None: return (None, 1) else: - cs = tuner.configuration_space + cs = tuner.search_space return (cs.samples(count), count) def tell(tuner, evaluations): @@ -107,7 +107,7 @@ def suggest(tuner): self.assertEqual("tuner", t.name) self.assertEqual(ccs.TunerType.USER_DEFINED, t.type) self.assertEqual(os.handle.value, t.objective_space.handle.value) - self.assertEqual(os.search_space.handle.value, t.configuration_space.handle.value) + self.assertEqual(os.search_space.handle.value, t.search_space.handle.value) func = lambda x, y, z: [(x-2)*(x-2), sin(z+y)] evals = [ccs.Evaluation(objective_space = os, configuration = c, values = func(*(c.values))) for c in t.ask(100)] t.tell(evals) diff --git a/bindings/ruby/Makefile.am b/bindings/ruby/Makefile.am index 6e257334..ed5bdf5c 100644 --- a/bindings/ruby/Makefile.am +++ b/bindings/ruby/Makefile.am @@ -2,12 +2,9 @@ EXTRA_DIST = \ lib/cconfigspace.rb \ lib/cconfigspace \ lib/cconfigspace/features_tuner.rb \ - lib/cconfigspace/tree_evaluation.rb \ lib/cconfigspace/tree.rb \ - lib/cconfigspace/evaluation_binding.rb \ lib/cconfigspace/evaluation.rb \ lib/cconfigspace/tuner.rb \ - lib/cconfigspace/tree_tuner.rb \ lib/cconfigspace/binding.rb \ lib/cconfigspace/tree_space.rb \ lib/cconfigspace/feature_space.rb \ diff --git a/bindings/ruby/lib/cconfigspace.rb b/bindings/ruby/lib/cconfigspace.rb index dc4be285..6ba71459 100644 --- a/bindings/ruby/lib/cconfigspace.rb +++ b/bindings/ruby/lib/cconfigspace.rb @@ -18,7 +18,6 @@ require_relative 'cconfigspace/feature_space' require_relative 'cconfigspace/features' require_relative 'cconfigspace/objective_space' -require_relative 'cconfigspace/evaluation_binding' require_relative 'cconfigspace/evaluation' require_relative 'cconfigspace/features_evaluation' require_relative 'cconfigspace/tuner' @@ -26,5 +25,3 @@ require_relative 'cconfigspace/tree' require_relative 'cconfigspace/tree_space' require_relative 'cconfigspace/tree_configuration' -require_relative 'cconfigspace/tree_evaluation' -require_relative 'cconfigspace/tree_tuner' diff --git a/bindings/ruby/lib/cconfigspace/base.rb b/bindings/ruby/lib/cconfigspace/base.rb index 22c75f7e..458eae61 100644 --- a/bindings/ruby/lib/cconfigspace/base.rb +++ b/bindings/ruby/lib/cconfigspace/base.rb @@ -100,11 +100,11 @@ class Version < FFI::Struct typedef :ccs_object_t, :ccs_search_space_t typedef :ccs_object_t, :ccs_configuration_space_t typedef :ccs_object_t, :ccs_binding_t + typedef :ccs_object_t, :ccs_search_configuration_t typedef :ccs_object_t, :ccs_configuration_t typedef :ccs_object_t, :ccs_feature_space_t typedef :ccs_object_t, :ccs_features_t typedef :ccs_object_t, :ccs_objective_space_t - typedef :ccs_object_t, :ccs_evaluation_binding_t typedef :ccs_object_t, :ccs_evaluation_t typedef :ccs_object_t, :ccs_features_evaluation_t typedef :ccs_object_t, :ccs_tuner_t @@ -114,8 +114,6 @@ class Version < FFI::Struct typedef :ccs_object_t, :ccs_tree_t typedef :ccs_object_t, :ccs_tree_space_t typedef :ccs_object_t, :ccs_tree_configuration_t - typedef :ccs_object_t, :ccs_tree_evaluation_t - typedef :ccs_object_t, :ccs_tree_tuner_t class MemoryPointer alias read_ccs_object_t read_pointer alias read_ccs_rng_t read_ccs_object_t @@ -127,11 +125,11 @@ class MemoryPointer alias read_ccs_search_space_t read_ccs_object_t alias read_ccs_configuration_space_t read_ccs_object_t alias read_ccs_binding_t read_ccs_object_t + alias read_ccs_search_configuration_t read_ccs_object_t alias read_ccs_configuration_t read_ccs_object_t alias read_ccs_feature_space_t read_ccs_object_t alias read_ccs_features_t read_ccs_object_t alias read_ccs_objective_space_t read_ccs_object_t - alias read_ccs_evaluation_binding_t read_ccs_object_t alias read_ccs_evaluation_t read_ccs_object_t alias read_ccs_features_evaluation_t read_ccs_object_t alias read_ccs_tuner_t read_ccs_object_t @@ -141,8 +139,6 @@ class MemoryPointer alias read_ccs_tree_t read_ccs_object_t alias read_ccs_tree_space_t read_ccs_object_t alias read_ccs_tree_configuration_t read_ccs_object_t - alias read_ccs_tree_evaluation_t read_ccs_object_t - alias read_ccs_tree_tuner_t read_ccs_object_t end ObjectType = enum FFI::Type::INT32, :ccs_object_type_t, [ @@ -164,8 +160,6 @@ class MemoryPointer :CCS_OBJECT_TYPE_TREE, :CCS_OBJECT_TYPE_TREE_SPACE, :CCS_OBJECT_TYPE_TREE_CONFIGURATION, - :CCS_OBJECT_TYPE_TREE_EVALUATION, - :CCS_OBJECT_TYPE_TREE_TUNER, :CCS_OBJECT_TYPE_DISTRIBUTION_SPACE ] Error = enum FFI::Type::INT32, :ccs_result_t, [ @@ -200,8 +194,7 @@ class MemoryPointer :CCS_RESULT_ERROR_EXTERNAL, -27, :CCS_RESULT_ERROR_INVALID_TREE, -28, :CCS_RESULT_ERROR_INVALID_TREE_SPACE, -29, - :CCS_RESULT_ERROR_INVALID_TREE_TUNER, -30, - :CCS_RESULT_ERROR_INVALID_DISTRIBUTION_SPACE, -31 ] + :CCS_RESULT_ERROR_INVALID_DISTRIBUTION_SPACE, -30 ] class MemoryPointer def read_ccs_object_type_t @@ -594,8 +587,6 @@ def self.class_map CCS_OBJECT_TYPE_TREE: CCS::Tree, CCS_OBJECT_TYPE_TREE_SPACE: CCS::TreeSpace, CCS_OBJECT_TYPE_TREE_CONFIGURATION: CCS::TreeConfiguration, - CCS_OBJECT_TYPE_TREE_EVALUATION: CCS::TreeEvaluation, - CCS_OBJECT_TYPE_TREE_TUNER: CCS::TreeTuner, CCS_OBJECT_TYPE_DISTRIBUTION_SPACE: CCS::DistributionSpace } end @@ -659,11 +650,16 @@ def self._from_handle(handle, retain: true, auto_release: true) private_class_method :_from_handle - def self.from_handle(handle) + def self.from_handle(handle, retain: true) ptr2 = MemoryPointer::new(:int32) CCS.error_check CCS.ccs_object_get_refcount(handle, ptr2) - opts = ptr2.read_int32 == 0 ? {retain: false, auto_release: false} : {} - _from_handle(handle, **opts) + if ptr2.read_int32 == 0 + retain = false + auto_release = false + else + auto_release = true + end + _from_handle(handle, retain: retain, auto_release: auto_release) end def to_ptr diff --git a/bindings/ruby/lib/cconfigspace/evaluation.rb b/bindings/ruby/lib/cconfigspace/evaluation.rb index 87db9c42..cdad2c8e 100644 --- a/bindings/ruby/lib/cconfigspace/evaluation.rb +++ b/bindings/ruby/lib/cconfigspace/evaluation.rb @@ -1,7 +1,26 @@ module CCS + Comparison = enum FFI::Type::INT32, :ccs_comparison_t, [ + :CCS_COMPARISON_BETTER, -1, + :CCS_COMPARISON_EQUIVALENT, 0, + :CCS_COMPARISON_WORSE, 1, + :CCS_COMPARISON_NOT_COMPARABLE, 2 + ] + class MemoryPointer + def read_ccs_comparison_t + Comparison.from_native(read_int32, nil) + end + end + attach_function :ccs_create_evaluation, [:ccs_objective_space_t, :ccs_configuration_t, :ccs_evaluation_result_t, :size_t, :pointer, :pointer], :ccs_result_t + attach_function :ccs_evaluation_get_result, [:ccs_evaluation_t, :pointer], :ccs_result_t + attach_function :ccs_evaluation_get_objective_values, [:ccs_evaluation_t, :size_t, :pointer, :pointer], :ccs_result_t + attach_function :ccs_evaluation_compare, [:ccs_evaluation_t, :ccs_evaluation_t, :pointer], :ccs_result_t + attach_function :ccs_evaluation_check, [:ccs_evaluation_t, :pointer], :ccs_result_t attach_function :ccs_evaluation_get_configuration, [:ccs_evaluation_t, :pointer], :ccs_result_t - class Evaluation < EvaluationBinding + + class Evaluation < Binding + alias objective_space context + add_property :result, :ccs_evaluation_result_t, :ccs_evaluation_get_result, memoize: true add_handle_property :configuration, :ccs_configuration_t, :ccs_evaluation_get_configuration, memoize: true def initialize(handle = nil, retain: false, auto_release: true, @@ -31,5 +50,41 @@ def self.from_handle(handle, retain: true, auto_release: true) self::new(handle, retain: retain, auto_release: auto_release) end + def num_objective_values + @num_objective_values ||= begin + ptr = MemoryPointer::new(:size_t) + CCS.error_check CCS.ccs_evaluation_get_objective_values(@handle, 0, nil, ptr) + ptr.read_size_t + end + end + + def objective_values + @objective_values ||= begin + count = num_objective_values + values = MemoryPointer::new(:ccs_datum_t, count) + CCS.error_check CCS.ccs_evaluation_get_objective_values(@handle, count, values, nil) + count.times.collect { |i| Datum::new(values[i]).value }.freeze + end + end + + def check + ptr = MemoryPointer::new(:ccs_bool_t) + CCS.error_check CCS.ccs_evaluation_check(@handle, ptr) + return ptr.read_ccs_bool_t == CCS::FALSE ? false : true + end + + def compare(other) + ptr = MemoryPointer::new(:ccs_comparison_t) + CCS.error_check CCS.ccs_evaluation_compare(@handle, other, ptr) + ptr.read_ccs_comparison_t + end + + def <=>(other) + ptr = MemoryPointer::new(:ccs_comparison_t) + CCS.error_check CCS.ccs_evaluation_compare(@handle, other, ptr) + r = ptr.read_int32 + r == 2 ? nil : r + end + end end diff --git a/bindings/ruby/lib/cconfigspace/evaluation_binding.rb b/bindings/ruby/lib/cconfigspace/evaluation_binding.rb deleted file mode 100644 index b0b16fa0..00000000 --- a/bindings/ruby/lib/cconfigspace/evaluation_binding.rb +++ /dev/null @@ -1,60 +0,0 @@ -module CCS - Comparison = enum FFI::Type::INT32, :ccs_comparison_t, [ - :CCS_COMPARISON_BETTER, -1, - :CCS_COMPARISON_EQUIVALENT, 0, - :CCS_COMPARISON_WORSE, 1, - :CCS_COMPARISON_NOT_COMPARABLE, 2 - ] - class MemoryPointer - def read_ccs_comparison_t - Comparison.from_native(read_int32, nil) - end - end - - attach_function :ccs_evaluation_binding_get_result, [:ccs_evaluation_binding_t, :pointer], :ccs_result_t - attach_function :ccs_evaluation_binding_get_objective_values, [:ccs_evaluation_binding_t, :size_t, :pointer, :pointer], :ccs_result_t - attach_function :ccs_evaluation_binding_compare, [:ccs_evaluation_binding_t, :ccs_evaluation_binding_t, :pointer], :ccs_result_t - attach_function :ccs_evaluation_binding_check, [:ccs_evaluation_binding_t, :pointer], :ccs_result_t - - class EvaluationBinding < Binding - alias objective_space context - add_property :result, :ccs_evaluation_binding_result_t, :ccs_evaluation_binding_get_result, memoize: true - - def num_objective_values - @num_objective_values ||= begin - ptr = MemoryPointer::new(:size_t) - CCS.error_check CCS.ccs_evaluation_binding_get_objective_values(@handle, 0, nil, ptr) - ptr.read_size_t - end - end - - def objective_values - @objective_values ||= begin - count = num_objective_values - values = MemoryPointer::new(:ccs_datum_t, count) - CCS.error_check CCS.ccs_evaluation_binding_get_objective_values(@handle, count, values, nil) - count.times.collect { |i| Datum::new(values[i]).value }.freeze - end - end - - def check - ptr = MemoryPointer::new(:ccs_bool_t) - CCS.error_check CCS.ccs_evaluation_binding_check(@handle, ptr) - return ptr.read_ccs_bool_t == CCS::FALSE ? false : true - end - - def compare(other) - ptr = MemoryPointer::new(:ccs_comparison_t) - CCS.error_check CCS.ccs_evaluation_binding_compare(@handle, other, ptr) - ptr.read_ccs_comparison_t - end - - def <=>(other) - ptr = MemoryPointer::new(:ccs_comparison_t) - CCS.error_check CCS.ccs_evaluation_binding_compare(@handle, other, ptr) - r = ptr.read_int32 - r == 2 ? nil : r - end - - end -end diff --git a/bindings/ruby/lib/cconfigspace/features_evaluation.rb b/bindings/ruby/lib/cconfigspace/features_evaluation.rb index 0e351cd5..e18e1119 100644 --- a/bindings/ruby/lib/cconfigspace/features_evaluation.rb +++ b/bindings/ruby/lib/cconfigspace/features_evaluation.rb @@ -1,10 +1,7 @@ module CCS attach_function :ccs_create_features_evaluation, [:ccs_objective_space_t, :ccs_configuration_t, :ccs_features_t, :ccs_evaluation_result_t, :size_t, :pointer, :pointer], :ccs_result_t - attach_function :ccs_features_evaluation_get_configuration, [:ccs_features_evaluation_t, :pointer], :ccs_result_t attach_function :ccs_features_evaluation_get_features, [:ccs_features_evaluation_t, :pointer], :ccs_result_t - class FeaturesEvaluation < EvaluationBinding - alias objective_space context - add_handle_property :configuration, :ccs_configuration_t, :ccs_features_evaluation_get_configuration, memoize: true + class FeaturesEvaluation < Evaluation add_handle_property :features, :ccs_features_t, :ccs_features_evaluation_get_features, memoize: true def initialize(handle = nil, retain: false, auto_release: true, diff --git a/bindings/ruby/lib/cconfigspace/features_tuner.rb b/bindings/ruby/lib/cconfigspace/features_tuner.rb index fbf2bf89..257fd6ca 100644 --- a/bindings/ruby/lib/cconfigspace/features_tuner.rb +++ b/bindings/ruby/lib/cconfigspace/features_tuner.rb @@ -12,7 +12,7 @@ def read_ccs_features_tuner_type_t attach_function :ccs_features_tuner_get_type, [:ccs_features_tuner_t, :pointer], :ccs_result_t attach_function :ccs_features_tuner_get_name, [:ccs_features_tuner_t, :pointer], :ccs_result_t - attach_function :ccs_features_tuner_get_configuration_space, [:ccs_features_tuner_t, :pointer], :ccs_result_t + attach_function :ccs_features_tuner_get_search_space, [:ccs_features_tuner_t, :pointer], :ccs_result_t attach_function :ccs_features_tuner_get_objective_space, [:ccs_features_tuner_t, :pointer], :ccs_result_t attach_function :ccs_features_tuner_get_feature_space, [:ccs_features_tuner_t, :pointer], :ccs_result_t attach_function :ccs_features_tuner_ask, [:ccs_features_tuner_t, :ccs_features_t, :size_t, :pointer, :pointer], :ccs_result_t @@ -23,7 +23,7 @@ def read_ccs_features_tuner_type_t class FeaturesTuner < Object add_property :type, :ccs_features_tuner_type_t, :ccs_features_tuner_get_type, memoize: true - add_handle_property :configuration_space, :ccs_configuration_space_t, :ccs_features_tuner_get_configuration_space, memoize: true + add_handle_property :search_space, :ccs_search_space_t, :ccs_features_tuner_get_search_space, memoize: true add_handle_property :feature_space, :ccs_feature_space_t, :ccs_features_tuner_get_feature_space, memoize: true add_handle_property :objective_space, :ccs_objective_space_t, :ccs_features_tuner_get_objective_space, memoize: true @@ -49,11 +49,11 @@ def name end def ask(features, count = 1) - p_confs = MemoryPointer::new(:ccs_configuration_t, count) + p_confs = MemoryPointer::new(:ccs_search_configuration_t, count) p_num = MemoryPointer::new(:size_t) CCS.error_check CCS.ccs_features_tuner_ask(@handle, features, count, p_confs, p_num) count = p_num.read_size_t - count.times.collect { |i| Configuration::new(p_confs[i].read_pointer, retain: false) } + count.times.collect { |i| Object::from_handle(p_confs[i].read_pointer, retain: false) } end def tell(evaluations) @@ -91,9 +91,9 @@ def optima(features: nil) end def suggest(features) - p_conf = MemoryPointer::new(:ccs_configuration_t) + p_conf = MemoryPointer::new(:ccs_search_configuration_t) CCS.error_check CCS.ccs_features_tuner_suggest(@handle, features, p_conf) - Configuration::new(p_conf.read_pointer, retain: false) + Object.from_handle(p_conf.read_pointer, retain: false) end end diff --git a/bindings/ruby/lib/cconfigspace/tree_evaluation.rb b/bindings/ruby/lib/cconfigspace/tree_evaluation.rb deleted file mode 100644 index 00951398..00000000 --- a/bindings/ruby/lib/cconfigspace/tree_evaluation.rb +++ /dev/null @@ -1,39 +0,0 @@ -module CCS - - attach_function :ccs_create_tree_evaluation, [:ccs_objective_space_t, :ccs_tree_configuration_t, :ccs_evaluation_result_t, :size_t, :pointer, :pointer], :ccs_result_t - attach_function :ccs_tree_evaluation_get_configuration, [:ccs_tree_evaluation_t, :pointer], :ccs_result_t - - class TreeEvaluation < EvaluationBinding - alias objective_space context - add_handle_property :configuration, :ccs_tree_configuration_t, :ccs_tree_evaluation_get_configuration, memoize: true - - def initialize(handle = nil, retain: false, auto_release: true, - objective_space: nil, configuration: nil, result: :CCS_RESULT_SUCCESS, values: nil) - if handle - super(handle, retain: retain, auto_release: auto_release) - else - if values - count = values.size - raise CCSError, :CCS_RESULT_ERROR_INVALID_VALUE if count == 0 - ss = [] - p_values = MemoryPointer::new(:ccs_datum_t, count) - values.each_with_index { |v, i| Datum::new(p_values[i]).set_value(v, string_store: ss) } - values = p_values - else - count = 0 - end - ptr = MemoryPointer::new(:ccs_tree_evaluation_t) - CCS.error_check CCS.ccs_create_tree_evaluation(objective_space, configuration, result, count, values, ptr) - super(ptr.read_ccs_tree_evaluation_t, retain: false) - @objective_space = objective_space - @configuration = configuration - end - end - - def self.from_handle(handle, retain: true, auto_release: true) - self::new(handle, retain: retain, auto_release: auto_release) - end - - end - -end diff --git a/bindings/ruby/lib/cconfigspace/tree_space.rb b/bindings/ruby/lib/cconfigspace/tree_space.rb index d8d80d92..0135181b 100644 --- a/bindings/ruby/lib/cconfigspace/tree_space.rb +++ b/bindings/ruby/lib/cconfigspace/tree_space.rb @@ -12,19 +12,18 @@ def read_ccs_tree_space_type_t attach_function :ccs_tree_space_get_type, [:ccs_tree_space_t, :pointer], :ccs_result_t attach_function :ccs_tree_space_get_name, [:ccs_tree_space_t, :pointer], :ccs_result_t - attach_function :ccs_tree_space_set_rng, [:ccs_tree_space_t, :ccs_rng_t], :ccs_result_t attach_function :ccs_tree_space_get_rng, [:ccs_tree_space_t, :pointer], :ccs_result_t attach_function :ccs_tree_space_get_tree, [:ccs_tree_space_t, :pointer], :ccs_result_t attach_function :ccs_tree_space_get_node_at_position, [:ccs_tree_space_t, :size_t, :pointer, :pointer], :ccs_result_t attach_function :ccs_tree_space_get_values_at_position, [:ccs_tree_space_t, :size_t, :pointer, :size_t, :pointer], :ccs_result_t attach_function :ccs_tree_space_check_position, [:ccs_tree_space_t, :size_t, :pointer, :pointer], :ccs_result_t attach_function :ccs_tree_space_check_configuration, [:ccs_tree_space_t, :ccs_tree_configuration_t, :pointer], :ccs_result_t - attach_function :ccs_tree_space_sample, [:ccs_tree_space_t, :pointer], :ccs_result_t - attach_function :ccs_tree_space_samples, [:ccs_tree_space_t, :size_t, :pointer], :ccs_result_t + attach_function :ccs_tree_space_sample, [:ccs_tree_space_t, :ccs_rng_t, :pointer], :ccs_result_t + attach_function :ccs_tree_space_samples, [:ccs_tree_space_t, :ccs_rng_t, :size_t, :pointer], :ccs_result_t class TreeSpace < Object add_property :type, :ccs_tree_space_type_t, :ccs_tree_space_get_type, memoize: true - add_handle_property :rng, :ccs_rng_t, :ccs_tree_space_get_rng, memoize: false + add_handle_property :rng, :ccs_rng_t, :ccs_tree_space_get_rng, memoize: true add_handle_property :tree, :ccs_tree_t, :ccs_tree_space_get_tree, memoize: true def self.from_handle(handle, retain: true, auto_release: true) @@ -48,11 +47,6 @@ def name end end - def rng=(rng) - CCS.error_check CCS.ccs_tree_space_set_rng(@handle, rng) - rng - end - def get_node_at_position(position) count = position.size ptr1 = MemoryPointer::new(:size_t, count) @@ -87,32 +81,32 @@ def check_configuration(configuration) ptr.read_ccs_bool_t == CCS::FALSE ? false : true end - def sample + def sample(rng: nil) ptr = MemoryPointer::new(:ccs_tree_configuration_t) - CCS.error_check CCS.ccs_tree_space_sample(@handle, ptr) + CCS.error_check CCS.ccs_tree_space_sample(@handle, rng ? rng.handle : nil, ptr) TreeConfiguration::new(ptr.read_ccs_tree_configuration_t, retain: false) end - def samples(count) + def samples(count, rng: nil) return [] if count == 0 ptr = MemoryPointer::new(:ccs_tree_configuration_t, count) - CCS.error_check CCS.ccs_tree_space_samples(@handle, count, ptr) + CCS.error_check CCS.ccs_tree_space_samples(@handle, rng ? rng.handle : nil, count, ptr) count.times.collect { |i| TreeConfiguration::new(ptr[i].read_pointer, retain: false) } end end - attach_function :ccs_create_static_tree_space, [:string, :ccs_tree_t, :pointer], :ccs_result_t + attach_function :ccs_create_static_tree_space, [:string, :ccs_tree_t, :ccs_rng_t, :pointer], :ccs_result_t class StaticTreeSpace < TreeSpace def initialize(handle = nil, retain: false, auto_release: true, - name: "", tree: nil) + name: "", tree: nil, rng: nil) if handle super(handle, retain: retain, auto_release: auto_release) else ptr = MemoryPointer::new(:ccs_tree_space_t) - CCS.error_check CCS.ccs_create_static_tree_space(name, tree, ptr) + CCS.error_check CCS.ccs_create_static_tree_space(name, tree, rng ? rng.handle : nil, ptr) super(ptr.read_ccs_tree_space_t, retain: false) end end @@ -187,14 +181,14 @@ def self.wrap_dynamic_tree_space_callbacks(del, get_child, serialize, deserializ return [delwrapper, get_childwrapper, serializewrapper, deserializewrapper] end - attach_function :ccs_create_dynamic_tree_space, [:string, :ccs_tree_t, DynamicTreeSpaceVector.by_ref, :value, :pointer], :ccs_result_t + attach_function :ccs_create_dynamic_tree_space, [:string, :ccs_tree_t, :ccs_rng_t, DynamicTreeSpaceVector.by_ref, :value, :pointer], :ccs_result_t attach_function :ccs_dynamic_tree_space_get_tree_space_data, [:ccs_tree_space_t, :pointer], :ccs_result_t class DynamicTreeSpace < TreeSpace add_property :tree_space_data, :value, :ccs_dynamic_tree_space_get_tree_space_data, memoize: true def initialize(handle = nil, retain: false, auto_release: true, - name: "", tree: nil, del: nil, get_child: nil, serialize: nil, deserialize: nil, tree_space_data: nil) + name: "", tree: nil, rng: nil, del: nil, get_child: nil, serialize: nil, deserialize: nil, tree_space_data: nil) if handle super(handle, retain: retain, auto_release: auto_release) else @@ -207,7 +201,7 @@ def initialize(handle = nil, retain: false, auto_release: true, vector[:serialize] = serializewrapper vector[:deserialize] = deserializewrapper ptr = MemoryPointer::new(:ccs_tree_space_t) - CCS.error_check CCS.ccs_create_dynamic_tree_space(name, tree, vector, tree_space_data, ptr) + CCS.error_check CCS.ccs_create_dynamic_tree_space(name, tree, rng ? rng.handle : nil, vector, tree_space_data, ptr) h = ptr.read_ccs_tree_space_t super(h, retain: false) CCS.register_vector(h, [delwrapper, get_childwrapper, serializewrapper, deserializewrapper, tree_space_data]) diff --git a/bindings/ruby/lib/cconfigspace/tree_tuner.rb b/bindings/ruby/lib/cconfigspace/tree_tuner.rb deleted file mode 100644 index 37e7a2e9..00000000 --- a/bindings/ruby/lib/cconfigspace/tree_tuner.rb +++ /dev/null @@ -1,313 +0,0 @@ -module CCS - - TreeTunerType = enum FFI::Type::INT32, :ccs_tree_tuner_type_t, [ - :CCS_TREE_TUNER_TYPE_RANDOM, - :CCS_TREE_TUNER_TYPE_USER_DEFINED - ] - class MemoryPointer - def read_ccs_tree_tuner_type_t - TreeTunerType.from_native(read_int32, nil) - end - end - - attach_function :ccs_tree_tuner_get_type, [:ccs_tree_tuner_t, :pointer], :ccs_result_t - attach_function :ccs_tree_tuner_get_name, [:ccs_tree_tuner_t, :pointer], :ccs_result_t - attach_function :ccs_tree_tuner_get_tree_space, [:ccs_tree_tuner_t, :pointer], :ccs_result_t - attach_function :ccs_tree_tuner_get_objective_space, [:ccs_tree_tuner_t, :pointer], :ccs_result_t - attach_function :ccs_tree_tuner_ask, [:ccs_tree_tuner_t, :size_t, :pointer, :pointer], :ccs_result_t - attach_function :ccs_tree_tuner_tell, [:ccs_tree_tuner_t, :size_t, :pointer], :ccs_result_t - attach_function :ccs_tree_tuner_get_optima, [:ccs_tree_tuner_t, :size_t, :pointer, :pointer], :ccs_result_t - attach_function :ccs_tree_tuner_get_history, [:ccs_tree_tuner_t, :size_t, :pointer, :pointer], :ccs_result_t - attach_function :ccs_tree_tuner_suggest, [:ccs_tree_tuner_t, :pointer], :ccs_result_t - - class TreeTuner < Object - add_property :type, :ccs_tree_tuner_type_t, :ccs_tree_tuner_get_type, memoize: true - add_handle_property :tree_space, :ccs_tree_space_t, :ccs_tree_tuner_get_tree_space, memoize: true - add_handle_property :objective_space, :ccs_objective_space_t, :ccs_tree_tuner_get_objective_space, memoize: true - - def self.from_handle(handle, retain: true, auto_release: true) - ptr = MemoryPointer::new(:ccs_tuner_type_t) - CCS.error_check CCS.ccs_tree_tuner_get_type(handle, ptr) - case ptr.read_ccs_tree_tuner_type_t - when :CCS_TREE_TUNER_TYPE_RANDOM - RandomTreeTuner - when :CCS_TREE_TUNER_TYPE_USER_DEFINED - UserDefinedTreeTuner - else - raise CCSError, :CCS_RESULT_ERROR_INVALID_TREE_TUNER - end.new(handle, retain: retain, auto_release: auto_release) - end - - def name - @name ||= begin - ptr = MemoryPointer::new(:pointer) - CCS.error_check CCS.ccs_tree_tuner_get_name(@handle, ptr) - ptr.read_pointer.read_string - end - end - - def ask(count = 1) - p_confs = MemoryPointer::new(:ccs_tree_configuration_t, count) - p_num = MemoryPointer::new(:size_t) - CCS.error_check CCS.ccs_tree_tuner_ask(@handle, count, p_confs, p_num) - count = p_num.read_size_t - count.times.collect { |i| TreeConfiguration::new(p_confs[i].read_pointer, retain: false) } - end - - def tell(evaluations) - count = evaluations.size - p_evals = MemoryPointer::new(:ccs_tree_evaluation_t, count) - p_evals.write_array_of_pointer(evaluations.collect(&:handle)) - CCS.error_check CCS.ccs_tree_tuner_tell(@handle, count, p_evals) - self - end - - def history_size - p_count = MemoryPointer::new(:size_t) - CCS.error_check CCS.ccs_tree_tuner_get_history(@handle, 0, nil, p_count) - return p_count.read_size_t - end - - def history - count = history_size - p_evals = MemoryPointer::new(:ccs_tree_evaluation_t, count) - CCS.error_check CCS.ccs_tree_tuner_get_history(@handle, count, p_evals, nil) - count.times.collect { |i| TreeEvaluation::from_handle(p_evals[i].read_pointer) } - end - - def num_optima - p_count = MemoryPointer::new(:size_t) - CCS.error_check CCS.ccs_tree_tuner_get_optima(@handle, 0, nil, p_count) - return p_count.read_size_t - end - - def optima - count = num_optima - p_evals = MemoryPointer::new(:ccs_tree_evaluation_t, count) - CCS.error_check CCS.ccs_tree_tuner_get_optima(@handle, count, p_evals, nil) - count.times.collect { |i| TreeEvaluation::from_handle(p_evals[i].read_pointer) } - end - - def suggest - p_conf = MemoryPointer::new(:ccs_tree_configuration_t) - CCS.error_check CCS.ccs_tree_tuner_suggest(@handle, p_conf) - TreeConfiguration::new(p_conf.read_pointer, retain: false) - end - - end - - attach_function :ccs_create_random_tree_tuner, [:string, :ccs_objective_space_t, :pointer], :ccs_result_t - - class RandomTreeTuner < TreeTuner - def initialize(handle = nil, retain: false, auto_release: true, - name: "", objective_space: nil) - if handle - super(handle, retain: retain, auto_release: auto_release) - else - ptr = MemoryPointer::new(:ccs_tree_tuner_t) - CCS.error_check CCS.ccs_create_random_tree_tuner(name, objective_space, ptr) - super(ptr.read_ccs_tree_tuner_t, retain: false) - end - end - end - - TreeTuner::Random = RandomTreeTuner - - callback :ccs_user_defined_tree_tuner_del, [:ccs_tree_tuner_t], :ccs_result_t - callback :ccs_user_defined_tree_tuner_ask, [:ccs_tree_tuner_t, :size_t, :pointer, :pointer], :ccs_result_t - callback :ccs_user_defined_tree_tuner_tell, [:ccs_tree_tuner_t, :size_t, :pointer], :ccs_result_t - callback :ccs_user_defined_tree_tuner_get_optima, [:ccs_tree_tuner_t, :size_t, :pointer, :pointer], :ccs_result_t - callback :ccs_user_defined_tree_tuner_get_history, [:ccs_tree_tuner_t, :size_t, :pointer, :pointer], :ccs_result_t - callback :ccs_user_defined_tree_tuner_suggest, [:ccs_tree_tuner_t, :pointer], :ccs_result_t - callback :ccs_user_defined_tree_tuner_serialize, [:ccs_tree_tuner_t, :size_t, :pointer, :pointer], :ccs_result_t - callback :ccs_user_defined_tree_tuner_deserialize, [:ccs_tree_tuner_t, :size_t, :pointer, :size_t, :pointer, :size_t, :pointer], :ccs_result_t - - class UserDefinedTreeTunerVector < FFI::Struct - layout :del, :ccs_user_defined_tree_tuner_del, - :ask, :ccs_user_defined_tree_tuner_ask, - :tell, :ccs_user_defined_tree_tuner_tell, - :get_optima, :ccs_user_defined_tree_tuner_get_optima, - :get_history, :ccs_user_defined_tree_tuner_get_history, - :suggest, :ccs_user_defined_tree_tuner_suggest, - :serialize, :ccs_user_defined_tree_tuner_serialize, - :deserialize, :ccs_user_defined_tree_tuner_deserialize - end - typedef UserDefinedTreeTunerVector.by_value, :ccs_user_definedi_tree_tuner_vector_t - - def self.wrap_user_defined_tree_tuner_callbacks(del, ask, tell, get_optima, get_history, suggest, serialize, deserialize) - delwrapper = lambda { |tun| - begin - del.call(CCS::Object.from_handle(tun)) if del - CCS.unregister_vector(tun) - CCSError.to_native(:CCS_RESULT_SUCCESS) - rescue => e - CCS.set_error(e) - end - } - askwrapper = lambda { |tun, count, p_configurations, p_count| - begin - configurations, count_ret = ask.call(TreeTuner.from_handle(tun), p_configurations.null? ? nil : count) - raise CCSError, :CCS_RESULT_ERROR_INVALID_VALUE if !p_configurations.null? && count < count_ret - if !p_configurations.null? - configurations.each_with_index { |c, i| - err = CCS.ccs_retain_object(c.handle) - CCS.error_check(err) - p_configurations.put_pointer(i*8, c.handle) - } - (count_ret...count).each { |i| p_configurations[i].put_pointer(i*8, 0) } - end - Pointer.new(p_count).write_size_t(count_ret) unless p_count.null? - CCSError.to_native(:CCS_RESULT_SUCCESS) - rescue => e - CCS.set_error(e) - end - } - tellwrapper = lambda { |tun, count, p_evaluations| - begin - if count > 0 - evals = count.times.collect { |i| TreeEvaluation::from_handle(p_evaluations.get_pointer(i*8)) } - tell.call(TreeTuner.from_handle(tun), evals) - end - CCSError.to_native(:CCS_RESULT_SUCCESS) - rescue => e - CCS.set_error(e) - end - } - get_optimawrapper = lambda { |tun, count, p_evaluations, p_count| - begin - optima = get_optima.call(TreeTuner.from_handle(tun)) - raise CCSError, :CCS_RESULT_ERROR_INVALID_VALUE if !p_evaluations.null? && count < optima.size - unless p_evaluations.null? - optima.each_with_index { |o, i| - p_evaluations.put_pointer(8*i, o.handle) - } - ((optima.size)...count).each { |i| p_evaluations.put_pointer(8*i, 0) } - end - Pointer.new(p_count).write_size_t(optima.size) unless p_count.null? - CCSError.to_native(:CCS_RESULT_SUCCESS) - rescue => e - CCS.set_error(e) - end - } - get_historywrapper = lambda { |tun, count, p_evaluations, p_count| - begin - history = get_history.call(TreeTuner.from_handle(tun)) - raise CCSError, :CCS_RESULT_ERROR_INVALID_VALUE if !p_evaluations.null? && count < history.size - unless p_evaluations.null? - history.each_with_index { |e, i| - p_evaluations.put_pointer(8*i, e.handle) - } - ((history.size)...count).each { |i| p_evaluations.put_pointer(8*i, 0) } - end - Pointer.new(p_count).write_size_t(history.size) unless p_count.null? - CCSError.to_native(:CCS_RESULT_SUCCESS) - rescue => e - CCS.set_error(e) - end - } - suggestwrapper = - if suggest - lambda { |tun, p_configuration| - begin - configuration = suggest.call(TreeTuner.from_handle(tun)) - err = CCS.ccs_retain_object(configuration.handle) - CCS.error_check(err) - p_configuration.write_pointer(configuration.handle) - CCSError.to_native(:CCS_RESULT_SUCCESS) - rescue => e - CCS.set_error(e) - end - } - else - nil - end - serializewrapper = - if serialize - lambda { |tun, state_size, p_state, p_state_size| - begin - state = serialize(TreeTuner.from_handle(tun), state_size == 0 ? true : false) - raise CCSError, :CCS_RESULT_ERROR_INVALID_VALUE if !p_state.null? && state_size < state.size - p_state.write_bytes(state.read_bytes(state.size)) unless p_state.null? - Pointer.new(p_state_size).write_size_t(state.size) unless p_state_size.null? - CCSError.to_native(:CCS_RESULT_SUCCESS) - rescue => e - CCS.set_error(e) - end - } - else - nil - end - deserializewrapper = - if deserialize - lambda { |tun, history_size, p_history, num_optima, p_optima, state_size, p_state| - begin - history = p_history.null? ? [] : history_size.times.collect { |i| TreeEvaluation::from_handle(p_p_history.get_pointer(i*8)) } - optima = p_optima.null? ? [] : num_optima.times.collect { |i| TreeEvaluation::from_handle(p_optima.get_pointer(i*8)) } - state = p_state.null? ? nil : p_state.slice(0, state_size) - deserialize(TreeTuner.from_handle(tun), history, optima, state) - CCSError.to_native(:CCS_RESULT_SUCCESS) - rescue => e - CCS.set_error(e) - end - } - else - nil - end - return [delwrapper, askwrapper, tellwrapper, get_optimawrapper, get_historywrapper, suggestwrapper, serializewrapper, deserializewrapper] - end - - attach_function :ccs_create_user_defined_tree_tuner, [:string, :ccs_objective_space_t, UserDefinedTreeTunerVector.by_ref, :value, :pointer], :ccs_result_t - attach_function :ccs_user_defined_tree_tuner_get_tuner_data, [:ccs_tree_tuner_t, :pointer], :ccs_result_t - - class UserDefinedTreeTuner < TreeTuner - add_property :tuner_data, :value, :ccs_user_defined_tree_tuner_get_tuner_data, memoize: true - - def initialize(handle = nil, retain: false, auto_release: true, - name: "", objective_space: nil, - del: nil, ask: nil, tell: nil, get_optima: nil, get_history: nil, suggest: nil, serialize: nil, deserialize: nil, tuner_data: nil) - if handle - super(handle, retain: retain, auto_release: auto_release) - else - raise CCSError, :CCS_RESULT_ERROR_INVALID_VALUE if ask.nil? || tell.nil? || get_optima.nil? || get_history.nil? - delwrapper, askwrapper, tellwrapper, get_optimawrapper, get_historywrapper, suggestwrapper, serializewrapper, deserializewrapper = - CCS.wrap_user_defined_tree_tuner_callbacks(del, ask, tell, get_optima, get_history, suggest, serialize, deserialize) - vector = UserDefinedTreeTunerVector::new - vector[:del] = delwrapper - vector[:ask] = askwrapper - vector[:tell] = tellwrapper - vector[:get_optima] = get_optimawrapper - vector[:get_history] = get_historywrapper - vector[:suggest] = suggestwrapper - vector[:serialize] = serializewrapper - vector[:deserialize] = deserializewrapper - ptr = MemoryPointer::new(:ccs_tree_tuner_t) - CCS.error_check CCS.ccs_create_user_defined_tree_tuner(name, objective_space, vector, tuner_data, ptr) - handle = ptr.read_ccs_tree_tuner_t - super(handle, retain: false) - CCS.register_vector(handle, [delwrapper, askwrapper, tellwrapper, get_optimawrapper, get_historywrapper, suggestwrapper, serializewrapper, deserializewrapper, tuner_data]) - end - end - - def self.deserialize(del: nil, ask: nil, tell: nil, get_optima: nil, get_history: nil, suggest: nil, serialize: nil, deserialize: nil, tuner_data: nil, format: :binary, handle_map: nil, path: nil, buffer: nil, file_descriptor: nil, callback: nil, callback_data: nil) - raise CCSError, :CCS_RESULT_ERROR_INVALID_VALUE if ask.nil? || tell.nil? || get_optima.nil? || get_history.nil? - delwrapper, askwrapper, tellwrapper, get_optimawrapper, get_historywrapper, suggestwrapper, serializewrapper, deserializewrapper = - CCS.wrap_user_defined_tree_tuner_callbacks(del, ask, tell, get_optima, get_history, suggest, serialize, deserialize) - vector = UserDefinedTreeTunerVector::new - vector[:del] = delwrapper - vector[:ask] = askwrapper - vector[:tell] = tellwrapper - vector[:get_optima] = get_optimawrapper - vector[:get_history] = get_historywrapper - vector[:suggest] = suggestwrapper - vector[:serialize] = serializewrapper - vector[:deserialize] = deserializewrapper - res = super(format: format, handle_map: handle_map, vector: vector.to_ptr, data: tuner_data, path: path, buffer: buffer, file_descriptor: file_descriptor, callback: callback, callback_data: callback_data) - CCS.register_vector(res.handle, [delwrapper, askwrapper, tellwrapper, get_optimawrapper, get_historywrapper, suggestwrapper, serializewrapper, deserializewrapper, tuner_data]) - res - end - - end - - TreeTuner::UserDefined = UserDefinedTreeTuner - -end diff --git a/bindings/ruby/lib/cconfigspace/tuner.rb b/bindings/ruby/lib/cconfigspace/tuner.rb index 7c041de9..174450f9 100644 --- a/bindings/ruby/lib/cconfigspace/tuner.rb +++ b/bindings/ruby/lib/cconfigspace/tuner.rb @@ -12,7 +12,7 @@ def read_ccs_tuner_type_t attach_function :ccs_tuner_get_type, [:ccs_tuner_t, :pointer], :ccs_result_t attach_function :ccs_tuner_get_name, [:ccs_tuner_t, :pointer], :ccs_result_t - attach_function :ccs_tuner_get_configuration_space, [:ccs_tuner_t, :pointer], :ccs_result_t + attach_function :ccs_tuner_get_search_space, [:ccs_tuner_t, :pointer], :ccs_result_t attach_function :ccs_tuner_get_objective_space, [:ccs_tuner_t, :pointer], :ccs_result_t attach_function :ccs_tuner_ask, [:ccs_tuner_t, :size_t, :pointer, :pointer], :ccs_result_t attach_function :ccs_tuner_tell, [:ccs_tuner_t, :size_t, :pointer], :ccs_result_t @@ -22,7 +22,7 @@ def read_ccs_tuner_type_t class Tuner < Object add_property :type, :ccs_tuner_type_t, :ccs_tuner_get_type, memoize: true - add_handle_property :configuration_space, :ccs_configuration_space_t, :ccs_tuner_get_configuration_space, memoize: true + add_handle_property :search_space, :ccs_search_space_t, :ccs_tuner_get_search_space, memoize: true add_handle_property :objective_space, :ccs_objective_space_t, :ccs_tuner_get_objective_space, memoize: true def self.from_handle(handle, retain: true, auto_release: true) @@ -47,11 +47,11 @@ def name end def ask(count = 1) - p_confs = MemoryPointer::new(:ccs_configuration_t, count) + p_confs = MemoryPointer::new(:ccs_search_configuration_t, count) p_num = MemoryPointer::new(:size_t) CCS.error_check CCS.ccs_tuner_ask(@handle, count, p_confs, p_num) count = p_num.read_size_t - count.times.collect { |i| Configuration::new(p_confs[i].read_pointer, retain: false) } + count.times.collect { |i| Object::from_handle(p_confs[i].read_pointer, retain: false) } end def tell(evaluations) @@ -89,9 +89,9 @@ def optima end def suggest - p_conf = MemoryPointer::new(:ccs_configuration_t) + p_conf = MemoryPointer::new(:ccs_search_configuration_t) CCS.error_check CCS.ccs_tuner_suggest(@handle, p_conf) - Configuration::new(p_conf.read_pointer, retain: false) + Object::from_handle(p_conf.read_pointer, retain: false) end end diff --git a/bindings/ruby/test/test_features_tuner.rb b/bindings/ruby/test/test_features_tuner.rb index 73d8b9b7..f5f0a3cc 100644 --- a/bindings/ruby/test/test_features_tuner.rb +++ b/bindings/ruby/test/test_features_tuner.rb @@ -76,7 +76,7 @@ def test_user_defined del = lambda { |tuner| nil } ask = lambda { |tuner, features, count| if count - cs = tuner.configuration_space + cs = tuner.search_space [cs.samples(count), count] else [nil, 1] diff --git a/bindings/ruby/test/test_tree_evaluation.rb b/bindings/ruby/test/test_tree_evaluation.rb index 293fbc5f..bcff58f5 100644 --- a/bindings/ruby/test/test_tree_evaluation.rb +++ b/bindings/ruby/test/test_tree_evaluation.rb @@ -26,20 +26,20 @@ def test_create e1 = CCS::Expression::Variable.new(parameter: v1) e2 = CCS::Expression::Variable.new(parameter: v2) os = CCS::ObjectiveSpace.new(name: 'ospace', search_space: ts, parameters: [v1, v2], objectives: { e1 => :CCS_OBJECTIVE_TYPE_MAXIMIZE, e2 => :CCS_OBJECTIVE_TYPE_MINIMIZE }) - ev1 = CCS::TreeEvaluation.new(objective_space: os, configuration: ts.sample, values: [0.5, 0.6]) + ev1 = CCS::Evaluation.new(objective_space: os, configuration: ts.sample, values: [0.5, 0.6]) assert_equal( [0.5, 0.6], ev1.values ) assert_equal( [0.5, 0.6], ev1.objective_values ) assert( ev1.check ) assert( os.check(ev1) ) - ev2 = CCS::TreeEvaluation.new(objective_space: os, configuration: ts.sample, values: [0.5, 0.6]) + ev2 = CCS::Evaluation.new(objective_space: os, configuration: ts.sample, values: [0.5, 0.6]) assert_equal( [0.5, 0.6], ev2.values ) assert_equal( [0.5, 0.6], ev2.objective_values ) assert_equal( :CCS_COMPARISON_EQUIVALENT, ev1.compare(ev2) ) - ev3 = CCS::TreeEvaluation.new(objective_space: os, configuration: ts.sample, values: [0.6, 0.5]) + ev3 = CCS::Evaluation.new(objective_space: os, configuration: ts.sample, values: [0.6, 0.5]) assert_equal( [0.6, 0.5], ev3.objective_values ) assert_equal( :CCS_COMPARISON_WORSE, ev1.compare(ev3) ) assert_equal( :CCS_COMPARISON_BETTER, ev3.compare(ev1) ) - ev4 = CCS::TreeEvaluation.new(objective_space: os, configuration: ts.sample, values: [0.6, 0.7]) + ev4 = CCS::Evaluation.new(objective_space: os, configuration: ts.sample, values: [0.6, 0.7]) assert_equal( [0.6, 0.7], ev4.objective_values ) assert_equal( :CCS_COMPARISON_NOT_COMPARABLE, ev1.compare(ev4) ) assert_equal( :CCS_COMPARISON_NOT_COMPARABLE, ev4.compare(ev1) ) @@ -53,7 +53,7 @@ def test_serialize e1 = CCS::Expression::Variable.new(parameter: v1) e2 = CCS::Expression::Variable.new(parameter: v2) os = CCS::ObjectiveSpace.new(name: 'ospace', search_space: ts, parameters: [v1, v2], objectives: { e1 => :CCS_OBJECTIVE_TYPE_MAXIMIZE, e2 => :CCS_OBJECTIVE_TYPE_MINIMIZE }) - evref = CCS::TreeEvaluation.new(objective_space: os, configuration: ts.sample, values: [0.5, 0.6]) + evref = CCS::Evaluation.new(objective_space: os, configuration: ts.sample, values: [0.5, 0.6]) buff = evref.serialize handle_map = CCS::Map.new handle_map[ts] = ts diff --git a/bindings/ruby/test/test_tree_space.rb b/bindings/ruby/test/test_tree_space.rb index 58eda0b8..bdd0c714 100644 --- a/bindings/ruby/test/test_tree_space.rb +++ b/bindings/ruby/test/test_tree_space.rb @@ -20,12 +20,11 @@ def generate_tree(depth, rank) def test_static_tree_space rng = CCS::Rng.new tree = generate_tree(4, 0) - ts = CCS::StaticTreeSpace.new(name: 'space', tree: tree) + ts = CCS::StaticTreeSpace.new(name: 'space', tree: tree, rng: rng) assert_equal( :CCS_OBJECT_TYPE_TREE_SPACE, ts.object_type ) assert_equal( "space", ts.name ) - assert_instance_of( CCS::Rng, ts.rng ) assert_equal( :CCS_TREE_SPACE_TYPE_STATIC, ts.type ) - ts.rng = rng + assert_instance_of( CCS::Rng, ts.rng ) assert_equal( rng.handle, ts.rng.handle ) assert_equal( tree.handle, ts.tree.handle ) assert_equal( tree.handle, ts.get_node_at_position([]).handle ) diff --git a/bindings/ruby/test/test_tree_tuner.rb b/bindings/ruby/test/test_tree_tuner.rb index 96223993..782bf74e 100644 --- a/bindings/ruby/test/test_tree_tuner.rb +++ b/bindings/ruby/test/test_tree_tuner.rb @@ -23,24 +23,24 @@ def create_tuning_problem ts = CCS::StaticTreeSpace.new(name: 'space', tree: tree) v1 = CCS::NumericalParameter::Float.new(lower: -Float::INFINITY, upper: Float::INFINITY) e1 = CCS::Expression::Variable.new(parameter: v1) - os = CCS::ObjectiveSpace.new(name: 'ospace', search_space: ts, parameters: [v1], objectives: {e1 => :CCS_OBJECTIVE_TYPE_MAXIMIZE}) + CCS::ObjectiveSpace.new(name: 'ospace', search_space: ts, parameters: [v1], objectives: {e1 => :CCS_OBJECTIVE_TYPE_MAXIMIZE}) end def test_create_random os = create_tuning_problem - t = CCS::RandomTreeTuner.new(name: "tuner", objective_space: os) + t = CCS::RandomTuner.new(name: "tuner", objective_space: os) t2 = CCS::Object.from_handle(t) assert_equal(t.class, t2.class) assert_equal("tuner", t.name) - assert_equal(:CCS_TREE_TUNER_TYPE_RANDOM, t.type) + assert_equal(:CCS_TUNER_TYPE_RANDOM, t.type) evals = t.ask(100).map { |c| - CCS::TreeEvaluation.new(objective_space: os, configuration: c, values: [c.values.reduce(:+)]) + CCS::Evaluation.new(objective_space: os, configuration: c, values: [c.values.reduce(:+)]) } t.tell(evals) hist = t.history assert_equal(100, hist.size) evals = t.ask(100).map { |c| - CCS::TreeEvaluation.new(objective_space: os, configuration: c, values: [c.values.reduce(:+)]) + CCS::Evaluation.new(objective_space: os, configuration: c, values: [c.values.reduce(:+)]) } t.tell(evals) hist = t.history @@ -74,7 +74,7 @@ def test_user_defined del = lambda { |tuner| nil } ask = lambda { |tuner, count| if count - ts = tuner.tree_space + ts = tuner.search_space [ts.samples(count), count] else [nil, 1] @@ -116,19 +116,19 @@ def test_user_defined end } os = create_tuning_problem - t = CCS::UserDefinedTreeTuner.new(name: "tuner", objective_space: os, del: del, ask: ask, tell: tell, get_optima: get_optima, get_history: get_history, suggest: suggest, tuner_data: TreeTunerData.new) + t = CCS::UserDefinedTuner.new(name: "tuner", objective_space: os, del: del, ask: ask, tell: tell, get_optima: get_optima, get_history: get_history, suggest: suggest, tuner_data: TreeTunerData.new) t2 = CCS::Object::from_handle(t) assert_equal( t.class, t2.class) assert_equal( "tuner", t.name ) - assert_equal( :CCS_TREE_TUNER_TYPE_USER_DEFINED, t.type ) + assert_equal( :CCS_TUNER_TYPE_USER_DEFINED, t.type ) evals = t.ask(100).map { |c| - CCS::TreeEvaluation.new(objective_space: os, configuration: c, values: [c.values.reduce(:+)]) + CCS::Evaluation.new(objective_space: os, configuration: c, values: [c.values.reduce(:+)]) } t.tell(evals) hist = t.history assert_equal(100, hist.size) evals = t.ask(100).map { |c| - CCS::TreeEvaluation.new(objective_space: os, configuration: c, values: [c.values.reduce(:+)]) + CCS::Evaluation.new(objective_space: os, configuration: c, values: [c.values.reduce(:+)]) } t.tell(evals) hist = t.history @@ -139,7 +139,7 @@ def test_user_defined assert_equal(hist.map { |e| e.objective_values.first }.max, best) assert(optims.map(&:configuration).include?(t.suggest)) buff = t.serialize - t_copy = CCS::UserDefinedTreeTuner.deserialize(buffer: buff, del: del, ask: ask, tell: tell, get_optima: get_optima, get_history: get_history, suggest: suggest, tuner_data: TreeTunerData.new) + t_copy = CCS::UserDefinedTuner.deserialize(buffer: buff, del: del, ask: ask, tell: tell, get_optima: get_optima, get_history: get_history, suggest: suggest, tuner_data: TreeTunerData.new) hist = t_copy.history assert_equal(200, hist.size) optims_2 = t_copy.optima diff --git a/bindings/ruby/test/test_tuner.rb b/bindings/ruby/test/test_tuner.rb index ba590193..55f6828f 100644 --- a/bindings/ruby/test/test_tuner.rb +++ b/bindings/ruby/test/test_tuner.rb @@ -15,7 +15,7 @@ def create_tuning_problem v2 = CCS::NumericalParameter::Float.new(lower: -Float::INFINITY, upper: Float::INFINITY) e1 = CCS::Expression::Variable::new(parameter: v1) e2 = CCS::Expression::Variable::new(parameter: v2) - os = CCS::ObjectiveSpace::new(name: "ospace", search_space: cs, parameters: [v1, v2], objectives: [e1, e2]) + CCS::ObjectiveSpace::new(name: "ospace", search_space: cs, parameters: [v1, v2], objectives: [e1, e2]) end def test_create_random @@ -65,7 +65,7 @@ def test_user_defined del = lambda { |tuner| nil } ask = lambda { |tuner, count| if count - cs = tuner.configuration_space + cs = tuner.search_space [cs.samples(count), count] else [nil, 1] diff --git a/connectors/kokkos/ccs-kokkos-connector.cpp b/connectors/kokkos/ccs-kokkos-connector.cpp index ba908c48..75031128 100644 --- a/connectors/kokkos/ccs-kokkos-connector.cpp +++ b/connectors/kokkos/ccs-kokkos-connector.cpp @@ -596,13 +596,15 @@ kokkosp_request_values( } if (!converged) - CCS_CHECK( - ccs_features_tuner_ask(tuner, feat, 1, &configuration, NULL)); + CCS_CHECK(ccs_features_tuner_ask( + tuner, feat, 1, (ccs_search_configuration_t *)&configuration, + NULL)); else - CCS_CHECK(ccs_features_tuner_suggest(tuner, feat, &configuration)); + CCS_CHECK(ccs_features_tuner_suggest( + tuner, feat, (ccs_search_configuration_t *)&configuration)); - CCS_CHECK(ccs_features_tuner_get_configuration_space( - tuner, &configuration_space)); + CCS_CHECK(ccs_features_tuner_get_search_space( + tuner, (ccs_search_space_t *)&configuration_space)); { ccs_datum_t *values = new ccs_datum_t[numTuningVariables]; CCS_CHECK(ccs_binding_get_values( @@ -682,8 +684,8 @@ kokkosp_end_context(size_t contextId) CCS_CHECK(ccs_features_tuner_get_objective_space( tuner, &objective_space)); CCS_CHECK(ccs_create_features_evaluation( - objective_space, configuration, feat, CCS_RESULT_SUCCESS, 1, - &elapsed, &evaluation)); + objective_space, (ccs_search_configuration_t)configuration, + feat, CCS_RESULT_SUCCESS, 1, &elapsed, &evaluation)); CCS_CHECK(ccs_features_tuner_tell(tuner, 1, &evaluation)); CCS_CHECK(ccs_release_object(evaluation)); diff --git a/include/Makefile.am b/include/Makefile.am index 3dd4ab9f..1af2ea09 100644 --- a/include/Makefile.am +++ b/include/Makefile.am @@ -17,7 +17,6 @@ include_ccs_HEADERS = \ cconfigspace/configuration.h \ cconfigspace/features.h \ cconfigspace/objective_space.h \ - cconfigspace/evaluation_binding.h \ cconfigspace/evaluation.h \ cconfigspace/features_evaluation.h \ cconfigspace/tuner.h \ @@ -25,7 +24,5 @@ include_ccs_HEADERS = \ cconfigspace/map.h \ cconfigspace/tree.h \ cconfigspace/tree_space.h \ - cconfigspace/tree_configuration.h \ - cconfigspace/tree_evaluation.h \ - cconfigspace/tree_tuner.h + cconfigspace/tree_configuration.h diff --git a/include/cconfigspace.h b/include/cconfigspace.h index e97c92d0..5c58b9e5 100644 --- a/include/cconfigspace.h +++ b/include/cconfigspace.h @@ -20,7 +20,6 @@ #include "cconfigspace/features.h" #include "cconfigspace/objective_space.h" #include "cconfigspace/evaluation.h" -#include "cconfigspace/evaluation_binding.h" #include "cconfigspace/features_evaluation.h" #include "cconfigspace/tuner.h" #include "cconfigspace/features_tuner.h" @@ -28,8 +27,6 @@ #include "cconfigspace/tree.h" #include "cconfigspace/tree_space.h" #include "cconfigspace/tree_configuration.h" -#include "cconfigspace/tree_evaluation.h" -#include "cconfigspace/tree_tuner.h" /** * @file cconfigspace.h diff --git a/include/cconfigspace/base.h b/include/cconfigspace/base.h index 41ad5286..2c98b1c7 100644 --- a/include/cconfigspace/base.h +++ b/include/cconfigspace/base.h @@ -84,103 +84,95 @@ extern const ccs_version_t ccs_version; /** * An opaque type defining a CCS random generator. */ -typedef struct _ccs_rng_s *ccs_rng_t; +typedef struct _ccs_rng_s *ccs_rng_t; /** * An opaque type defining a CCS distribution. */ -typedef struct _ccs_distribution_s *ccs_distribution_t; +typedef struct _ccs_distribution_s *ccs_distribution_t; /** * An opaque type defining a CCS parameter. */ -typedef struct _ccs_parameter_s *ccs_parameter_t; +typedef struct _ccs_parameter_s *ccs_parameter_t; /** * An opaque type defining a CCS expression. */ -typedef struct _ccs_expression_s *ccs_expression_t; +typedef struct _ccs_expression_s *ccs_expression_t; /** * An opaque type defining a CCS context. */ -typedef struct _ccs_context_s *ccs_context_t; +typedef struct _ccs_context_s *ccs_context_t; /** * An opaque type defining a CCS distribution space. */ -typedef struct _ccs_distribution_space_s *ccs_distribution_space_t; +typedef struct _ccs_distribution_space_s *ccs_distribution_space_t; /** * An opaque type defining a CCS search space. */ -typedef struct _ccs_search_space_s *ccs_search_space_t; +typedef struct _ccs_search_space_s *ccs_search_space_t; /** * An opaque type defining a CCS configuration space. */ -typedef struct _ccs_configuration_space_s *ccs_configuration_space_t; +typedef struct _ccs_configuration_space_s *ccs_configuration_space_t; /** * An opaque type defining a CCS binding. */ -typedef struct _ccs_binding_s *ccs_binding_t; +typedef struct _ccs_binding_s *ccs_binding_t; +/** + * An opaque type defining a CCS search space configuration + */ +typedef struct _ccs_search_configuration_s *ccs_search_configuration_t; /** * An opaque type defining a CCS configuration. */ -typedef struct _ccs_configuration_s *ccs_configuration_t; +typedef struct _ccs_configuration_s *ccs_configuration_t; /** * An opaque type defining a CCS feature space. */ -typedef struct _ccs_feature_space_s *ccs_feature_space_t; +typedef struct _ccs_feature_space_s *ccs_feature_space_t; /** * An opaque type defining a CCS features. */ -typedef struct _ccs_features_s *ccs_features_t; +typedef struct _ccs_features_s *ccs_features_t; /** * An opaque type defining a CCS objective space. */ -typedef struct _ccs_objective_space_s *ccs_objective_space_t; -/** - * An opaque type defining a CCS evaluation binding. - */ -typedef struct _ccs_evaluation_binding_s *ccs_evaluation_binding_t; +typedef struct _ccs_objective_space_s *ccs_objective_space_t; /** * An opaque type defining a CCS evaluation. */ -typedef struct _ccs_evaluation_s *ccs_evaluation_t; +typedef struct _ccs_evaluation_s *ccs_evaluation_t; /** * An opaque type defining a CCS features evaluation. */ -typedef struct _ccs_features_evaluation_s *ccs_features_evaluation_t; +typedef struct _ccs_features_evaluation_s *ccs_features_evaluation_t; /** * An opaque type defining a CCS tuner. */ -typedef struct _ccs_tuner_s *ccs_tuner_t; +typedef struct _ccs_tuner_s *ccs_tuner_t; /** * An opaque type defining a CCS features tuner. */ -typedef struct _ccs_features_tuner_s *ccs_features_tuner_t; +typedef struct _ccs_features_tuner_s *ccs_features_tuner_t; /** * An opaque type defining a CCS key-value store. */ -typedef struct _ccs_map_s *ccs_map_t; +typedef struct _ccs_map_s *ccs_map_t; /** * An opaque type defining a CCS error stack. */ -typedef struct _ccs_error_stack_s *ccs_error_stack_t; +typedef struct _ccs_error_stack_s *ccs_error_stack_t; /** * An opaque type defining a CCS tree. */ -typedef struct _ccs_tree_s *ccs_tree_t; +typedef struct _ccs_tree_s *ccs_tree_t; /** * An opaque type defining a CCS tree space. */ -typedef struct _ccs_tree_space_s *ccs_tree_space_t; +typedef struct _ccs_tree_space_s *ccs_tree_space_t; /** * An opaque type defining a CCS tree space configuration. */ -typedef struct _ccs_tree_configuration_s *ccs_tree_configuration_t; -/** - * An opaque type defining a CCS tree evaluation. - */ -typedef struct _ccs_tree_evaluation_s *ccs_tree_evaluation_t; -/** - * An opaque type defining a CCS tree tuner. - */ -typedef struct _ccs_tree_tuner_s *ccs_tree_tuner_t; +typedef struct _ccs_tree_configuration_s *ccs_tree_configuration_t; /** * The different possible return codes of a CCS function. @@ -252,11 +244,9 @@ enum ccs_result_e { /** The provided tree space is invalid */ CCS_RESULT_ERROR_INVALID_TREE_SPACE = -29, /** The provided tree tuner is invalid */ - CCS_RESULT_ERROR_INVALID_TREE_TUNER = -30, - /** The provided distribution space is invalid */ - CCS_RESULT_ERROR_INVALID_DISTRIBUTION_SPACE = -31, + CCS_RESULT_ERROR_INVALID_DISTRIBUTION_SPACE = -30, /** Guard */ - CCS_RESULT_MIN = -32, + CCS_RESULT_MIN = -31, /** Try forcing 32 bits value for bindings */ CCS_RESULT_FORCE_32BIT = INT32_MAX }; @@ -311,8 +301,6 @@ enum ccs_object_type_e { CCS_OBJECT_TYPE_TREE_SPACE, /** A configuration on a tree space */ CCS_OBJECT_TYPE_TREE_CONFIGURATION, - /** An evaluation of a tree configuration */ - CCS_OBJECT_TYPE_TREE_EVALUATION, /** A tree tuner */ CCS_OBJECT_TYPE_TREE_TUNER, /** A distribution space */ diff --git a/include/cconfigspace/evaluation.h b/include/cconfigspace/evaluation.h index b6f7712d..81d4c470 100644 --- a/include/cconfigspace/evaluation.h +++ b/include/cconfigspace/evaluation.h @@ -6,11 +6,37 @@ extern "C" { #endif /** - * @file evaluation.h An evaluation is an evaluation binding - * (see evaluation_binding.h) given a specific configuration - * (see configuration.h). + * @file evaluation.h + * An evaluation is a binding (see binding.h) over an objective space + * (see objective_space.h) given a specific search configuration. + * Successful evaluations over the same objective space are weakly + * ordered by their objective values. Evaluation that have failed must + * report a result code different than CCS_RESULT_SUCCESS. */ +/** + * The different possible return codes when comparing two evaluations. + */ +enum ccs_comparison_e { + /** The first configuration is better then the second */ + CCS_COMPARISON_BETTER = -1, + /** The two configurations are equivalent */ + CCS_COMPARISON_EQUIVALENT = 0, + /** The first configuration is worse than the second */ + CCS_COMPARISON_WORSE = 1, + /** The two configurations cannot be compared */ + CCS_COMPARISON_NOT_COMPARABLE = 2, + /** Guard */ + CCS_COMPARISON_MAX, + /** Try forcing 32 bits value for bindings */ + CCS_COMPARISON_FORCE_32BIT = INT32_MAX +}; + +/** + * A commodity type to represent CCS the result of comparing evaluations. + */ +typedef enum ccs_comparison_e ccs_comparison_t; + /** * Create a new instance of an evaluation on a given objective_space for a given * configuration. @@ -24,8 +50,11 @@ extern "C" { * @param[out] evaluation_ret a pointer to the variable that will hold the * newly created evaluation * @return #CCS_RESULT_SUCCESS on success - * @return #CCS_RESULT_ERROR_INVALID_OBJECT if \p objective_space is not a valid - * CCS objective space; or if \p configuration is not a valid CCS configuration + * @return #CCS_RESULT_ERROR_INVALID_OBJECT if \p objective_space is not + * a valid CCS objective space; or if \p configuration is not a valid CCS + * search configuration + * @return #CCS_RESULT_ERROR_INVALID_CONFIGURATION if \p configuration search + * space is not the same as \p objective_space search space * @return #CCS_RESULT_ERROR_INVALID_VALUE if \p evaluation_ret is NULL; or if * \p values is NULL and \p num_values is greater than 0; or if the number of * values provided is not equal to the number of parameters in the objective @@ -37,12 +66,145 @@ extern "C" { */ extern ccs_result_t ccs_create_evaluation( - ccs_objective_space_t objective_space, - ccs_configuration_t configuration, - ccs_evaluation_result_t result, - size_t num_values, - ccs_datum_t *values, - ccs_evaluation_t *evaluation_ret); + ccs_objective_space_t objective_space, + ccs_search_configuration_t configuration, + ccs_evaluation_result_t result, + size_t num_values, + ccs_datum_t *values, + ccs_evaluation_t *evaluation_ret); + +/** + * Get the objective space associated with an evaluation. + * @param[in] evaluation + * @param[out] objective_space_ret a pointer to the variable that will + * contain the objective space + * @return #CCS_RESULT_SUCCESS on success + * @return #CCS_RESULT_ERROR_INVALID_OBJECT if \p evaluation is not a + * valid CCS evaluation + * @return #CCS_RESULT_ERROR_INVALID_VALUE if \p objective_space_ret is NULL + * @remarks + * This function is thread-safe + */ +extern ccs_result_t +ccs_evaluation_get_objective_space( + ccs_evaluation_t evaluation, + ccs_objective_space_t *objective_space_ret); + +/** + * Get the result code associated with an evaluation. + * @param[in] evaluation + * @param[out] result_ret a pointer to the variable that will contain the + * returned result code + * @return #CCS_RESULT_SUCCESS on success + * @return #CCS_RESULT_ERROR_INVALID_OBJECT if \p evaluation is not a valid CCS + * evaluation + * @return #CCS_RESULT_ERROR_INVALID_VALUE if \p result_ret is NULL + * @remarks + * This function is thread-safe + */ +extern ccs_result_t +ccs_evaluation_get_result( + ccs_evaluation_t evaluation, + ccs_evaluation_result_t *result_ret); + +/** + * Get the value of an objective for a valid evaluation in the context of its + * objective space. + * @param[in] evaluation + * @param[in] index the index of the objective in the objective space + * @param[out] value_ret a pointer to the variable that will contain the value + * of the objective + * @return #CCS_RESULT_SUCCESS on success + * @return #CCS_RESULT_ERROR_INVALID_OBJECT if \p evaluation is not a valid CCS + * evaluation + * @return #CCS_RESULT_ERROR_INVALID_VALUE if \p value_ret is NULL; or if there + * was an issue evaluating the objective + * @return #CCS_RESULT_ERROR_OUT_OF_BOUNDS if \p index is greater than the + * number of objective in the objective space + * @remarks + * This function is thread-safe + */ +extern ccs_result_t +ccs_evaluation_get_objective_value( + ccs_evaluation_t evaluation, + size_t index, + ccs_datum_t *value_ret); + +/** + * Get the values of the objectives for a valid evaluation in the context of its + * objective space. + * @param[in] evaluation + * @param[in] num_values the number of values that \p values can contain + * @param[out] values an optional array of values that will contain the returned + * objective values. If values is bigger than the number of + * objectives, extra values will be set to + * #CCS_DATA_TYPE_NONE + * @param[out] num_values_ret an optional pointer to a variable that will + * contain the number of values that are or would be + * returned. Can be NULL + * @return #CCS_RESULT_SUCCESS on success + * @return #CCS_RESULT_ERROR_INVALID_OBJECT if \p evaluation is not a valid CCS + * evaluation + * @return #CCS_RESULT_ERROR_INVALID_VALUE if \p values is NULL and \p + * num_values is greater than 0; or if values is NULL and num_values_ret is + * NULL; or if there was an issue evaluating any of the objectives + * @remarks + * This function is thread-safe + */ +extern ccs_result_t +ccs_evaluation_get_objective_values( + ccs_evaluation_t evaluation, + size_t num_values, + ccs_datum_t *values, + size_t *num_values_ret); + +/** + * Check that an evaluation values are valid in the objective space. + * @param[in] evaluation + * @param[out] is_valid_ret a pointer to a variable that will hold the result + * of the check. Result will be #CCS_TRUE if the + * evaluation is valid. Result will be #CCS_FALSE if + * an parameter value is not a valid value + * for this parameter + * @return #CCS_RESULT_SUCCESS on success + * @return #CCS_RESULT_ERROR_INVALID_OBJECT if \p evaluation is not a valid CCS + * evaluation + * @return #CCS_RESULT_ERROR_INVALID_EVALUATION if \p evaluation was found to be + * invalid in the context of the objective space + * @remarks + * This function is thread-safe + */ +extern ccs_result_t +ccs_evaluation_check(ccs_evaluation_t evaluation, ccs_bool_t *is_valid_ret); + +/** + * Compare two successful evaluations objectives. + * @param[in] evaluation the first evaluation + * @param[in] other_evaluation the second evaluation + * @param[out] result_ret a pointer to the variable that will contain the result + * of the comparison. Will contain + * #CCS_COMPARISON_BETTER, #CCS_COMPARISON_EQUIVALENT, + * #CCS_COMPARISON_WORSE, or + * #CCS_COMPARISON_NOT_COMPARABLE if the first + * evaluation is found to be respectively better, + * equivalent, worse, or not comparable with the second + * evaluation. + * @return #CCS_RESULT_SUCCESS on success + * @return #CCS_RESULT_ERROR_INVALID_OBJECT if \p evaluation or \p + * other_evaluation are not valid CCS evaluations; or if \p evaluation and \p + * other_evaluation do not share the same objective space; or if any of the + * the evaluation is associated a result code different than #CCS_RESULT_SUCESS; + * or if both evaluations are not ot the same type + * @return #CCS_RESULT_ERROR_INVALID_VALUE if \p result_ret is NULL; or if there + * was an issue evaluating any of the objectives + * @remarks + * This function is thread-safe + */ +extern ccs_result_t +ccs_evaluation_compare( + ccs_evaluation_t evaluation, + ccs_evaluation_t other_evaluation, + ccs_comparison_t *result_ret); /** * Get the configuration associated with an evaluation. @@ -58,8 +220,8 @@ ccs_create_evaluation( */ extern ccs_result_t ccs_evaluation_get_configuration( - ccs_evaluation_t evaluation, - ccs_configuration_t *configuration_ret); + ccs_evaluation_t evaluation, + ccs_search_configuration_t *configuration_ret); #ifdef __cplusplus } diff --git a/include/cconfigspace/evaluation_binding.h b/include/cconfigspace/evaluation_binding.h deleted file mode 100644 index a2fe8e4a..00000000 --- a/include/cconfigspace/evaluation_binding.h +++ /dev/null @@ -1,178 +0,0 @@ -#ifndef _CCS_EVALUATION_BINDING_H -#define _CCS_EVALUATION_BINDING_H - -#ifdef __cplusplus -extern "C" { -#endif - -/** - * @file evaluation_binding.h An evaluation binding is a binding (see - * binding.h) over an objective space (see objective_space.h). Successful - * evaluations over the same objective space are weakly ordered by their - * objective values. Evaluation that have failed must report a result code - * different than CCS_RESULT_SUCCESS. - */ - -/** - * The different possible return codes when comparing two evaluations. - */ -enum ccs_comparison_e { - /** The first configuration is better then the second */ - CCS_COMPARISON_BETTER = -1, - /** The two configurations are equivalent */ - CCS_COMPARISON_EQUIVALENT = 0, - /** The first configuration is worse than the second */ - CCS_COMPARISON_WORSE = 1, - /** The two configurations cannot be compared */ - CCS_COMPARISON_NOT_COMPARABLE = 2, - /** Guard */ - CCS_COMPARISON_MAX, - /** Try forcing 32 bits value for bindings */ - CCS_COMPARISON_FORCE_32BIT = INT32_MAX -}; - -/** - * A commodity type to represent CCS the result of comparing evaluations. - */ -typedef enum ccs_comparison_e ccs_comparison_t; - -/** - * Get the objective space associated with an evaluation binding. - * @param[in] evaluation_binding - * @param[out] objective_space_ret a pointer to the variable that will - * contain the objective space - * @return #CCS_RESULT_SUCCESS on success - * @return #CCS_RESULT_ERROR_INVALID_OBJECT if \p evaluation_binding is not a - * valid CCS evaluation binding - * @return #CCS_RESULT_ERROR_INVALID_VALUE if \p objective_space_ret is NULL - * @remarks - * This function is thread-safe - */ -extern ccs_result_t -ccs_evaluation_binding_get_objective_space( - ccs_evaluation_binding_t evaluation, - ccs_objective_space_t *objective_space_ret); - -/** - * Get the result code associated with an evaluation. - * @param[in] evaluation - * @param[out] result_ret a pointer to the variable that will contain the - * returned result code - * @return #CCS_RESULT_SUCCESS on success - * @return #CCS_RESULT_ERROR_INVALID_OBJECT if \p evaluation is not a valid CCS - * evaluation - * @return #CCS_RESULT_ERROR_INVALID_VALUE if \p result_ret is NULL - * @remarks - * This function is thread-safe - */ -extern ccs_result_t -ccs_evaluation_binding_get_result( - ccs_evaluation_binding_t evaluation, - ccs_evaluation_result_t *result_ret); - -/** - * Get the value of an objective for a valid evaluation in the context of its - * objective space. - * @param[in] evaluation - * @param[in] index the index of the objective in the objective space - * @param[out] value_ret a pointer to the variable that will contain the value - * of the objective - * @return #CCS_RESULT_SUCCESS on success - * @return #CCS_RESULT_ERROR_INVALID_OBJECT if \p evaluation is not a valid CCS - * evaluation - * @return #CCS_RESULT_ERROR_INVALID_VALUE if \p value_ret is NULL; or if there - * was an issue evaluating the objective - * @return #CCS_RESULT_ERROR_OUT_OF_BOUNDS if \p index is greater than the - * number of objective in the objective space - * @remarks - * This function is thread-safe - */ -extern ccs_result_t -ccs_evaluation_binding_get_objective_value( - ccs_evaluation_binding_t evaluation, - size_t index, - ccs_datum_t *value_ret); - -/** - * Get the values of the objectives for a valid evaluation in the context of its - * objective space. - * @param[in] evaluation - * @param[in] num_values the number of values that \p values can contain - * @param[out] values an optional array of values that will contain the returned - * objective values. If values is bigger than the number of - * objectives, extra values will be set to - * #CCS_DATA_TYPE_NONE - * @param[out] num_values_ret an optional pointer to a variable that will - * contain the number of values that are or would be - * returned. Can be NULL - * @return #CCS_RESULT_SUCCESS on success - * @return #CCS_RESULT_ERROR_INVALID_OBJECT if \p evaluation is not a valid CCS - * evaluation binding - * @return #CCS_RESULT_ERROR_INVALID_VALUE if \p values is NULL and \p - * num_values is greater than 0; or if values is NULL and num_values_ret is - * NULL; or if there was an issue evaluating any of the objectives - * @remarks - * This function is thread-safe - */ -extern ccs_result_t -ccs_evaluation_binding_get_objective_values( - ccs_evaluation_binding_t evaluation, - size_t num_values, - ccs_datum_t *values, - size_t *num_values_ret); - -/** - * Check that an evaluation values are valid in the objective space. - * @param[in] evaluation - * @param[out] is_valid_ret a pointer to a variable that will hold the result - * of the check. Result will be #CCS_TRUE if the - * evaluation is valid. Result will be #CCS_FALSE if - * an parameter value is not a valid value - * for this parameter - * @return #CCS_RESULT_SUCCESS on success - * @return #CCS_RESULT_ERROR_INVALID_OBJECT if \p evaluation is not a valid CCS - * evaluation - * @return #CCS_RESULT_ERROR_INVALID_EVALUATION if \p evaluation was found to be - * invalid in the context of the objective space - * @remarks - * This function is thread-safe - */ -extern ccs_result_t -ccs_evaluation_binding_check( - ccs_evaluation_binding_t evaluation, - ccs_bool_t *is_valid_ret); - -/** - * Compare two successful evaluations objectives. - * @param[in] evaluation the first evaluation - * @param[in] other_evaluation the second evaluation - * @param[out] result_ret a pointer to the variable that will contain the result - * of the comparison. Will contain - * #CCS_COMPARISON_BETTER, #CCS_COMPARISON_EQUIVALENT, - * #CCS_COMPARISON_WORSE, or - * #CCS_COMPARISON_NOT_COMPARABLE if the first - * evaluation is found to be respectively better, - * equivalent, worse, or not comparable with the second - * evaluation. - * @return #CCS_RESULT_SUCCESS on success - * @return #CCS_RESULT_ERROR_INVALID_OBJECT if \p evaluation or \p - * other_evaluation are not valid CCS evaluations; or if \p evaluation and \p - * other_evaluation do not share the same objective space; or if any of the - * the evaluation is associated a result code different than #CCS_RESULT_SUCESS; - * or if both evaluations are not ot the same type - * @return #CCS_RESULT_ERROR_INVALID_VALUE if \p result_ret is NULL; or if there - * was an issue evaluating any of the objectives - * @remarks - * This function is thread-safe - */ -extern ccs_result_t -ccs_evaluation_binding_compare( - ccs_evaluation_binding_t evaluation, - ccs_evaluation_binding_t other_evaluation, - ccs_comparison_t *result_ret); - -#ifdef __cplusplus -} -#endif - -#endif //_CCS_EVALUATION_BINDING_H diff --git a/include/cconfigspace/features_evaluation.h b/include/cconfigspace/features_evaluation.h index 07b96810..11cfa5dc 100644 --- a/include/cconfigspace/features_evaluation.h +++ b/include/cconfigspace/features_evaluation.h @@ -7,8 +7,8 @@ extern "C" { /** * @file features_evaluation.h - * A features evaluation is an evaluation binding (see evaluation_binding.h) - * configuration (see configuration.h) and features (see features.h). + * A features evaluation is an evaluation (see evaluation.h) + * on a given set of features (see features.h). */ /** @@ -25,9 +25,11 @@ extern "C" { * @param[out] features_evaluation_ret a pointer to the variable that will hold * the newly created evaluation * @return #CCS_RESULT_SUCCESS on success - * @return #CCS_RESULT_ERROR_INVALID_OBJECT if \p objective_space is not a valid - * CCS objective space; or if \p configuration is not a valid CCS configuration; - * or the features is not a valid CCS features + * @return #CCS_RESULT_ERROR_INVALID_OBJECT if \p objective_space is not + * a valid CCS objective space; or if \p configuration is not a valid CCS + * search configuration; or the features is not a valid CCS features + * @return #CCS_RESULT_ERROR_INVALID_CONFIGURATION if \p configuration search + * space is not the same as \p objective_space search space * @return #CCS_RESULT_ERROR_INVALID_VALUE if \p features evaluation_ret is * NULL; or if \p values is NULL and \p num_values is greater than 0; or if the * number of values provided is not equal to the number of parameters in the @@ -40,30 +42,13 @@ extern "C" { extern ccs_result_t ccs_create_features_evaluation( ccs_objective_space_t objective_space, - ccs_configuration_t configuration, + ccs_search_configuration_t configuration, ccs_features_t features, ccs_evaluation_result_t result, size_t num_values, ccs_datum_t *values, ccs_features_evaluation_t *features_evaluation_ret); -/** - * Get the configuration associated with a features evaluation. - * @param[in] features_evaluation - * @param[out] configuration_ret a pointer to the variable that will contain - * the configuration - * @return #CCS_RESULT_SUCCESS on success - * @return #CCS_RESULT_ERROR_INVALID_OBJECT if \p features_evaluation is not a - * valid CCS features_evaluation - * @return #CCS_RESULT_ERROR_INVALID_VALUE if \p configuration_ret is NULL - * @remarks - * This function is thread-safe - */ -extern ccs_result_t -ccs_features_evaluation_get_configuration( - ccs_features_evaluation_t features_evaluation, - ccs_configuration_t *configuration_ret); - /** * Get the features associated with a features evaluation. * @param[in] features_evaluation diff --git a/include/cconfigspace/features_tuner.h b/include/cconfigspace/features_tuner.h index 6909eb50..81d0c510 100644 --- a/include/cconfigspace/features_tuner.h +++ b/include/cconfigspace/features_tuner.h @@ -8,10 +8,10 @@ extern "C" { /** * @file features_tuner.h * A CCS features tuner defines an ask and tell interface to optimize an - * objective space (see objective_space.h) given a configuration spaces (see - * configuration_space.h) and a feature space (see feature_space.h). The tuner - * will propose configurations (see configuration.h) and the user will return - * features evaluations (see features_evaluation.h). + * objective space (see objective_space.h) given a feature space (see + * feature_space.h). The tuner will propose configurations (see + * configuration.h) and the user will return features evaluations (see + * features_evaluation.h). */ /** @@ -68,21 +68,21 @@ ccs_features_tuner_get_name( const char **name_ret); /** - * Get the associated configuration space. + * Get the associated search space. * @param[in] features_tuner - * @param[out] configuration_space_ret a pointer to the variable that will - * contain the configuration space + * @param[out] search_space_ret a pointer to the variable that will + * contain the search space * @return #CCS_RESULT_SUCCESS on success * @return #CCS_RESULT_ERROR_INVALID_OBJECT if \p features_tuner is not a valid * CCS features tuner - * @return #CCS_RESULT_ERROR_INVALID_VALUE if \p configuration_space_ret is NULL + * @return #CCS_RESULT_ERROR_INVALID_VALUE if \p search_space_ret is NULL * @remarks * This function is thread-safe */ extern ccs_result_t -ccs_features_tuner_get_configuration_space( - ccs_features_tuner_t features_tuner, - ccs_configuration_space_t *configuration_space_ret); +ccs_features_tuner_get_search_space( + ccs_features_tuner_t features_tuner, + ccs_search_space_t *search_space_ret); /** * Get the associated objective space. @@ -154,11 +154,11 @@ ccs_features_tuner_get_feature_space( */ extern ccs_result_t ccs_features_tuner_ask( - ccs_features_tuner_t features_tuner, - ccs_features_t features, - size_t num_configurations, - ccs_configuration_t *configurations, - size_t *num_configurations_ret); + ccs_features_tuner_t features_tuner, + ccs_features_t features, + size_t num_configurations, + ccs_search_configuration_t *configurations, + size_t *num_configurations_ret); /** * Give a list of results to a features tuner through evaluations. @@ -206,9 +206,9 @@ ccs_features_tuner_tell( */ extern ccs_result_t ccs_features_tuner_suggest( - ccs_features_tuner_t features_tuner, - ccs_features_t features, - ccs_configuration_t *configuration); + ccs_features_tuner_t features_tuner, + ccs_features_t features, + ccs_search_configuration_t *configuration); /** * Ask a features tuner for the discovered Pareto front. For single objective @@ -286,8 +286,7 @@ ccs_features_tuner_get_history( * the newly created features tuner * @return #CCS_RESULT_SUCCESS on success * @return #CCS_RESULT_ERROR_INVALID_OBJECT if \p objective_space is not - * a valid CCS objective space; or if \p objective_space search space is - * not a valid CCS configuration space; or if \p feature_space is not a + * a valid CCS objective space; or if \p feature_space is not a * valid CCS feature space * @return #CCS_RESULT_ERROR_INVALID_VALUE if \p name is NULL; or if \p features * tuner_ret is NULL @@ -316,11 +315,11 @@ struct ccs_user_defined_features_tuner_vector_s { /** The features tuner ask interface see ccs_features_tuner_ask */ ccs_result_t (*ask)( - ccs_features_tuner_t features_tuner, - ccs_features_t features, - size_t num_configurations, - ccs_configuration_t *configurations, - size_t *num_configurations_ret); + ccs_features_tuner_t features_tuner, + ccs_features_t features, + size_t num_configurations, + ccs_search_configuration_t *configurations, + size_t *num_configurations_ret); /** The features tuner tell interface see ccs_features_tuner_tell */ ccs_result_t (*tell)( @@ -354,9 +353,9 @@ struct ccs_user_defined_features_tuner_vector_s { * The features tuner suggest interface see ccs_features_tuner_suggest, * can be NULL */ ccs_result_t (*suggest)( - ccs_features_tuner_t features_tuner, - ccs_features_t features, - ccs_configuration_t *configuration); + ccs_features_tuner_t features_tuner, + ccs_features_t features, + ccs_search_configuration_t *configuration); /** * The tuner serialization interface, can be NULL, in which case @@ -401,8 +400,7 @@ typedef struct ccs_user_defined_features_tuner_vector_s * the newly created features tuner * @return #CCS_RESULT_SUCCESS on success * @return #CCS_RESULT_ERROR_INVALID_OBJECT if \p objective_space is not - * a valid CCS objective space; or if \p objective_space search space is - * not a valid CCS configuration space; or if \p feature_space is not a + * a valid CCS objective space; or if \p feature_space is not a * valid CCS feature space * @return #CCS_RESULT_ERROR_INVALID_VALUE if \p name is NULL; or if \p * features_tuner_ret is NULL; or if \p vector is NULL; or if any interface diff --git a/include/cconfigspace/objective_space.h b/include/cconfigspace/objective_space.h index 90e5a283..65a8db29 100644 --- a/include/cconfigspace/objective_space.h +++ b/include/cconfigspace/objective_space.h @@ -160,18 +160,18 @@ ccs_objective_space_get_objectives( * @return #CCS_RESULT_SUCCESS on success * @return #CCS_RESULT_ERROR_INVALID_OBJECT if \p objective_space is not a * valid CCS objective space; or if \p evaluation is not a valid CCS - * evaluation binding + * evaluation * @return #CCS_RESULT_ERROR_INVALID_VALUE if \p is_valid_ret is NULL - * @return #CCS_RESULT_ERROR_INVALID_EVALUATION_BINDING if \p evaluation + * @return #CCS_RESULT_ERROR_INVALID_EVALUATION if \p evaluation * is not associated to the objective space * @remarks * This function is thread-safe */ extern ccs_result_t ccs_objective_space_check_evaluation( - ccs_objective_space_t objective_space, - ccs_evaluation_binding_t evaluation, - ccs_bool_t *is_valid_ret); + ccs_objective_space_t objective_space, + ccs_evaluation_t evaluation, + ccs_bool_t *is_valid_ret); #ifdef __cplusplus } diff --git a/include/cconfigspace/tree_evaluation.h b/include/cconfigspace/tree_evaluation.h deleted file mode 100644 index cc865005..00000000 --- a/include/cconfigspace/tree_evaluation.h +++ /dev/null @@ -1,69 +0,0 @@ -#ifndef _CCS_TREE_EVALUATION_H -#define _CCS_TREE_EVALUATION_H - -#ifdef __cplusplus -extern "C" { -#endif - -/** - * @file tree_evaluation.h A tree evaluation is an evaluation binding - * (see evaluation_binding.h) given a specific tree configuration - * (see tree_configuration.h). - */ - -/** - * Create a new instance of a tree evaluation on a given objective space for a - * given tree configuration. - * @param[in] objective_space the objective space to associate with the - * evaluation - * @param[in] configuration the configuration to associate with the evaluation - * @param[in] result the result code associated with the evaluation - * @param[in] num_values the number of provided values to initialize the - * evaluation - * @param[in] values an optional array of values to initialize the evaluation - * @param[out] evaluation_ret a pointer to the variable that will hold the - * newly created evaluation - * @return #CCS_RESULT_SUCCESS on success - * @return #CCS_RESULT_ERROR_INVALID_OBJECT if \p objective_space is not a valid - * CCS objective space; or if \p configuration is not a valid CCS tree - * configuration - * @return #CCS_RESULT_ERROR_INVALID_VALUE if \p evaluation_ret is NULL; or if - * \p values is NULL and \p num_values is greater than 0; or if the number of - * values provided is not equal to the number of parameters in the objective - * space - * @return #CCS_RESULT_ERROR_OUT_OF_MEMORY if there was a lack of memory to - * allocate the new evaluation - * @remarks - * This function is thread-safe - */ -extern ccs_result_t -ccs_create_tree_evaluation( - ccs_objective_space_t objective_space, - ccs_tree_configuration_t configuration, - ccs_evaluation_result_t result, - size_t num_values, - ccs_datum_t *values, - ccs_tree_evaluation_t *evaluation_ret); - -/** - * Get the configuration associated with a tree evaluation. - * @param[in] evaluation - * @param[out] configuration_ret a pointer to the variable that will contain - * the configuration - * @return #CCS_RESULT_SUCCESS on success - * @return #CCS_RESULT_ERROR_INVALID_OBJECT if \p evaluation is not a valid CCS - * tree evaluation - * @return #CCS_RESULT_ERROR_INVALID_VALUE if \p configuration_ret is NULL - * @remarks - * This function is thread-safe - */ -extern ccs_result_t -ccs_tree_evaluation_get_configuration( - ccs_tree_evaluation_t evaluation, - ccs_tree_configuration_t *configuration_ret); - -#ifdef __cplusplus -} -#endif - -#endif //_CCS_EVALUATION_H diff --git a/include/cconfigspace/tree_space.h b/include/cconfigspace/tree_space.h index 1a0ce9f2..88519ae0 100644 --- a/include/cconfigspace/tree_space.h +++ b/include/cconfigspace/tree_space.h @@ -40,11 +40,14 @@ typedef enum ccs_tree_space_type_e ccs_tree_space_type_t; * Create a new static tree space. * @param[in] name pointer to a string that will be copied internally * @param[in] tree the tree defining the tree space + * @param[in] rng an optional CCS rng object * @param[out] tree_space_ret a pointer to the variable that will hold * the newly created tree space. * @return #CCS_RESULT_SUCCESS on success * @return #CCS_RESULT_ERROR_INVALID_VALUE if \p name is NULL; or if \p * tree_space_ret is NULL + * @return #CCS_RESULT_ERROR_INVALID_OBJECT if \p rng is not NULL and is not a + * valid CCS rng * @return #CCS_RESULT_ERROR_OUT_OF_MEMORY if there was a lack of memory to * allocate the new tree space * @remarks @@ -54,6 +57,7 @@ extern ccs_result_t ccs_create_static_tree_space( const char *name, ccs_tree_t tree, + ccs_rng_t rng, ccs_tree_space_t *tree_space_ret); /** @@ -115,6 +119,7 @@ typedef struct ccs_dynamic_tree_space_vector_s ccs_dynamic_tree_space_vector_t; * Create a new static tree space. * @param[in] name pointer to a string that will be copied internally * @param[in] tree the tree defining the tree space + * @param[in] rng an optional CCS rng object * @param[in] vector the callback vector implementing the dynamic tree space * interface * @param[in] tree_space_data a pointer to the tree space internal data @@ -124,6 +129,8 @@ typedef struct ccs_dynamic_tree_space_vector_s ccs_dynamic_tree_space_vector_t; * @return #CCS_RESULT_SUCCESS on success * @return #CCS_RESULT_ERROR_INVALID_VALUE if \p name is NULL; or if \p * tree_space_ret is NULL; or if any non optional interface pointer is NULL + * @return #CCS_RESULT_ERROR_INVALID_OBJECT if \p rng is not NULL and is not a + * valid CCS rng * @return #CCS_RESULT_ERROR_OUT_OF_MEMORY if there was a lack of memory to * allocate the new tree space * @remarks @@ -133,6 +140,7 @@ extern ccs_result_t ccs_create_dynamic_tree_space( const char *name, ccs_tree_t tree, + ccs_rng_t rng, ccs_dynamic_tree_space_vector_t *vector, void *tree_space_data, ccs_tree_space_t *tree_space_ret); @@ -169,19 +177,6 @@ ccs_tree_space_get_type( extern ccs_result_t ccs_tree_space_get_name(ccs_tree_space_t tree_space, const char **name_ret); -/** - * Set (replace) the internal rng of the tree space. - * @param[in,out] tree_space - * @param[in] rng the rng to use in the tree space - * @return #CCS_RESULT_SUCCESS on success - * @return #CCS_RESULT_ERROR_INVALID_OBJECT if \p tree_space is not a valid CCS - * tree space; or \p rng is not a valid CCS rng - * @remarks - * This function is NOT thread-safe - */ -extern ccs_result_t -ccs_tree_space_set_rng(ccs_tree_space_t tree_space, ccs_rng_t rng); - /** * Get the internal rng of the tree space. * @param[in] tree_space @@ -319,11 +314,12 @@ ccs_tree_space_check_configuration( * sampled according to the weight and bias of the individual tree nodes. If * those are at their default values, the tree nodes are sampled uniformly. * @param[in] tree_space + * @param[in] rng an optional rng to use * @param[out] configuration_ret a pointer to the variable that will contain the * returned tree configuration * @return #CCS_RESULT_SUCCESS on success * @return #CCS_RESULT_ERROR_INVALID_OBJECT if \p tree space is not a valid CCS - * tree space + * tree space; or if \p rng is not a valid CCS rng * @return #CCS_RESULT_ERROR_INVALID_VALUE if configuration_ret is NULL * @return #CCS_RESULT_ERROR_OUT_OF_MEMORY if there was not enough memory to * allocate the new configuration @@ -333,6 +329,7 @@ ccs_tree_space_check_configuration( extern ccs_result_t ccs_tree_space_sample( ccs_tree_space_t tree_space, + ccs_rng_t rng, ccs_tree_configuration_t *configuration_ret); /** @@ -341,12 +338,13 @@ ccs_tree_space_sample( * nodes. If those are at their default values, the tree nodes are sampled * uniformely. * @param[in] tree_space + * @param[in] rng an optional rng to use * @param[in] num_configurations the number of requested configurations * @param[out] configurations an array of \p num_configurations that will * contain the requested configurations * @return #CCS_RESULT_SUCCESS on success * @return #CCS_RESULT_ERROR_INVALID_OBJECT if \p tree space is not a valid CCS - * tree space + * tree space; or if \p rng is not a valid CCS rng * @return #CCS_RESULT_ERROR_INVALID_VALUE if \p configurations is NULL and \p * num_configurations is greater than 0 * @return #CCS_RESULT_ERROR_OUT_OF_MEMORY if there was not enough memory to @@ -357,6 +355,7 @@ ccs_tree_space_sample( extern ccs_result_t ccs_tree_space_samples( ccs_tree_space_t tree_space, + ccs_rng_t rng, size_t num_configurations, ccs_tree_configuration_t *configurations); diff --git a/include/cconfigspace/tree_tuner.h b/include/cconfigspace/tree_tuner.h deleted file mode 100644 index 1649b854..00000000 --- a/include/cconfigspace/tree_tuner.h +++ /dev/null @@ -1,386 +0,0 @@ -#ifndef _CCS_TREE_TUNER_H -#define _CCS_TREE_TUNER_H - -#ifdef __cplusplus -extern "C" { -#endif - -/** - * @file tree_tuner.h A CCS tree tuner defines an ask and tell interface to - * optimize an objective space (see objective_space.h) given a tree space (see - * tree_space.h). The tuner will propose tree configurations (see - * tree_configuration.h) and the user will return tree evaluations (see - * tree_evaluation.h). - */ - -/** - * CCS supported tuner types. - */ -enum ccs_tree_tuner_type_e { - /** A random tuner */ - CCS_TREE_TUNER_TYPE_RANDOM, - /** A user defined tuner */ - CCS_TREE_TUNER_TYPE_USER_DEFINED, - /** Guard */ - CCS_TREE_TUNER_TYPE_MAX, - /** Try forcing 32 bits value for bindings */ - CCS_TREE_TUNER_TYPE_32BIT = INT_MAX -}; - -/** - * A commodity type to represent CCS tree tuner types. - */ -typedef enum ccs_tree_tuner_type_e ccs_tree_tuner_type_t; - -/** - * Get the type of a tree tuner. - * @param [in] tuner - * @param [out] type_ret a pointer to the variable that will contain the - * returned tree tuner type - * @return #CCS_RESULT_SUCCESS on success - * @return #CCS_RESULT_ERROR_INVALID_OBJECT if \p tuner is not a valid CCS tree - * tuner - * @return #CCS_RESULT_ERROR_INVALID_VALUE if \p type_ret is NULL - * @remarks - * This function is thread-safe - */ -extern ccs_result_t -ccs_tree_tuner_get_type(ccs_tree_tuner_t tuner, ccs_tree_tuner_type_t *type_ret); - -/** - * Get the name of a tree tuner. - * @param[in] tuner - * @param[out] name_ret a pointer to the variable that will contain a pointer to - * the name of the tree tuner - * @return #CCS_RESULT_SUCCESS on success - * @return #CCS_RESULT_ERROR_INVALID_OBJECT if \p tuner is not a valid CCS tuner - * @return #CCS_RESULT_ERROR_INVALID_VALUE if \p name_ret is NULL - * @remarks - * This function is thread-safe - */ -extern ccs_result_t -ccs_tree_tuner_get_name(ccs_tree_tuner_t tuner, const char **name_ret); - -/** - * Get the associated tree space. - * @param[in] tuner - * @param[out] tree_space_ret a pointer to the variable that will contain - * the tree space - * @return #CCS_RESULT_SUCCESS on success - * @return #CCS_RESULT_ERROR_INVALID_OBJECT if \p tuner is not a valid CCS tree - * tuner - * @return #CCS_RESULT_ERROR_INVALID_VALUE if \p tree_space_ret is NULL - * @remarks - * This function is thread-safe - */ -extern ccs_result_t -ccs_tree_tuner_get_tree_space( - ccs_tree_tuner_t tuner, - ccs_tree_space_t *tree_space_ret); - -/** - * Get the associated objective space. - * @param[in] tuner - * @param[out] objective_space_ret a pointer to the variable that will - * contain the objective space - * @return #CCS_RESULT_SUCCESS on success - * @return #CCS_RESULT_ERROR_INVALID_OBJECT if \p tuner is not a valid CCS tree - * tuner - * @return #CCS_RESULT_ERROR_INVALID_VALUE if \p objective_space_ret is NULL - * @remarks - * This function is thread-safe - */ -extern ccs_result_t -ccs_tree_tuner_get_objective_space( - ccs_tree_tuner_t tuner, - ccs_objective_space_t *objective_space_ret); - -/** - * Ask a tree tuner for a set of configurations to evaluate. Configuration's - * ownership is transferred to the user who doesn't need to retain them, but - * will need to release them once the user is done using them. - * @param[in,out] tuner - * @param[in] num_configurations the number of configurations requested by the - * user - * @param[out] configurations an array of \p num_configurations configurations - * that will contain the returned configurations. Can - * be NULL - * @param[out] num_configurations_ret a pointer to the variable that will - * contain the number of configuration that - * are returned, or, if \p configurations is - * NULL, a suggestion for the number of - * configuration to ask for - * @return #CCS_RESULT_SUCCESS on success - * @return #CCS_RESULT_ERROR_INVALID_OBJECT if \p tuner is not a valid CCSi tree - * tuner - * @return #CCS_RESULT_ERROR_INVALID_VALUE if \p configurations is NULL and \p - * num_configurations is greater than 0; or if \p configurations and \p - * num_configurations_ret are both NULL - * @return #CCS_RESULT_ERROR_SAMPLING_UNSUCCESSFUL if no or not enough valid - * configurations could be sampled. Configurations that could be sampled will be - * returned contiguously, and the rest will be NULL - * @return #CCS_RESULT_ERROR_OUT_OF_MEMORY if there was not enough memory to - * allocate new configurations. Configurations that could be allocated will be - * returned, and the rest will be NULL - * @remarks - * This function is NOT thread-safe - */ -extern ccs_result_t -ccs_tree_tuner_ask( - ccs_tree_tuner_t tuner, - size_t num_configurations, - ccs_tree_configuration_t *configurations, - size_t *num_configurations_ret); - -/** - * Give a list of results to a tree tuner through tree evaluations. - * @param[in,out] tuner - * @param[in] num_evaluations the size of the \p evaluations array - * @param[in] evaluations an array of \p num_evaluations to provide to the - * tuner - * @return #CCS_RESULT_SUCCESS on success - * @return #CCS_RESULT_ERROR_INVALID_OBJECT if \p tuner is not a valid CCS tree - * tuner; or if one of the evaluations is not a valid CCS tree evaluation - * @return #CCS_RESULT_ERROR_INVALID_VALUE if \p evaluations is NULL and \p - * num_evaluations is greater than 0 - * @return #CCS_RESULT_ERROR_INVALID_EVALUATION if an evaluation is not a valid - * tree evaluation for the problem the tuner is optimizing - * @return #CCS_RESULT_ERROR_OUT_OF_MEMORY if there was not enough memory to - * allocate internal data structures - * @remarks - * This function is NOT thread-safe - */ -extern ccs_result_t -ccs_tree_tuner_tell( - ccs_tree_tuner_t tuner, - size_t num_evaluations, - ccs_tree_evaluation_t *evaluations); - -/** - * Ask a tree tuner to suggest a good configuration. - * @param[in,out] tuner - * @param[out] configuration a pointer to the variable that will contain the - * suggested configuration - * @return #CCS_RESULT_SUCCESS on success - * @return #CCS_RESULT_ERROR_INVALID_OBJECT if \p tuner is not a valid CCS tree - * tuner - * @return #CCS_RESULT_ERROR_INVALID_VALUE if \p configuration is NULL - * @return #CCS_RESULT_ERROR_UNSUPPORTED_OPERATION if the tuner does not support - * the suggest interface - * @return #CCS_RESULT_ERROR_OUT_OF_MEMORY if there was not enough memory to - * allocate new configurations - * @remarks - * This function is NOT thread-safe - */ -extern ccs_result_t -ccs_tree_tuner_suggest( - ccs_tree_tuner_t tuner, - ccs_tree_configuration_t *configuration); - -/** - * Ask a tree tuner for the discovered Pareto front. For single objective - * objective spaces this would be the best point found. - * @param[in] tuner - * @param[in] num_evaluations the size of the \p evaluations array - * @param[out] evaluations an array of \p num_evaluations that will contain the - * optimal evaluations - * @param[out] num_evaluations_ret a pointer to the variable that will contain - * the number of evaluations that are or would - * be returned - * @return #CCS_RESULT_SUCCESS on success - * @return #CCS_RESULT_ERROR_INVALID_OBJECT if \p tuner is not a valid CCS tree - * tuner - * @return #CCS_RESULT_ERROR_INVALID_VALUE if \p evaluations is NULL and - * num_evaluations is greater than 0; or if \p evaluations is NULL and \p - * num_evaluations_ret is NULL - * @remarks - * This function is thread-safe - */ -extern ccs_result_t -ccs_tree_tuner_get_optima( - ccs_tree_tuner_t tuner, - size_t num_evaluations, - ccs_tree_evaluation_t *evaluations, - size_t *num_evaluations_ret); - -/** - * Ask a tree tuner for the evaluation history. - * @param[in] tuner - * @param[in] num_evaluations the size of the \p evaluations array - * @param[out] evaluations an array of \p num_evaluations that will contain the - * the history - * @param[out] num_evaluations_ret a pointer to the variable that will contain - * the number of evaluations that are or would - * be returned - * @return #CCS_RESULT_SUCCESS on success - * @return #CCS_RESULT_ERROR_INVALID_OBJECT if \p tuner is not a valid CCS tree - * tuner - * @return #CCS_RESULT_ERROR_INVALID_VALUE if \p evaluations is NULL and - * num_evaluations is greater than 0; or if \p evaluations is NULL and \p - * num_evaluations_ret is NULL - * @remarks - * This function is thread-safe - */ -extern ccs_result_t -ccs_tree_tuner_get_history( - ccs_tree_tuner_t tuner, - size_t num_evaluations, - ccs_tree_evaluation_t *evaluations, - size_t *num_evaluations_ret); - -/** - * Create a new random tree tuner. The random tuner should be viewed as a - * baseline for evaluating tuners, and as a tool for developing interfaces. - * @param[in] name the name of the tree tuner - * @param[in] objective_space the objective space to potimize - * @param[out] tuner_ret a pointer to the variable that will contain the - * newly created tree tuner - * @return #CCS_RESULT_SUCCESS on success - * @return #CCS_RESULT_ERROR_INVALID_OBJECT if \p objective_space is not - * a valid CCS objective space; or if \p objective_space search space is - * not a valid CCS tree space - * @return #CCS_RESULT_ERROR_INVALID_VALUE if \p name is NULL; or if \p - * tuner_ret is NULL - * @return #CCS_RESULT_ERROR_OUT_OF_MEMORY if there was not enough memory to - * allocate the new tree tuner instance - * @remarks - * This function is thread-safe - */ -extern ccs_result_t -ccs_create_random_tree_tuner( - const char *name, - ccs_objective_space_t objective_space, - ccs_tree_tuner_t *tuner_ret); - -/** - * A structure that define the callbacks the user must provide to create a user - * defined tree tuner. - */ -struct ccs_user_defined_tree_tuner_vector_s { - /** - * The deletion callback that will be called once the reference count - * of the tuner reaches 0. - */ - ccs_result_t (*del)(ccs_tree_tuner_t tuner); - - /** The tree tuner ask interface see ccs_tree_tuner_ask */ - ccs_result_t (*ask)( - ccs_tree_tuner_t tuner, - size_t num_configurations, - ccs_tree_configuration_t *configurations, - size_t *num_configurations_ret); - - /** The tree tuner tell interface see ccs_tree_tuner_tell */ - ccs_result_t (*tell)( - ccs_tree_tuner_t tuner, - size_t num_evaluations, - ccs_tree_evaluation_t *evaluations); - - /** - * The tree tuner get_optima interface see - * ccs_tree_tuner_get_optima - */ - ccs_result_t (*get_optima)( - ccs_tree_tuner_t tuner, - size_t num_evaluations, - ccs_tree_evaluation_t *evaluations, - size_t *num_evaluations_ret); - - /** - * The tree tuner get_history interface see ccs_tree_tuner_get_history - */ - ccs_result_t (*get_history)( - ccs_tree_tuner_t tuner, - size_t num_evaluations, - ccs_tree_evaluation_t *evaluations, - size_t *num_evaluations_ret); - - /** The tree tuner suggest interface see ccs_tree_tuner_suggest, can be - * NULL - */ - ccs_result_t (*suggest)( - ccs_tree_tuner_t tuner, - ccs_tree_configuration_t *configuration); - - /** - * The tree tuner serialization interface, can be NULL, in which case - * common tuner data, history and optima will be serialized - */ - ccs_result_t (*serialize_user_state)( - ccs_tree_tuner_t tuner, - size_t sate_size, - void *state, - size_t *state_size_ret); - - /** - * The tree tuner deserialization interface, can be NULL, in which case, - * the history will be set through the tell interface - */ - ccs_result_t (*deserialize_state)( - ccs_tree_tuner_t tuner, - size_t size_history, - ccs_tree_evaluation_t *history, - size_t num_optima, - ccs_tree_evaluation_t *optima, - size_t state_size, - const void *state); -}; - -/** - * a commodity type to represent a user defined tuner callback vector. - */ -typedef struct ccs_user_defined_tree_tuner_vector_s - ccs_user_defined_tree_tuner_vector_t; - -/** - * Create a new user defined tree tuner. - * @param[in] name the name of the tuner - * @param[in] objective_space the objective space to optimize - * @param[in] vector the vector of callbacks implementing the tuner interface - * @param[in] tuner_data a pointer to the tuner internal data structures. Can be - * NULL - * @param[out] tuner_ret a pointer to the variable that will contain the newly - * created tuner - * @return #CCS_RESULT_SUCCESS on success - * @return #CCS_RESULT_ERROR_INVALID_OBJECT \p objective_space is not a - * valid CCS objective space; or if \p objective_space search space is - * not a valid CCS tree space - * @return #CCS_RESULT_ERROR_INVALID_VALUE if \p name is NULL; or if \p - * tuner_ret is NULL; or if \p vector is NULL; or if any interface pointer - * except suggest is NULL - * @return #CCS_RESULT_ERROR_OUT_OF_MEMORY if there was not enough memory to - * allocate the new tree tuner instance - * @remarks - * This function is thread-safe - */ -extern ccs_result_t -ccs_create_user_defined_tree_tuner( - const char *name, - ccs_objective_space_t objective_space, - ccs_user_defined_tree_tuner_vector_t *vector, - void *tuner_data, - ccs_tree_tuner_t *tuner_ret); - -/** - * Get the user defined tree tuner internal data pointer. - * @param[in] tuner - * @param[out] tuner_data_ret - * @return #CCS_RESULT_SUCCESS on success - * @return #CCS_RESULT_ERROR_INVALID_OBJECT if \p tuner is not a valid CCS tree - * tuner - * @return #CCS_RESULT_ERROR_INVALID_TUNER if \p tuner is not a user defined - * tree tuner - * @return #CCS_RESULT_ERROR_INVALID_VALUE if \p tuner_data_ret is NULL - * @remarks - * This function is thread-safe - */ -extern ccs_result_t -ccs_user_defined_tree_tuner_get_tuner_data( - ccs_tree_tuner_t tuner, - void **tuner_data_ret); - -#ifdef __cplusplus -} -#endif - -#endif //_CCS_TREE_TUNER_H diff --git a/include/cconfigspace/tuner.h b/include/cconfigspace/tuner.h index 49abc9a5..39d6dd7e 100644 --- a/include/cconfigspace/tuner.h +++ b/include/cconfigspace/tuner.h @@ -8,8 +8,7 @@ extern "C" { /** * @file tuner.h * A CCS tuner defines an ask and tell interface to optimize an objective space - * (see objective_space.h) given a configuration space (see - * configuration_space.h). The tuner will propose configurations (see + * (see objective_space.h). The tuner will propose configurations (see * configuration.h) and the user will return evaluations (see evaluation.h). */ @@ -61,20 +60,20 @@ extern ccs_result_t ccs_tuner_get_name(ccs_tuner_t tuner, const char **name_ret); /** - * Get the associated configuration space. + * Get the associated search space. * @param[in] tuner - * @param[out] configuration_space_ret a pointer to the variable that will - * contain the configuration space + * @param[out] search_space_ret a pointer to the variable that will + * contain the search space * @return #CCS_RESULT_SUCCESS on success * @return #CCS_RESULT_ERROR_INVALID_OBJECT if \p tuner is not a valid CCS tuner - * @return #CCS_RESULT_ERROR_INVALID_VALUE if \p configuration_space_ret is NULL + * @return #CCS_RESULT_ERROR_INVALID_VALUE if \p search_space_ret is NULL * @remarks * This function is thread-safe */ extern ccs_result_t -ccs_tuner_get_configuration_space( - ccs_tuner_t tuner, - ccs_configuration_space_t *configuration_space_ret); +ccs_tuner_get_search_space( + ccs_tuner_t tuner, + ccs_search_space_t *configuration_space_ret); /** * Get the associated objective space. @@ -123,10 +122,10 @@ ccs_tuner_get_objective_space( */ extern ccs_result_t ccs_tuner_ask( - ccs_tuner_t tuner, - size_t num_configurations, - ccs_configuration_t *configurations, - size_t *num_configurations_ret); + ccs_tuner_t tuner, + size_t num_configurations, + ccs_search_configuration_t *configurations, + size_t *num_configurations_ret); /** * Give a list of results to a tuner through evaluations. @@ -168,7 +167,7 @@ ccs_tuner_tell( * This function is thread-safe */ extern ccs_result_t -ccs_tuner_suggest(ccs_tuner_t tuner, ccs_configuration_t *configuration); +ccs_tuner_suggest(ccs_tuner_t tuner, ccs_search_configuration_t *configuration); /** * Ask a tuner for the discovered Pareto front. For single objective objective @@ -228,8 +227,7 @@ ccs_tuner_get_history( * created tuner * @return #CCS_RESULT_SUCCESS on success * @return #CCS_RESULT_ERROR_INVALID_OBJECT if \p objective_space is not - * a valid CCS objective space; or if \p objective_space search space is - * not a valid CCS configuration space + * a valid CCS objective space * @return #CCS_RESULT_ERROR_INVALID_VALUE if \p name is NULL; or if \p * tuner_ret is NULL * @return #CCS_RESULT_ERROR_OUT_OF_MEMORY if there was not enough memory to @@ -256,10 +254,10 @@ struct ccs_user_defined_tuner_vector_s { /** The tuner ask interface see ccs_tuner_ask */ ccs_result_t (*ask)( - ccs_tuner_t tuner, - size_t num_configurations, - ccs_configuration_t *configurations, - size_t *num_configurations_ret); + ccs_tuner_t tuner, + size_t num_configurations, + ccs_search_configuration_t *configurations, + size_t *num_configurations_ret); /** The tuner tell interface see ccs_tuner_tell */ ccs_result_t (*tell)( @@ -283,8 +281,8 @@ struct ccs_user_defined_tuner_vector_s { /** The tuner suggest interface see ccs_tuner_suggest, can be NULL */ ccs_result_t (*suggest)( - ccs_tuner_t tuner, - ccs_configuration_t *configuration); + ccs_tuner_t tuner, + ccs_search_configuration_t *configuration); /** * The tuner serialization interface, can be NULL, in which case @@ -326,8 +324,7 @@ typedef struct ccs_user_defined_tuner_vector_s ccs_user_defined_tuner_vector_t; * created tuner * @return #CCS_RESULT_SUCCESS on success * @return #CCS_RESULT_ERROR_INVALID_OBJECT if \p objective_space is not - * a valid CCS objective space; or if \p objective_space search space is - * not a valid CCS configuration space + * a valid CCS objective space * @return #CCS_RESULT_ERROR_INVALID_VALUE if \p name is NULL; or if \p * tuner_ret is NULL; or if \p vector is NULL; or if any non optional interface * pointer is NULL diff --git a/samples/test_python.c b/samples/test_python.c index a7b87f1b..b69cda82 100644 --- a/samples/test_python.c +++ b/samples/test_python.c @@ -65,9 +65,9 @@ test_tuner(ccs_tuner_t tuner, ccs_objective_space_t ospace) ccs_result_t err; for (size_t i = 0; i < 100; i++) { - ccs_datum_t values[2], res; - ccs_configuration_t configuration; - ccs_evaluation_t evaluation; + ccs_datum_t values[2], res; + ccs_search_configuration_t configuration; + ccs_evaluation_t evaluation; err = ccs_tuner_ask(tuner, 1, &configuration, NULL); assert(err == CCS_RESULT_SUCCESS); err = ccs_binding_get_values( @@ -96,8 +96,7 @@ test_tuner(ccs_tuner_t tuner, ccs_objective_space_t ospace) for (size_t i = 0; i < 100; i++) { ccs_datum_t res; - err = ccs_evaluation_binding_get_objective_value( - (ccs_evaluation_binding_t)history[i], 0, &res); + err = ccs_evaluation_get_objective_value(history[i], 0, &res); assert(err == CCS_RESULT_SUCCESS); if (res.value.f < min.value.f) min.value.f = res.value.f; @@ -107,8 +106,7 @@ test_tuner(ccs_tuner_t tuner, ccs_objective_space_t ospace) ccs_datum_t res; err = ccs_tuner_get_optima(tuner, 1, &evaluation, NULL); assert(err == CCS_RESULT_SUCCESS); - err = ccs_evaluation_binding_get_objective_value( - (ccs_evaluation_binding_t)evaluation, 0, &res); + err = ccs_evaluation_get_objective_value(evaluation, 0, &res); assert(res.value.f == min.value.f); } diff --git a/samples/test_python.py b/samples/test_python.py index 3992eb9a..8465b3b1 100644 --- a/samples/test_python.py +++ b/samples/test_python.py @@ -14,7 +14,7 @@ def ask(tuner, count): if count is None: return (None, 1) else: - cs = tuner.configuration_space + cs = tuner.search_space return (cs.samples(count), count) def tell(tuner, evaluations): @@ -73,7 +73,7 @@ def test_user_defined(self): self.assertEqual("tuner", t.name) self.assertEqual(ccs.TunerType.USER_DEFINED, t.type) self.assertEqual(os.handle.value, t.objective_space.handle.value) - self.assertEqual(os.search_space.handle.value, t.configuration_space.handle.value) + self.assertEqual(os.search_space.handle.value, t.search_space.handle.value) func = lambda x, y, z: [(x-2)*(x-2), sin(z+y)] evals = [ccs.Evaluation(objective_space = os, configuration = c, values = func(*(c.values))) for c in t.ask(100)] t.tell(evals) diff --git a/samples/test_ruby.c b/samples/test_ruby.c index ba865279..79bbd72a 100644 --- a/samples/test_ruby.c +++ b/samples/test_ruby.c @@ -74,9 +74,9 @@ test_tuner(ccs_tuner_t tuner, ccs_objective_space_t ospace) ccs_result_t err; for (size_t i = 0; i < 100; i++) { - ccs_datum_t values[2], res; - ccs_configuration_t configuration; - ccs_evaluation_t evaluation; + ccs_datum_t values[2], res; + ccs_search_configuration_t configuration; + ccs_evaluation_t evaluation; err = ccs_tuner_ask(tuner, 1, &configuration, NULL); assert(err == CCS_RESULT_SUCCESS); err = ccs_binding_get_values( @@ -105,8 +105,7 @@ test_tuner(ccs_tuner_t tuner, ccs_objective_space_t ospace) for (size_t i = 0; i < 100; i++) { ccs_datum_t res; - err = ccs_evaluation_binding_get_objective_value( - (ccs_evaluation_binding_t)history[i], 0, &res); + err = ccs_evaluation_get_objective_value(history[i], 0, &res); assert(err == CCS_RESULT_SUCCESS); if (res.value.f < min.value.f) min.value.f = res.value.f; @@ -116,8 +115,7 @@ test_tuner(ccs_tuner_t tuner, ccs_objective_space_t ospace) ccs_datum_t res; err = ccs_tuner_get_optima(tuner, 1, &evaluation, NULL); assert(err == CCS_RESULT_SUCCESS); - err = ccs_evaluation_binding_get_objective_value( - (ccs_evaluation_binding_t)evaluation, 0, &res); + err = ccs_evaluation_get_objective_value(evaluation, 0, &res); assert(res.value.f == min.value.f); } diff --git a/samples/test_ruby.rb b/samples/test_ruby.rb index 66191a5a..6ba594a1 100644 --- a/samples/test_ruby.rb +++ b/samples/test_ruby.rb @@ -7,7 +7,7 @@ def initialize(os) del = lambda { |tuner| nil } ask = lambda { |tuner, count| if count - cs = tuner.configuration_space + cs = tuner.search_space [cs.samples(count), count] else [nil, 1] diff --git a/src/Makefile.am b/src/Makefile.am index e0aebcdd..7f918247 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -69,6 +69,7 @@ libcconfigspace_la_SOURCES = \ distribution_space_deserialize.h \ binding.c \ binding_internal.h \ + search_configuration_internal.h \ configuration.c \ configuration_internal.h \ configuration_deserialize.h \ @@ -78,8 +79,6 @@ libcconfigspace_la_SOURCES = \ objective_space.c \ objective_space_internal.h \ objective_space_deserialize.h \ - evaluation_binding.c \ - evaluation_binding_internal.h \ evaluation.c \ evaluation_internal.h \ evaluation_deserialize.h \ @@ -115,15 +114,7 @@ libcconfigspace_la_SOURCES = \ tree_space_dynamic.c \ tree_configuration.c \ tree_configuration_internal.h \ - tree_configuration_deserialize.h \ - tree_evaluation.c \ - tree_evaluation_internal.h \ - tree_evaluation_deserialize.h \ - tree_tuner.c \ - tree_tuner_internal.h \ - tree_tuner_deserialize.h \ - tree_tuner_random.c \ - tree_tuner_user_defined.c + tree_configuration_deserialize.h @DYNAMIC_VERSION_RULES@ diff --git a/src/cconfigspace.c b/src/cconfigspace.c index 4c88df38..9efbec44 100644 --- a/src/cconfigspace.c +++ b/src/cconfigspace.c @@ -909,7 +909,6 @@ ccs_get_result_name(ccs_result_t result, const char **name) ETOCASE(CCS_RESULT_ERROR_EXTERNAL); ETOCASE(CCS_RESULT_ERROR_INVALID_TREE); ETOCASE(CCS_RESULT_ERROR_INVALID_TREE_SPACE); - ETOCASE(CCS_RESULT_ERROR_INVALID_TREE_TUNER); ETOCASE(CCS_RESULT_ERROR_INVALID_DISTRIBUTION_SPACE); default: *name = NULL; diff --git a/src/cconfigspace_deserialize.h b/src/cconfigspace_deserialize.h index f37666f6..cc67140e 100644 --- a/src/cconfigspace_deserialize.h +++ b/src/cconfigspace_deserialize.h @@ -38,8 +38,6 @@ _ccs_object_deserialize_with_opts( #include "tree_deserialize.h" #include "tree_space_deserialize.h" #include "tree_configuration_deserialize.h" -#include "tree_evaluation_deserialize.h" -#include "tree_tuner_deserialize.h" static inline ccs_result_t _ccs_object_deserialize_options( @@ -185,16 +183,6 @@ _ccs_object_deserialize_with_opts_type( (ccs_tree_configuration_t *)object_ret, format, version, buffer_size, buffer, opts)); break; - case CCS_OBJECT_TYPE_TREE_EVALUATION: - CCS_VALIDATE(_ccs_tree_evaluation_deserialize( - (ccs_tree_evaluation_t *)object_ret, format, version, - buffer_size, buffer, opts)); - break; - case CCS_OBJECT_TYPE_TREE_TUNER: - CCS_VALIDATE(_ccs_tree_tuner_deserialize( - (ccs_tree_tuner_t *)object_ret, format, version, - buffer_size, buffer, opts)); - break; case CCS_OBJECT_TYPE_DISTRIBUTION_SPACE: CCS_VALIDATE(_ccs_distribution_space_deserialize( (ccs_distribution_space_t *)object_ret, format, version, diff --git a/src/cconfigspace_internal.h b/src/cconfigspace_internal.h index 32856d6c..e2c0a137 100644 --- a/src/cconfigspace_internal.h +++ b/src/cconfigspace_internal.h @@ -249,26 +249,24 @@ _ccs_do_nothing(void) CCS_RESULT_ERROR_INVALID_OBJECT, \ "Invalid CCS context '%s' == %p supplied", #c, c) -#define CCS_CHECK_EVALUATION_BINDING(e) \ - CCS_REFUTE_MSG( \ - !CCS_OBJ_IS_VALID(e) || \ - !(CCS_OBJ_IS_TYPE(e, CCS_OBJECT_TYPE_EVALUATION) || \ - CCS_OBJ_IS_TYPE( \ - e, CCS_OBJECT_TYPE_FEATURES_EVALUATION) || \ - CCS_OBJ_IS_TYPE(e, CCS_OBJECT_TYPE_TREE_EVALUATION)), \ - CCS_RESULT_ERROR_INVALID_OBJECT, \ +#define CCS_CHECK_EVALUATION(e) \ + CCS_REFUTE_MSG( \ + !CCS_OBJ_IS_VALID(e) || \ + !(CCS_OBJ_IS_TYPE(e, CCS_OBJECT_TYPE_EVALUATION) || \ + CCS_OBJ_IS_TYPE( \ + e, CCS_OBJECT_TYPE_FEATURES_EVALUATION)), \ + CCS_RESULT_ERROR_INVALID_OBJECT, \ "Invalid CCS evaluation '%s' == %p supplied", #e, e) -#define CCS_CHECK_BINDING(b) \ - CCS_REFUTE_MSG( \ - !CCS_OBJ_IS_VALID(b) || \ - !(CCS_OBJ_IS_TYPE(b, CCS_OBJECT_TYPE_CONFIGURATION) || \ - CCS_OBJ_IS_TYPE(b, CCS_OBJECT_TYPE_EVALUATION) || \ - CCS_OBJ_IS_TYPE(b, CCS_OBJECT_TYPE_FEATURES) || \ - CCS_OBJ_IS_TYPE( \ - b, CCS_OBJECT_TYPE_FEATURES_EVALUATION) || \ - CCS_OBJ_IS_TYPE(b, CCS_OBJECT_TYPE_TREE_EVALUATION)), \ - CCS_RESULT_ERROR_INVALID_OBJECT, \ +#define CCS_CHECK_BINDING(b) \ + CCS_REFUTE_MSG( \ + !CCS_OBJ_IS_VALID(b) || \ + !(CCS_OBJ_IS_TYPE(b, CCS_OBJECT_TYPE_CONFIGURATION) || \ + CCS_OBJ_IS_TYPE(b, CCS_OBJECT_TYPE_EVALUATION) || \ + CCS_OBJ_IS_TYPE(b, CCS_OBJECT_TYPE_FEATURES) || \ + CCS_OBJ_IS_TYPE( \ + b, CCS_OBJECT_TYPE_FEATURES_EVALUATION)), \ + CCS_RESULT_ERROR_INVALID_OBJECT, \ "Invalid CCS binding '%s' == %p supplied", #b, b) #define CCS_CHECK_SEARCH_SPACE(s) \ @@ -280,6 +278,15 @@ _ccs_do_nothing(void) CCS_RESULT_ERROR_INVALID_OBJECT, \ "Invalid CCS search space '%s' == %p supplied", #s, s) +#define CCS_CHECK_SEARCH_CONFIGURATION(c) \ + CCS_REFUTE_MSG( \ + !CCS_OBJ_IS_VALID(c) || \ + !(CCS_OBJ_IS_TYPE(c, CCS_OBJECT_TYPE_CONFIGURATION) || \ + CCS_OBJ_IS_TYPE( \ + c, CCS_OBJECT_TYPE_TREE_CONFIGURATION)), \ + CCS_RESULT_ERROR_INVALID_OBJECT, \ + "Invalid CCS search configuration '%s' == %p supplied", #c, c) + #define CCS_CHECK_PTR(p) \ CCS_REFUTE_MSG( \ !(p), CCS_RESULT_ERROR_INVALID_VALUE, \ @@ -888,7 +895,6 @@ CCS_CONVERTER(ccs_objective_type, ccs_objective_type_t, 32) CCS_CONVERTER(ccs_tuner_type, ccs_tuner_type_t, 32) CCS_CONVERTER(ccs_features_tuner_type, ccs_features_tuner_type_t, 32) CCS_CONVERTER(ccs_tree_space_type, ccs_tree_space_type_t, 32) -CCS_CONVERTER(ccs_tree_tuner_type, ccs_tree_tuner_type_t, 32) CCS_CONVERTER(ccs_evaluation_result, ccs_evaluation_result_t, 32) CCS_CONVERTER(ccs_object, ccs_object_t, 64) #else @@ -917,7 +923,6 @@ CCS_CONVERTER_COMPRESSED(ccs_objective_type, ccs_objective_type_t, 32) CCS_CONVERTER_COMPRESSED(ccs_tuner_type, ccs_tuner_type_t, 32) CCS_CONVERTER_COMPRESSED(ccs_features_tuner_type, ccs_features_tuner_type_t, 32) CCS_CONVERTER_COMPRESSED(ccs_tree_space_type, ccs_tree_space_type_t, 32) -CCS_CONVERTER_COMPRESSED(ccs_tree_tuner_type, ccs_tree_tuner_type_t, 32) CCS_CONVERTER_COMPRESSED_SIGNED( ccs_evaluation_result, ccs_evaluation_result_t, diff --git a/src/evaluation.c b/src/evaluation.c index 4eb36552..27ad82be 100644 --- a/src/evaluation.c +++ b/src/evaluation.c @@ -1,10 +1,16 @@ #include "cconfigspace_internal.h" -#include "evaluation_binding_internal.h" #include "evaluation_internal.h" +#include "search_configuration_internal.h" #include "configuration_internal.h" #include "objective_space_internal.h" #include +static inline _ccs_evaluation_ops_t * +ccs_evaluation_get_ops(ccs_evaluation_t binding) +{ + return (_ccs_evaluation_ops_t *)binding->obj.ops; +} + static ccs_result_t _ccs_evaluation_del(ccs_object_t object) { @@ -119,55 +125,6 @@ _ccs_evaluation_serialize( return CCS_RESULT_SUCCESS; } -static ccs_result_t -_ccs_evaluation_hash(ccs_evaluation_t evaluation, ccs_hash_t *hash_ret) -{ - _ccs_evaluation_data_t *data = evaluation->data; - ccs_hash_t h, ht; - CCS_VALIDATE(_ccs_binding_hash((ccs_binding_t)evaluation, &h)); - CCS_VALIDATE(ccs_binding_hash((ccs_binding_t)data->configuration, &ht)); - h = _hash_combine(h, ht); - HASH_JEN(&(data->result), sizeof(data->result), ht); - h = _hash_combine(h, ht); - *hash_ret = h; - return CCS_RESULT_SUCCESS; -} - -static ccs_result_t -_ccs_evaluation_cmp( - ccs_evaluation_t evaluation, - ccs_evaluation_t other, - int *cmp_ret) -{ - CCS_VALIDATE(_ccs_binding_cmp( - (ccs_binding_t)evaluation, (ccs_binding_t)other, cmp_ret)); - if (*cmp_ret) - return CCS_RESULT_SUCCESS; - _ccs_evaluation_data_t *data = evaluation->data; - _ccs_evaluation_data_t *other_data = other->data; - *cmp_ret = data->result < other_data->result ? -1 : - data->result > other_data->result ? 1 : - 0; - if (*cmp_ret) - return CCS_RESULT_SUCCESS; - CCS_VALIDATE(ccs_binding_cmp( - (ccs_binding_t)data->configuration, - (ccs_binding_t)other_data->configuration, cmp_ret)); - return CCS_RESULT_SUCCESS; -} - -static ccs_result_t -_ccs_evaluation_compare( - ccs_evaluation_t evaluation, - ccs_evaluation_t other, - ccs_comparison_t *result_ret) -{ - CCS_VALIDATE(_ccs_evaluation_binding_compare( - (ccs_evaluation_binding_t)evaluation, - (ccs_evaluation_binding_t)other, result_ret)); - return CCS_RESULT_SUCCESS; -} - static _ccs_evaluation_ops_t _evaluation_ops = { {&_ccs_evaluation_del, &_ccs_evaluation_serialize_size, &_ccs_evaluation_serialize}, @@ -177,15 +134,19 @@ static _ccs_evaluation_ops_t _evaluation_ops = { ccs_result_t ccs_create_evaluation( - ccs_objective_space_t objective_space, - ccs_configuration_t configuration, - ccs_evaluation_result_t result, - size_t num_values, - ccs_datum_t *values, - ccs_evaluation_t *evaluation_ret) + ccs_objective_space_t objective_space, + ccs_search_configuration_t configuration, + ccs_evaluation_result_t result, + size_t num_values, + ccs_datum_t *values, + ccs_evaluation_t *evaluation_ret) { CCS_CHECK_OBJ(objective_space, CCS_OBJECT_TYPE_OBJECTIVE_SPACE); - CCS_CHECK_OBJ(configuration, CCS_OBJECT_TYPE_CONFIGURATION); + CCS_CHECK_SEARCH_CONFIGURATION(configuration); + CCS_REFUTE( + objective_space->data->search_space != + configuration->data->space, + CCS_RESULT_ERROR_INVALID_CONFIGURATION); CCS_CHECK_PTR(evaluation_ret); CCS_CHECK_ARY(num_values, values); ccs_result_t err; @@ -239,13 +200,124 @@ ccs_create_evaluation( return err; } +ccs_result_t +ccs_evaluation_get_objective_space( + ccs_evaluation_t evaluation, + ccs_objective_space_t *objective_space_ret) +{ + CCS_CHECK_EVALUATION(evaluation); + CCS_CHECK_PTR(objective_space_ret); + *objective_space_ret = evaluation->data->objective_space; + return CCS_RESULT_SUCCESS; +} + +ccs_result_t +ccs_evaluation_get_result( + ccs_evaluation_t evaluation, + ccs_evaluation_result_t *result_ret) +{ + CCS_CHECK_EVALUATION(evaluation); + CCS_CHECK_PTR(result_ret); + *result_ret = evaluation->data->result; + return CCS_RESULT_SUCCESS; +} + ccs_result_t ccs_evaluation_get_configuration( - ccs_evaluation_t evaluation, - ccs_configuration_t *configuration_ret) + ccs_evaluation_t evaluation, + ccs_search_configuration_t *configuration_ret) { - CCS_CHECK_OBJ(evaluation, CCS_OBJECT_TYPE_EVALUATION); + CCS_CHECK_EVALUATION(evaluation); CCS_CHECK_PTR(configuration_ret); *configuration_ret = evaluation->data->configuration; return CCS_RESULT_SUCCESS; } + +ccs_result_t +ccs_evaluation_check(ccs_evaluation_t evaluation, ccs_bool_t *is_valid_ret) +{ + CCS_CHECK_EVALUATION(evaluation); + CCS_VALIDATE(ccs_objective_space_check_evaluation( + evaluation->data->objective_space, evaluation, is_valid_ret)); + return CCS_RESULT_SUCCESS; +} + +ccs_result_t +ccs_evaluation_get_objective_value( + ccs_evaluation_t evaluation, + size_t index, + ccs_datum_t *value_ret) +{ + CCS_CHECK_EVALUATION(evaluation); + CCS_CHECK_PTR(value_ret); + ccs_expression_t expression; + ccs_objective_type_t type; + CCS_VALIDATE(ccs_objective_space_get_objective( + evaluation->data->objective_space, index, &expression, &type)); + CCS_VALIDATE(ccs_expression_eval( + expression, 1, (ccs_binding_t *)&evaluation, value_ret)); + return CCS_RESULT_SUCCESS; +} + +ccs_result_t +ccs_evaluation_get_objective_values( + ccs_evaluation_t evaluation, + size_t num_values, + ccs_datum_t *values, + size_t *num_values_ret) +{ + CCS_CHECK_EVALUATION(evaluation); + CCS_CHECK_ARY(num_values, values); + CCS_REFUTE(!values && !num_values_ret, CCS_RESULT_ERROR_INVALID_VALUE); + size_t count; + CCS_VALIDATE(ccs_objective_space_get_objectives( + evaluation->data->objective_space, 0, NULL, NULL, &count)); + if (values) { + CCS_REFUTE(count < num_values, CCS_RESULT_ERROR_INVALID_VALUE); + for (size_t i = 0; i < count; i++) { + ccs_expression_t expression; + ccs_objective_type_t type; + + CCS_VALIDATE(ccs_objective_space_get_objective( + evaluation->data->objective_space, i, + &expression, &type)); + CCS_VALIDATE(ccs_expression_eval( + expression, 1, (ccs_binding_t *)&evaluation, + values + i)); + } + for (size_t i = count; i < num_values; i++) + values[i] = ccs_none; + } + if (num_values_ret) + *num_values_ret = count; + return CCS_RESULT_SUCCESS; +} + +ccs_result_t +ccs_evaluation_compare( + ccs_evaluation_t evaluation, + ccs_evaluation_t other_evaluation, + ccs_comparison_t *result_ret) +{ + CCS_CHECK_EVALUATION(evaluation); + CCS_CHECK_EVALUATION(other_evaluation); + CCS_REFUTE( + evaluation->obj.type != other_evaluation->obj.type, + CCS_RESULT_ERROR_INVALID_OBJECT); + CCS_CHECK_PTR(result_ret); + if (evaluation == other_evaluation) { + *result_ret = CCS_COMPARISON_EQUIVALENT; + return CCS_RESULT_SUCCESS; + } + CCS_REFUTE( + evaluation->data->result || other_evaluation->data->result, + CCS_RESULT_ERROR_INVALID_OBJECT); + CCS_REFUTE( + evaluation->data->objective_space != + other_evaluation->data->objective_space, + CCS_RESULT_ERROR_INVALID_OBJECT); + + _ccs_evaluation_ops_t *ops = ccs_evaluation_get_ops(evaluation); + CCS_VALIDATE(ops->compare(evaluation, other_evaluation, result_ret)); + return CCS_RESULT_SUCCESS; +} diff --git a/src/evaluation_binding.c b/src/evaluation_binding.c deleted file mode 100644 index 61663a73..00000000 --- a/src/evaluation_binding.c +++ /dev/null @@ -1,122 +0,0 @@ -#include "cconfigspace_internal.h" -#include "evaluation_binding_internal.h" - -static inline _ccs_evaluation_binding_ops_t * -ccs_evaluation_binding_get_ops(ccs_evaluation_binding_t binding) -{ - return (_ccs_evaluation_binding_ops_t *)binding->obj.ops; -} - -ccs_result_t -ccs_evaluation_binding_get_objective_space( - ccs_evaluation_binding_t evaluation, - ccs_objective_space_t *objective_space_ret) -{ - CCS_CHECK_EVALUATION_BINDING(evaluation); - CCS_CHECK_PTR(objective_space_ret); - *objective_space_ret = evaluation->data->objective_space; - return CCS_RESULT_SUCCESS; -} - -ccs_result_t -ccs_evaluation_binding_get_result( - ccs_evaluation_binding_t evaluation, - ccs_evaluation_result_t *result_ret) -{ - CCS_CHECK_EVALUATION_BINDING(evaluation); - CCS_CHECK_PTR(result_ret); - *result_ret = evaluation->data->result; - return CCS_RESULT_SUCCESS; -} - -ccs_result_t -ccs_evaluation_binding_check( - ccs_evaluation_binding_t evaluation, - ccs_bool_t *is_valid_ret) -{ - CCS_CHECK_EVALUATION_BINDING(evaluation); - CCS_VALIDATE(ccs_objective_space_check_evaluation( - evaluation->data->objective_space, evaluation, is_valid_ret)); - return CCS_RESULT_SUCCESS; -} - -ccs_result_t -ccs_evaluation_binding_get_objective_value( - ccs_evaluation_binding_t evaluation, - size_t index, - ccs_datum_t *value_ret) -{ - CCS_CHECK_EVALUATION_BINDING(evaluation); - CCS_CHECK_PTR(value_ret); - ccs_expression_t expression; - ccs_objective_type_t type; - CCS_VALIDATE(ccs_objective_space_get_objective( - evaluation->data->objective_space, index, &expression, &type)); - CCS_VALIDATE(ccs_expression_eval( - expression, 1, (ccs_binding_t *)&evaluation, value_ret)); - return CCS_RESULT_SUCCESS; -} - -ccs_result_t -ccs_evaluation_binding_get_objective_values( - ccs_evaluation_binding_t evaluation, - size_t num_values, - ccs_datum_t *values, - size_t *num_values_ret) -{ - CCS_CHECK_EVALUATION_BINDING(evaluation); - CCS_CHECK_ARY(num_values, values); - CCS_REFUTE(!values && !num_values_ret, CCS_RESULT_ERROR_INVALID_VALUE); - size_t count; - CCS_VALIDATE(ccs_objective_space_get_objectives( - evaluation->data->objective_space, 0, NULL, NULL, &count)); - if (values) { - CCS_REFUTE(count < num_values, CCS_RESULT_ERROR_INVALID_VALUE); - for (size_t i = 0; i < count; i++) { - ccs_expression_t expression; - ccs_objective_type_t type; - - CCS_VALIDATE(ccs_objective_space_get_objective( - evaluation->data->objective_space, i, - &expression, &type)); - CCS_VALIDATE(ccs_expression_eval( - expression, 1, (ccs_binding_t *)&evaluation, - values + i)); - } - for (size_t i = count; i < num_values; i++) - values[i] = ccs_none; - } - if (num_values_ret) - *num_values_ret = count; - return CCS_RESULT_SUCCESS; -} - -ccs_result_t -ccs_evaluation_binding_compare( - ccs_evaluation_binding_t evaluation, - ccs_evaluation_binding_t other_evaluation, - ccs_comparison_t *result_ret) -{ - CCS_CHECK_EVALUATION_BINDING(evaluation); - CCS_CHECK_EVALUATION_BINDING(other_evaluation); - CCS_REFUTE( - evaluation->obj.type != other_evaluation->obj.type, - CCS_RESULT_ERROR_INVALID_OBJECT); - CCS_CHECK_PTR(result_ret); - if (evaluation == other_evaluation) { - *result_ret = CCS_COMPARISON_EQUIVALENT; - return CCS_RESULT_SUCCESS; - } - CCS_REFUTE( - evaluation->data->result || other_evaluation->data->result, - CCS_RESULT_ERROR_INVALID_OBJECT); - CCS_REFUTE( - evaluation->data->objective_space != - other_evaluation->data->objective_space, - CCS_RESULT_ERROR_INVALID_OBJECT); - - _ccs_evaluation_binding_ops_t *ops = - ccs_evaluation_binding_get_ops(evaluation); - CCS_VALIDATE(ops->compare(evaluation, other_evaluation, result_ret)); - return CCS_RESULT_SUCCESS; -} diff --git a/src/evaluation_binding_internal.h b/src/evaluation_binding_internal.h deleted file mode 100644 index e30919f5..00000000 --- a/src/evaluation_binding_internal.h +++ /dev/null @@ -1,92 +0,0 @@ -#ifndef _EVALUATION_BINDING_INTERNAL_H -#define _EVALUATION_BINDING_INTERNAL_H - -typedef struct _ccs_evaluation_binding_data_s _ccs_evaluation_binding_data_t; - -struct _ccs_evaluation_binding_ops_s { - _ccs_object_ops_t obj_ops; - - ccs_result_t (*hash)(ccs_binding_t binding, ccs_hash_t *hash_ret); - - ccs_result_t ( - *cmp)(ccs_binding_t binding, ccs_binding_t other, int *cmp_ret); - - ccs_result_t (*compare)( - ccs_evaluation_binding_t evaluation, - ccs_evaluation_binding_t other_evaluation, - ccs_comparison_t *result_ret); -}; -typedef struct _ccs_evaluation_binding_ops_s _ccs_evaluation_binding_ops_t; - -struct _ccs_evaluation_binding_data_s { - ccs_objective_space_t objective_space; - size_t num_values; - ccs_datum_t *values; - ccs_evaluation_result_t result; -}; - -struct _ccs_evaluation_binding_s { - _ccs_object_internal_t obj; - _ccs_evaluation_binding_data_t *data; -}; - -static inline int -_numeric_compare(const ccs_datum_t *a, const ccs_datum_t *b) -{ - if (a->type == CCS_DATA_TYPE_FLOAT) { - return a->value.f < b->value.f ? -1 : - a->value.f > b->value.f ? 1 : - 0; - } else { - return a->value.i < b->value.i ? -1 : - a->value.i > b->value.i ? 1 : - 0; - } -} - -static inline ccs_result_t -_ccs_evaluation_binding_compare( - ccs_evaluation_binding_t evaluation, - ccs_evaluation_binding_t other_evaluation, - ccs_comparison_t *result_ret) -{ - size_t count; - CCS_VALIDATE(ccs_objective_space_get_objectives( - evaluation->data->objective_space, 0, NULL, NULL, &count)); - *result_ret = CCS_COMPARISON_EQUIVALENT; - for (size_t i = 0; i < count; i++) { - ccs_expression_t expression; - ccs_objective_type_t type; - ccs_datum_t values[2]; - int cmp; - - CCS_VALIDATE(ccs_objective_space_get_objective( - evaluation->data->objective_space, i, &expression, - &type)); - CCS_VALIDATE(ccs_expression_eval( - expression, 1, (ccs_binding_t *)&evaluation, values)); - CCS_VALIDATE(ccs_expression_eval( - expression, 1, (ccs_binding_t *)&other_evaluation, - values + 1)); - if ((values[0].type != CCS_DATA_TYPE_INT && - values[0].type != CCS_DATA_TYPE_FLOAT) || - values[0].type != values[1].type) { - *result_ret = CCS_COMPARISON_NOT_COMPARABLE; - return CCS_RESULT_SUCCESS; - } - cmp = _numeric_compare(values, values + 1); - if (cmp) { - if (type == CCS_OBJECTIVE_TYPE_MAXIMIZE) - cmp = -cmp; - if (*result_ret == CCS_COMPARISON_EQUIVALENT) - *result_ret = (ccs_comparison_t)cmp; - else if (*result_ret != cmp) { - *result_ret = CCS_COMPARISON_NOT_COMPARABLE; - return CCS_RESULT_SUCCESS; - } - } - } - return CCS_RESULT_SUCCESS; -} - -#endif // _EVALUATION_BINDING_INTERNAL_H diff --git a/src/evaluation_deserialize.h b/src/evaluation_deserialize.h index 7dc3b371..11c3215b 100644 --- a/src/evaluation_deserialize.h +++ b/src/evaluation_deserialize.h @@ -5,9 +5,9 @@ #include "configuration_deserialize.h" struct _ccs_evaluation_data_mock_s { - _ccs_binding_data_t base; - ccs_configuration_t configuration; - ccs_evaluation_result_t result; + _ccs_binding_data_t base; + ccs_search_configuration_t configuration; + ccs_evaluation_result_t result; }; typedef struct _ccs_evaluation_data_mock_s _ccs_evaluation_data_mock_t; @@ -21,10 +21,10 @@ _ccs_deserialize_bin_ccs_evaluation_data( { CCS_VALIDATE(_ccs_deserialize_bin_ccs_binding_data( &data->base, version, buffer_size, buffer)); - CCS_VALIDATE(_ccs_object_deserialize_with_opts_check( + CCS_VALIDATE(_ccs_object_deserialize_with_opts( (ccs_object_t *)&data->configuration, - CCS_OBJECT_TYPE_CONFIGURATION, CCS_SERIALIZE_FORMAT_BINARY, - version, buffer_size, buffer, opts)); + CCS_SERIALIZE_FORMAT_BINARY, version, buffer_size, buffer, + opts)); CCS_VALIDATE(_ccs_deserialize_bin_ccs_evaluation_result( &data->result, buffer_size, buffer)); return CCS_RESULT_SUCCESS; diff --git a/src/evaluation_internal.h b/src/evaluation_internal.h index 2e4d83f5..e15f01ef 100644 --- a/src/evaluation_internal.h +++ b/src/evaluation_internal.h @@ -1,6 +1,7 @@ #ifndef _EVALUATION_INTERNAL_H #define _EVALUATION_INTERNAL_H #include "binding_internal.h" +#include "search_configuration_internal.h" struct _ccs_evaluation_data_s; typedef struct _ccs_evaluation_data_s _ccs_evaluation_data_t; @@ -28,11 +29,106 @@ struct _ccs_evaluation_s { }; struct _ccs_evaluation_data_s { - ccs_objective_space_t objective_space; - size_t num_values; - ccs_datum_t *values; - ccs_evaluation_result_t result; - ccs_configuration_t configuration; + ccs_objective_space_t objective_space; + size_t num_values; + ccs_datum_t *values; + ccs_evaluation_result_t result; + ccs_search_configuration_t configuration; }; +static inline ccs_result_t +_ccs_evaluation_hash(ccs_evaluation_t evaluation, ccs_hash_t *hash_ret) +{ + _ccs_evaluation_data_t *data = evaluation->data; + ccs_hash_t h, ht; + CCS_VALIDATE(_ccs_binding_hash((ccs_binding_t)evaluation, &h)); + CCS_VALIDATE(_ccs_search_configuration_hash(data->configuration, &ht)); + h = _hash_combine(h, ht); + HASH_JEN(&(data->result), sizeof(data->result), ht); + h = _hash_combine(h, ht); + *hash_ret = h; + return CCS_RESULT_SUCCESS; +} + +static inline ccs_result_t +_ccs_evaluation_cmp( + ccs_evaluation_t evaluation, + ccs_evaluation_t other, + int *cmp_ret) +{ + CCS_VALIDATE(_ccs_binding_cmp( + (ccs_binding_t)evaluation, (ccs_binding_t)other, cmp_ret)); + if (*cmp_ret) + return CCS_RESULT_SUCCESS; + _ccs_evaluation_data_t *data = evaluation->data; + _ccs_evaluation_data_t *other_data = other->data; + *cmp_ret = data->result < other_data->result ? -1 : + data->result > other_data->result ? 1 : + 0; + if (*cmp_ret) + return CCS_RESULT_SUCCESS; + CCS_VALIDATE(_ccs_search_configuration_cmp( + data->configuration, other_data->configuration, cmp_ret)); + return CCS_RESULT_SUCCESS; +} + +static inline int +_numeric_compare(const ccs_datum_t *a, const ccs_datum_t *b) +{ + if (a->type == CCS_DATA_TYPE_FLOAT) { + return a->value.f < b->value.f ? -1 : + a->value.f > b->value.f ? 1 : + 0; + } else { + return a->value.i < b->value.i ? -1 : + a->value.i > b->value.i ? 1 : + 0; + } +} + +static inline ccs_result_t +_ccs_evaluation_compare( + ccs_evaluation_t evaluation, + ccs_evaluation_t other_evaluation, + ccs_comparison_t *result_ret) +{ + size_t count; + CCS_VALIDATE(ccs_objective_space_get_objectives( + evaluation->data->objective_space, 0, NULL, NULL, &count)); + *result_ret = CCS_COMPARISON_EQUIVALENT; + for (size_t i = 0; i < count; i++) { + ccs_expression_t expression; + ccs_objective_type_t type; + ccs_datum_t values[2]; + int cmp; + + CCS_VALIDATE(ccs_objective_space_get_objective( + evaluation->data->objective_space, i, &expression, + &type)); + CCS_VALIDATE(ccs_expression_eval( + expression, 1, (ccs_binding_t *)&evaluation, values)); + CCS_VALIDATE(ccs_expression_eval( + expression, 1, (ccs_binding_t *)&other_evaluation, + values + 1)); + if ((values[0].type != CCS_DATA_TYPE_INT && + values[0].type != CCS_DATA_TYPE_FLOAT) || + values[0].type != values[1].type) { + *result_ret = CCS_COMPARISON_NOT_COMPARABLE; + return CCS_RESULT_SUCCESS; + } + cmp = _numeric_compare(values, values + 1); + if (cmp) { + if (type == CCS_OBJECTIVE_TYPE_MAXIMIZE) + cmp = -cmp; + if (*result_ret == CCS_COMPARISON_EQUIVALENT) + *result_ret = (ccs_comparison_t)cmp; + else if (*result_ret != cmp) { + *result_ret = CCS_COMPARISON_NOT_COMPARABLE; + return CCS_RESULT_SUCCESS; + } + } + } + return CCS_RESULT_SUCCESS; +} + #endif //_EVALUATION_INTERNAL_H diff --git a/src/features_evaluation.c b/src/features_evaluation.c index 12ae7871..8f92e46a 100644 --- a/src/features_evaluation.c +++ b/src/features_evaluation.c @@ -1,5 +1,5 @@ #include "cconfigspace_internal.h" -#include "evaluation_binding_internal.h" +#include "evaluation_internal.h" #include "features_evaluation_internal.h" #include "configuration_internal.h" #include "features_internal.h" @@ -190,9 +190,9 @@ _ccs_features_evaluation_compare( *result_ret = CCS_COMPARISON_NOT_COMPARABLE; return CCS_RESULT_SUCCESS; } - CCS_VALIDATE(_ccs_evaluation_binding_compare( - (ccs_evaluation_binding_t)evaluation, - (ccs_evaluation_binding_t)other_evaluation, result_ret)); + CCS_VALIDATE(_ccs_evaluation_compare( + (ccs_evaluation_t)evaluation, + (ccs_evaluation_t)other_evaluation, result_ret)); return CCS_RESULT_SUCCESS; } @@ -207,7 +207,7 @@ static _ccs_features_evaluation_ops_t _features_evaluation_ops = { ccs_result_t ccs_create_features_evaluation( ccs_objective_space_t objective_space, - ccs_configuration_t configuration, + ccs_search_configuration_t configuration, ccs_features_t features, ccs_evaluation_result_t result, size_t num_values, @@ -216,6 +216,10 @@ ccs_create_features_evaluation( { CCS_CHECK_OBJ(objective_space, CCS_OBJECT_TYPE_OBJECTIVE_SPACE); CCS_CHECK_OBJ(configuration, CCS_OBJECT_TYPE_CONFIGURATION); + CCS_REFUTE( + objective_space->data->search_space != + configuration->data->space, + CCS_RESULT_ERROR_INVALID_CONFIGURATION); CCS_CHECK_OBJ(features, CCS_OBJECT_TYPE_FEATURES); CCS_CHECK_PTR(evaluation_ret); CCS_CHECK_ARY(num_values, values); @@ -279,17 +283,6 @@ ccs_create_features_evaluation( return err; } -ccs_result_t -ccs_features_evaluation_get_configuration( - ccs_features_evaluation_t evaluation, - ccs_configuration_t *configuration_ret) -{ - CCS_CHECK_OBJ(evaluation, CCS_OBJECT_TYPE_FEATURES_EVALUATION); - CCS_CHECK_PTR(configuration_ret); - *configuration_ret = evaluation->data->configuration; - return CCS_RESULT_SUCCESS; -} - ccs_result_t ccs_features_evaluation_get_features( ccs_features_evaluation_t evaluation, diff --git a/src/features_evaluation_deserialize.h b/src/features_evaluation_deserialize.h index 022df5bc..04ddf657 100644 --- a/src/features_evaluation_deserialize.h +++ b/src/features_evaluation_deserialize.h @@ -3,10 +3,10 @@ #include "features_evaluation_internal.h" struct _ccs_features_evaluation_data_mock_s { - _ccs_binding_data_t base; - ccs_configuration_t configuration; - ccs_features_t features; - ccs_evaluation_result_t result; + _ccs_binding_data_t base; + ccs_search_configuration_t configuration; + ccs_features_t features; + ccs_evaluation_result_t result; }; typedef struct _ccs_features_evaluation_data_mock_s _ccs_features_evaluation_data_mock_t; @@ -21,10 +21,10 @@ _ccs_deserialize_bin_ccs_features_evaluation_data( { CCS_VALIDATE(_ccs_deserialize_bin_ccs_binding_data( &data->base, version, buffer_size, buffer)); - CCS_VALIDATE(_ccs_object_deserialize_with_opts_check( + CCS_VALIDATE(_ccs_object_deserialize_with_opts( (ccs_object_t *)&data->configuration, - CCS_OBJECT_TYPE_CONFIGURATION, CCS_SERIALIZE_FORMAT_BINARY, - version, buffer_size, buffer, opts)); + CCS_SERIALIZE_FORMAT_BINARY, version, buffer_size, buffer, + opts)); CCS_VALIDATE(_ccs_object_deserialize_with_opts_check( (ccs_object_t *)&data->features, CCS_OBJECT_TYPE_FEATURES, CCS_SERIALIZE_FORMAT_BINARY, version, buffer_size, buffer, diff --git a/src/features_evaluation_internal.h b/src/features_evaluation_internal.h index cc1fd683..8d020107 100644 --- a/src/features_evaluation_internal.h +++ b/src/features_evaluation_internal.h @@ -30,12 +30,12 @@ struct _ccs_features_evaluation_s { }; struct _ccs_features_evaluation_data_s { - ccs_objective_space_t objective_space; - size_t num_values; - ccs_datum_t *values; - ccs_evaluation_result_t result; - ccs_configuration_t configuration; - ccs_features_t features; + ccs_objective_space_t objective_space; + size_t num_values; + ccs_datum_t *values; + ccs_evaluation_result_t result; + ccs_search_configuration_t configuration; + ccs_features_t features; }; #endif //_FEATURES_EVALUATION_INTERNAL_H diff --git a/src/features_tuner.c b/src/features_tuner.c index 6a0db096..cde75632 100644 --- a/src/features_tuner.c +++ b/src/features_tuner.c @@ -32,15 +32,15 @@ ccs_features_tuner_get_name(ccs_features_tuner_t tuner, const char **name_ret) } ccs_result_t -ccs_features_tuner_get_configuration_space( - ccs_features_tuner_t tuner, - ccs_configuration_space_t *configuration_space_ret) +ccs_features_tuner_get_search_space( + ccs_features_tuner_t tuner, + ccs_search_space_t *search_space_ret) { CCS_CHECK_OBJ(tuner, CCS_OBJECT_TYPE_FEATURES_TUNER); - CCS_CHECK_PTR(configuration_space_ret); + CCS_CHECK_PTR(search_space_ret); _ccs_features_tuner_common_data_t *d = (_ccs_features_tuner_common_data_t *)tuner->data; - *configuration_space_ret = d->configuration_space; + *search_space_ret = d->search_space; return CCS_RESULT_SUCCESS; } @@ -72,11 +72,11 @@ ccs_features_tuner_get_feature_space( ccs_result_t ccs_features_tuner_ask( - ccs_features_tuner_t tuner, - ccs_features_t features, - size_t num_configurations, - ccs_configuration_t *configurations, - size_t *num_configurations_ret) + ccs_features_tuner_t tuner, + ccs_features_t features, + size_t num_configurations, + ccs_search_configuration_t *configurations, + size_t *num_configurations_ret) { CCS_CHECK_OBJ(tuner, CCS_OBJECT_TYPE_FEATURES_TUNER); CCS_CHECK_OBJ(features, CCS_OBJECT_TYPE_FEATURES); @@ -183,9 +183,9 @@ ccs_features_tuner_get_history( ccs_result_t ccs_features_tuner_suggest( - ccs_features_tuner_t tuner, - ccs_features_t features, - ccs_configuration_t *configuration) + ccs_features_tuner_t tuner, + ccs_features_t features, + ccs_search_configuration_t *configuration) { CCS_CHECK_OBJ(tuner, CCS_OBJECT_TYPE_FEATURES_TUNER); _ccs_features_tuner_ops_t *ops = ccs_features_tuner_get_ops(tuner); diff --git a/src/features_tuner_internal.h b/src/features_tuner_internal.h index d5d9933b..9157fa9f 100644 --- a/src/features_tuner_internal.h +++ b/src/features_tuner_internal.h @@ -12,11 +12,11 @@ struct _ccs_features_tuner_ops_s { _ccs_object_ops_t obj_ops; ccs_result_t (*ask)( - ccs_features_tuner_t tuner, - ccs_features_t features, - size_t num_configurations, - ccs_configuration_t *configurations, - size_t *num_configurations_ret); + ccs_features_tuner_t tuner, + ccs_features_t features, + size_t num_configurations, + ccs_search_configuration_t *configurations, + size_t *num_configurations_ret); ccs_result_t (*tell)( ccs_features_tuner_t tuner, @@ -38,9 +38,9 @@ struct _ccs_features_tuner_ops_s { size_t *num_evaluations_ret); ccs_result_t (*suggest)( - ccs_features_tuner_t tuner, - ccs_features_t features, - ccs_configuration_t *configuration); + ccs_features_tuner_t tuner, + ccs_features_t features, + ccs_search_configuration_t *configuration); }; typedef struct _ccs_features_tuner_ops_s _ccs_features_tuner_ops_t; @@ -52,7 +52,7 @@ struct _ccs_features_tuner_s { struct _ccs_features_tuner_common_data_s { ccs_features_tuner_type_t type; const char *name; - ccs_configuration_space_t configuration_space; + ccs_search_space_t search_space; ccs_objective_space_t objective_space; ccs_feature_space_t feature_space; }; diff --git a/src/features_tuner_random.c b/src/features_tuner_random.c index a71ee62d..25839d74 100644 --- a/src/features_tuner_random.c +++ b/src/features_tuner_random.c @@ -19,7 +19,7 @@ _ccs_features_tuner_random_del(ccs_object_t o) _ccs_random_features_tuner_data_t *d = (_ccs_random_features_tuner_data_t *)((ccs_features_tuner_t)o) ->data; - ccs_release_object(d->common_data.configuration_space); + ccs_release_object(d->common_data.search_space); ccs_release_object(d->common_data.objective_space); ccs_release_object(d->common_data.feature_space); ccs_features_evaluation_t *e = NULL; @@ -156,11 +156,11 @@ _ccs_random_features_tuner_serialize( static ccs_result_t _ccs_features_tuner_random_ask( - ccs_features_tuner_t tuner, - ccs_features_t features, - size_t num_configurations, - ccs_configuration_t *configurations, - size_t *num_configurations_ret) + ccs_features_tuner_t tuner, + ccs_features_t features, + size_t num_configurations, + ccs_search_configuration_t *configurations, + size_t *num_configurations_ret) { (void)features; _ccs_random_features_tuner_data_t *d = @@ -169,9 +169,17 @@ _ccs_features_tuner_random_ask( *num_configurations_ret = 1; return CCS_RESULT_SUCCESS; } - CCS_VALIDATE(ccs_configuration_space_samples( - d->common_data.configuration_space, NULL, NULL, - num_configurations, configurations)); + ccs_search_space_t search_space = d->common_data.search_space; + if (CCS_OBJ_TYPE(search_space) == CCS_OBJECT_TYPE_CONFIGURATION_SPACE) + CCS_VALIDATE(ccs_configuration_space_samples( + (ccs_configuration_space_t)search_space, NULL, NULL, + num_configurations, + (ccs_configuration_t *)configurations)); + else + CCS_VALIDATE(ccs_tree_space_samples( + (ccs_tree_space_t)search_space, NULL, + num_configurations, + (ccs_tree_configuration_t *)configurations)); if (num_configurations_ret) *num_configurations_ret = num_configurations; return CCS_RESULT_SUCCESS; @@ -196,8 +204,8 @@ _ccs_features_tuner_random_tell( ccs_result_t err; for (size_t i = 0; i < num_evaluations; i++) { ccs_evaluation_result_t result; - CCS_VALIDATE(ccs_evaluation_binding_get_result( - (ccs_evaluation_binding_t)evaluations[i], &result)); + CCS_VALIDATE(ccs_evaluation_get_result( + (ccs_evaluation_t)evaluations[i], &result)); if (result == CCS_RESULT_SUCCESS) { int discard = 0; UT_array *tmp; @@ -220,11 +228,9 @@ _ccs_features_tuner_random_tell( utarray_next(d->old_optima, eval))) { if (!discard) { ccs_comparison_t cmp; - err = ccs_evaluation_binding_compare( - (ccs_evaluation_binding_t) - evaluations[i], - (ccs_evaluation_binding_t)*eval, - &cmp); + err = ccs_evaluation_compare( + (ccs_evaluation_t)evaluations[i], + (ccs_evaluation_t)*eval, &cmp); if (err) discard = 1; else @@ -388,9 +394,9 @@ _ccs_features_tuner_random_get_history( static ccs_result_t _ccs_features_tuner_random_suggest( - ccs_features_tuner_t tuner, - ccs_features_t features, - ccs_configuration_t *configuration) + ccs_features_tuner_t tuner, + ccs_features_t features, + ccs_search_configuration_t *configuration) { _ccs_random_features_tuner_data_t *d = (_ccs_random_features_tuner_data_t *)tuner->data; @@ -408,10 +414,19 @@ _ccs_features_tuner_random_suggest( count += 1; } if (count > 0) { - ccs_rng_t rng; - unsigned long int indx; - CCS_VALIDATE(ccs_configuration_space_get_rng( - d->common_data.configuration_space, &rng)); + ccs_rng_t rng; + unsigned long int indx; + ccs_search_space_t search_space = d->common_data.search_space; + if (CCS_OBJ_TYPE(search_space) == + CCS_OBJECT_TYPE_CONFIGURATION_SPACE) + CCS_VALIDATE(ccs_configuration_space_get_rng( + (ccs_configuration_space_t) + d->common_data.search_space, + &rng)); + else + CCS_VALIDATE(ccs_tree_space_get_rng( + (ccs_tree_space_t)d->common_data.search_space, + &rng)); CCS_VALIDATE(ccs_rng_get(rng, &indx)); indx = indx % count; while ((eval = (ccs_features_evaluation_t *)utarray_next( @@ -428,8 +443,8 @@ _ccs_features_tuner_random_suggest( indx--; } } - CCS_VALIDATE(ccs_features_evaluation_get_configuration( - *eval, configuration)); + CCS_VALIDATE(ccs_evaluation_get_configuration( + (ccs_evaluation_t)*eval, configuration)); CCS_VALIDATE(ccs_retain_object(*configuration)); } else CCS_VALIDATE(_ccs_features_tuner_random_ask( @@ -468,13 +483,12 @@ ccs_create_random_features_tuner( ccs_objective_space_t objective_space, ccs_features_tuner_t *tuner_ret) { - ccs_configuration_space_t configuration_space; + ccs_search_space_t search_space; CCS_CHECK_PTR(name); CCS_CHECK_OBJ(feature_space, CCS_OBJECT_TYPE_FEATURE_SPACE); CCS_CHECK_OBJ(objective_space, CCS_OBJECT_TYPE_OBJECTIVE_SPACE); CCS_VALIDATE(ccs_objective_space_get_search_space( - objective_space, (ccs_search_space_t *)&configuration_space)); - CCS_CHECK_OBJ(configuration_space, CCS_OBJECT_TYPE_CONFIGURATION_SPACE); + objective_space, &search_space)); CCS_CHECK_PTR(tuner_ret); uintptr_t mem = (uintptr_t)calloc( @@ -486,8 +500,7 @@ ccs_create_random_features_tuner( _ccs_random_features_tuner_data_t *data; ccs_result_t err; - CCS_VALIDATE_ERR_GOTO( - err, ccs_retain_object(configuration_space), errmem); + CCS_VALIDATE_ERR_GOTO(err, ccs_retain_object(search_space), errmem); CCS_VALIDATE_ERR_GOTO(err, ccs_retain_object(objective_space), errcs); CCS_VALIDATE_ERR_GOTO(err, ccs_retain_object(feature_space), erros); @@ -502,9 +515,9 @@ ccs_create_random_features_tuner( data->common_data.name = (const char *)(mem + sizeof(struct _ccs_features_tuner_s) + sizeof(struct _ccs_random_features_tuner_data_s)); - data->common_data.configuration_space = configuration_space; - data->common_data.objective_space = objective_space; - data->common_data.feature_space = feature_space; + data->common_data.search_space = search_space; + data->common_data.objective_space = objective_space; + data->common_data.feature_space = feature_space; utarray_new(data->history, &_evaluation_icd); utarray_new(data->optima, &_evaluation_icd); utarray_new(data->old_optima, &_evaluation_icd); @@ -524,7 +537,7 @@ ccs_create_random_features_tuner( erros: ccs_release_object(objective_space); errcs: - ccs_release_object(configuration_space); + ccs_release_object(search_space); errmem: free((void *)mem); return err; diff --git a/src/features_tuner_user_defined.c b/src/features_tuner_user_defined.c index b02c93cd..771b24db 100644 --- a/src/features_tuner_user_defined.c +++ b/src/features_tuner_user_defined.c @@ -20,7 +20,7 @@ _ccs_features_tuner_user_defined_del(ccs_object_t o) ->data; ccs_result_t err; err = d->vector.del((ccs_features_tuner_t)o); - ccs_release_object(d->common_data.configuration_space); + ccs_release_object(d->common_data.search_space); ccs_release_object(d->common_data.objective_space); ccs_release_object(d->common_data.feature_space); return err; @@ -239,11 +239,11 @@ _ccs_features_tuner_user_defined_serialize( static ccs_result_t _ccs_features_tuner_user_defined_ask( - ccs_features_tuner_t tuner, - ccs_features_t features, - size_t num_configurations, - ccs_configuration_t *configurations, - size_t *num_configurations_ret) + ccs_features_tuner_t tuner, + ccs_features_t features, + size_t num_configurations, + ccs_search_configuration_t *configurations, + size_t *num_configurations_ret) { _ccs_user_defined_features_tuner_data_t *d = (_ccs_user_defined_features_tuner_data_t *)tuner->data; @@ -299,9 +299,9 @@ _ccs_features_tuner_user_defined_get_history( static ccs_result_t _ccs_features_tuner_user_defined_suggest( - ccs_features_tuner_t tuner, - ccs_features_t features, - ccs_configuration_t *configuration_ret) + ccs_features_tuner_t tuner, + ccs_features_t features, + ccs_search_configuration_t *configuration_ret) { _ccs_user_defined_features_tuner_data_t *d = (_ccs_user_defined_features_tuner_data_t *)tuner->data; @@ -329,13 +329,12 @@ ccs_create_user_defined_features_tuner( void *tuner_data, ccs_features_tuner_t *tuner_ret) { - ccs_configuration_space_t configuration_space; + ccs_search_space_t search_space; CCS_CHECK_PTR(name); CCS_CHECK_OBJ(feature_space, CCS_OBJECT_TYPE_FEATURE_SPACE); CCS_CHECK_OBJ(objective_space, CCS_OBJECT_TYPE_OBJECTIVE_SPACE); CCS_VALIDATE(ccs_objective_space_get_search_space( - objective_space, (ccs_search_space_t *)&configuration_space)); - CCS_CHECK_OBJ(configuration_space, CCS_OBJECT_TYPE_CONFIGURATION_SPACE); + objective_space, &search_space)); CCS_CHECK_PTR(tuner_ret); CCS_CHECK_PTR(vector); CCS_CHECK_PTR(vector->del); @@ -354,8 +353,7 @@ ccs_create_user_defined_features_tuner( _ccs_user_defined_features_tuner_data_t *data; ccs_result_t err; - CCS_VALIDATE_ERR_GOTO( - err, ccs_retain_object(configuration_space), errmem); + CCS_VALIDATE_ERR_GOTO(err, ccs_retain_object(search_space), errmem); CCS_VALIDATE_ERR_GOTO(err, ccs_retain_object(objective_space), errcs); CCS_VALIDATE_ERR_GOTO(err, ccs_retain_object(feature_space), erros); @@ -370,18 +368,18 @@ ccs_create_user_defined_features_tuner( data->common_data.name = (const char *)(mem + sizeof(struct _ccs_features_tuner_s) + sizeof(struct _ccs_user_defined_features_tuner_data_s)); - data->common_data.configuration_space = configuration_space; - data->common_data.objective_space = objective_space; - data->common_data.feature_space = feature_space; - data->vector = *vector; - data->tuner_data = tuner_data; + data->common_data.search_space = search_space; + data->common_data.objective_space = objective_space; + data->common_data.feature_space = feature_space; + data->vector = *vector; + data->tuner_data = tuner_data; strcpy((char *)data->common_data.name, name); *tuner_ret = tun; return CCS_RESULT_SUCCESS; erros: ccs_release_object(objective_space); errcs: - ccs_release_object(configuration_space); + ccs_release_object(search_space); errmem: free((void *)mem); return err; diff --git a/src/objective_space.c b/src/objective_space.c index 9c71d14c..690d8d31 100644 --- a/src/objective_space.c +++ b/src/objective_space.c @@ -1,7 +1,7 @@ #include "cconfigspace_internal.h" #include "search_space_internal.h" #include "objective_space_internal.h" -#include "evaluation_binding_internal.h" +#include "evaluation_internal.h" #include "expression_internal.h" static ccs_result_t @@ -303,9 +303,9 @@ ccs_objective_space_get_search_space( static inline ccs_result_t _check_evaluation( - ccs_objective_space_t objective_space, - ccs_evaluation_binding_t evaluation, - ccs_bool_t *is_valid_ret) + ccs_objective_space_t objective_space, + ccs_evaluation_t evaluation, + ccs_bool_t *is_valid_ret) { ccs_parameter_t *parameters = objective_space->data->parameters; size_t num_parameters = objective_space->data->num_parameters; @@ -323,12 +323,12 @@ _check_evaluation( ccs_result_t ccs_objective_space_check_evaluation( - ccs_objective_space_t objective_space, - ccs_evaluation_binding_t evaluation, - ccs_bool_t *is_valid_ret) + ccs_objective_space_t objective_space, + ccs_evaluation_t evaluation, + ccs_bool_t *is_valid_ret) { CCS_CHECK_OBJ(objective_space, CCS_OBJECT_TYPE_OBJECTIVE_SPACE); - CCS_CHECK_EVALUATION_BINDING(evaluation); + CCS_CHECK_EVALUATION(evaluation); CCS_REFUTE( evaluation->data->objective_space != objective_space, CCS_RESULT_ERROR_INVALID_EVALUATION); diff --git a/src/search_configuration_internal.h b/src/search_configuration_internal.h new file mode 100644 index 00000000..3e3af95e --- /dev/null +++ b/src/search_configuration_internal.h @@ -0,0 +1,53 @@ +#ifndef _SEARCH_CONFIGURATION_INTERNAL_H +#define _SEARCH_CONFIGURATION_INTERNAL_H + +struct _ccs_search_configuration_data_s; +typedef struct _ccs_search_configuration_data_s _ccs_search_configuration_data_t; + +struct _ccs_search_configuration_ops_s { + _ccs_object_ops_t obj_ops; + + ccs_result_t (*hash)( + ccs_search_configuration_t configuration, + ccs_hash_t *hash_ret); + + ccs_result_t (*cmp)( + ccs_search_configuration_t configuration, + ccs_search_configuration_t other, + int *cmp_ret); +}; +typedef struct _ccs_search_configuration_ops_s _ccs_search_configuration_ops_t; + +struct _ccs_search_configuration_s { + _ccs_object_internal_t obj; + _ccs_search_configuration_data_t *data; +}; + +struct _ccs_search_configuration_data_s { + ccs_search_space_t space; +}; + +static inline ccs_result_t +_ccs_search_configuration_hash( + ccs_search_configuration_t configuration, + ccs_hash_t *hash_ret) +{ + _ccs_search_configuration_ops_t *ops = + (_ccs_search_configuration_ops_t *)configuration->obj.ops; + CCS_VALIDATE(ops->hash(configuration, hash_ret)); + return CCS_RESULT_SUCCESS; +} + +static inline ccs_result_t +_ccs_search_configuration_cmp( + ccs_search_configuration_t configuration, + ccs_search_configuration_t other, + int *cmp_ret) +{ + _ccs_search_configuration_ops_t *ops = + (_ccs_search_configuration_ops_t *)configuration->obj.ops; + CCS_VALIDATE(ops->cmp(configuration, other, cmp_ret)); + return CCS_RESULT_SUCCESS; +} + +#endif //_SEARCH_CONFIGURATION_INTERNAL_H diff --git a/src/tree_configuration.c b/src/tree_configuration.c index 4b76e1ab..c642826c 100644 --- a/src/tree_configuration.c +++ b/src/tree_configuration.c @@ -109,9 +109,22 @@ _ccs_tree_configuration_serialize( return CCS_RESULT_SUCCESS; } +static ccs_result_t +_ccs_tree_configuration_hash( + ccs_tree_configuration_t configuration, + ccs_hash_t *hash_ret); + +static ccs_result_t +_ccs_tree_configuration_cmp( + ccs_tree_configuration_t configuration, + ccs_tree_configuration_t other_configuration, + int *cmp_ret); + static _ccs_tree_configuration_ops_t _tree_configuration_ops = { {&_ccs_tree_configuration_del, &_ccs_tree_configuration_serialize_size, - &_ccs_tree_configuration_serialize}}; + &_ccs_tree_configuration_serialize}, + &_ccs_tree_configuration_hash, + &_ccs_tree_configuration_cmp}; ccs_result_t ccs_create_tree_configuration( @@ -235,15 +248,12 @@ ccs_tree_configuration_check( #define CCS_CMP(a, b) ((a) < (b) ? -1 : ((a) > (b) ? 1 : 0)) -ccs_result_t -ccs_tree_configuration_cmp( +static ccs_result_t +_ccs_tree_configuration_cmp( ccs_tree_configuration_t configuration, ccs_tree_configuration_t other_configuration, int *cmp_ret) { - CCS_CHECK_OBJ(configuration, CCS_OBJECT_TYPE_TREE_CONFIGURATION); - CCS_CHECK_OBJ(other_configuration, CCS_OBJECT_TYPE_TREE_CONFIGURATION); - CCS_CHECK_PTR(cmp_ret); if (configuration == other_configuration) { *cmp_ret = 0; return CCS_RESULT_SUCCESS; @@ -269,14 +279,26 @@ ccs_tree_configuration_cmp( return CCS_RESULT_SUCCESS; } -#include "datum_hash.h" ccs_result_t -ccs_tree_configuration_hash( +ccs_tree_configuration_cmp( ccs_tree_configuration_t configuration, - ccs_hash_t *hash_ret) + ccs_tree_configuration_t other_configuration, + int *cmp_ret) { CCS_CHECK_OBJ(configuration, CCS_OBJECT_TYPE_TREE_CONFIGURATION); - CCS_CHECK_PTR(hash_ret); + CCS_CHECK_OBJ(other_configuration, CCS_OBJECT_TYPE_TREE_CONFIGURATION); + CCS_CHECK_PTR(cmp_ret); + CCS_VALIDATE(_ccs_tree_configuration_cmp( + configuration, other_configuration, cmp_ret)); + return CCS_RESULT_SUCCESS; +} + +#include "datum_hash.h" +static ccs_result_t +_ccs_tree_configuration_hash( + ccs_tree_configuration_t configuration, + ccs_hash_t *hash_ret) +{ ccs_hash_t h, ht; HASH_JEN( &(configuration->data->tree_space), @@ -292,3 +314,14 @@ ccs_tree_configuration_hash( *hash_ret = h; return CCS_RESULT_SUCCESS; } + +ccs_result_t +ccs_tree_configuration_hash( + ccs_tree_configuration_t configuration, + ccs_hash_t *hash_ret) +{ + CCS_CHECK_OBJ(configuration, CCS_OBJECT_TYPE_TREE_CONFIGURATION); + CCS_CHECK_PTR(hash_ret); + CCS_VALIDATE(_ccs_tree_configuration_hash(configuration, hash_ret)); + return CCS_RESULT_SUCCESS; +} diff --git a/src/tree_configuration_internal.h b/src/tree_configuration_internal.h index 94452644..ee6de434 100644 --- a/src/tree_configuration_internal.h +++ b/src/tree_configuration_internal.h @@ -6,6 +6,15 @@ typedef struct _ccs_tree_configuration_data_s _ccs_tree_configuration_data_t; struct _ccs_tree_configuration_ops_s { _ccs_object_ops_t obj_ops; + + ccs_result_t (*hash)( + ccs_tree_configuration_t configuration, + ccs_hash_t *hash_ret); + + ccs_result_t (*cmp)( + ccs_tree_configuration_t configuration, + ccs_tree_configuration_t other, + int *cmp_ret); }; typedef struct _ccs_tree_configuration_ops_s _ccs_tree_configuration_ops_t; diff --git a/src/tree_evaluation.c b/src/tree_evaluation.c deleted file mode 100644 index ef629a0c..00000000 --- a/src/tree_evaluation.c +++ /dev/null @@ -1,253 +0,0 @@ -#include "cconfigspace_internal.h" -#include "evaluation_binding_internal.h" -#include "tree_evaluation_internal.h" -#include "tree_configuration_internal.h" -#include "objective_space_internal.h" -#include - -static ccs_result_t -_ccs_tree_evaluation_del(ccs_object_t object) -{ - ccs_tree_evaluation_t evaluation = (ccs_tree_evaluation_t)object; - ccs_release_object(evaluation->data->objective_space); - ccs_release_object(evaluation->data->configuration); - return CCS_RESULT_SUCCESS; -} - -static inline ccs_result_t -_ccs_serialize_bin_size_ccs_tree_evaluation_data( - _ccs_tree_evaluation_data_t *data, - size_t *cum_size, - _ccs_object_serialize_options_t *opts) -{ - *cum_size += _ccs_serialize_bin_size_ccs_binding_data( - (_ccs_binding_data_t *)data); - CCS_VALIDATE(data->configuration->obj.ops->serialize_size( - data->configuration, CCS_SERIALIZE_FORMAT_BINARY, cum_size, - opts)); - *cum_size += - _ccs_serialize_bin_size_ccs_evaluation_result(data->result); - return CCS_RESULT_SUCCESS; -} - -static inline ccs_result_t -_ccs_serialize_bin_ccs_tree_evaluation_data( - _ccs_tree_evaluation_data_t *data, - size_t *buffer_size, - char **buffer, - _ccs_object_serialize_options_t *opts) -{ - CCS_VALIDATE(_ccs_serialize_bin_ccs_binding_data( - (_ccs_binding_data_t *)data, buffer_size, buffer)); - CCS_VALIDATE(data->configuration->obj.ops->serialize( - data->configuration, CCS_SERIALIZE_FORMAT_BINARY, buffer_size, - buffer, opts)); - CCS_VALIDATE(_ccs_serialize_bin_ccs_evaluation_result( - data->result, buffer_size, buffer)); - return CCS_RESULT_SUCCESS; -} - -static inline ccs_result_t -_ccs_serialize_bin_size_ccs_tree_evaluation( - ccs_tree_evaluation_t evaluation, - size_t *cum_size, - _ccs_object_serialize_options_t *opts) -{ - *cum_size += _ccs_serialize_bin_size_ccs_object_internal( - (_ccs_object_internal_t *)evaluation); - CCS_VALIDATE(_ccs_serialize_bin_size_ccs_tree_evaluation_data( - evaluation->data, cum_size, opts)); - return CCS_RESULT_SUCCESS; -} - -static inline ccs_result_t -_ccs_serialize_bin_ccs_tree_evaluation( - ccs_tree_evaluation_t evaluation, - size_t *buffer_size, - char **buffer, - _ccs_object_serialize_options_t *opts) -{ - CCS_VALIDATE(_ccs_serialize_bin_ccs_object_internal( - (_ccs_object_internal_t *)evaluation, buffer_size, buffer)); - CCS_VALIDATE(_ccs_serialize_bin_ccs_tree_evaluation_data( - evaluation->data, buffer_size, buffer, opts)); - return CCS_RESULT_SUCCESS; -} - -static ccs_result_t -_ccs_tree_evaluation_serialize_size( - ccs_object_t object, - ccs_serialize_format_t format, - size_t *cum_size, - _ccs_object_serialize_options_t *opts) -{ - switch (format) { - case CCS_SERIALIZE_FORMAT_BINARY: - CCS_VALIDATE(_ccs_serialize_bin_size_ccs_tree_evaluation( - (ccs_tree_evaluation_t)object, cum_size, opts)); - break; - default: - CCS_RAISE( - CCS_RESULT_ERROR_INVALID_VALUE, - "Unsupported serialization format: %d", format); - } - CCS_VALIDATE(_ccs_object_serialize_user_data_size( - object, format, cum_size, opts)); - return CCS_RESULT_SUCCESS; -} - -static ccs_result_t -_ccs_tree_evaluation_serialize( - ccs_object_t object, - ccs_serialize_format_t format, - size_t *buffer_size, - char **buffer, - _ccs_object_serialize_options_t *opts) -{ - switch (format) { - case CCS_SERIALIZE_FORMAT_BINARY: - CCS_VALIDATE(_ccs_serialize_bin_ccs_tree_evaluation( - (ccs_tree_evaluation_t)object, buffer_size, buffer, - opts)); - break; - default: - CCS_RAISE( - CCS_RESULT_ERROR_INVALID_VALUE, - "Unsupported serialization format: %d", format); - } - CCS_VALIDATE(_ccs_object_serialize_user_data( - object, format, buffer_size, buffer, opts)); - return CCS_RESULT_SUCCESS; -} - -static ccs_result_t -_ccs_tree_evaluation_hash( - ccs_tree_evaluation_t tree_evaluation, - ccs_hash_t *hash_ret) -{ - _ccs_tree_evaluation_data_t *data = tree_evaluation->data; - ccs_hash_t h, ht; - CCS_VALIDATE(_ccs_binding_hash((ccs_binding_t)tree_evaluation, &h)); - CCS_VALIDATE(ccs_tree_configuration_hash(data->configuration, &ht)); - h = _hash_combine(h, ht); - HASH_JEN(&(data->result), sizeof(data->result), ht); - h = _hash_combine(h, ht); - *hash_ret = h; - return CCS_RESULT_SUCCESS; -} - -static ccs_result_t -_ccs_tree_evaluation_cmp( - ccs_tree_evaluation_t tree_evaluation, - ccs_tree_evaluation_t other, - int *cmp_ret) -{ - CCS_VALIDATE(_ccs_binding_cmp( - (ccs_binding_t)tree_evaluation, (ccs_binding_t)other, cmp_ret)); - if (*cmp_ret) - return CCS_RESULT_SUCCESS; - _ccs_tree_evaluation_data_t *data = tree_evaluation->data; - _ccs_tree_evaluation_data_t *other_data = other->data; - *cmp_ret = data->result < other_data->result ? -1 : - data->result > other_data->result ? 1 : - 0; - if (*cmp_ret) - return CCS_RESULT_SUCCESS; - CCS_VALIDATE(ccs_tree_configuration_cmp( - data->configuration, other_data->configuration, cmp_ret)); - return CCS_RESULT_SUCCESS; -} - -static ccs_result_t -_ccs_tree_evaluation_compare( - ccs_tree_evaluation_t evaluation, - ccs_tree_evaluation_t other, - ccs_comparison_t *result_ret) -{ - CCS_VALIDATE(_ccs_evaluation_binding_compare( - (ccs_evaluation_binding_t)evaluation, - (ccs_evaluation_binding_t)other, result_ret)); - return CCS_RESULT_SUCCESS; -} - -static _ccs_tree_evaluation_ops_t _evaluation_ops = { - {&_ccs_tree_evaluation_del, &_ccs_tree_evaluation_serialize_size, - &_ccs_tree_evaluation_serialize}, - &_ccs_tree_evaluation_hash, - &_ccs_tree_evaluation_cmp, - &_ccs_tree_evaluation_compare}; - -ccs_result_t -ccs_create_tree_evaluation( - ccs_objective_space_t objective_space, - ccs_tree_configuration_t configuration, - ccs_evaluation_result_t result, - size_t num_values, - ccs_datum_t *values, - ccs_tree_evaluation_t *evaluation_ret) -{ - CCS_CHECK_OBJ(objective_space, CCS_OBJECT_TYPE_OBJECTIVE_SPACE); - CCS_CHECK_OBJ(configuration, CCS_OBJECT_TYPE_TREE_CONFIGURATION); - CCS_CHECK_PTR(evaluation_ret); - CCS_CHECK_ARY(num_values, values); - ccs_result_t err; - size_t num_parameters = objective_space->data->num_parameters; - CCS_REFUTE( - values && num_parameters != num_values, - CCS_RESULT_ERROR_INVALID_VALUE); - uintptr_t mem = (uintptr_t)calloc( - 1, sizeof(struct _ccs_tree_evaluation_s) + - sizeof(struct _ccs_tree_evaluation_data_s) + - num_parameters * sizeof(ccs_datum_t)); - CCS_REFUTE(!mem, CCS_RESULT_ERROR_OUT_OF_MEMORY); - CCS_VALIDATE_ERR_GOTO(err, ccs_retain_object(objective_space), errmem); - CCS_VALIDATE_ERR_GOTO(err, ccs_retain_object(configuration), erros); - ccs_tree_evaluation_t eval; - eval = (ccs_tree_evaluation_t)mem; - _ccs_object_init( - &(eval->obj), CCS_OBJECT_TYPE_TREE_EVALUATION, - (_ccs_object_ops_t *)&_evaluation_ops); - eval->data = (struct _ccs_tree_evaluation_data_s - *)(mem + sizeof(struct _ccs_tree_evaluation_s)); - eval->data->num_values = num_parameters; - eval->data->objective_space = objective_space; - eval->data->configuration = configuration; - eval->data->result = result; - eval->data->values = - (ccs_datum_t - *)(mem + sizeof(struct _ccs_tree_evaluation_s) + sizeof(struct _ccs_tree_evaluation_data_s)); - if (values) { - memcpy(eval->data->values, values, - num_parameters * sizeof(ccs_datum_t)); - for (size_t i = 0; i < num_values; i++) - if (values[i].flags & CCS_DATUM_FLAG_TRANSIENT) - CCS_VALIDATE_ERR_GOTO( - err, - ccs_context_validate_value( - (ccs_context_t)objective_space, - i, values[i], - eval->data->values + i), - errc); - } - *evaluation_ret = eval; - return CCS_RESULT_SUCCESS; -errc: - _ccs_object_deinit(&(eval->obj)); - ccs_release_object(configuration); -erros: - ccs_release_object(objective_space); -errmem: - free((void *)mem); - return err; -} - -ccs_result_t -ccs_tree_evaluation_get_configuration( - ccs_tree_evaluation_t evaluation, - ccs_tree_configuration_t *configuration_ret) -{ - CCS_CHECK_OBJ(evaluation, CCS_OBJECT_TYPE_TREE_EVALUATION); - CCS_CHECK_PTR(configuration_ret); - *configuration_ret = evaluation->data->configuration; - return CCS_RESULT_SUCCESS; -} diff --git a/src/tree_evaluation_deserialize.h b/src/tree_evaluation_deserialize.h deleted file mode 100644 index a6472adb..00000000 --- a/src/tree_evaluation_deserialize.h +++ /dev/null @@ -1,122 +0,0 @@ -#ifndef _TREE_EVALUATION_DESERIALIZE_H -#define _TREE_EVALUATION_DESERIALIZE_H -#include "tree_evaluation_internal.h" - -struct _ccs_tree_evaluation_data_mock_s { - _ccs_binding_data_t base; - ccs_tree_configuration_t configuration; - ccs_evaluation_result_t result; -}; -typedef struct _ccs_tree_evaluation_data_mock_s _ccs_tree_evaluation_data_mock_t; - -static inline ccs_result_t -_ccs_deserialize_bin_ccs_tree_evaluation_data( - _ccs_tree_evaluation_data_mock_t *data, - uint32_t version, - size_t *buffer_size, - const char **buffer, - _ccs_object_deserialize_options_t *opts) -{ - CCS_VALIDATE(_ccs_deserialize_bin_ccs_binding_data( - &data->base, version, buffer_size, buffer)); - CCS_VALIDATE(_ccs_object_deserialize_with_opts_check( - (ccs_object_t *)&data->configuration, - CCS_OBJECT_TYPE_TREE_CONFIGURATION, CCS_SERIALIZE_FORMAT_BINARY, - version, buffer_size, buffer, opts)); - CCS_VALIDATE(_ccs_deserialize_bin_ccs_evaluation_result( - &data->result, buffer_size, buffer)); - return CCS_RESULT_SUCCESS; -} - -static inline ccs_result_t -_ccs_deserialize_bin_ccs_tree_evaluation( - ccs_tree_evaluation_t *evaluation_ret, - uint32_t version, - size_t *buffer_size, - const char **buffer, - _ccs_object_deserialize_options_t *opts) -{ - CCS_CHECK_OBJ(opts->handle_map, CCS_OBJECT_TYPE_MAP); - _ccs_object_deserialize_options_t new_opts = *opts; - _ccs_object_internal_t obj; - ccs_object_t handle; - ccs_datum_t d; - ccs_objective_space_t os; - ccs_result_t res = CCS_RESULT_SUCCESS; - CCS_VALIDATE(_ccs_deserialize_bin_ccs_object_internal( - &obj, buffer_size, buffer, &handle)); - CCS_REFUTE( - obj.type != CCS_OBJECT_TYPE_TREE_EVALUATION, - CCS_RESULT_ERROR_INVALID_TYPE); - - new_opts.map_values = CCS_FALSE; - _ccs_tree_evaluation_data_mock_t data = { - {NULL, 0, NULL}, NULL, CCS_RESULT_SUCCESS}; - CCS_VALIDATE_ERR_GOTO( - res, - _ccs_deserialize_bin_ccs_tree_evaluation_data( - &data, version, buffer_size, buffer, &new_opts), - end); - - CCS_VALIDATE_ERR_GOTO( - res, - ccs_map_get(opts->handle_map, ccs_object(data.base.context), &d), - end); - CCS_REFUTE_ERR_GOTO( - res, d.type != CCS_DATA_TYPE_OBJECT, - CCS_RESULT_ERROR_INVALID_HANDLE, end); - os = (ccs_objective_space_t)(d.value.o); - - CCS_VALIDATE_ERR_GOTO( - res, - ccs_create_tree_evaluation( - os, data.configuration, data.result, - data.base.num_values, data.base.values, evaluation_ret), - end); - - if (opts->map_values) - CCS_VALIDATE_ERR_GOTO( - res, - _ccs_object_handle_check_add( - opts->handle_map, handle, - (ccs_object_t)*evaluation_ret), - err_evaluation); - goto end; - -err_evaluation: - ccs_release_object(*evaluation_ret); - *evaluation_ret = NULL; -end: - if (data.configuration) - ccs_release_object(data.configuration); - if (data.base.values) - free(data.base.values); - return res; -} - -static ccs_result_t -_ccs_tree_evaluation_deserialize( - ccs_tree_evaluation_t *evaluation_ret, - ccs_serialize_format_t format, - uint32_t version, - size_t *buffer_size, - const char **buffer, - _ccs_object_deserialize_options_t *opts) -{ - switch (format) { - case CCS_SERIALIZE_FORMAT_BINARY: - CCS_VALIDATE(_ccs_deserialize_bin_ccs_tree_evaluation( - evaluation_ret, version, buffer_size, buffer, opts)); - break; - default: - CCS_RAISE( - CCS_RESULT_ERROR_INVALID_VALUE, - "Unsupported serialization format: %d", format); - } - CCS_VALIDATE(_ccs_object_deserialize_user_data( - (ccs_object_t)*evaluation_ret, format, version, buffer_size, - buffer, opts)); - return CCS_RESULT_SUCCESS; -} - -#endif //_TREE_EVALUATION_DESERIALIZE_H diff --git a/src/tree_evaluation_internal.h b/src/tree_evaluation_internal.h deleted file mode 100644 index ec5f5847..00000000 --- a/src/tree_evaluation_internal.h +++ /dev/null @@ -1,40 +0,0 @@ -#ifndef _TREE_EVALUATION_INTERNAL_H -#define _TREE_EVALUATION_INTERNAL_H -#include "binding_internal.h" - -struct _ccs_tree_evaluation_data_s; -typedef struct _ccs_tree_evaluation_data_s _ccs_tree_evaluation_data_t; - -struct _ccs_tree_evaluation_ops_s { - _ccs_object_ops_t obj_ops; - - ccs_result_t (*hash)( - ccs_tree_evaluation_t tree_evaluation, - ccs_hash_t *hash_ret); - - ccs_result_t (*cmp)( - ccs_tree_evaluation_t tree_evaluation, - ccs_tree_evaluation_t other, - int *cmp_ret); - - ccs_result_t (*compare)( - ccs_tree_evaluation_t evaluation, - ccs_tree_evaluation_t other_evaluation, - ccs_comparison_t *result_ret); -}; -typedef struct _ccs_tree_evaluation_ops_s _ccs_tree_evaluation_ops_t; - -struct _ccs_tree_evaluation_s { - _ccs_object_internal_t obj; - _ccs_tree_evaluation_data_t *data; -}; - -struct _ccs_tree_evaluation_data_s { - ccs_objective_space_t objective_space; - size_t num_values; - ccs_datum_t *values; - ccs_evaluation_result_t result; - ccs_tree_configuration_t configuration; -}; - -#endif //_TREE_EVALUATION_INTERNAL_H diff --git a/src/tree_space.c b/src/tree_space.c index c835e1b7..481d9dce 100644 --- a/src/tree_space.c +++ b/src/tree_space.c @@ -30,19 +30,6 @@ ccs_tree_space_get_name(ccs_tree_space_t tree_space, const char **name_ret) return CCS_RESULT_SUCCESS; } -ccs_result_t -ccs_tree_space_set_rng(ccs_tree_space_t tree_space, ccs_rng_t rng) -{ - CCS_CHECK_OBJ(tree_space, CCS_OBJECT_TYPE_TREE_SPACE); - CCS_CHECK_OBJ(rng, CCS_OBJECT_TYPE_RNG); - CCS_VALIDATE(ccs_retain_object(rng)); - ccs_rng_t tmp = - ((_ccs_tree_space_common_data_t *)(tree_space->data))->rng; - ((_ccs_tree_space_common_data_t *)(tree_space->data))->rng = rng; - CCS_VALIDATE(ccs_release_object(tmp)); - return CCS_RESULT_SUCCESS; -} - ccs_result_t ccs_tree_space_get_rng(ccs_tree_space_t tree_space, ccs_rng_t *rng_ret) { @@ -142,12 +129,14 @@ ccs_tree_space_check_configuration( static inline ccs_result_t _ccs_tree_space_samples( ccs_tree_space_t tree_space, + ccs_rng_t rng, size_t num_configurations, ccs_tree_configuration_t *configurations) { _ccs_tree_space_common_data_t *data = (_ccs_tree_space_common_data_t *)(tree_space->data); - ccs_rng_t rng = data->rng; + if (!rng) + rng = data->rng; ccs_result_t err = CCS_RESULT_SUCCESS; UT_array *arr = NULL; utarray_new(arr, &_size_t_icd); @@ -189,25 +178,32 @@ _ccs_tree_space_samples( ccs_result_t ccs_tree_space_sample( ccs_tree_space_t tree_space, + ccs_rng_t rng, ccs_tree_configuration_t *configuration_ret) { CCS_CHECK_OBJ(tree_space, CCS_OBJECT_TYPE_TREE_SPACE); + if (rng) + CCS_CHECK_OBJ(rng, CCS_OBJECT_TYPE_RNG); CCS_CHECK_PTR(configuration_ret); - CCS_VALIDATE(_ccs_tree_space_samples(tree_space, 1, configuration_ret)); + CCS_VALIDATE( + _ccs_tree_space_samples(tree_space, rng, 1, configuration_ret)); return CCS_RESULT_SUCCESS; } ccs_result_t ccs_tree_space_samples( ccs_tree_space_t tree_space, + ccs_rng_t rng, size_t num_configurations, ccs_tree_configuration_t *configurations) { CCS_CHECK_OBJ(tree_space, CCS_OBJECT_TYPE_TREE_SPACE); + if (rng) + CCS_CHECK_OBJ(rng, CCS_OBJECT_TYPE_RNG); CCS_CHECK_ARY(num_configurations, configurations); if (num_configurations == 0) return CCS_RESULT_SUCCESS; CCS_VALIDATE(_ccs_tree_space_samples( - tree_space, num_configurations, configurations)); + tree_space, rng, num_configurations, configurations)); return CCS_RESULT_SUCCESS; } diff --git a/src/tree_space_deserialize.h b/src/tree_space_deserialize.h index 8a6f469e..849781ec 100644 --- a/src/tree_space_deserialize.h +++ b/src/tree_space_deserialize.h @@ -46,7 +46,7 @@ _ccs_deserialize_bin_tree_space_static( CCS_VALIDATE_ERR_GOTO( res, ccs_create_static_tree_space( - data.name, data.tree, tree_space_ret), + data.name, data.tree, data.rng, tree_space_ret), end); end: if (data.rng) @@ -84,13 +84,10 @@ _ccs_deserialize_bin_tree_space_dynamic( CCS_VALIDATE_ERR_GOTO( res, ccs_create_dynamic_tree_space( - data.common_data.name, data.common_data.tree, vector, - opts->data, tree_space_ret), + data.common_data.name, data.common_data.tree, + data.common_data.rng, vector, opts->data, + tree_space_ret), end); - CCS_VALIDATE_ERR_GOTO( - res, - ccs_tree_space_set_rng(*tree_space_ret, data.common_data.rng), - tree_space); if (vector->deserialize_state) CCS_VALIDATE_ERR_GOTO( res, diff --git a/src/tree_space_dynamic.c b/src/tree_space_dynamic.c index b0888291..0ff5a2ed 100644 --- a/src/tree_space_dynamic.c +++ b/src/tree_space_dynamic.c @@ -251,12 +251,15 @@ ccs_result_t ccs_create_dynamic_tree_space( const char *name, ccs_tree_t tree, + ccs_rng_t rng, ccs_dynamic_tree_space_vector_t *vector, void *tree_space_data, ccs_tree_space_t *tree_space_ret) { CCS_CHECK_PTR(name); CCS_CHECK_OBJ(tree, CCS_OBJECT_TYPE_TREE); + if (rng) + CCS_CHECK_OBJ(rng, CCS_OBJECT_TYPE_RNG); CCS_CHECK_PTR(vector); CCS_CHECK_PTR(vector->del); CCS_CHECK_PTR(vector->get_child); @@ -267,8 +270,10 @@ ccs_create_dynamic_tree_space( sizeof(struct _ccs_tree_space_dynamic_data_s) + strlen(name) + 1); CCS_REFUTE(!mem, CCS_RESULT_ERROR_OUT_OF_MEMORY); - ccs_rng_t rng; - CCS_VALIDATE_ERR_GOTO(err, ccs_create_rng(&rng), errmem); + if (!rng) + CCS_VALIDATE_ERR_GOTO(err, ccs_create_rng(&rng), errmem); + else + CCS_VALIDATE_ERR_GOTO(err, ccs_retain_object(rng), errmem); CCS_VALIDATE_ERR_GOTO(err, ccs_retain_object(tree), err_rng); ccs_tree_space_t tree_space; diff --git a/src/tree_space_static.c b/src/tree_space_static.c index f4ef62ee..00c41ee7 100644 --- a/src/tree_space_static.c +++ b/src/tree_space_static.c @@ -172,10 +172,13 @@ ccs_result_t ccs_create_static_tree_space( const char *name, ccs_tree_t tree, + ccs_rng_t rng, ccs_tree_space_t *tree_space_ret) { CCS_CHECK_PTR(name); CCS_CHECK_OBJ(tree, CCS_OBJECT_TYPE_TREE); + if (rng) + CCS_CHECK_OBJ(rng, CCS_OBJECT_TYPE_RNG); CCS_CHECK_PTR(tree_space_ret); ccs_result_t err; uintptr_t mem = (uintptr_t)calloc( @@ -183,8 +186,10 @@ ccs_create_static_tree_space( sizeof(struct _ccs_tree_space_static_data_s) + strlen(name) + 1); CCS_REFUTE(!mem, CCS_RESULT_ERROR_OUT_OF_MEMORY); - ccs_rng_t rng; - CCS_VALIDATE_ERR_GOTO(err, ccs_create_rng(&rng), errmem); + if (!rng) + CCS_VALIDATE_ERR_GOTO(err, ccs_create_rng(&rng), errmem); + else + CCS_VALIDATE_ERR_GOTO(err, ccs_retain_object(rng), errmem); CCS_VALIDATE_ERR_GOTO(err, ccs_retain_object(tree), err_rng); ccs_tree_space_t tree_space; diff --git a/src/tree_tuner.c b/src/tree_tuner.c deleted file mode 100644 index be2374bd..00000000 --- a/src/tree_tuner.c +++ /dev/null @@ -1,139 +0,0 @@ -#include "cconfigspace_internal.h" -#include "tree_tuner_internal.h" - -static inline _ccs_tree_tuner_ops_t * -ccs_tree_tuner_get_ops(ccs_tree_tuner_t tuner) -{ - return (_ccs_tree_tuner_ops_t *)tuner->obj.ops; -} - -ccs_result_t -ccs_tree_tuner_get_type(ccs_tree_tuner_t tuner, ccs_tree_tuner_type_t *type_ret) -{ - CCS_CHECK_OBJ(tuner, CCS_OBJECT_TYPE_TREE_TUNER); - CCS_CHECK_PTR(type_ret); - _ccs_tree_tuner_common_data_t *d = - (_ccs_tree_tuner_common_data_t *)tuner->data; - *type_ret = d->type; - return CCS_RESULT_SUCCESS; -} - -ccs_result_t -ccs_tree_tuner_get_name(ccs_tree_tuner_t tuner, const char **name_ret) -{ - CCS_CHECK_OBJ(tuner, CCS_OBJECT_TYPE_TREE_TUNER); - CCS_CHECK_PTR(name_ret); - _ccs_tree_tuner_common_data_t *d = - (_ccs_tree_tuner_common_data_t *)tuner->data; - *name_ret = d->name; - return CCS_RESULT_SUCCESS; -} - -ccs_result_t -ccs_tree_tuner_get_tree_space( - ccs_tree_tuner_t tuner, - ccs_tree_space_t *tree_space_ret) -{ - CCS_CHECK_OBJ(tuner, CCS_OBJECT_TYPE_TREE_TUNER); - CCS_CHECK_PTR(tree_space_ret); - _ccs_tree_tuner_common_data_t *d = - (_ccs_tree_tuner_common_data_t *)tuner->data; - *tree_space_ret = d->tree_space; - return CCS_RESULT_SUCCESS; -} - -ccs_result_t -ccs_tree_tuner_get_objective_space( - ccs_tree_tuner_t tuner, - ccs_objective_space_t *objective_space_ret) -{ - CCS_CHECK_OBJ(tuner, CCS_OBJECT_TYPE_TREE_TUNER); - CCS_CHECK_PTR(objective_space_ret); - _ccs_tree_tuner_common_data_t *d = - (_ccs_tree_tuner_common_data_t *)tuner->data; - *objective_space_ret = d->objective_space; - return CCS_RESULT_SUCCESS; -} - -ccs_result_t -ccs_tree_tuner_ask( - ccs_tree_tuner_t tuner, - size_t num_configurations, - ccs_tree_configuration_t *configurations, - size_t *num_configurations_ret) -{ - CCS_CHECK_OBJ(tuner, CCS_OBJECT_TYPE_TREE_TUNER); - CCS_CHECK_ARY(num_configurations, configurations); - CCS_REFUTE( - !configurations && !num_configurations_ret, - CCS_RESULT_ERROR_INVALID_VALUE); - _ccs_tree_tuner_ops_t *ops = ccs_tree_tuner_get_ops(tuner); - CCS_VALIDATE(ops->ask( - tuner, num_configurations, configurations, - num_configurations_ret)); - return CCS_RESULT_SUCCESS; -} - -ccs_result_t -ccs_tree_tuner_tell( - ccs_tree_tuner_t tuner, - size_t num_evaluations, - ccs_tree_evaluation_t *evaluations) -{ - CCS_CHECK_OBJ(tuner, CCS_OBJECT_TYPE_TREE_TUNER); - CCS_CHECK_ARY(num_evaluations, evaluations); - /* TODO: check that evaluations have the same objective and - * configuration sapce than the tuner */ - _ccs_tree_tuner_ops_t *ops = ccs_tree_tuner_get_ops(tuner); - CCS_VALIDATE(ops->tell(tuner, num_evaluations, evaluations)); - return CCS_RESULT_SUCCESS; -} - -ccs_result_t -ccs_tree_tuner_get_optima( - ccs_tree_tuner_t tuner, - size_t num_evaluations, - ccs_tree_evaluation_t *evaluations, - size_t *num_evaluations_ret) -{ - CCS_CHECK_OBJ(tuner, CCS_OBJECT_TYPE_TREE_TUNER); - CCS_CHECK_ARY(num_evaluations, evaluations); - CCS_REFUTE( - !evaluations && !num_evaluations_ret, - CCS_RESULT_ERROR_INVALID_VALUE); - _ccs_tree_tuner_ops_t *ops = ccs_tree_tuner_get_ops(tuner); - CCS_VALIDATE(ops->get_optima( - tuner, num_evaluations, evaluations, num_evaluations_ret)); - return CCS_RESULT_SUCCESS; -} - -ccs_result_t -ccs_tree_tuner_get_history( - ccs_tree_tuner_t tuner, - size_t num_evaluations, - ccs_tree_evaluation_t *evaluations, - size_t *num_evaluations_ret) -{ - CCS_CHECK_OBJ(tuner, CCS_OBJECT_TYPE_TREE_TUNER); - CCS_CHECK_ARY(num_evaluations, evaluations); - CCS_REFUTE( - !evaluations && !num_evaluations_ret, - CCS_RESULT_ERROR_INVALID_VALUE); - _ccs_tree_tuner_ops_t *ops = ccs_tree_tuner_get_ops(tuner); - CCS_VALIDATE(ops->get_history( - tuner, num_evaluations, evaluations, num_evaluations_ret)); - return CCS_RESULT_SUCCESS; -} - -ccs_result_t -ccs_tree_tuner_suggest( - ccs_tree_tuner_t tuner, - ccs_tree_configuration_t *configuration) -{ - CCS_CHECK_OBJ(tuner, CCS_OBJECT_TYPE_TREE_TUNER); - _ccs_tree_tuner_ops_t *ops = ccs_tree_tuner_get_ops(tuner); - CCS_REFUTE(!ops->suggest, CCS_RESULT_ERROR_UNSUPPORTED_OPERATION); - CCS_CHECK_PTR(configuration); - CCS_VALIDATE(ops->suggest(tuner, configuration)); - return CCS_RESULT_SUCCESS; -} diff --git a/src/tree_tuner_deserialize.h b/src/tree_tuner_deserialize.h deleted file mode 100644 index 9b1f6f2b..00000000 --- a/src/tree_tuner_deserialize.h +++ /dev/null @@ -1,321 +0,0 @@ -#ifndef _TREE_TUNER_DESERIALIZE_H -#define _TREE_TUNER_DESERIALIZE_H -#include "tree_tuner_internal.h" - -struct _ccs_random_tree_tuner_data_mock_s { - _ccs_tree_tuner_common_data_t common_data; - size_t size_history; - size_t size_optima; - ccs_tree_evaluation_t *history; - ccs_tree_evaluation_t *optima; -}; -typedef struct _ccs_random_tree_tuner_data_mock_s - _ccs_random_tree_tuner_data_mock_t; - -static inline ccs_result_t -_ccs_deserialize_bin_size_ccs_tree_tuner_common_data( - _ccs_tree_tuner_common_data_t *data, - uint32_t version, - size_t *buffer_size, - const char **buffer, - _ccs_object_deserialize_options_t *opts) -{ - CCS_VALIDATE(_ccs_deserialize_bin_ccs_tree_tuner_type( - &data->type, buffer_size, buffer)); - CCS_VALIDATE( - _ccs_deserialize_bin_string(&data->name, buffer_size, buffer)); - CCS_VALIDATE(_ccs_object_deserialize_with_opts_check( - (ccs_object_t *)&data->objective_space, - CCS_OBJECT_TYPE_OBJECTIVE_SPACE, CCS_SERIALIZE_FORMAT_BINARY, - version, buffer_size, buffer, opts)); - return CCS_RESULT_SUCCESS; -} - -static inline ccs_result_t -_ccs_deserialize_bin_ccs_random_tree_tuner_data( - _ccs_random_tree_tuner_data_mock_t *data, - uint32_t version, - size_t *buffer_size, - const char **buffer, - _ccs_object_deserialize_options_t *opts) -{ - uintptr_t mem; - - CCS_VALIDATE(_ccs_deserialize_bin_size_ccs_tree_tuner_common_data( - &data->common_data, version, buffer_size, buffer, opts)); - CCS_VALIDATE(_ccs_deserialize_bin_size( - &data->size_history, buffer_size, buffer)); - CCS_VALIDATE(_ccs_deserialize_bin_size( - &data->size_optima, buffer_size, buffer)); - - if (!(data->size_history + data->size_optima)) - return CCS_RESULT_SUCCESS; - mem = (uintptr_t)calloc( - (data->size_history + data->size_optima), - sizeof(ccs_tree_evaluation_t)); - CCS_REFUTE(!mem, CCS_RESULT_ERROR_OUT_OF_MEMORY); - - data->history = (ccs_tree_evaluation_t *)mem; - mem += data->size_history * sizeof(ccs_tree_evaluation_t); - data->optima = (ccs_tree_evaluation_t *)mem; - - for (size_t i = 0; i < data->size_history; i++) - CCS_VALIDATE(_ccs_object_deserialize_with_opts_check( - (ccs_object_t *)data->history + i, - CCS_OBJECT_TYPE_TREE_EVALUATION, - CCS_SERIALIZE_FORMAT_BINARY, version, buffer_size, - buffer, opts)); - - for (size_t i = 0; i < data->size_optima; i++) - CCS_VALIDATE(_ccs_deserialize_bin_ccs_object( - (ccs_object_t *)data->optima + i, buffer_size, buffer)); - for (size_t i = 0; i < data->size_optima; i++) { - ccs_datum_t d; - CCS_VALIDATE(ccs_map_get( - opts->handle_map, ccs_object(data->optima[i]), &d)); - CCS_REFUTE( - d.type != CCS_DATA_TYPE_OBJECT, - CCS_RESULT_ERROR_INVALID_HANDLE); - data->optima[i] = (ccs_tree_evaluation_t)(d.value.o); - } - return CCS_RESULT_SUCCESS; -} - -struct _ccs_random_tree_tuner_data_clone_s { - _ccs_tree_tuner_common_data_t common_data; - UT_array *history; - UT_array *optima; - UT_array *old_optima; -}; -typedef struct _ccs_random_tree_tuner_data_clone_s - _ccs_random_tree_tuner_data_clone_t; - -#undef utarray_oom -#define utarray_oom() \ - { \ - CCS_RAISE_ERR_GOTO( \ - res, CCS_RESULT_ERROR_OUT_OF_MEMORY, tuner, \ - "Out of memory to allocate array"); \ - } - -static inline ccs_result_t -_ccs_deserialize_bin_random_tree_tuner( - ccs_tree_tuner_t *tuner_ret, - uint32_t version, - size_t *buffer_size, - const char **buffer, - _ccs_object_deserialize_options_t *opts) -{ - _ccs_random_tree_tuner_data_mock_t data = { - {(ccs_tree_tuner_type_t)0, NULL, NULL, NULL}, 0, 0, NULL, NULL}; - _ccs_random_tree_tuner_data_clone_t *odata = NULL; - ccs_result_t res = CCS_RESULT_SUCCESS; - CCS_VALIDATE_ERR_GOTO( - res, - _ccs_deserialize_bin_ccs_random_tree_tuner_data( - &data, version, buffer_size, buffer, opts), - evaluations); - CCS_VALIDATE_ERR_GOTO( - res, - ccs_create_random_tree_tuner( - data.common_data.name, data.common_data.objective_space, - tuner_ret), - evaluations); - odata = (_ccs_random_tree_tuner_data_clone_t *)((*tuner_ret)->data); - for (size_t i = 0; i < data.size_history; i++) - utarray_push_back(odata->history, data.history + i); - for (size_t i = 0; i < data.size_optima; i++) - utarray_push_back(odata->optima, data.optima + i); - goto end; -tuner: - ccs_release_object(*tuner_ret); - *tuner_ret = NULL; -evaluations: - if (data.history) - for (size_t i = 0; i < data.size_history; i++) - if (data.history[i]) - ccs_release_object(data.history[i]); -end: - if (data.common_data.objective_space) - ccs_release_object(data.common_data.objective_space); - if (data.history) - free(data.history); - return res; -} - -#undef utarray_oom - -struct _ccs_user_defined_tree_tuner_data_mock_s { - _ccs_random_tree_tuner_data_mock_t base_data; - _ccs_blob_t blob; -}; -typedef struct _ccs_user_defined_tree_tuner_data_mock_s - _ccs_user_defined_tree_tuner_data_mock_t; - -static inline ccs_result_t -_ccs_deserialize_bin_ccs_user_defined_tree_tuner_data( - _ccs_user_defined_tree_tuner_data_mock_t *data, - uint32_t version, - size_t *buffer_size, - const char **buffer, - _ccs_object_deserialize_options_t *opts) -{ - CCS_VALIDATE(_ccs_deserialize_bin_ccs_random_tree_tuner_data( - &data->base_data, version, buffer_size, buffer, opts)); - CCS_VALIDATE(_ccs_deserialize_bin_ccs_blob( - &data->blob, buffer_size, buffer)); - return CCS_RESULT_SUCCESS; -} - -static inline ccs_result_t -_ccs_deserialize_bin_user_defined_tree_tuner( - ccs_tree_tuner_t *tuner_ret, - uint32_t version, - size_t *buffer_size, - const char **buffer, - _ccs_object_deserialize_options_t *opts) -{ - _ccs_user_defined_tree_tuner_data_mock_t data = { - {{(ccs_tree_tuner_type_t)0, NULL, NULL, NULL}, 0, 0, NULL, NULL}, - {0, NULL}}; - ccs_user_defined_tree_tuner_vector_t *vector = - (ccs_user_defined_tree_tuner_vector_t *)opts->vector; - ccs_result_t res = CCS_RESULT_SUCCESS; - CCS_VALIDATE_ERR_GOTO( - res, - _ccs_deserialize_bin_ccs_user_defined_tree_tuner_data( - &data, version, buffer_size, buffer, opts), - end); - CCS_VALIDATE_ERR_GOTO( - res, - ccs_create_user_defined_tree_tuner( - data.base_data.common_data.name, - data.base_data.common_data.objective_space, vector, - opts->data, tuner_ret), - end); - if (vector->deserialize_state) - CCS_VALIDATE_ERR_GOTO( - res, - vector->deserialize_state( - *tuner_ret, data.base_data.size_history, - data.base_data.history, - data.base_data.size_optima, - data.base_data.optima, data.blob.sz, - data.blob.blob), - tuner); - else - CCS_VALIDATE_ERR_GOTO( - res, - vector->tell( - *tuner_ret, data.base_data.size_history, - data.base_data.history), - tuner); - goto end; -tuner: - ccs_release_object(*tuner_ret); - *tuner_ret = NULL; -end: - if (data.base_data.common_data.objective_space) - ccs_release_object(data.base_data.common_data.objective_space); - if (data.base_data.history) { - for (size_t i = 0; i < data.base_data.size_history; i++) - if (data.base_data.history[i]) - ccs_release_object(data.base_data.history[i]); - free(data.base_data.history); - } - return res; -} - -static inline ccs_result_t -_ccs_deserialize_bin_tree_tuner( - ccs_tree_tuner_t *tuner_ret, - uint32_t version, - size_t *buffer_size, - const char **buffer, - _ccs_object_deserialize_options_t *opts) -{ - _ccs_object_deserialize_options_t new_opts = *opts; - _ccs_object_internal_t obj; - ccs_object_t handle; - ccs_result_t res; - CCS_VALIDATE(_ccs_deserialize_bin_ccs_object_internal( - &obj, buffer_size, buffer, &handle)); - CCS_REFUTE( - obj.type != CCS_OBJECT_TYPE_TREE_TUNER, - CCS_RESULT_ERROR_INVALID_TYPE); - - ccs_tree_tuner_type_t ttype; - CCS_VALIDATE( - _ccs_peek_bin_ccs_tree_tuner_type(&ttype, buffer_size, buffer)); - if (ttype == CCS_TREE_TUNER_TYPE_USER_DEFINED) - CCS_CHECK_PTR(opts->vector); - - new_opts.map_values = CCS_TRUE; - CCS_VALIDATE(ccs_create_map(&new_opts.handle_map)); - - switch (ttype) { - case CCS_TREE_TUNER_TYPE_RANDOM: - CCS_VALIDATE_ERR_GOTO( - res, - _ccs_deserialize_bin_random_tree_tuner( - tuner_ret, version, buffer_size, buffer, - &new_opts), - end); - break; - case CCS_TREE_TUNER_TYPE_USER_DEFINED: - CCS_VALIDATE_ERR_GOTO( - res, - _ccs_deserialize_bin_user_defined_tree_tuner( - tuner_ret, version, buffer_size, buffer, - &new_opts), - end); - break; - default: - CCS_RAISE( - CCS_RESULT_ERROR_INVALID_TYPE, - "Unsupported tuner type: %d", ttype); - } - if (opts->handle_map) - CCS_VALIDATE_ERR_GOTO( - res, - _ccs_object_handle_check_add( - opts->handle_map, handle, - (ccs_object_t)*tuner_ret), - err_tuner); - - res = CCS_RESULT_SUCCESS; - goto end; -err_tuner: - ccs_release_object(*tuner_ret); - *tuner_ret = NULL; -end: - ccs_release_object(new_opts.handle_map); - return res; -} - -static ccs_result_t -_ccs_tree_tuner_deserialize( - ccs_tree_tuner_t *tuner_ret, - ccs_serialize_format_t format, - uint32_t version, - size_t *buffer_size, - const char **buffer, - _ccs_object_deserialize_options_t *opts) -{ - switch (format) { - case CCS_SERIALIZE_FORMAT_BINARY: - CCS_VALIDATE(_ccs_deserialize_bin_tree_tuner( - tuner_ret, version, buffer_size, buffer, opts)); - break; - default: - CCS_RAISE( - CCS_RESULT_ERROR_INVALID_VALUE, - "Unsupported serialization format: %d", format); - } - CCS_VALIDATE(_ccs_object_deserialize_user_data( - (ccs_object_t)*tuner_ret, format, version, buffer_size, buffer, - opts)); - return CCS_RESULT_SUCCESS; -} - -#endif //_TREE_TUNER_DESERIALIZE_H diff --git a/src/tree_tuner_internal.h b/src/tree_tuner_internal.h deleted file mode 100644 index 5672c635..00000000 --- a/src/tree_tuner_internal.h +++ /dev/null @@ -1,86 +0,0 @@ -#ifndef _TREE_TUNER_INTERNAL_H -#define _TREE_TUNER_INTERNAL_H -#include "cconfigspace_internal.h" -#include "tree_space_internal.h" -#include "objective_space_internal.h" - -struct _ccs_tree_tuner_data_s; -typedef struct _ccs_tree_tuner_data_s _ccs_tree_tuner_data_t; - -struct _ccs_tree_tuner_ops_s { - _ccs_object_ops_t obj_ops; - - ccs_result_t (*ask)( - ccs_tree_tuner_t tree, - size_t num_configurations, - ccs_tree_configuration_t *configurations, - size_t *num_configurations_ret); - - ccs_result_t (*tell)( - ccs_tree_tuner_t tree, - size_t num_evaluations, - ccs_tree_evaluation_t *evaluations); - - ccs_result_t (*get_optima)( - ccs_tree_tuner_t tree, - size_t num_evaluations, - ccs_tree_evaluation_t *evaluations, - size_t *num_evaluations_ret); - - ccs_result_t (*get_history)( - ccs_tree_tuner_t tree, - size_t num_evaluations, - ccs_tree_evaluation_t *evaluations, - size_t *num_evaluations_ret); - - ccs_result_t (*suggest)( - ccs_tree_tuner_t tree, - ccs_tree_configuration_t *configuration); -}; -typedef struct _ccs_tree_tuner_ops_s _ccs_tree_tuner_ops_t; - -struct _ccs_tree_tuner_s { - _ccs_object_internal_t obj; - _ccs_tree_tuner_data_t *data; -}; - -struct _ccs_tree_tuner_common_data_s { - ccs_tree_tuner_type_t type; - const char *name; - ccs_tree_space_t tree_space; - ccs_objective_space_t objective_space; -}; -typedef struct _ccs_tree_tuner_common_data_s _ccs_tree_tuner_common_data_t; - -static inline ccs_result_t -_ccs_serialize_bin_size_ccs_tree_tuner_common_data( - _ccs_tree_tuner_common_data_t *data, - size_t *cum_size, - _ccs_object_serialize_options_t *opts) -{ - *cum_size += _ccs_serialize_bin_size_ccs_tree_tuner_type(data->type); - *cum_size += _ccs_serialize_bin_size_string(data->name); - CCS_VALIDATE(data->objective_space->obj.ops->serialize_size( - data->objective_space, CCS_SERIALIZE_FORMAT_BINARY, cum_size, - opts)); - return CCS_RESULT_SUCCESS; -} - -static inline ccs_result_t -_ccs_serialize_bin_ccs_tree_tuner_common_data( - _ccs_tree_tuner_common_data_t *data, - size_t *buffer_size, - char **buffer, - _ccs_object_serialize_options_t *opts) -{ - CCS_VALIDATE(_ccs_serialize_bin_ccs_tree_tuner_type( - data->type, buffer_size, buffer)); - CCS_VALIDATE( - _ccs_serialize_bin_string(data->name, buffer_size, buffer)); - CCS_VALIDATE(data->objective_space->obj.ops->serialize( - data->objective_space, CCS_SERIALIZE_FORMAT_BINARY, buffer_size, - buffer, opts)); - return CCS_RESULT_SUCCESS; -} - -#endif //_TREE_TUNER_INTERNAL_H diff --git a/src/tree_tuner_random.c b/src/tree_tuner_random.c deleted file mode 100644 index ffcbe062..00000000 --- a/src/tree_tuner_random.c +++ /dev/null @@ -1,414 +0,0 @@ -#include "cconfigspace_internal.h" -#include "tree_tuner_internal.h" -#include "tree_evaluation_internal.h" - -#include "utarray.h" - -struct _ccs_random_tree_tuner_data_s { - _ccs_tree_tuner_common_data_t common_data; - UT_array *history; - UT_array *optima; - UT_array *old_optima; -}; -typedef struct _ccs_random_tree_tuner_data_s _ccs_random_tree_tuner_data_t; - -static ccs_result_t -_ccs_tree_tuner_random_del(ccs_object_t o) -{ - _ccs_random_tree_tuner_data_t *d = - (_ccs_random_tree_tuner_data_t *)((ccs_tree_tuner_t)o)->data; - ccs_release_object(d->common_data.tree_space); - ccs_release_object(d->common_data.objective_space); - ccs_tree_evaluation_t *e = NULL; - while ((e = (ccs_tree_evaluation_t *)utarray_next(d->history, e))) - ccs_release_object(*e); - utarray_free(d->history); - utarray_free(d->optima); - utarray_free(d->old_optima); - return CCS_RESULT_SUCCESS; -} - -static inline ccs_result_t -_ccs_serialize_bin_size_ccs_random_tree_tuner_data( - _ccs_random_tree_tuner_data_t *data, - size_t *cum_size, - _ccs_object_serialize_options_t *opts) -{ - ccs_tree_evaluation_t *e = NULL; - CCS_VALIDATE(_ccs_serialize_bin_size_ccs_tree_tuner_common_data( - &data->common_data, cum_size, opts)); - *cum_size += _ccs_serialize_bin_size_size(utarray_len(data->history)); - *cum_size += _ccs_serialize_bin_size_size(utarray_len(data->optima)); - while ((e = (ccs_tree_evaluation_t *)utarray_next(data->history, e))) - CCS_VALIDATE((*e)->obj.ops->serialize_size( - *e, CCS_SERIALIZE_FORMAT_BINARY, cum_size, opts)); - e = NULL; - while ((e = (ccs_tree_evaluation_t *)utarray_next(data->optima, e))) - *cum_size += _ccs_serialize_bin_size_ccs_object(*e); - return CCS_RESULT_SUCCESS; -} - -static inline ccs_result_t -_ccs_serialize_bin_ccs_random_tree_tuner_data( - _ccs_random_tree_tuner_data_t *data, - size_t *buffer_size, - char **buffer, - _ccs_object_serialize_options_t *opts) -{ - ccs_tree_evaluation_t *e = NULL; - CCS_VALIDATE(_ccs_serialize_bin_ccs_tree_tuner_common_data( - &data->common_data, buffer_size, buffer, opts)); - CCS_VALIDATE(_ccs_serialize_bin_size( - utarray_len(data->history), buffer_size, buffer)); - CCS_VALIDATE(_ccs_serialize_bin_size( - utarray_len(data->optima), buffer_size, buffer)); - while ((e = (ccs_tree_evaluation_t *)utarray_next(data->history, e))) - CCS_VALIDATE((*e)->obj.ops->serialize( - *e, CCS_SERIALIZE_FORMAT_BINARY, buffer_size, buffer, - opts)); - e = NULL; - while ((e = (ccs_tree_evaluation_t *)utarray_next(data->optima, e))) - CCS_VALIDATE( - _ccs_serialize_bin_ccs_object(*e, buffer_size, buffer)); - return CCS_RESULT_SUCCESS; -} - -static inline ccs_result_t -_ccs_serialize_bin_size_ccs_random_tree_tuner( - ccs_tree_tuner_t tuner, - size_t *cum_size, - _ccs_object_serialize_options_t *opts) -{ - _ccs_random_tree_tuner_data_t *data = - (_ccs_random_tree_tuner_data_t *)(tuner->data); - *cum_size += _ccs_serialize_bin_size_ccs_object_internal( - (_ccs_object_internal_t *)tuner); - CCS_VALIDATE(_ccs_serialize_bin_size_ccs_random_tree_tuner_data( - data, cum_size, opts)); - return CCS_RESULT_SUCCESS; -} - -static inline ccs_result_t -_ccs_serialize_bin_ccs_random_tree_tuner( - ccs_tree_tuner_t tuner, - size_t *buffer_size, - char **buffer, - _ccs_object_serialize_options_t *opts) -{ - _ccs_random_tree_tuner_data_t *data = - (_ccs_random_tree_tuner_data_t *)(tuner->data); - CCS_VALIDATE(_ccs_serialize_bin_ccs_object_internal( - (_ccs_object_internal_t *)tuner, buffer_size, buffer)); - CCS_VALIDATE(_ccs_serialize_bin_ccs_random_tree_tuner_data( - data, buffer_size, buffer, opts)); - return CCS_RESULT_SUCCESS; -} - -static ccs_result_t -_ccs_tree_tuner_random_serialize_size( - ccs_object_t object, - ccs_serialize_format_t format, - size_t *cum_size, - _ccs_object_serialize_options_t *opts) -{ - switch (format) { - case CCS_SERIALIZE_FORMAT_BINARY: - CCS_VALIDATE(_ccs_serialize_bin_size_ccs_random_tree_tuner( - (ccs_tree_tuner_t)object, cum_size, opts)); - break; - default: - CCS_RAISE( - CCS_RESULT_ERROR_INVALID_VALUE, - "Unsupported serialization format: %d", format); - } - CCS_VALIDATE(_ccs_object_serialize_user_data_size( - object, format, cum_size, opts)); - return CCS_RESULT_SUCCESS; -} - -static ccs_result_t -_ccs_tree_tuner_random_serialize( - ccs_object_t object, - ccs_serialize_format_t format, - size_t *buffer_size, - char **buffer, - _ccs_object_serialize_options_t *opts) -{ - switch (format) { - case CCS_SERIALIZE_FORMAT_BINARY: - CCS_VALIDATE(_ccs_serialize_bin_ccs_random_tree_tuner( - (ccs_tree_tuner_t)object, buffer_size, buffer, opts)); - break; - default: - CCS_RAISE( - CCS_RESULT_ERROR_INVALID_VALUE, - "Unsupported serialization format: %d", format); - } - CCS_VALIDATE(_ccs_object_serialize_user_data( - object, format, buffer_size, buffer, opts)); - return CCS_RESULT_SUCCESS; -} - -static ccs_result_t -_ccs_tree_tuner_random_ask( - ccs_tree_tuner_t tuner, - size_t num_configurations, - ccs_tree_configuration_t *configurations, - size_t *num_configurations_ret) -{ - _ccs_random_tree_tuner_data_t *d = - (_ccs_random_tree_tuner_data_t *)tuner->data; - if (!configurations) { - *num_configurations_ret = 1; - return CCS_RESULT_SUCCESS; - } - CCS_VALIDATE(ccs_tree_space_samples( - d->common_data.tree_space, num_configurations, configurations)); - if (num_configurations_ret) - *num_configurations_ret = num_configurations; - return CCS_RESULT_SUCCESS; -} -#undef utarray_oom -#define utarray_oom() \ - { \ - ccs_release_object(evaluations[i]); \ - CCS_RAISE( \ - CCS_RESULT_ERROR_OUT_OF_MEMORY, \ - "Out of memory to allocate array"); \ - } -static ccs_result_t -_ccs_tree_tuner_random_tell( - ccs_tree_tuner_t tuner, - size_t num_evaluations, - ccs_tree_evaluation_t *evaluations) -{ - _ccs_random_tree_tuner_data_t *d = - (_ccs_random_tree_tuner_data_t *)tuner->data; - UT_array *history = d->history; - ccs_result_t err; - for (size_t i = 0; i < num_evaluations; i++) { - ccs_evaluation_result_t result; - CCS_VALIDATE(ccs_evaluation_binding_get_result( - (ccs_evaluation_binding_t)evaluations[i], &result)); - if (!result) { - int discard = 0; - UT_array *tmp; - ccs_retain_object(evaluations[i]); - utarray_push_back(history, evaluations + i); - tmp = d->old_optima; - d->old_optima = d->optima; - d->optima = tmp; - utarray_clear(d->optima); - ccs_tree_evaluation_t *eval = NULL; -#undef utarray_oom -#define utarray_oom() \ - { \ - d->optima = d->old_optima; \ - CCS_RAISE( \ - CCS_RESULT_ERROR_OUT_OF_MEMORY, \ - "Out of memory to allocate array"); \ - } - while ((eval = (ccs_tree_evaluation_t *)utarray_next( - d->old_optima, eval))) { - if (!discard) { - ccs_comparison_t cmp; - err = ccs_evaluation_binding_compare( - (ccs_evaluation_binding_t) - evaluations[i], - (ccs_evaluation_binding_t)*eval, - &cmp); - if (err) - discard = 1; - else - switch (cmp) { - case CCS_COMPARISON_EQUIVALENT: - case CCS_COMPARISON_WORSE: - discard = 1; - utarray_push_back( - d->optima, - eval); - break; - case CCS_COMPARISON_BETTER: - break; - case CCS_COMPARISON_NOT_COMPARABLE: - default: - utarray_push_back( - d->optima, - eval); - break; - } - } else { - utarray_push_back(d->optima, eval); - } - } - if (!discard) - utarray_push_back(d->optima, evaluations + i); - } - } - return CCS_RESULT_SUCCESS; -} - -static ccs_result_t -_ccs_tree_tuner_random_get_optima( - ccs_tree_tuner_t tuner, - size_t num_evaluations, - ccs_tree_evaluation_t *evaluations, - size_t *num_evaluations_ret) -{ - _ccs_random_tree_tuner_data_t *d = - (_ccs_random_tree_tuner_data_t *)tuner->data; - size_t count = utarray_len(d->optima); - if (evaluations) { - CCS_REFUTE( - num_evaluations < count, - CCS_RESULT_ERROR_INVALID_VALUE); - ccs_tree_evaluation_t *eval = NULL; - size_t index = 0; - while ((eval = (ccs_tree_evaluation_t *)utarray_next( - d->optima, eval))) - evaluations[index++] = *eval; - for (size_t i = count; i < num_evaluations; i++) - evaluations[i] = NULL; - } - if (num_evaluations_ret) - *num_evaluations_ret = count; - return CCS_RESULT_SUCCESS; -} - -static ccs_result_t -_ccs_tree_tuner_random_get_history( - ccs_tree_tuner_t tuner, - size_t num_evaluations, - ccs_tree_evaluation_t *evaluations, - size_t *num_evaluations_ret) -{ - _ccs_random_tree_tuner_data_t *d = - (_ccs_random_tree_tuner_data_t *)tuner->data; - size_t count = utarray_len(d->history); - if (evaluations) { - CCS_REFUTE( - num_evaluations < count, - CCS_RESULT_ERROR_INVALID_VALUE); - ccs_tree_evaluation_t *eval = NULL; - size_t index = 0; - while ((eval = (ccs_tree_evaluation_t *)utarray_next( - d->history, eval))) - evaluations[index++] = *eval; - for (size_t i = count; i < num_evaluations; i++) - evaluations[i] = NULL; - } - if (num_evaluations_ret) - *num_evaluations_ret = count; - return CCS_RESULT_SUCCESS; -} - -static ccs_result_t -_ccs_tree_tuner_random_suggest( - ccs_tree_tuner_t tuner, - ccs_tree_configuration_t *configuration) -{ - _ccs_random_tree_tuner_data_t *d = - (_ccs_random_tree_tuner_data_t *)tuner->data; - size_t count = utarray_len(d->optima); - if (count > 0) { - ccs_rng_t rng; - unsigned long int indx; - CCS_VALIDATE(ccs_tree_space_get_rng( - d->common_data.tree_space, &rng)); - CCS_VALIDATE(ccs_rng_get(rng, &indx)); - indx = indx % count; - ccs_tree_evaluation_t *eval = - (ccs_tree_evaluation_t *)utarray_eltptr( - d->optima, indx); - CCS_VALIDATE(ccs_tree_evaluation_get_configuration( - *eval, configuration)); - CCS_VALIDATE(ccs_retain_object(*configuration)); - } else - CCS_VALIDATE(_ccs_tree_tuner_random_ask( - tuner, 1, configuration, NULL)); - return CCS_RESULT_SUCCESS; -} - -static _ccs_tree_tuner_ops_t _ccs_tree_tuner_random_ops = { - {&_ccs_tree_tuner_random_del, &_ccs_tree_tuner_random_serialize_size, - &_ccs_tree_tuner_random_serialize}, - &_ccs_tree_tuner_random_ask, - &_ccs_tree_tuner_random_tell, - &_ccs_tree_tuner_random_get_optima, - &_ccs_tree_tuner_random_get_history, - &_ccs_tree_tuner_random_suggest}; - -static const UT_icd _evaluation_icd = { - sizeof(ccs_tree_evaluation_t), - NULL, - NULL, - NULL, -}; - -#undef utarray_oom -#define utarray_oom() \ - { \ - CCS_RAISE_ERR_GOTO( \ - err, CCS_RESULT_ERROR_OUT_OF_MEMORY, arrays, \ - "Out of memory to allocate array"); \ - } -ccs_result_t -ccs_create_random_tree_tuner( - const char *name, - ccs_objective_space_t objective_space, - ccs_tree_tuner_t *tuner_ret) -{ - ccs_tree_space_t tree_space; - CCS_CHECK_PTR(name); - CCS_CHECK_OBJ(objective_space, CCS_OBJECT_TYPE_OBJECTIVE_SPACE); - CCS_VALIDATE(ccs_objective_space_get_search_space( - objective_space, (ccs_search_space_t *)&tree_space)); - CCS_CHECK_OBJ(tree_space, CCS_OBJECT_TYPE_TREE_SPACE); - CCS_CHECK_PTR(tuner_ret); - - uintptr_t mem = (uintptr_t)calloc( - 1, sizeof(struct _ccs_tree_tuner_s) + - sizeof(struct _ccs_random_tree_tuner_data_s) + - strlen(name) + 1); - CCS_REFUTE(!mem, CCS_RESULT_ERROR_OUT_OF_MEMORY); - ccs_tree_tuner_t tun; - _ccs_random_tree_tuner_data_t *data; - ccs_result_t err; - CCS_VALIDATE_ERR_GOTO(err, ccs_retain_object(tree_space), errmemory); - CCS_VALIDATE_ERR_GOTO( - err, ccs_retain_object(objective_space), errconfigs); - tun = (ccs_tree_tuner_t)mem; - _ccs_object_init( - &(tun->obj), CCS_OBJECT_TYPE_TREE_TUNER, - (_ccs_object_ops_t *)&_ccs_tree_tuner_random_ops); - tun->data = (struct _ccs_tree_tuner_data_s - *)(mem + sizeof(struct _ccs_tree_tuner_s)); - data = (_ccs_random_tree_tuner_data_t *)tun->data; - data->common_data.type = CCS_TREE_TUNER_TYPE_RANDOM; - data->common_data.name = - (const char - *)(mem + sizeof(struct _ccs_tree_tuner_s) + sizeof(struct _ccs_random_tree_tuner_data_s)); - data->common_data.tree_space = tree_space; - data->common_data.objective_space = objective_space; - utarray_new(data->history, &_evaluation_icd); - utarray_new(data->optima, &_evaluation_icd); - utarray_new(data->old_optima, &_evaluation_icd); - strcpy((char *)data->common_data.name, name); - *tuner_ret = tun; - return CCS_RESULT_SUCCESS; - -arrays: - if (data->history) - utarray_free(data->history); - if (data->optima) - utarray_free(data->optima); - if (data->old_optima) - utarray_free(data->old_optima); - _ccs_object_deinit(&(tun->obj)); - ccs_release_object(objective_space); -errconfigs: - ccs_release_object(tree_space); -errmemory: - free((void *)mem); - return err; -} diff --git a/src/tree_tuner_user_defined.c b/src/tree_tuner_user_defined.c deleted file mode 100644 index c160290a..00000000 --- a/src/tree_tuner_user_defined.c +++ /dev/null @@ -1,376 +0,0 @@ -#include "cconfigspace_internal.h" -#include "tree_tuner_internal.h" -#include "tree_evaluation_internal.h" -#include "string.h" - -struct _ccs_user_defined_tree_tuner_data_s { - _ccs_tree_tuner_common_data_t common_data; - ccs_user_defined_tree_tuner_vector_t vector; - void *tuner_data; -}; -typedef struct _ccs_user_defined_tree_tuner_data_s - _ccs_user_defined_tree_tuner_data_t; - -static ccs_result_t -_ccs_tree_tuner_user_defined_del(ccs_object_t o) -{ - _ccs_user_defined_tree_tuner_data_t *d = - (_ccs_user_defined_tree_tuner_data_t *)((ccs_tree_tuner_t)o) - ->data; - ccs_result_t err; - err = d->vector.del((ccs_tree_tuner_t)o); - ccs_release_object(d->common_data.tree_space); - ccs_release_object(d->common_data.objective_space); - return err; -} - -static inline ccs_result_t -_ccs_serialize_bin_size_ccs_user_defined_tree_tuner( - ccs_tree_tuner_t tuner, - size_t *cum_size, - _ccs_object_serialize_options_t *opts) -{ - ccs_result_t res = CCS_RESULT_SUCCESS; - _ccs_user_defined_tree_tuner_data_t *data = - (_ccs_user_defined_tree_tuner_data_t *)(tuner->data); - *cum_size += _ccs_serialize_bin_size_ccs_object_internal( - (_ccs_object_internal_t *)tuner); - CCS_VALIDATE(_ccs_serialize_bin_size_ccs_tree_tuner_common_data( - &data->common_data, cum_size, opts)); - size_t history_size = 0; - size_t num_optima = 0; - size_t state_size = 0; - ccs_tree_evaluation_t *history = NULL; - ccs_tree_evaluation_t *optima = NULL; - CCS_VALIDATE(data->vector.get_history(tuner, 0, NULL, &history_size)); - CCS_VALIDATE(data->vector.get_optima(tuner, 0, NULL, &num_optima)); - *cum_size += _ccs_serialize_bin_size_size(history_size); - *cum_size += _ccs_serialize_bin_size_size(num_optima); - if (0 != history_size + num_optima) { - history = (ccs_tree_evaluation_t *)calloc( - sizeof(ccs_tree_evaluation_t), - history_size + num_optima); - CCS_REFUTE(!history, CCS_RESULT_ERROR_OUT_OF_MEMORY); - optima = history + history_size; - if (history_size) { - CCS_VALIDATE_ERR_GOTO( - res, - data->vector.get_history( - tuner, history_size, history, NULL), - end); - for (size_t i = 0; i < history_size; i++) - CCS_VALIDATE_ERR_GOTO( - res, - history[i]->obj.ops->serialize_size( - history[i], - CCS_SERIALIZE_FORMAT_BINARY, - cum_size, opts), - end); - } - if (num_optima) { - CCS_VALIDATE_ERR_GOTO( - res, - data->vector.get_optima( - tuner, num_optima, optima, NULL), - end); - for (size_t i = 0; i < num_optima; i++) - *cum_size += _ccs_serialize_bin_size_ccs_object( - optima[i]); - } - } - if (data->vector.serialize_user_state) - CCS_VALIDATE_ERR_GOTO( - res, - data->vector.serialize_user_state( - tuner, 0, NULL, &state_size), - end); - *cum_size += _ccs_serialize_bin_size_size(state_size); - *cum_size += state_size; -end: - if (history) - free(history); - return res; -} - -static inline ccs_result_t -_ccs_serialize_bin_ccs_user_defined_tree_tuner( - ccs_tree_tuner_t tuner, - size_t *buffer_size, - char **buffer, - _ccs_object_serialize_options_t *opts) -{ - ccs_result_t res = CCS_RESULT_SUCCESS; - _ccs_user_defined_tree_tuner_data_t *data = - (_ccs_user_defined_tree_tuner_data_t *)(tuner->data); - CCS_VALIDATE(_ccs_serialize_bin_ccs_object_internal( - (_ccs_object_internal_t *)tuner, buffer_size, buffer)); - CCS_VALIDATE(_ccs_serialize_bin_ccs_tree_tuner_common_data( - &data->common_data, buffer_size, buffer, opts)); - size_t history_size = 0; - size_t num_optima = 0; - size_t state_size = 0; - ccs_tree_evaluation_t *history = NULL; - ccs_tree_evaluation_t *optima = NULL; - CCS_VALIDATE(data->vector.get_history(tuner, 0, NULL, &history_size)); - CCS_VALIDATE(data->vector.get_optima(tuner, 0, NULL, &num_optima)); - CCS_VALIDATE( - _ccs_serialize_bin_size(history_size, buffer_size, buffer)); - CCS_VALIDATE(_ccs_serialize_bin_size(num_optima, buffer_size, buffer)); - if (0 != history_size + num_optima) { - history = (ccs_tree_evaluation_t *)calloc( - sizeof(ccs_tree_evaluation_t), - history_size + num_optima); - CCS_REFUTE(!history, CCS_RESULT_ERROR_OUT_OF_MEMORY); - optima = history + history_size; - if (history_size) { - CCS_VALIDATE_ERR_GOTO( - res, - data->vector.get_history( - tuner, history_size, history, NULL), - end); - for (size_t i = 0; i < history_size; i++) - CCS_VALIDATE_ERR_GOTO( - res, - history[i]->obj.ops->serialize( - history[i], - CCS_SERIALIZE_FORMAT_BINARY, - buffer_size, buffer, opts), - end); - } - if (num_optima) { - CCS_VALIDATE_ERR_GOTO( - res, - data->vector.get_optima( - tuner, num_optima, optima, NULL), - end); - for (size_t i = 0; i < num_optima; i++) - CCS_VALIDATE_ERR_GOTO( - res, - _ccs_serialize_bin_ccs_object( - optima[i], buffer_size, buffer), - end); - } - } - if (data->vector.serialize_user_state) - CCS_VALIDATE_ERR_GOTO( - res, - data->vector.serialize_user_state( - tuner, 0, NULL, &state_size), - end); - CCS_VALIDATE_ERR_GOTO( - res, _ccs_serialize_bin_size(state_size, buffer_size, buffer), - end); - if (state_size) { - CCS_REFUTE_ERR_GOTO( - res, *buffer_size < state_size, - CCS_RESULT_ERROR_NOT_ENOUGH_DATA, end); - CCS_VALIDATE_ERR_GOTO( - res, - data->vector.serialize_user_state( - tuner, state_size, *buffer, NULL), - end); - *buffer_size -= state_size; - *buffer += state_size; - } -end: - if (history) - free(history); - return res; -} - -static ccs_result_t -_ccs_tree_tuner_user_defined_serialize_size( - ccs_object_t object, - ccs_serialize_format_t format, - size_t *cum_size, - _ccs_object_serialize_options_t *opts) -{ - switch (format) { - case CCS_SERIALIZE_FORMAT_BINARY: - CCS_VALIDATE( - _ccs_serialize_bin_size_ccs_user_defined_tree_tuner( - (ccs_tree_tuner_t)object, cum_size, opts)); - break; - default: - CCS_RAISE( - CCS_RESULT_ERROR_INVALID_VALUE, - "Unsupported serialization format: %d", format); - } - CCS_VALIDATE(_ccs_object_serialize_user_data_size( - object, format, cum_size, opts)); - return CCS_RESULT_SUCCESS; -} - -static ccs_result_t -_ccs_tree_tuner_user_defined_serialize( - ccs_object_t object, - ccs_serialize_format_t format, - size_t *buffer_size, - char **buffer, - _ccs_object_serialize_options_t *opts) -{ - switch (format) { - case CCS_SERIALIZE_FORMAT_BINARY: - CCS_VALIDATE(_ccs_serialize_bin_ccs_user_defined_tree_tuner( - (ccs_tree_tuner_t)object, buffer_size, buffer, opts)); - break; - default: - CCS_RAISE( - CCS_RESULT_ERROR_INVALID_VALUE, - "Unsupported serialization format: %d", format); - } - CCS_VALIDATE(_ccs_object_serialize_user_data( - object, format, buffer_size, buffer, opts)); - return CCS_RESULT_SUCCESS; -} - -static ccs_result_t -_ccs_tree_tuner_user_defined_ask( - ccs_tree_tuner_t tuner, - size_t num_configurations, - ccs_tree_configuration_t *configurations, - size_t *num_configurations_ret) -{ - _ccs_user_defined_tree_tuner_data_t *d = - (_ccs_user_defined_tree_tuner_data_t *)tuner->data; - CCS_VALIDATE(d->vector.ask( - tuner, num_configurations, configurations, - num_configurations_ret)); - return CCS_RESULT_SUCCESS; -} - -static ccs_result_t -_ccs_tree_tuner_user_defined_tell( - ccs_tree_tuner_t tuner, - size_t num_evaluations, - ccs_tree_evaluation_t *evaluations) -{ - _ccs_user_defined_tree_tuner_data_t *d = - (_ccs_user_defined_tree_tuner_data_t *)tuner->data; - CCS_VALIDATE(d->vector.tell(tuner, num_evaluations, evaluations)); - return CCS_RESULT_SUCCESS; -} - -static ccs_result_t -_ccs_tree_tuner_user_defined_get_optima( - ccs_tree_tuner_t tuner, - size_t num_evaluations, - ccs_tree_evaluation_t *evaluations, - size_t *num_evaluations_ret) -{ - _ccs_user_defined_tree_tuner_data_t *d = - (_ccs_user_defined_tree_tuner_data_t *)tuner->data; - CCS_VALIDATE(d->vector.get_optima( - tuner, num_evaluations, evaluations, num_evaluations_ret)); - return CCS_RESULT_SUCCESS; -} - -static ccs_result_t -_ccs_tree_tuner_user_defined_get_history( - ccs_tree_tuner_t tuner, - size_t num_evaluations, - ccs_tree_evaluation_t *evaluations, - size_t *num_evaluations_ret) -{ - _ccs_user_defined_tree_tuner_data_t *d = - (_ccs_user_defined_tree_tuner_data_t *)tuner->data; - CCS_VALIDATE(d->vector.get_history( - tuner, num_evaluations, evaluations, num_evaluations_ret)); - return CCS_RESULT_SUCCESS; -} - -static ccs_result_t -_ccs_tree_tuner_user_defined_suggest( - ccs_tree_tuner_t tuner, - ccs_tree_configuration_t *configuration_ret) -{ - _ccs_user_defined_tree_tuner_data_t *d = - (_ccs_user_defined_tree_tuner_data_t *)tuner->data; - CCS_REFUTE(!d->vector.suggest, CCS_RESULT_ERROR_UNSUPPORTED_OPERATION); - CCS_VALIDATE(d->vector.suggest(tuner, configuration_ret)); - return CCS_RESULT_SUCCESS; -} - -static _ccs_tree_tuner_ops_t _ccs_tree_tuner_user_defined_ops = { - {&_ccs_tree_tuner_user_defined_del, - &_ccs_tree_tuner_user_defined_serialize_size, - &_ccs_tree_tuner_user_defined_serialize}, - &_ccs_tree_tuner_user_defined_ask, - &_ccs_tree_tuner_user_defined_tell, - &_ccs_tree_tuner_user_defined_get_optima, - &_ccs_tree_tuner_user_defined_get_history, - &_ccs_tree_tuner_user_defined_suggest}; - -ccs_result_t -ccs_create_user_defined_tree_tuner( - const char *name, - ccs_objective_space_t objective_space, - ccs_user_defined_tree_tuner_vector_t *vector, - void *tuner_data, - ccs_tree_tuner_t *tuner_ret) -{ - ccs_tree_space_t tree_space; - CCS_CHECK_PTR(name); - CCS_CHECK_OBJ(objective_space, CCS_OBJECT_TYPE_OBJECTIVE_SPACE); - CCS_VALIDATE(ccs_objective_space_get_search_space( - objective_space, (ccs_search_space_t *)&tree_space)); - CCS_CHECK_OBJ(tree_space, CCS_OBJECT_TYPE_TREE_SPACE); - CCS_CHECK_PTR(tuner_ret); - CCS_CHECK_PTR(vector); - CCS_CHECK_PTR(vector->del); - CCS_CHECK_PTR(vector->ask); - CCS_CHECK_PTR(vector->tell); - CCS_CHECK_PTR(vector->get_optima); - CCS_CHECK_PTR(vector->get_history); - - uintptr_t mem = (uintptr_t)calloc( - 1, sizeof(struct _ccs_tree_tuner_s) + - sizeof(struct _ccs_user_defined_tree_tuner_data_s) + - strlen(name) + 1); - CCS_REFUTE(!mem, CCS_RESULT_ERROR_OUT_OF_MEMORY); - ccs_tree_tuner_t tun; - _ccs_user_defined_tree_tuner_data_t *data; - ccs_result_t err; - CCS_VALIDATE_ERR_GOTO(err, ccs_retain_object(tree_space), errmem); - CCS_VALIDATE_ERR_GOTO(err, ccs_retain_object(objective_space), errcs); - - tun = (ccs_tree_tuner_t)mem; - _ccs_object_init( - &(tun->obj), CCS_OBJECT_TYPE_TREE_TUNER, - (_ccs_object_ops_t *)&_ccs_tree_tuner_user_defined_ops); - tun->data = (struct _ccs_tree_tuner_data_s - *)(mem + sizeof(struct _ccs_tree_tuner_s)); - data = (_ccs_user_defined_tree_tuner_data_t *)tun->data; - data->common_data.type = CCS_TREE_TUNER_TYPE_USER_DEFINED; - data->common_data.name = - (const char - *)(mem + sizeof(struct _ccs_tree_tuner_s) + sizeof(struct _ccs_user_defined_tree_tuner_data_s)); - data->common_data.tree_space = tree_space; - data->common_data.objective_space = objective_space; - data->vector = *vector; - data->tuner_data = tuner_data; - strcpy((char *)data->common_data.name, name); - *tuner_ret = tun; - return CCS_RESULT_SUCCESS; -errcs: - ccs_release_object(tree_space); -errmem: - free((void *)mem); - return err; -} - -ccs_result_t -ccs_user_defined_tree_tuner_get_tuner_data( - ccs_tree_tuner_t tuner, - void **tuner_data_ret) -{ - CCS_CHECK_OBJ(tuner, CCS_OBJECT_TYPE_TREE_TUNER); - CCS_CHECK_PTR(tuner_data_ret); - _ccs_user_defined_tree_tuner_data_t *d = - (_ccs_user_defined_tree_tuner_data_t *)tuner->data; - CCS_REFUTE( - d->common_data.type != CCS_TREE_TUNER_TYPE_USER_DEFINED, - CCS_RESULT_ERROR_INVALID_TUNER); - *tuner_data_ret = d->tuner_data; - return CCS_RESULT_SUCCESS; -} diff --git a/src/tuner.c b/src/tuner.c index 73e7d5e1..158dead4 100644 --- a/src/tuner.c +++ b/src/tuner.c @@ -28,14 +28,14 @@ ccs_tuner_get_name(ccs_tuner_t tuner, const char **name_ret) } ccs_result_t -ccs_tuner_get_configuration_space( - ccs_tuner_t tuner, - ccs_configuration_space_t *configuration_space_ret) +ccs_tuner_get_search_space( + ccs_tuner_t tuner, + ccs_search_space_t *search_space_ret) { CCS_CHECK_OBJ(tuner, CCS_OBJECT_TYPE_TUNER); - CCS_CHECK_PTR(configuration_space_ret); + CCS_CHECK_PTR(search_space_ret); _ccs_tuner_common_data_t *d = (_ccs_tuner_common_data_t *)tuner->data; - *configuration_space_ret = d->configuration_space; + *search_space_ret = d->search_space; return CCS_RESULT_SUCCESS; } @@ -53,10 +53,10 @@ ccs_tuner_get_objective_space( ccs_result_t ccs_tuner_ask( - ccs_tuner_t tuner, - size_t num_configurations, - ccs_configuration_t *configurations, - size_t *num_configurations_ret) + ccs_tuner_t tuner, + size_t num_configurations, + ccs_search_configuration_t *configurations, + size_t *num_configurations_ret) { CCS_CHECK_OBJ(tuner, CCS_OBJECT_TYPE_TUNER); CCS_CHECK_ARY(num_configurations, configurations); @@ -151,7 +151,7 @@ ccs_tuner_get_history( } ccs_result_t -ccs_tuner_suggest(ccs_tuner_t tuner, ccs_configuration_t *configuration) +ccs_tuner_suggest(ccs_tuner_t tuner, ccs_search_configuration_t *configuration) { CCS_CHECK_OBJ(tuner, CCS_OBJECT_TYPE_TUNER); _ccs_tuner_ops_t *ops = ccs_tuner_get_ops(tuner); diff --git a/src/tuner_deserialize.h b/src/tuner_deserialize.h index deac4b35..7f8e7b0f 100644 --- a/src/tuner_deserialize.h +++ b/src/tuner_deserialize.h @@ -133,8 +133,6 @@ _ccs_deserialize_bin_random_tuner( if (data.history[i]) ccs_release_object(data.history[i]); end: - if (data.common_data.configuration_space) - ccs_release_object(data.common_data.configuration_space); if (data.common_data.objective_space) ccs_release_object(data.common_data.objective_space); if (data.history) diff --git a/src/tuner_internal.h b/src/tuner_internal.h index 83edc1d2..b1ab70e7 100644 --- a/src/tuner_internal.h +++ b/src/tuner_internal.h @@ -11,10 +11,10 @@ struct _ccs_tuner_ops_s { _ccs_object_ops_t obj_ops; ccs_result_t (*ask)( - ccs_tuner_t tuner, - size_t num_configurations, - ccs_configuration_t *configurations, - size_t *num_configurations_ret); + ccs_tuner_t tuner, + size_t num_configurations, + ccs_search_configuration_t *configurations, + size_t *num_configurations_ret); ccs_result_t (*tell)( ccs_tuner_t tuner, @@ -34,8 +34,8 @@ struct _ccs_tuner_ops_s { size_t *num_evaluations_ret); ccs_result_t (*suggest)( - ccs_tuner_t tuner, - ccs_configuration_t *configuration); + ccs_tuner_t tuner, + ccs_search_configuration_t *configuration); }; typedef struct _ccs_tuner_ops_s _ccs_tuner_ops_t; @@ -45,10 +45,10 @@ struct _ccs_tuner_s { }; struct _ccs_tuner_common_data_s { - ccs_tuner_type_t type; - const char *name; - ccs_configuration_space_t configuration_space; - ccs_objective_space_t objective_space; + ccs_tuner_type_t type; + const char *name; + ccs_search_space_t search_space; + ccs_objective_space_t objective_space; }; typedef struct _ccs_tuner_common_data_s _ccs_tuner_common_data_t; diff --git a/src/tuner_random.c b/src/tuner_random.c index 05c1217c..a196756e 100644 --- a/src/tuner_random.c +++ b/src/tuner_random.c @@ -17,7 +17,7 @@ _ccs_tuner_random_del(ccs_object_t o) { _ccs_random_tuner_data_t *d = (_ccs_random_tuner_data_t *)((ccs_tuner_t)o)->data; - ccs_release_object(d->common_data.configuration_space); + ccs_release_object(d->common_data.search_space); ccs_release_object(d->common_data.objective_space); ccs_evaluation_t *e = NULL; while ((e = (ccs_evaluation_t *)utarray_next(d->history, e))) @@ -151,19 +151,27 @@ _ccs_tuner_random_serialize( static ccs_result_t _ccs_tuner_random_ask( - ccs_tuner_t tuner, - size_t num_configurations, - ccs_configuration_t *configurations, - size_t *num_configurations_ret) + ccs_tuner_t tuner, + size_t num_configurations, + ccs_search_configuration_t *configurations, + size_t *num_configurations_ret) { _ccs_random_tuner_data_t *d = (_ccs_random_tuner_data_t *)tuner->data; if (!configurations) { *num_configurations_ret = 1; return CCS_RESULT_SUCCESS; } - CCS_VALIDATE(ccs_configuration_space_samples( - d->common_data.configuration_space, NULL, NULL, - num_configurations, configurations)); + ccs_search_space_t search_space = d->common_data.search_space; + if (CCS_OBJ_TYPE(search_space) == CCS_OBJECT_TYPE_CONFIGURATION_SPACE) + CCS_VALIDATE(ccs_configuration_space_samples( + (ccs_configuration_space_t)search_space, NULL, NULL, + num_configurations, + (ccs_configuration_t *)configurations)); + else + CCS_VALIDATE(ccs_tree_space_samples( + (ccs_tree_space_t)search_space, NULL, + num_configurations, + (ccs_tree_configuration_t *)configurations)); if (num_configurations_ret) *num_configurations_ret = num_configurations; return CCS_RESULT_SUCCESS; @@ -187,8 +195,8 @@ _ccs_tuner_random_tell( ccs_result_t err; for (size_t i = 0; i < num_evaluations; i++) { ccs_evaluation_result_t result; - CCS_VALIDATE(ccs_evaluation_binding_get_result( - (ccs_evaluation_binding_t)evaluations[i], &result)); + CCS_VALIDATE(ccs_evaluation_get_result( + (ccs_evaluation_t)evaluations[i], &result)); if (!result) { int discard = 0; UT_array *tmp; @@ -211,11 +219,9 @@ _ccs_tuner_random_tell( d->old_optima, eval))) { if (!discard) { ccs_comparison_t cmp; - err = ccs_evaluation_binding_compare( - (ccs_evaluation_binding_t) - evaluations[i], - (ccs_evaluation_binding_t)*eval, - &cmp); + err = ccs_evaluation_compare( + (ccs_evaluation_t)evaluations[i], + (ccs_evaluation_t)*eval, &cmp); if (err) discard = 1; else @@ -300,15 +306,26 @@ _ccs_tuner_random_get_history( } static ccs_result_t -_ccs_tuner_random_suggest(ccs_tuner_t tuner, ccs_configuration_t *configuration) +_ccs_tuner_random_suggest( + ccs_tuner_t tuner, + ccs_search_configuration_t *configuration) { _ccs_random_tuner_data_t *d = (_ccs_random_tuner_data_t *)tuner->data; size_t count = utarray_len(d->optima); if (count > 0) { - ccs_rng_t rng; - unsigned long int indx; - CCS_VALIDATE(ccs_configuration_space_get_rng( - d->common_data.configuration_space, &rng)); + ccs_rng_t rng; + unsigned long int indx; + ccs_search_space_t search_space = d->common_data.search_space; + if (CCS_OBJ_TYPE(search_space) == + CCS_OBJECT_TYPE_CONFIGURATION_SPACE) + CCS_VALIDATE(ccs_configuration_space_get_rng( + (ccs_configuration_space_t) + d->common_data.search_space, + &rng)); + else + CCS_VALIDATE(ccs_tree_space_get_rng( + (ccs_tree_space_t)d->common_data.search_space, + &rng)); CCS_VALIDATE(ccs_rng_get(rng, &indx)); indx = indx % count; ccs_evaluation_t *eval = @@ -351,12 +368,11 @@ ccs_create_random_tuner( ccs_objective_space_t objective_space, ccs_tuner_t *tuner_ret) { - ccs_configuration_space_t configuration_space; + ccs_search_space_t search_space; CCS_CHECK_PTR(name); CCS_CHECK_OBJ(objective_space, CCS_OBJECT_TYPE_OBJECTIVE_SPACE); CCS_VALIDATE(ccs_objective_space_get_search_space( - objective_space, (ccs_search_space_t *)&configuration_space)); - CCS_CHECK_OBJ(configuration_space, CCS_OBJECT_TYPE_CONFIGURATION_SPACE); + objective_space, &search_space)); CCS_CHECK_PTR(tuner_ret); uintptr_t mem = (uintptr_t)calloc( @@ -367,8 +383,7 @@ ccs_create_random_tuner( ccs_tuner_t tun; _ccs_random_tuner_data_t *data; ccs_result_t err; - CCS_VALIDATE_ERR_GOTO( - err, ccs_retain_object(configuration_space), errmemory); + CCS_VALIDATE_ERR_GOTO(err, ccs_retain_object(search_space), errmemory); CCS_VALIDATE_ERR_GOTO( err, ccs_retain_object(objective_space), errconfigs); tun = (ccs_tuner_t)mem; @@ -382,8 +397,8 @@ ccs_create_random_tuner( data->common_data.name = (const char *)(mem + sizeof(struct _ccs_tuner_s) + sizeof(struct _ccs_random_tuner_data_s)); - data->common_data.configuration_space = configuration_space; - data->common_data.objective_space = objective_space; + data->common_data.search_space = search_space; + data->common_data.objective_space = objective_space; utarray_new(data->history, &_evaluation_icd); utarray_new(data->optima, &_evaluation_icd); utarray_new(data->old_optima, &_evaluation_icd); @@ -401,7 +416,7 @@ ccs_create_random_tuner( _ccs_object_deinit(&(tun->obj)); ccs_release_object(objective_space); errconfigs: - ccs_release_object(configuration_space); + ccs_release_object(search_space); errmemory: free((void *)mem); return err; diff --git a/src/tuner_user_defined.c b/src/tuner_user_defined.c index b5bc346b..78623a82 100644 --- a/src/tuner_user_defined.c +++ b/src/tuner_user_defined.c @@ -17,7 +17,7 @@ _ccs_tuner_user_defined_del(ccs_object_t o) (_ccs_user_defined_tuner_data_t *)((ccs_tuner_t)o)->data; ccs_result_t err; err = d->vector.del((ccs_tuner_t)o); - ccs_release_object(d->common_data.configuration_space); + ccs_release_object(d->common_data.search_space); ccs_release_object(d->common_data.objective_space); return err; } @@ -221,10 +221,10 @@ _ccs_tuner_user_defined_serialize( static ccs_result_t _ccs_tuner_user_defined_ask( - ccs_tuner_t tuner, - size_t num_configurations, - ccs_configuration_t *configurations, - size_t *num_configurations_ret) + ccs_tuner_t tuner, + size_t num_configurations, + ccs_search_configuration_t *configurations, + size_t *num_configurations_ret) { _ccs_user_defined_tuner_data_t *d = (_ccs_user_defined_tuner_data_t *)tuner->data; @@ -276,8 +276,8 @@ _ccs_tuner_user_defined_get_history( static ccs_result_t _ccs_tuner_user_defined_suggest( - ccs_tuner_t tuner, - ccs_configuration_t *configuration_ret) + ccs_tuner_t tuner, + ccs_search_configuration_t *configuration_ret) { _ccs_user_defined_tuner_data_t *d = (_ccs_user_defined_tuner_data_t *)tuner->data; @@ -303,12 +303,11 @@ ccs_create_user_defined_tuner( void *tuner_data, ccs_tuner_t *tuner_ret) { - ccs_configuration_space_t configuration_space; + ccs_search_space_t search_space; CCS_CHECK_PTR(name); CCS_CHECK_OBJ(objective_space, CCS_OBJECT_TYPE_OBJECTIVE_SPACE); CCS_VALIDATE(ccs_objective_space_get_search_space( - objective_space, (ccs_search_space_t *)&configuration_space)); - CCS_CHECK_OBJ(configuration_space, CCS_OBJECT_TYPE_CONFIGURATION_SPACE); + objective_space, &search_space)); CCS_CHECK_PTR(tuner_ret); CCS_CHECK_PTR(vector); CCS_CHECK_PTR(vector->del); @@ -325,8 +324,7 @@ ccs_create_user_defined_tuner( ccs_tuner_t tun; _ccs_user_defined_tuner_data_t *data; ccs_result_t err; - CCS_VALIDATE_ERR_GOTO( - err, ccs_retain_object(configuration_space), errmem); + CCS_VALIDATE_ERR_GOTO(err, ccs_retain_object(search_space), errmem); CCS_VALIDATE_ERR_GOTO(err, ccs_retain_object(objective_space), errcs); tun = (ccs_tuner_t)mem; @@ -340,15 +338,15 @@ ccs_create_user_defined_tuner( data->common_data.name = (const char *)(mem + sizeof(struct _ccs_tuner_s) + sizeof(struct _ccs_user_defined_tuner_data_s)); - data->common_data.configuration_space = configuration_space; - data->common_data.objective_space = objective_space; - data->vector = *vector; - data->tuner_data = tuner_data; + data->common_data.search_space = search_space; + data->common_data.objective_space = objective_space; + data->vector = *vector; + data->tuner_data = tuner_data; strcpy((char *)data->common_data.name, name); *tuner_ret = tun; return CCS_RESULT_SUCCESS; errcs: - ccs_release_object(configuration_space); + ccs_release_object(search_space); errmem: free((void *)mem); return err; diff --git a/tests/test_dynamic_tree_space.c b/tests/test_dynamic_tree_space.c index 1c675b18..56533821 100644 --- a/tests/test_dynamic_tree_space.c +++ b/tests/test_dynamic_tree_space.c @@ -55,8 +55,10 @@ test_dynamic_tree_space(void) &my_tree_del, &my_tree_get_child, NULL, NULL}; err = ccs_create_tree(4, ccs_int(4 * 100), &root); assert(err == CCS_RESULT_SUCCESS); + err = ccs_create_rng(&rng); + assert(err == CCS_RESULT_SUCCESS); err = ccs_create_dynamic_tree_space( - "space", root, &vector, NULL, &tree_space); + "space", root, rng, &vector, NULL, &tree_space); assert(err == CCS_RESULT_SUCCESS); err = ccs_tree_space_get_type(tree_space, &tree_type); @@ -67,11 +69,6 @@ test_dynamic_tree_space(void) assert(err == CCS_RESULT_SUCCESS); assert(!strcmp(name, "space")); - err = ccs_create_rng(&rng); - assert(err == CCS_RESULT_SUCCESS); - err = ccs_tree_space_set_rng(tree_space, rng); - assert(err == CCS_RESULT_SUCCESS); - err = ccs_tree_space_get_rng(tree_space, &rng2); assert(err == CCS_RESULT_SUCCESS); assert(rng == rng2); @@ -119,10 +116,10 @@ test_dynamic_tree_space(void) free(values); free(position); - err = ccs_tree_space_sample(tree_space, &config); + err = ccs_tree_space_sample(tree_space, NULL, &config); assert(err == CCS_RESULT_SUCCESS); - err = ccs_tree_space_samples(tree_space, NUM_SAMPLES, configs); + err = ccs_tree_space_samples(tree_space, NULL, NUM_SAMPLES, configs); assert(err == CCS_RESULT_SUCCESS); char *buff; @@ -183,7 +180,7 @@ test_dynamic_tree_space(void) assert(err == CCS_RESULT_SUCCESS); free(buff); - err = ccs_tree_space_samples(tree_space, NUM_SAMPLES, configs); + err = ccs_tree_space_samples(tree_space, NULL, NUM_SAMPLES, configs); assert(err == CCS_RESULT_SUCCESS); inv_sum = 0; diff --git a/tests/test_random_features_tuner.c b/tests/test_random_features_tuner.c index bc2f691c..3774b3e0 100644 --- a/tests/test_random_features_tuner.c +++ b/tests/test_random_features_tuner.c @@ -27,9 +27,9 @@ test(void) assert(err == CCS_RESULT_SUCCESS); for (size_t i = 0; i < 50; i++) { - ccs_datum_t values[2], res; - ccs_configuration_t configuration; - ccs_features_evaluation_t evaluation; + ccs_datum_t values[2], res; + ccs_search_configuration_t configuration; + ccs_features_evaluation_t evaluation; err = ccs_features_tuner_ask( tuner, features_on, 1, &configuration, NULL); assert(err == CCS_RESULT_SUCCESS); @@ -52,9 +52,9 @@ test(void) } for (size_t i = 0; i < 50; i++) { - ccs_datum_t values[2], res; - ccs_configuration_t configuration; - ccs_features_evaluation_t evaluation; + ccs_datum_t values[2], res; + ccs_search_configuration_t configuration; + ccs_features_evaluation_t evaluation; err = ccs_features_tuner_ask( tuner, features_off, 1, &configuration, NULL); assert(err == CCS_RESULT_SUCCESS); @@ -96,8 +96,8 @@ test(void) for (size_t i = 0; i < 50; i++) { ccs_datum_t res; - err = ccs_evaluation_binding_get_objective_value( - (ccs_evaluation_binding_t)history[i], 0, &res); + err = ccs_evaluation_get_objective_value( + (ccs_evaluation_t)history[i], 0, &res); assert(err == CCS_RESULT_SUCCESS); if (res.value.f < min_on.value.f) min_on.value.f = res.value.f; @@ -110,8 +110,8 @@ test(void) for (size_t i = 0; i < 50; i++) { ccs_datum_t res; - err = ccs_evaluation_binding_get_objective_value( - (ccs_evaluation_binding_t)history[i], 0, &res); + err = ccs_evaluation_get_objective_value( + (ccs_evaluation_t)history[i], 0, &res); assert(err == CCS_RESULT_SUCCESS); if (res.value.f < min_off.value.f) min_off.value.f = res.value.f; @@ -121,15 +121,15 @@ test(void) err = ccs_features_tuner_get_optima( tuner, features_on, 1, &evaluation, NULL); assert(err == CCS_RESULT_SUCCESS); - err = ccs_evaluation_binding_get_objective_value( - (ccs_evaluation_binding_t)evaluation, 0, &res); + err = ccs_evaluation_get_objective_value( + (ccs_evaluation_t)evaluation, 0, &res); assert(res.value.f == min_on.value.f); err = ccs_features_tuner_get_optima( tuner, features_off, 1, &evaluation, NULL); assert(err == CCS_RESULT_SUCCESS); - err = ccs_evaluation_binding_get_objective_value( - (ccs_evaluation_binding_t)evaluation, 0, &res); + err = ccs_evaluation_get_objective_value( + (ccs_evaluation_t)evaluation, 0, &res); assert(res.value.f == min_off.value.f); /* Test (de)serialization */ @@ -214,8 +214,8 @@ test_evaluation_deserialize(void) res = ccs_float(1.5); err = ccs_create_features_evaluation( - ospace, configuration, features_on, CCS_RESULT_SUCCESS, 1, &res, - &evaluation_ref); + ospace, (ccs_search_configuration_t)configuration, features_on, + CCS_RESULT_SUCCESS, 1, &res, &evaluation_ref); assert(err == CCS_RESULT_SUCCESS); err = ccs_create_map(&map); diff --git a/tests/test_random_tree_tuner.c b/tests/test_random_tree_tuner.c index b8b18e5f..813102ec 100644 --- a/tests/test_random_tree_tuner.c +++ b/tests/test_random_tree_tuner.c @@ -35,7 +35,7 @@ create_tree_tuning_problem( ccs_result_t err; generate_tree(&root, 5, 0); - err = ccs_create_static_tree_space("space", root, tree_space); + err = ccs_create_static_tree_space("space", root, NULL, tree_space); assert(err == CCS_RESULT_SUCCESS); parameter = create_numerical("sum", -CCS_INFINITY, CCS_INFINITY); @@ -62,7 +62,7 @@ test(void) { ccs_tree_space_t tree_space; ccs_objective_space_t ospace; - ccs_tree_tuner_t tuner, tuner_copy; + ccs_tuner_t tuner, tuner_copy; ccs_result_t err; ccs_datum_t d; char *buff; @@ -71,30 +71,31 @@ test(void) create_tree_tuning_problem(&tree_space, &ospace); - err = ccs_create_random_tree_tuner("problem", ospace, &tuner); + err = ccs_create_random_tuner("problem", ospace, &tuner); assert(err == CCS_RESULT_SUCCESS); for (size_t i = 0; i < 100; i++) { - ccs_datum_t values[6], res; - size_t num_values; - ccs_tree_configuration_t configuration; - ccs_tree_evaluation_t evaluation; - ccs_int_t v; - err = ccs_tree_tuner_ask(tuner, 1, &configuration, NULL); + ccs_datum_t values[6], res; + size_t num_values; + ccs_search_configuration_t configuration; + ccs_evaluation_t evaluation; + ccs_int_t v; + err = ccs_tuner_ask(tuner, 1, &configuration, NULL); assert(err == CCS_RESULT_SUCCESS); err = ccs_tree_configuration_get_values( - configuration, 6, values, &num_values); + (ccs_tree_configuration_t)configuration, 6, values, + &num_values); assert(err == CCS_RESULT_SUCCESS); v = 0; for (size_t i = 0; i < num_values; i++) { v += values[i].value.i; } res = ccs_float(v); - err = ccs_create_tree_evaluation( + err = ccs_create_evaluation( ospace, configuration, CCS_RESULT_SUCCESS, 1, &res, &evaluation); assert(err == CCS_RESULT_SUCCESS); - err = ccs_tree_tuner_tell(tuner, 1, &evaluation); + err = ccs_tuner_tell(tuner, 1, &evaluation); assert(err == CCS_RESULT_SUCCESS); err = ccs_release_object(configuration); assert(err == CCS_RESULT_SUCCESS); @@ -102,28 +103,26 @@ test(void) assert(err == CCS_RESULT_SUCCESS); } - size_t count; - ccs_tree_evaluation_t history[100]; - ccs_datum_t max = ccs_float(-INFINITY); - err = ccs_tree_tuner_get_history(tuner, 100, history, &count); + size_t count; + ccs_evaluation_t history[100]; + ccs_datum_t max = ccs_float(-INFINITY); + err = ccs_tuner_get_history(tuner, 100, history, &count); assert(err == CCS_RESULT_SUCCESS); assert(count == 100); for (size_t i = 0; i < 100; i++) { ccs_datum_t res; - err = ccs_evaluation_binding_get_objective_value( - (ccs_evaluation_binding_t)history[i], 0, &res); + err = ccs_evaluation_get_objective_value(history[i], 0, &res); assert(err == CCS_RESULT_SUCCESS); if (res.value.f > max.value.f) max.value.f = res.value.f; } - ccs_tree_evaluation_t evaluation; - ccs_datum_t res; - err = ccs_tree_tuner_get_optima(tuner, 1, &evaluation, NULL); + ccs_evaluation_t evaluation; + ccs_datum_t res; + err = ccs_tuner_get_optima(tuner, 1, &evaluation, NULL); assert(err == CCS_RESULT_SUCCESS); - err = ccs_evaluation_binding_get_objective_value( - (ccs_evaluation_binding_t)evaluation, 0, &res); + err = ccs_evaluation_get_objective_value(evaluation, 0, &res); assert(res.value.f == max.value.f); /* Test (de)serialization */ @@ -150,11 +149,11 @@ test(void) CCS_DESERIALIZE_OPTION_END); assert(err == CCS_RESULT_SUCCESS); - err = ccs_tree_tuner_get_history(tuner_copy, 100, history, &count); + err = ccs_tuner_get_history(tuner_copy, 100, history, &count); assert(err == CCS_RESULT_SUCCESS); assert(count == 100); - err = ccs_tree_tuner_get_optima(tuner_copy, 1, &evaluation, &count); + err = ccs_tuner_get_optima(tuner_copy, 1, &evaluation, &count); assert(err == CCS_RESULT_SUCCESS); assert(count == 1); @@ -182,7 +181,7 @@ test_tree_evaluation_deserialize(void) ccs_tree_space_t tree_space; ccs_objective_space_t ospace; ccs_tree_configuration_t configuration; - ccs_tree_evaluation_t evaluation_ref, evaluation; + ccs_evaluation_t evaluation_ref, evaluation; ccs_datum_t res, d; ccs_result_t err; char *buff; @@ -192,13 +191,13 @@ test_tree_evaluation_deserialize(void) create_tree_tuning_problem(&tree_space, &ospace); - err = ccs_tree_space_sample(tree_space, &configuration); + err = ccs_tree_space_sample(tree_space, NULL, &configuration); assert(err == CCS_RESULT_SUCCESS); res = ccs_float(1.5); - err = ccs_create_tree_evaluation( - ospace, configuration, CCS_RESULT_SUCCESS, 1, &res, - &evaluation_ref); + err = ccs_create_evaluation( + ospace, (ccs_search_configuration_t)configuration, + CCS_RESULT_SUCCESS, 1, &res, &evaluation_ref); assert(err == CCS_RESULT_SUCCESS); err = ccs_create_map(&map); diff --git a/tests/test_random_tuner.c b/tests/test_random_tuner.c index f0bc20b3..43fc1d07 100644 --- a/tests/test_random_tuner.c +++ b/tests/test_random_tuner.c @@ -23,9 +23,9 @@ test(void) assert(err == CCS_RESULT_SUCCESS); for (size_t i = 0; i < 100; i++) { - ccs_datum_t values[2], res; - ccs_configuration_t configuration; - ccs_evaluation_t evaluation; + ccs_datum_t values[2], res; + ccs_search_configuration_t configuration; + ccs_evaluation_t evaluation; err = ccs_tuner_ask(tuner, 1, &configuration, NULL); assert(err == CCS_RESULT_SUCCESS); err = ccs_binding_get_values( @@ -55,8 +55,7 @@ test(void) for (size_t i = 0; i < 100; i++) { ccs_datum_t res; - err = ccs_evaluation_binding_get_objective_value( - (ccs_evaluation_binding_t)history[i], 0, &res); + err = ccs_evaluation_get_objective_value(history[i], 0, &res); assert(err == CCS_RESULT_SUCCESS); if (res.value.f < min.value.f) min.value.f = res.value.f; @@ -66,8 +65,7 @@ test(void) ccs_datum_t res; err = ccs_tuner_get_optima(tuner, 1, &evaluation, NULL); assert(err == CCS_RESULT_SUCCESS); - err = ccs_evaluation_binding_get_objective_value( - (ccs_evaluation_binding_t)evaluation, 0, &res); + err = ccs_evaluation_get_objective_value(evaluation, 0, &res); assert(res.value.f == min.value.f); /* Test (de)serialization */ @@ -123,22 +121,22 @@ test(void) void test_evaluation_deserialize(void) { - ccs_configuration_space_t cspace; - ccs_objective_space_t ospace; - ccs_result_t err; - ccs_configuration_t configuration; - ccs_evaluation_t evaluation_ref, evaluation; - ccs_datum_t res, d; - char *buff; - size_t buff_size; - ccs_map_t map; - int cmp; + ccs_configuration_space_t cspace; + ccs_objective_space_t ospace; + ccs_result_t err; + ccs_search_configuration_t configuration; + ccs_evaluation_t evaluation_ref, evaluation; + ccs_datum_t res, d; + char *buff; + size_t buff_size; + ccs_map_t map; + int cmp; cspace = create_2d_plane(); ospace = create_height_objective(cspace); err = ccs_configuration_space_sample( - cspace, NULL, NULL, &configuration); + cspace, NULL, NULL, (ccs_configuration_t *)&configuration); assert(err == CCS_RESULT_SUCCESS); res = ccs_float(1.5); diff --git a/tests/test_static_tree_space.c b/tests/test_static_tree_space.c index 27fe6a0e..8884c836 100644 --- a/tests/test_static_tree_space.c +++ b/tests/test_static_tree_space.c @@ -40,7 +40,9 @@ test_static_tree_space(void) ccs_tree_configuration_t config, configs[NUM_SAMPLES]; generate_tree(&root, 4, 0); - err = ccs_create_static_tree_space("space", root, &tree_space); + err = ccs_create_rng(&rng); + assert(err == CCS_RESULT_SUCCESS); + err = ccs_create_static_tree_space("space", root, rng, &tree_space); assert(err == CCS_RESULT_SUCCESS); err = ccs_tree_space_get_type(tree_space, &tree_type); @@ -51,11 +53,6 @@ test_static_tree_space(void) assert(err == CCS_RESULT_SUCCESS); assert(!strcmp(name, "space")); - err = ccs_create_rng(&rng); - assert(err == CCS_RESULT_SUCCESS); - err = ccs_tree_space_set_rng(tree_space, rng); - assert(err == CCS_RESULT_SUCCESS); - err = ccs_tree_space_get_rng(tree_space, &rng2); assert(err == CCS_RESULT_SUCCESS); assert(rng == rng2); @@ -84,7 +81,7 @@ test_static_tree_space(void) free(values); free(position); - err = ccs_tree_space_sample(tree_space, &config); + err = ccs_tree_space_sample(tree_space, NULL, &config); assert(err == CCS_RESULT_SUCCESS); ccs_map_t map; @@ -136,7 +133,7 @@ test_static_tree_space(void) err = ccs_release_object(map); assert(err == CCS_RESULT_SUCCESS); - err = ccs_tree_space_samples(tree_space, NUM_SAMPLES, configs); + err = ccs_tree_space_samples(tree_space, NULL, NUM_SAMPLES, configs); assert(err == CCS_RESULT_SUCCESS); inv_sum = 0; @@ -189,7 +186,7 @@ test_static_tree_space(void) assert(err == CCS_RESULT_SUCCESS); free(buff); - err = ccs_tree_space_samples(tree_space, NUM_SAMPLES, configs); + err = ccs_tree_space_samples(tree_space, NULL, NUM_SAMPLES, configs); assert(err == CCS_RESULT_SUCCESS); inv_sum = 0; diff --git a/tests/test_user_defined_features_tuner.c b/tests/test_user_defined_features_tuner.c index 1f0cca12..e9dd2439 100644 --- a/tests/test_user_defined_features_tuner.c +++ b/tests/test_user_defined_features_tuner.c @@ -26,11 +26,11 @@ tuner_last_del(ccs_features_tuner_t tuner) ccs_result_t tuner_last_ask( - ccs_features_tuner_t tuner, - ccs_features_t features, - size_t num_configurations, - ccs_configuration_t *configurations, - size_t *num_configurations_ret) + ccs_features_tuner_t tuner, + ccs_features_t features, + size_t num_configurations, + ccs_search_configuration_t *configurations, + size_t *num_configurations_ret) { (void)features; if (!configurations) { @@ -39,13 +39,13 @@ tuner_last_ask( } ccs_result_t err; ccs_configuration_space_t configuration_space; - err = ccs_features_tuner_get_configuration_space( - tuner, &configuration_space); + err = ccs_features_tuner_get_search_space( + tuner, (ccs_search_space_t *)&configuration_space); if (err) return err; err = ccs_configuration_space_samples( configuration_space, NULL, NULL, num_configurations, - configurations); + (ccs_configuration_t *)configurations); if (err) return err; if (num_configurations_ret) @@ -176,9 +176,9 @@ test(void) ccs_features_evaluation_t last_evaluation; for (size_t i = 0; i < 50; i++) { - ccs_datum_t values[2], res; - ccs_configuration_t configuration; - ccs_features_evaluation_t evaluation; + ccs_datum_t values[2], res; + ccs_search_configuration_t configuration; + ccs_features_evaluation_t evaluation; err = ccs_features_tuner_ask( tuner, features_on, 1, &configuration, NULL); assert(err == CCS_RESULT_SUCCESS); @@ -202,9 +202,9 @@ test(void) } for (size_t i = 0; i < 50; i++) { - ccs_datum_t values[2], res; - ccs_configuration_t configuration; - ccs_features_evaluation_t evaluation; + ccs_datum_t values[2], res; + ccs_search_configuration_t configuration; + ccs_features_evaluation_t evaluation; err = ccs_features_tuner_ask( tuner, features_off, 1, &configuration, NULL); assert(err == CCS_RESULT_SUCCESS); diff --git a/tests/test_user_defined_tree_tuner.c b/tests/test_user_defined_tree_tuner.c index e2912dc1..1190e431 100644 --- a/tests/test_user_defined_tree_tuner.c +++ b/tests/test_user_defined_tree_tuner.c @@ -35,7 +35,7 @@ create_tree_tuning_problem( ccs_result_t err; generate_tree(&root, 5, 0); - err = ccs_create_static_tree_space("space", root, tree_space); + err = ccs_create_static_tree_space("space", root, NULL, tree_space); assert(err == CCS_RESULT_SUCCESS); parameter = create_numerical("sum", -CCS_INFINITY, CCS_INFINITY); @@ -57,16 +57,16 @@ create_tree_tuning_problem( } struct tuner_last_s { - ccs_tree_evaluation_t last_eval; + ccs_evaluation_t last_eval; }; typedef struct tuner_last_s tuner_last_t; ccs_result_t -tuner_last_del(ccs_tree_tuner_t tuner) +tuner_last_del(ccs_tuner_t tuner) { tuner_last_t *tuner_data; ccs_result_t err; - err = ccs_user_defined_tree_tuner_get_tuner_data( + err = ccs_user_defined_tuner_get_tuner_data( tuner, (void **)&tuner_data); if (err) return err; @@ -78,10 +78,10 @@ tuner_last_del(ccs_tree_tuner_t tuner) ccs_result_t tuner_last_ask( - ccs_tree_tuner_t tuner, - size_t num_configurations, - ccs_tree_configuration_t *configurations, - size_t *num_configurations_ret) + ccs_tuner_t tuner, + size_t num_configurations, + ccs_search_configuration_t *configurations, + size_t *num_configurations_ret) { if (!configurations) { *num_configurations_ret = 1; @@ -89,11 +89,13 @@ tuner_last_ask( } ccs_result_t err; ccs_tree_space_t tree_space; - err = ccs_tree_tuner_get_tree_space(tuner, &tree_space); + err = ccs_tuner_get_search_space( + tuner, (ccs_search_space_t *)&tree_space); if (err) return err; err = ccs_tree_space_samples( - tree_space, num_configurations, configurations); + tree_space, NULL, num_configurations, + (ccs_tree_configuration_t *)configurations); if (err) return err; if (num_configurations_ret) @@ -103,15 +105,15 @@ tuner_last_ask( ccs_result_t tuner_last_tell( - ccs_tree_tuner_t tuner, - size_t num_evaluations, - ccs_tree_evaluation_t *evaluations) + ccs_tuner_t tuner, + size_t num_evaluations, + ccs_evaluation_t *evaluations) { if (!num_evaluations) return CCS_RESULT_SUCCESS; ccs_result_t err; tuner_last_t *tuner_data; - err = ccs_user_defined_tree_tuner_get_tuner_data( + err = ccs_user_defined_tuner_get_tuner_data( tuner, (void **)&tuner_data); if (err) return err; @@ -126,17 +128,17 @@ tuner_last_tell( ccs_result_t tuner_last_get_optima( - ccs_tree_tuner_t tuner, - size_t num_evaluations, - ccs_tree_evaluation_t *evaluations, - size_t *num_evaluations_ret) + ccs_tuner_t tuner, + size_t num_evaluations, + ccs_evaluation_t *evaluations, + size_t *num_evaluations_ret) { if (evaluations) { if (num_evaluations < 1) return CCS_RESULT_ERROR_INVALID_VALUE; ccs_result_t err; tuner_last_t *tuner_data; - err = ccs_user_defined_tree_tuner_get_tuner_data( + err = ccs_user_defined_tuner_get_tuner_data( tuner, (void **)&tuner_data); if (err) return err; @@ -151,17 +153,17 @@ tuner_last_get_optima( ccs_result_t tuner_last_get_history( - ccs_tree_tuner_t tuner, - size_t num_evaluations, - ccs_tree_evaluation_t *evaluations, - size_t *num_evaluations_ret) + ccs_tuner_t tuner, + size_t num_evaluations, + ccs_evaluation_t *evaluations, + size_t *num_evaluations_ret) { if (evaluations) { if (num_evaluations < 1) return CCS_RESULT_ERROR_INVALID_VALUE; ccs_result_t err; tuner_last_t *tuner_data; - err = ccs_user_defined_tree_tuner_get_tuner_data( + err = ccs_user_defined_tuner_get_tuner_data( tuner, (void **)&tuner_data); if (err) return err; @@ -174,7 +176,7 @@ tuner_last_get_history( return CCS_RESULT_SUCCESS; } -ccs_user_defined_tree_tuner_vector_t tuner_last_vector = { +ccs_user_defined_tuner_vector_t tuner_last_vector = { &tuner_last_del, &tuner_last_ask, &tuner_last_tell, @@ -189,7 +191,7 @@ test(void) { ccs_tree_space_t tree_space; ccs_objective_space_t ospace; - ccs_tree_tuner_t tuner, tuner_copy; + ccs_tuner_t tuner, tuner_copy; ccs_result_t err; tuner_last_t *tuner_data; ccs_datum_t d; @@ -202,32 +204,33 @@ test(void) tuner_data = (tuner_last_t *)calloc(1, sizeof(tuner_last_t)); assert(tuner_data); - err = ccs_create_user_defined_tree_tuner( + err = ccs_create_user_defined_tuner( "problem", ospace, &tuner_last_vector, tuner_data, &tuner); assert(err == CCS_RESULT_SUCCESS); - ccs_tree_evaluation_t last_evaluation; + ccs_evaluation_t last_evaluation; for (size_t i = 0; i < 100; i++) { - ccs_datum_t values[6], res; - size_t num_values; - ccs_tree_configuration_t configuration; - ccs_tree_evaluation_t evaluation; - ccs_int_t v; - err = ccs_tree_tuner_ask(tuner, 1, &configuration, NULL); + ccs_datum_t values[6], res; + size_t num_values; + ccs_search_configuration_t configuration; + ccs_evaluation_t evaluation; + ccs_int_t v; + err = ccs_tuner_ask(tuner, 1, &configuration, NULL); assert(err == CCS_RESULT_SUCCESS); err = ccs_tree_configuration_get_values( - configuration, 6, values, &num_values); + (ccs_tree_configuration_t)configuration, 6, values, + &num_values); assert(err == CCS_RESULT_SUCCESS); v = 0; for (size_t i = 0; i < num_values; i++) { v += values[i].value.i; } res = ccs_float(v); - err = ccs_create_tree_evaluation( + err = ccs_create_evaluation( ospace, configuration, CCS_RESULT_SUCCESS, 1, &res, &evaluation); assert(err == CCS_RESULT_SUCCESS); - err = ccs_tree_tuner_tell(tuner, 1, &evaluation); + err = ccs_tuner_tell(tuner, 1, &evaluation); assert(err == CCS_RESULT_SUCCESS); last_evaluation = evaluation; err = ccs_release_object(configuration); @@ -236,14 +239,14 @@ test(void) assert(err == CCS_RESULT_SUCCESS); } - size_t count; - ccs_tree_evaluation_t history[100]; - err = ccs_tree_tuner_get_history(tuner, 100, history, &count); + size_t count; + ccs_evaluation_t history[100]; + err = ccs_tuner_get_history(tuner, 100, history, &count); assert(err == CCS_RESULT_SUCCESS); assert(count == 1); - ccs_tree_evaluation_t evaluation; - err = ccs_tree_tuner_get_optima(tuner, 1, &evaluation, NULL); + ccs_evaluation_t evaluation; + err = ccs_tuner_get_optima(tuner, 1, &evaluation, NULL); assert(err == CCS_RESULT_SUCCESS); assert(last_evaluation == evaluation); @@ -276,11 +279,11 @@ test(void) CCS_DESERIALIZE_OPTION_END); assert(err == CCS_RESULT_SUCCESS); - err = ccs_tree_tuner_get_history(tuner_copy, 100, history, &count); + err = ccs_tuner_get_history(tuner_copy, 100, history, &count); assert(err == CCS_RESULT_SUCCESS); assert(count == 1); - err = ccs_tree_tuner_get_optima(tuner_copy, 1, &evaluation, &count); + err = ccs_tuner_get_optima(tuner_copy, 1, &evaluation, &count); assert(err == CCS_RESULT_SUCCESS); assert(count == 1); diff --git a/tests/test_user_defined_tuner.c b/tests/test_user_defined_tuner.c index 1615ba47..e73bbd74 100644 --- a/tests/test_user_defined_tuner.c +++ b/tests/test_user_defined_tuner.c @@ -26,10 +26,10 @@ tuner_last_del(ccs_tuner_t tuner) ccs_result_t tuner_last_ask( - ccs_tuner_t tuner, - size_t num_configurations, - ccs_configuration_t *configurations, - size_t *num_configurations_ret) + ccs_tuner_t tuner, + size_t num_configurations, + ccs_search_configuration_t *configurations, + size_t *num_configurations_ret) { if (!configurations) { *num_configurations_ret = 1; @@ -37,12 +37,13 @@ tuner_last_ask( } ccs_result_t err; ccs_configuration_space_t configuration_space; - err = ccs_tuner_get_configuration_space(tuner, &configuration_space); + err = ccs_tuner_get_search_space( + tuner, (ccs_search_space_t *)&configuration_space); if (err) return err; err = ccs_configuration_space_samples( configuration_space, NULL, NULL, num_configurations, - configurations); + (ccs_configuration_t *)configurations); if (err) return err; if (num_configurations_ret) @@ -158,9 +159,9 @@ test(void) ccs_evaluation_t last_evaluation; for (size_t i = 0; i < 100; i++) { - ccs_datum_t values[2], res; - ccs_configuration_t configuration; - ccs_evaluation_t evaluation; + ccs_datum_t values[2], res; + ccs_search_configuration_t configuration; + ccs_evaluation_t evaluation; err = ccs_tuner_ask(tuner, 1, &configuration, NULL); assert(err == CCS_RESULT_SUCCESS); err = ccs_binding_get_values(