Parameter shift rule with optimal phase selection