Refactor ParameterGrid to use OrderedDict to keep the parameters sorted alphabetically.

See #4017 and #3267

@amueller @larsmans