Causal Invariance Learning via Efficient Optimization of a Nonconvex Objective