I'm trying to run an optimization step and I want to update a global variable from within a function. I'm using an optimization script and I want to save the data when there are any updates but I cannot update the global variable from within a function.
Is there a way to update a global variable from within a function call? I am making sure not to run the optimization step in parallel so this technically should be ok.
global current_minimum
current_minimum = 0
def update():
current_minimum = -0.1
_ = update()
print(current_minimum)
# 0