An optimal Petrov-Galerkin framework for operator networks