Skip to content

Commit

Permalink
Fixed leaks in Python test, and upgrade ruby to use same strategy.
Browse files Browse the repository at this point in the history
  • Loading branch information
Kerilk committed Sep 7, 2023
1 parent ba548e7 commit f672e66
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 15 deletions.
2 changes: 1 addition & 1 deletion bindings/python/cconfigspace/tree_space.py
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ def tree_space_data(self):
self._tree_space_data = ct.cast(v, ct.py_object).value
else:
self._tree_space_data = None
return self._tuner_data
return self._tree_space_data

TreeSpace.Dynamic = DynamicTreeSpace

Expand Down
16 changes: 8 additions & 8 deletions samples/test_python.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@

class TestTuner(ccs.UserDefinedTuner):
def __init__(self, cs, os):
self.__history = []
self.__optima = []
data = [[], []]

def delete(tuner):
return None
Expand All @@ -19,11 +18,12 @@ def ask(tuner, count):
return (cs.samples(count), count)

def tell(tuner, evaluations):
self.__history += evaluations
history_optima = tuner.tuner_data
history_optima[0] += evaluations
for e in evaluations:
discard = False
new_optima = []
for o in self.__optima:
for o in history_optima[1]:
if discard:
new_optima.append(o)
else:
Expand All @@ -35,16 +35,16 @@ def tell(tuner, evaluations):
new_optima.append(o)
if not discard:
new_optima.append(e)
self.__optima = new_optima
history_optima[1] = new_optima
return None

def get_history(tuner):
return self.__history
return tuner.tuner_data[0]

def get_optima(tuner):
return self.__optima
return tuner.tuner_data[1]

super().__init__(name = "tuner", configuration_space = cs, objective_space = os, delete = delete, ask = ask, tell = tell, get_optima = get_optima, get_history = get_history)
super().__init__(name = "tuner", configuration_space = cs, objective_space = os, delete = delete, ask = ask, tell = tell, get_optima = get_optima, get_history = get_history, tuner_data = data)


def create_test_tuner(cs_ptr, os_ptr):
Expand Down
13 changes: 7 additions & 6 deletions samples/test_ruby.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,11 @@ def initialize(cs, os)
end
}
tell = lambda { |tuner, evaluations|
@history += evaluations
history_optima = tuner.tuner_data
history_optima[0] += evaluations
evaluations.each { |e|
discard = false
@optima = @optima.collect { |o|
history_optima[1] = history_optima[1].collect { |o|
unless discard
case e.compare(o)
when :CCS_COMPARISON_EQUIVALENT, :CCS_COMPARISON_WORSE
Expand All @@ -32,16 +33,16 @@ def initialize(cs, os)
o
end
}.compact
@optima.push(e) unless discard
history_optima[1].push(e) unless discard
}
}
get_history = lambda { |tuner|
@history
tuner.tuner_data[0]
}
get_optima = lambda { |tuner|
@optima
tuner.tuner_data[1]
}
super(name: "tuner", configuration_space: cs, objective_space: os, del: del, ask: ask, tell: tell, get_optima: get_optima, get_history: get_history)
super(name: "tuner", configuration_space: cs, objective_space: os, del: del, ask: ask, tell: tell, get_optima: get_optima, get_history: get_history, tuner_data: [[],[]])
end
end

Expand Down

0 comments on commit f672e66

Please sign in to comment.