Repository: ESMCI/cime

Issue:
query_config --grids doesn't show new MOM grid unless --comp_interface nuopc is specified
When I run `query_config --grids` with cesm2_3_beta15, there is no mention of the recently added MOM grid `tx2_3v2`.
It shows up if I add the argument `--comp_interface nuopc` to the command line invocation.
It looks like this is because the default for `--comp_interface` is `mct`:https://github.com/ESMCI/cime/blob/bc19d7150c9b87384de578d3ef67f0b9e0b627b0/CIME/scripts/query_config.py#L315-L320
For CESM, this default differs from the default for `--driver` in `create_newcase`,
so CESM users see output from `query_config` that doesn't match `create_newcase` (by default).
Would it make sense to make the default for `--comp_interface` in `query_config` be `get_cime_default_driver()`,
as is done in `create_newcase`? https://github.com/ESMCI/cime/blob/bc19d7150c9b87384de578d3ef67f0b9e0b627b0/CIME/scripts/create_newcase.py#L240-L245

(Is there a reason for this option to be named `--driver` in `create_newcase` and `--comp_interface` in `query_config`? I find it confusing, but perhaps there is a distinction that I'm not aware of.)


Discussion:
I have the same problem with the mizuRoute grids, that I've been putting up with, but would like the default updated as well. Since, CESM has MCT deprecated, we really should update the default to be NUOPC.
It looks like one way to have a different default for cesm is to do something like:

``` python
comp_interface_default = "mct"
if config.test_mode == "cesm":
   comp_interface_default = "nuopc"

 parser.add_argument( 
     "--comp_interface", 
     choices=supported_comp_interfaces, 
     default=comp_interface_default, 
     help="Coupler/Driver interface", 
 ) 
```

Although the way outlined above how it's done for create_newcase seems a simpler and better method.
Is there a reason to not use the `get_cime_default_driver()` function from `CIME.utils`, like is done for `create_newcase`?
This is what I was getting at in the initial comment.
Ahhh, I see what you mean. I didn't pick that up on my first read through. I do think that's the way to do it, and it might as well also use drv_choices to list the options the same was as done in create_newcase.

For the purposes of these two scripts, I don't think there is an important distinction between "driver" and "comp_interface". The name of the internal XML variable is "COMP_INTERFACE", so --comp_interface corresponds closer to that. But, you also can't just create a case and change the COMP_INTERFACE variable and get the case to work. It is something that you need to know at the top level to get it to work correctly.
In looking at the blame and git log for these two scripts, it looks like create_newcase always used driver and query_config always used comp_interface going all the way back. The query_config script does have several internal variables that use comp_interface, so having the command line option be "driver", would be a little strange unless you changed all of that. I also get the impression that the query_config could use the simpler methodology used in create_newcase, but I can't say for sure.

@jasonb5 you did a lot of the work on query_config for this, do you think the distinction for comp_interface in query_config is important? Could it be changed to use "driver" and more similar to the methodology used in create_newcase?
@ekluzek The distinction is not very important. I'd be fine with updating the argument to be `driver`. @jgfouca Any thoughts on this change?

The model specific driver options and defaults are exposed through the `Config` class
https://github.com/ESMCI/cime/blob/5877fde1677982ad5b2fdd3adc49be59aa231dae/CIME/config.py#L190-L197

If the defaults don't work, you can [customize](https://esmci.github.io/cime/versions/master/html/users_guide/cime-customize.html) it in your model's `cime_config` directory, you can reference the [E3SM config](https://github.com/E3SM-Project/E3SM/blob/fc9f903ccd497204c699a2517cc0dbc0df83d54b/cime_config/customize/config.py#L34-L35).
I'd be fine with changing the arg to driver.

Resolving patch:
diff --git a/CIME/scripts/create_newcase.py b/CIME/scripts/create_newcase.py
--- a/CIME/scripts/create_newcase.py
+++ b/CIME/scripts/create_newcase.py
@@ -239,6 +239,8 @@ def parse_command_line(args, cimeroot, description):
 
     parser.add_argument(
         "--driver",
+        # use get_cime_default_driver rather than config.driver_default as it considers
+        # environment, user config then config.driver_default
         default=get_cime_default_driver(),
         choices=drv_choices,
         help=drv_help,
diff --git a/CIME/scripts/query_config.py b/CIME/scripts/query_config.py
--- a/CIME/scripts/query_config.py
+++ b/CIME/scripts/query_config.py
@@ -8,7 +8,7 @@
 
 from CIME.Tools.standard_script_setup import *
 import re
-from CIME.utils import expect
+from CIME.utils import expect, get_cime_default_driver, deprecate_action
 from CIME.XML.files import Files
 from CIME.XML.component import Component
 from CIME.XML.compsets import Compsets
@@ -314,8 +314,16 @@ def parse_command_line(args, description):
 
     parser.add_argument(
         "--comp_interface",
-        choices=supported_comp_interfaces,
+        choices=supported_comp_interfaces,  # same as config.driver_choices
         default="mct",
+        action=deprecate_action(", use --driver argument"),
+        help="DEPRECATED: Use --driver argument",
+    )
+
+    parser.add_argument(
+        "--driver",
+        choices=config.driver_choices,
+        default=get_cime_default_driver(),
         help="Coupler/Driver interface",
     )
 
@@ -332,7 +340,7 @@ def parse_command_line(args, description):
         args.machines,
         args.long,
         args.xml,
-        files[args.comp_interface],
+        files[args.driver],
     )
 
 
diff --git a/CIME/utils.py b/CIME/utils.py
--- a/CIME/utils.py
+++ b/CIME/utils.py
@@ -8,6 +8,7 @@
 import importlib.util
 import errno, signal, warnings, filecmp
 import stat as statlib
+from argparse import Action
 from contextlib import contextmanager
 
 from distutils import file_util
@@ -21,6 +22,14 @@
 GLOBAL = {}
 
 
+def deprecate_action(message):
+    class ActionStoreDeprecated(Action):
+        def __call__(self, parser, namespace, values, option_string=None):
+            raise DeprecationWarning(f"{option_string} is deprecated{message}")
+
+    return ActionStoreDeprecated
+
+
 def import_from_file(name, file_path):
     loader = importlib.machinery.SourceFileLoader(name, file_path)
 


Test patch:
diff --git a/CIME/scripts/create_test.py b/CIME/scripts/create_test.py
--- a/CIME/scripts/create_test.py
+++ b/CIME/scripts/create_test.py
@@ -219,7 +219,7 @@ def parse_command_line(args, description):
 
         parser.add_argument(
             "--driver",
-            choices=("mct", "nuopc", "moab"),
+            choices=model_config.driver_choices,
             help="Override driver specified in tests and use this one.",
         )