Convex and Bilevel Optimization for Neuro-Symbolic Inference and Learning