Optimizing sparse fermionic Hamiltonians