Unable to provide initial condition to specific states

Hi,
I want to provide initial condition to only specific states using nbx_0 and idxbx_0 in python. For example, I have 12 states and want to provide initial condition to only [2, 5, 8, 11] state indices.

When I set nbx_0 = 4 and idxbx_0 = [2, 5, 8, 11] and run the code, acados_ocp.json has “idxbx_0”: [ 0, 1, 2, 3 ] instead of [2, 5, 8, 11]. As a result the initial conditions are provided to states [0, 1, 2, 3] than [2, 5, 8, 11].

Can you please let me know if I am doing something wrong here?

Thanks!

cheers,
Jay

Hi Jay,

I just tried to reproduce what you reported, modifying the example https://github.com/acados/acados/blob/master/examples/acados_python/getting_started/ocp/minimal_example_ocp.py

replacing

ocp.constraints.x0 = np.array([0.0, np.pi, 0.0, 0.0])

with

ocp.constraints.idxbx_0 = np.array([1, 2, 3])
ocp.constraints.lbx_0 = np.array([np.pi, 0, 0])
ocp.constraints.ubx_0 = np.array([np.pi, 0, 0])

such that the initial condition for the position of the car is free.
For me this works as expected.

Can you try this?
Can you do a minimal modification of the example to reproduce the behavior you described?

Best,
Jonathan

EDIT: Please try on the latest master, especially after this merge https://github.com/acados/acados/pull/637

Hi Jonathan,

Thanks for the reply! It worked for me only with the [ 2c64cab] commit.

However if you try in the car example replacing line with https://github.com/acados/acados/blob/master/examples/acados_python/race_cars/acados_settings_dev.py#L156 with

ocp.constraints.idxbx_0 = np.arange(nx)
ocp.constraints.lbx_0 = model.x0
ocp.constraints.ubx_0 = model.x0

It throws an error

Exception: acados -- mismatching dimensions for field idxbxe_0. 
Provided data has dimensions (0,), while associated dimensions ['nbxe_0'] are (6,)

It seems similar to the one you fixed in the latest commit [ 2c64cab], so I wonder why won’t it work.
Btw, I have written my code using race_car as an example and I get same error.

Cheers,
Jay

Hi Jay,

you are right, I fixed the previous commit https://github.com/acados/acados/pull/638
I hope everything works for you now as expected.

Best,
Jonathan

Hi Jonathan,

When I tried this again with the latest hotfix [ f5fcf95]

I get this error

line 157, in make_ocp_dims_consistent
and dims.nbxe_0 == None and all(constraints.idxbxe_0 == constraints.idxbx_0):
TypeError: 'bool' object is not iterable

Thanks,
Jay

Right, sorry that was sloppy.
I made another hotfix. https://github.com/acados/acados/pull/639
Please pull again the latest master and let me know if there is another issue.

Cheers,
Jonathan

It works now!
Thanks a lot Jonathan for your patience and help :slightly_smiling_face:

Cheers,
Jay