Skip to content

Commit

Permalink
Merge pull request #51 from LucasAlegre/hotfix/recover-solver-error-ols
Browse files Browse the repository at this point in the history
Recover from solver error in OLS
  • Loading branch information
ffelten authored Apr 4, 2023
2 parents d7cecab + f1f84ec commit 50ffbc6
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
1 change: 1 addition & 0 deletions examples/pcn_minecart.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ def make_env():
)

agent.train(
eval_env=make_env(),
total_timesteps=int(1e7),
ref_point=np.array([0, 0, -200.0]),
num_er_episodes=20,
Expand Down
8 changes: 7 additions & 1 deletion morl_baselines/multi_policy/linear_support/linear_support.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import cdd
import cvxpy as cp
import numpy as np
from cvxpy import SolverError
from gymnasium.core import Env

from morl_baselines.common.evaluation import policy_evaluation_mo
Expand Down Expand Up @@ -289,7 +290,12 @@ def max_value_lp(self, w_new: np.ndarray) -> float:
# such that it is consistent with other optimal values for other visited weights
constraints = [W @ v <= V]
prob = cp.Problem(objective, constraints)
return prob.solve(verbose=False)
try:
result = prob.solve(verbose=False)
except SolverError:
print("ECOS solver error, trying another one.")
result = prob.solve(solver=cp.SCS, verbose=False)
return result

def compute_corner_weights(self) -> List[np.ndarray]:
"""Returns the corner weights for the current set of values.
Expand Down

0 comments on commit 50ffbc6

Please sign in to comment.