Skip to content

Commit deae73f

Browse files
committed
move Ching-An's bug fix from experimental branch to main branch
1 parent 0a08745 commit deae73f

File tree

3 files changed

+14
-4
lines changed

3 files changed

+14
-4
lines changed

opto/optimizers/optoprime.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -537,9 +537,12 @@ def extract_llm_suggestion(self, response: str):
537537

538538
# if the suggested value is a code, and the entire code body is empty (i.e., not even function signature is present)
539539
# then we remove such suggestion
540+
keys_to_remove = []
540541
for key, value in suggestion.items():
541-
if "__code" in key and value == "":
542-
del suggestion[key]
542+
if "__code" in key and value.strip() == "":
543+
keys_to_remove.append(key)
544+
for key in keys_to_remove:
545+
del suggestion[key]
543546

544547
return suggestion
545548

opto/version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = "0.1.3.7"
1+
__version__ = "0.1.3.8"

tests/unit_tests/test_optimizer.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,7 @@ def my_fun(x):
150150
"""Test function"""
151151
return x**2 + 1
152152

153+
old_func_value = my_fun.parameter.data
153154

154155
x = node(-1, trainable=False)
155156
optimizer = OptoPrime([my_fun.parameter])
@@ -163,17 +164,23 @@ def my_fun(x):
163164
print(p.name, p.data)
164165
optimizer.step(verbose=True)
165166

167+
new_func_value = my_fun.parameter.data
168+
169+
assert str(old_func_value) != str(new_func_value), "Update failed"
170+
if str(old_func_value) != str(new_func_value):
171+
print(f"Function failed to update: old func value: {str(new_func_value)}, new func value: {str(new_func_value)}")
172+
166173

167174
# Test directly providing feedback to parameters
168175
GRAPH.clear()
169176
x = node(-1, trainable=True)
177+
170178
optimizer = OptoPrime([x])
171179
feedback = "test"
172180
optimizer.zero_feedback()
173181
optimizer.backward(x, feedback)
174182
optimizer.step(verbose=True)
175183

176-
177184
# Test if we can save log in both pickle and json
178185
import json, pickle
179186
json.dump(optimizer.log, open("log.json", "w"))

0 commit comments

Comments
 (0)