def target_robustness_1d(system, amps,dt,Utarget, gvar, vals):
    # initialize the fidelities
    fidelities = empty(len(vals))
    
    for k in range(len(vals)):
        c_sys = control_system(system.drift + vals[k]*gvar, system.control_generators.copy())
        fidelities[k] = grape_objective(Utarget, evolve_system(c_sys,amps,dt))/4
    
    plt.plot(vals, fidelities)
    plt.ticklabel_format(useOffset=False)
    plt.show()
    def obj(x):
        #nonlocal num
        #num = num+1
        # evolve the system that computes both the final unitary as well
        # as decoupling terms
        prop = evolve_system(dec_sys, x, dt, deriv=1)

        #extract the final unitary, as well as the array of derivatives
        # with respect to control amplitudes
        Ufinal = prop[0][0:2, 0:2]
        Uderiv = prop[1][:, :, 0:2, 0:2]

        # compute the grape objective; the fidelity to the target gate
        # as well its jacobian
        g, gp = grape_objective(Utarget, (Ufinal, Uderiv), deriv=1)

        # compute the norms of the decoupling terms, as well as their
        # derivatives
        decx, decxp = zero_block_objective(prop, 2, 0, 1, deriv=1)
        decy, decyp = zero_block_objective(prop, 2, 1, 2, deriv=1)
        decz, deczp = zero_block_objective(prop, 2, 2, 3, deriv=1)

        # add together the decoupling objectives and derivatives
        dec = decx + decy + decz
        decp = decxp + decyp + deczp

        shape, shaped = cons.mono_objective(x,
                                            power_lb,
                                            power_ub,
                                            power_tol,
                                            change_b,
                                            change_tol,
                                            deriv=1)

        #if num % 100 == 0:
        #    print('Value at ' + str(num) + ' iterations: '+  str(real(-g+dec+shape)))

        #return real(-g+dec+power+change/20),real(-gp+decp+powerp+changep/20)
        return real(-g + dec + shape / 100), real(-gp + decp + shaped / 100)
    def obj(x):
        # fora given control value, propagate the decoupling system, and compute
        # derivatives
        prop = evolve_system(dec_z_sys, x, dt, deriv=1)

        # extract the final unitary and its derivatives
        Ufinal = prop[0][0:2, 0:2]
        Uderiv = prop[1][:, :, 0:2, 0:2]

        # compute the target unitary objective and its derivatives
        g, gp = grape_objective(Utarget, (Ufinal, Uderiv), deriv=1)

        # compute the decoupling objective and its derivatives
        dec, decp = zero_block_objective(prop, 2, 0, 1, deriv=1)

        shape, shaped = cons.mono_objective(x,
                                            power_lb,
                                            power_ub,
                                            power_tol,
                                            change_b,
                                            change_tol,
                                            deriv=1)

        return real(-g + dec + shape / 20), real(-gp + decp + shaped / 20)