New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Understanding BoundedConstraint class #62
Comments
Hi Nicholas, Thanks for the comment. You actually have to set
as
On another note, why do you only have 3 states? |
If missing, can you then create a patch/PR with the dimension check on It could also be something to mention in the docstrings of safe-control-gym/safe_control_gym/envs/constraints.py Lines 285 to 292 in c031b74
(I think Nicholas has a different state vector length because wants to work on creating a new environment) |
@JacopoPan Yes for sure, but I just want to make sure this is actually the issue first, so I'll wait until Nicholas gets it working. |
Hi @adamhall Thanks a lot for the detailed response and explanation, as well as helping me check if it is working on your end. Yes indeed I actually tried that out as well, which as I mentioned in the above post, if I set
However, I did a sanity check with the following code and indeed it works.
After further debugging, I realized since I've been experimenting with classical control for my own environment, I haven't been paying attention to my I just found out safe-control-gym/safe_control_gym/envs/benchmark_env.py Lines 182 to 187 in d7a59cc
so when I forgot to update my I fixed the Thank you so much for your clarification. It's a silly mistake for me forgetting to maintain my |
@adamhall PR patch to |
Some warnings and checks for the dimension of the bounds and the active_dims added as part of PR #88. |
I'm not sure if this is a bug or i'm using the functionality wrong, so please let me know accordingly.
Here is how I'm trying to use BoundedConstraint, specified in my
task_config
yaml
file.When i use BoundedConstraint for constraining state (I have 3 states but want to constraint only 1), I realize I needed to supply
lower_bounds
&upper_bounds
with shapes that are equal to the number of states (e.g. 3 if have 3 states), due toself.dim
being defined as such:self.dim = env.state_dim
which is used inself.constraint_filter = np.eye(self.dim)[active_dims]
here, where it is supposed to only extractactive_dims
from these bounds for the target state to be constrained.But when i do so, where
lower_bounds
matches shape ofenv.state_dim
, the assertion hereassert A.shape[1] == self.dim, '[ERROR] A has the wrong dimension!'
fails.This seem to fail because in
Constraint
, inside this code chunk, afterconstraint_filter
is defined,self.dim
is overwritten bylen(active_dims)
, so it would have shape ofactive_dims
which when I use is 1, whileA
already has shape(6, 3)
due toself.dim
being set toenv.state_dim
which was 3 earlier.Could you please check if this was the issue?
Another attempt I took was to set
lower_bounds
to have shape same asactive_dims
, e.g. 1 (only want to constraint 1 state). It doesn't work, becausematmul
would fail hereself.sym_func = lambda x: self.A @ self.constraint_filter @ x - self.b
forLinearConstraint
.Full error:
ValueError: matmul: Input operand 1 has a mismatch in its core dimension 0, with gufunc signature (n?,k),(k,m?)->(n?,m?) (size 1 is different from 3)
Summary:
What is the right shape for
lower_bounds
andupper_bounds
?env.state_dim
, I get error fromassert A.shape[1] == self.dim, '[ERROR] A has the wrong dimension!'
becauseself.dim = len(active_dims)
.len(active_dims)
, it throws errorValueError: matmul: Input operand 1 has a mismatch in its core dimension 0, with gufunc signature (n?,k),(k,m?)->(n?,m?) (size 1 is different from 3)
because ofself.sym_func = lambda x: self.A @ self.constraint_filter @ x - self.b
.Would love to know if this is indeed a bug or if I'm using it wrong. I'll also keep trying again in case maybe I missed anything.
Thank you!
@adamhall @JacopoPan @Justin-Yuan
The text was updated successfully, but these errors were encountered: