Ab-initio Automated Optimization of Nonlocality in Photonic Quantum States