Skip to content

Commit

Permalink
Merge pull request #49 from bendudson/measures-catch-exceptions
Browse files Browse the repository at this point in the history
Check for exceptions in measures
  • Loading branch information
bendudson committed Feb 9, 2021
2 parents f29b3ce + e2b7532 commit c21f4e0
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions freegs/optimise.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,10 @@ def weighted_sum(*args):
else:
args_with_weights.append(arg)

return lambda eq: sum(func(eq) * weight for func, weight in args_with_weights)
def combined_measure(eq):
return sum(func(eq) * weight for func, weight in args_with_weights)

return combined_measure


#### Controls for Equilibrium objects
Expand Down Expand Up @@ -193,11 +196,11 @@ def solve_and_measure(eq):
try:
# Re-solve
picard.solve(eq, eq._profiles, eq._constraints)
# Call user-supplied evaluation function
return measure(eq)
except:
# Solve failed.
return float("inf")
# Call user-supplied evaluation function
return measure(eq)

# Call the generic optimiser,
return optimiser.optimise(
Expand Down

0 comments on commit c21f4e0

Please sign in to comment.