Skip to content

Commit

Permalink
Minor changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Federico-PizarroBejarano committed Nov 1, 2024
1 parent 9bb7088 commit 36afdbb
Show file tree
Hide file tree
Showing 8 changed files with 17 additions and 21 deletions.
5 changes: 1 addition & 4 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ examples/mpsc/unsafe_rl_temp_data/
examples/pid/*data/
#
experiments/mpsc/results*
experiments/mpsc/models/rl_models*
#
Results/
results/
z_docstring.py
TODOs.md
Expand Down Expand Up @@ -158,6 +158,3 @@ dmypy.json

*c_generated_code/
*acados_ocp*.json
gpmpc_update/
temp
models/
2 changes: 1 addition & 1 deletion examples/hpo/train_rl_model.sh
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ python ./hpo_experiment.py \
--overrides \
./rl/${ALGO}/config_overrides/${SYS}/${ALGO}_${SYS}.yaml \
./rl/config_overrides/${SYS}/${SYS}_${TASK}.yaml \
--output_dir ./Results/${SYS}_${ALGO}_data/ \
--output_dir ./results/${SYS}_${ALGO}_data/ \
--tag Test \
--opt_hps ./rl/${ALGO}/config_overrides/${SYS}/optimized_hyperparameters.yaml \
--task ${SYS} --seed 2 \
Expand Down
4 changes: 2 additions & 2 deletions examples/rl/rl_experiment.sh
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,6 @@ do
task_config.task_info.ilqr_ref=False \
task_config.task_info.ilqr_traj_data='../lqr/ilqr_ref_traj.npy' \
task_config.noise_scale=${NS}
# --pretrain_path ./Results/Benchmark_data/ilqr_ref/${SYS}_${ALGO}_data/${SEED}
# --pretrain_path ./results/benchmark_data/ilqr_ref/${SYS}_${ALGO}_data/${SEED}
done
#done
#done
2 changes: 1 addition & 1 deletion examples/rl/train_rl_model.sh
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ do
--overrides \
./config_overrides/${SYS}/${ALGO}_${SYS}.yaml \
./config_overrides/${SYS}/${SYS}_${TASK}.yaml \
--output_dir ./Results/${EXP_NAME}/${SYS}_${ALGO}_data/${SEED}/ \
--output_dir ./results/${EXP_NAME}/${SYS}_${ALGO}_data/${SEED}/ \
--seed ${SEED} \
--use_gpu \
--kv_overrides \
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,5 @@ sf_config:
decay_factor: 0.85

# Softening
soften_constraints: False
soften_constraints: True
slack_cost: 250
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,8 @@ task_config:
lower_bounds: [-0.9, -2, 0.55, -2, -0.75, -3]
- constraint_form: default_constraint
constrained_variable: input
upper_bounds: [0.58212, 0.7]
lower_bounds: [0.09702, -0.7]
upper_bounds: [0.58212, 0.4]
lower_bounds: [0.09702, -0.4]

done_on_out_of_bound: True
done_on_violation: False
5 changes: 3 additions & 2 deletions experiments/mpsc/mpsc_experiment.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,8 +162,9 @@ def run_multiple_models(plot, all_models):
'config': config,
'X_GOAL': X_GOAL}

with open(f'./results_mpsc/{model}.pkl', 'wb') as f:
pickle.dump(all_results, f)
if not plot:
with open(f'./results_mpsc/{model}.pkl', 'wb') as f:
pickle.dump(all_results, f)


if __name__ == '__main__':
Expand Down
14 changes: 6 additions & 8 deletions safe_control_gym/safety_filters/mpsc/nl_mpsc.py
Original file line number Diff line number Diff line change
Expand Up @@ -1003,9 +1003,6 @@ def setup_acados_optimizer(self):
ocp.cost.Vu[nx:nx + nu, :] = np.eye(nu)
ocp.cost.Vx_e = np.eye(nx)

ocp.model.cost_y_expr = cs.vertcat(model.x, model.u)
ocp.model.cost_y_expr_e = model.x

# Updated on each iteration
ocp.cost.yref = np.concatenate((self.model.X_EQ, self.model.U_EQ))
ocp.cost.yref_e = self.model.X_EQ
Expand All @@ -1021,11 +1018,12 @@ def setup_acados_optimizer(self):
ocp.constraints.ug = np.zeros((self.p))

# Slack
ocp.constraints.Jsg = np.eye(self.p)
ocp.cost.Zu = np.array([500] * self.p)
ocp.cost.Zl = np.array([500] * self.p)
ocp.cost.zu = np.array([500] * self.p)
ocp.cost.zl = np.array([500] * self.p)
if self.soften_constraints:
ocp.constraints.Jsg = np.eye(self.p)
ocp.cost.Zu = self.slack_cost * np.ones(self.p)
ocp.cost.Zl = self.slack_cost * np.ones(self.p)
ocp.cost.zu = self.slack_cost * np.ones(self.p)
ocp.cost.zl = self.slack_cost * np.ones(self.p)

# Options
ocp.solver_options.qp_solver = 'FULL_CONDENSING_HPIPM'
Expand Down

0 comments on commit 36afdbb

Please sign in to comment.