Error mitigation for variational quantum algorithms through mid-circuit measurements