Optimization of a Spatially Varying Grating with Dynamic Link