COGNAC: Circuit Optimization via Gradients and Noise-Aware Compilation