9001639a8d317bc069661222a56d5d216d872085,tests/test_mpc.py,,test_lqr_linear_unbounded,#,91

Before Change


    dynamics = AffineDynamics(R[0,0], S[0,0], f[0,0])

    u_lqr = None
    x_lqr, u_lqr, objs_lqr = mpc.MPC(
        n_state, n_ctrl, T, x_init, u_lower, u_upper, u_lqr,
        lqr_iter=10,
        backprop=False,
        verbose=1,
        exit_unconverged=False,
    )(C, c, dynamics)
    tau_lqr = torch.cat((x_lqr, u_lqr), 2)
    tau_lqr = util.get_data_maybe(tau_lqr)
    npt.assert_allclose(tau_cp, tau_lqr[:,0].numpy(), rtol=1e-3)

    u_lqr = None
    x_lqr, u_lqr, objs_lqr = mpc.MPC(
        n_state, n_ctrl, T, x_init, None, None, u_lqr,
        lqr_iter=10,
        backprop=False,
        exit_unconverged=False,
    )(C, c, dynamics)
    tau_lqr = torch.cat((x_lqr, u_lqr), 2)
    tau_lqr = util.get_data_maybe(tau_lqr)
    npt.assert_allclose(tau_cp, tau_lqr[:,0].numpy(), rtol=1e-3)

After Change


    n_sc = n_state + n_ctrl
    T = 5
    C = npr.randn(T, n_batch, n_sc, n_sc)
    C = np.matmul(C.transpose(0, 1, 3, 2), C)
    c = npr.randn(T, n_batch, n_sc)
    alpha = 0.2
    R = np.tile(np.eye(n_state)+alpha*np.random.randn(n_state, n_state),
                (T, n_batch, 1, 1))
    S = np.tile(np.random.randn(n_state, n_ctrl), (T, n_batch, 1, 1))
    F = np.concatenate((R, S), axis=3)
    f = np.tile(npr.randn(n_state), (T, n_batch, 1))
    x_init = npr.randn(n_batch, n_state)
    // u_lower = -100.*npr.random((T, n_batch, n_ctrl))
    // u_upper = 100.*npr.random((T, n_batch, n_ctrl))
    u_lower = -1e4*np.ones((T, n_batch, n_ctrl))
    u_upper = 1e4*np.ones((T, n_batch, n_ctrl))

    tau_cp, objs_cp = lqr_cp(
        C[:,0], c[:,0], F[:,0], f[:,0], x_init[0], T, n_state, n_ctrl,
        None, None
    )
    tau_cp = tau_cp.T
    x_cp = tau_cp[:,:n_state]
    u_cp = tau_cp[:,n_state:]

    C, c, R, S, F, f, x_init, u_lower, u_upper = [
        Variable(torch.Tensor(x).double()) if x is not None else None
        for x in [C, c, R, S, F, f, x_init, u_lower, u_upper]
    ]

    dynamics = AffineDynamics(R[0,0], S[0,0], f[0,0])

    u_lqr = None
    x_lqr, u_lqr, objs_lqr = mpc.MPC(
        n_state, n_ctrl, T, u_lower, u_upper, u_lqr,
        lqr_iter=10,
        backprop=False,
        verbose=1,
        exit_unconverged=True,
    )(x_init, QuadCost(C, c), dynamics)
    tau_lqr = torch.cat((x_lqr, u_lqr), 2)
    tau_lqr = util.get_data_maybe(tau_lqr)
    npt.assert_allclose(tau_cp, tau_lqr[:,0].numpy(), rtol=1e-3)

    u_lqr = None
    x_lqr, u_lqr, objs_lqr = mpc.MPC(
        n_state, n_ctrl, T, None, None, u_lqr,
        lqr_iter=10,
        backprop=False,
        exit_unconverged=False,
    )(x_init, QuadCost(C, c), dynamics)
    tau_lqr = torch.cat((x_lqr, u_lqr), 2)
    tau_lqr = util.get_data_maybe(tau_lqr)
    npt.assert_allclose(tau_cp, tau_lqr[:,0].numpy(), rtol=1e-3)
Italian Trulli
In pattern: SUPERPATTERN

Frequency: 4

Non-data size: 3

Instances


Project Name: locuslab/mpc.pytorch
Commit Name: 9001639a8d317bc069661222a56d5d216d872085
Time: 2018-10-10
Author: bamos@cs.cmu.edu
File Name: tests/test_mpc.py
Class Name:
Method Name: test_lqr_linear_unbounded


Project Name: locuslab/mpc.pytorch
Commit Name: 9001639a8d317bc069661222a56d5d216d872085
Time: 2018-10-10
Author: bamos@cs.cmu.edu
File Name: tests/test_mpc.py
Class Name:
Method Name: test_lqr_cuda_singleton


Project Name: locuslab/mpc.pytorch
Commit Name: 9001639a8d317bc069661222a56d5d216d872085
Time: 2018-10-10
Author: bamos@cs.cmu.edu
File Name: tests/test_mpc.py
Class Name:
Method Name: test_lqr_linear_unbounded