A Hierarchical Approach to the Design and Optimization of Photonics