Guilin Sun
Ansys Employee

Lumerical has a built-in optimization based on particle-swarm method, and if you have API license you can use either Matlab or Python optimization.

In this example the blaze grating is script with theta, and period. You can modify it, or use your own math to modify the script to create the desired grating. Please try.