From 86b6acdab7094053944ba7d9b8ff7cc02750c99d Mon Sep 17 00:00:00 2001 From: ChunYen-Chen Date: Sun, 29 Sep 2024 15:29:09 +0800 Subject: [PATCH 01/29] Add autocomplete related --- src/configure.py | 80 +++++++++++++++++++++++++------- tool/bash/config_autocomplete.sh | 24 ++++++++++ 2 files changed, 86 insertions(+), 18 deletions(-) create mode 100755 tool/bash/config_autocomplete.sh diff --git a/src/configure.py b/src/configure.py index 2b36819c45..1689e7f6c2 100755 --- a/src/configure.py +++ b/src/configure.py @@ -34,7 +34,6 @@ LOGGER = logging.getLogger() LOG_FORMAT = '%(asctime)s %(levelname)-8s: %(message)s' -logging.basicConfig( filename=GAMER_MAKE_OUT+'.log', filemode='w', level=logging.INFO, format=LOG_FORMAT ) @@ -219,6 +218,39 @@ def print_help( self, *args, **kwargs ): if "print_detail" in kwargs: self.print_option() if "epilog" in self.program: print(self.program["epilog"]) + def print_autocomplete( self, target_option, *args, **kwargs ): + if target_option == "all": + all_options = [] + for option in self.options: + all_options += option["flags"] + print( " ".join(all_options) ) + return + + if target_option == "--machine": + all_files = os.listdir( GAMER_CONFIG_DIR ) + config_files = [ f for f in all_files if ".config" in f ] + config_files = list( map( lambda f: f.replace( ".config", "" ), config_files ) ) + print( " ".join(config_files) ) + return + + for option in self.options: + if target_option not in option["flags"]: continue + + # option with choices + if "choices" in option: + print( " ".join(option["choices"]) ) + return + + # help like option + if "type" not in option: return + + # boolean type choices + if option["type"] == str2bool: + print( "true false" ) + return + + return + #################################################################################################### @@ -369,6 +401,12 @@ def load_arguments(): help="Show this help message in detail and exit.\n" ) + # autocomplete information + parser.add_argument( "--autocomplete_info", type=str, metavar="--OPTION", + default=None, + help="Print out the autocomplete information. See: ../tool/bash/config_autocomplete.sh\n" + ) + # machine config setup parser.add_argument( "--machine", type=str, metavar="MACHINE", default="eureka_intel", @@ -688,6 +726,11 @@ def load_arguments(): parser.print_help(print_detail=True) exit() + # 2. Print out autocomplete information then exit. + if args["autocomplete_info"] is not None: + parser.print_autocomplete( args["autocomplete_info"] ) + exit() + # 2. Conditional default arguments. args = set_conditional_defaults( args ) return args, name_table, depends, constraints @@ -934,45 +977,46 @@ def warning( paths, **kwargs ): # Main execution #################################################################################################### if __name__ == "__main__": - # 0. Set the logger - ch = logging.StreamHandler() - ch.setFormatter( CustomFormatter() ) - LOGGER.addHandler( ch ) - # 1. Get the execution command - command = " ".join(["# This makefile is generated by the following command:", "\n#", sys.executable] + sys.argv + ["\n"]) - LOGGER.info( " ".join( [sys.executable] + sys.argv ) ) + command = " ".join( ["# This makefile is generated by the following command:", "\n#", sys.executable] + sys.argv + ["\n"] ) # 2. Load the input arguments args, name_table, depends, constraints = load_arguments() - # 3. Prepare the makefile args - # 3.1 Load the machine setup + # 3. Set the logger + logging.basicConfig( filename=GAMER_MAKE_OUT+'.log', filemode='w', level=logging.INFO, format=LOG_FORMAT ) + ch = logging.StreamHandler() + ch.setFormatter( CustomFormatter() ) + LOGGER.addHandler( ch ) + LOGGER.info( " ".join( [sys.executable] + sys.argv ) ) + + # 4. Prepare the makefile args + # 4.1 Load the machine setup paths, compilers, flags, gpus = load_config( os.path.join(GAMER_CONFIG_DIR, args["machine"]+".config") ) - # 3.2 Validate arguments + # 4.2 Validate arguments validation( paths, depends, constraints, **args ) warning( paths, **args ) - # 3.3 Add the SIMU_OPTION + # 4.3 Add the SIMU_OPTION LOGGER.info("========================================") LOGGER.info("GAMER has the following setting.") LOGGER.info("----------------------------------------") sims = set_sims( name_table, depends, **args ) - # 3.4 Set the compiler + # 4.4 Set the compiler compiles = set_compile( paths, compilers, flags, args ) - # 3.5 Set the GPU + # 4.5 Set the GPU gpu_setup = set_gpu( gpus, flags, args ) - # 4. Create Makefile - # 4.1 Read + # 5. Create Makefile + # 5.1 Read with open( GAMER_MAKE_BASE, "r" ) as make_base: makefile = make_base.read() - # 4.2 Replace + # 5.2 Replace LOGGER.info("----------------------------------------") for key, val in paths.items(): LOGGER.info("%-25s : %s"%(key, val)) @@ -1001,7 +1045,7 @@ def warning( paths, **kwargs ): if num == 0: raise BaseException("The string @@@%s@@@ is not replaced correctly."%key) LOGGER.warning("@@@%s@@@ is replaced to '' since there is no given value."%key) - # 4.3 Write + # 5.3 Write with open( GAMER_MAKE_OUT, "w") as make_out: make_out.write( command + makefile ) diff --git a/tool/bash/config_autocomplete.sh b/tool/bash/config_autocomplete.sh new file mode 100755 index 0000000000..ed92d323c9 --- /dev/null +++ b/tool/bash/config_autocomplete.sh @@ -0,0 +1,24 @@ +#!/bin/bash + +_gamer_configure_autocomplete() { + local options + local subcommand="${COMP_WORDS[COMP_CWORD-1]}" + all_options=$(./configure.py --autocomplete_info=all) + IFS=' ' read -r -a option_array <<< "${all_options}" + + not_set=true + for opt in "${option_array[@]}" + do + if [[ "$subcommand" != "$opt" ]]; then continue; fi + + options=$(./configure.py --autocomplete_info="$opt") + not_set=false + break + done + + if ${not_set}; then options=${all_options}; fi + + COMPREPLY=( $(compgen -W "${options}" -- "${COMP_WORDS[COMP_CWORD]}") ) +} + +complete -F _gamer_configure_autocomplete ./configure.py From d640bfb9be49c57203e84aaaf70be84488971e59 Mon Sep 17 00:00:00 2001 From: ChunYen-Chen Date: Sun, 29 Sep 2024 15:38:35 +0800 Subject: [PATCH 02/29] Let `-lh` be in alphabetical order --- src/configure.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/configure.py b/src/configure.py index 1689e7f6c2..f52a5b26ee 100755 --- a/src/configure.py +++ b/src/configure.py @@ -188,7 +188,7 @@ def print_option( self ): option_indent = len(option["flags2"]) template = " %-" + str(option_indent) + "s " - for option in self.options: + for option in sorted(self.options, key=lambda item: item["flags2"]): indent = template %(option["flags2"]) output = indent From a030aae9ac75dc7c34d822645285a491fd5f04fa Mon Sep 17 00:00:00 2001 From: Chun-Yen Chen <70311975+ChunYen-Chen@users.noreply.github.com> Date: Sun, 29 Sep 2024 16:59:42 +0800 Subject: [PATCH 03/29] Update autocomplete wiki --- doc/wiki/Installation:-Configure.py.md | 39 +++++++++++++++++++++++++- 1 file changed, 38 insertions(+), 1 deletion(-) diff --git a/doc/wiki/Installation:-Configure.py.md b/doc/wiki/Installation:-Configure.py.md index db086688ef..75d16db7ae 100644 --- a/doc/wiki/Installation:-Configure.py.md +++ b/doc/wiki/Installation:-Configure.py.md @@ -39,6 +39,43 @@ python configure.py --machine=pleiades --fftw=FFTW2 --gravity=true --gpu=true An example script `generate_make.sh` can be found in each test problem folder (e.g., `example/test_problem/Hydro/AcousticWave/generate_make.sh`). +> [!TIP] +> Since there are too many options in GAMER, we introduce the autocomplete feature of `configure.py`. You can set the feature by the following steps: +> 1. Update the [shebang](https://en.wikipedia.org/wiki/Shebang_(Unix)) of `configure.py` if needed +> +> For example, replace `#!/usr/bin/python3` with your `python` path. +>
+> top of configure.py +>
+>    #!/usr/bin/python3
+>    """
+>    User and developer guides of this script are provided in the following link.
+>
+>    https://github.com/gamer-project/gamer/wiki/Installation%3A-Configure.py
+>
+>    """
+>    
+>
+> +> 1. Copy the autocomplete shell script to your `/home/usr` (`~`) +> ```bash +> cp tool/bash/config_autocomplete.sh ~/ +> ``` +> +> 1. Update the `~/.bashrc` to load the autocomplete script +> +> Please add the following line to `~/.bashrc`: +> ```bash +> source ~/config_autocomplete.sh +> ``` +> +> 1. Reload `~/.bashrc` to enable the feature +> ```bash +> source ~/.bashrc +> ``` +> +> Now, try to type `./configure.py` then press `` twice! + *** ## Developer Guide @@ -163,4 +200,4 @@ NEW_FLAG -new_flag ``` ### Rules of `Makefile_base` -The strings to be replaced by `configure.py` must be sandwiched by `@@@`. \ No newline at end of file +The strings to be replaced by `configure.py` must be sandwiched by `@@@`. From 3b0c6d4ba6717c077ed7b19a201dd36e588b7b1c Mon Sep 17 00:00:00 2001 From: ChunYen-Chen Date: Wed, 6 Nov 2024 16:46:14 +0800 Subject: [PATCH 04/29] Add the verbose mode argument --- src/Makefile_base | 2 +- src/configure.py | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/src/Makefile_base b/src/Makefile_base index 9f152af27f..1d53f54745 100644 --- a/src/Makefile_base +++ b/src/Makefile_base @@ -21,7 +21,7 @@ EXECUTABLE := gamer # output detailed compilation commands (0/1 = off/on) ####################################################################################################### -COMPILE_VERBOSE := 0 +COMPILE_VERBOSE := @@@COMPILE_VERBOSE@@@ diff --git a/src/configure.py b/src/configure.py index f52a5b26ee..540605e76b 100755 --- a/src/configure.py +++ b/src/configure.py @@ -413,6 +413,12 @@ def load_arguments(): help="Select the MACHINE.config file under ../configs directory. \nChoice: [eureka_intel, YOUR_MACHINE_NAME] => " ) + # verbose compilation mode + parser.add_argument( "--verbose_make", type=str2bool, metavar="BOOLEAN", + default=False, + help="Output detailed compilation commands.\n" + ) + # A. options of diffierent physical models parser.add_argument( "--model", type=str, metavar="TYPE", gamer_name="MODEL", default="HYDRO", choices=["HYDRO", "ELBDM", "PAR_ONLY"], @@ -1039,6 +1045,10 @@ def warning( paths, **kwargs ): makefile, num = re.subn(r"@@@%s@@@"%(key), val, makefile) if num == 0: raise BaseException("The string @@@%s@@@ is not replaced correctly."%key) + verbose_mode = "1" if args["verbose_make"] else "0" + makefile, num = re.subn(r"@@@COMPILE_VERBOSE@@@", verbose_mode, makefile) + if num == 0: raise BaseException("The string @@@COMPILE_VERBOSE@@@ is not replaced correctly.") + LOGGER.info("----------------------------------------") for key in re.findall(r"@@@(.+?)@@@", makefile): makefile, num = re.subn(r"@@@%s@@@"%key, "", makefile) @@ -1051,4 +1061,5 @@ def warning( paths, **kwargs ): LOGGER.info("========================================") LOGGER.info("%s is created."%GAMER_MAKE_OUT) + if args["verbose_make"]: LOGGER.info("%s is in verbose mode!"%GAMER_MAKE_OUT) LOGGER.info("========================================") From f6ebfd9aa93872c864af52184309892dc601fd25 Mon Sep 17 00:00:00 2001 From: ChunYen-Chen Date: Wed, 11 Dec 2024 22:20:12 +0800 Subject: [PATCH 05/29] Generalize prefix and suffix of simulation option --- src/configure.py | 95 ++++++++++++++++++++++++++---------------------- 1 file changed, 52 insertions(+), 43 deletions(-) diff --git a/src/configure.py b/src/configure.py index d249f5b76a..ef63f161bd 100755 --- a/src/configure.py +++ b/src/configure.py @@ -73,6 +73,8 @@ def __init__( self, *args, **kwargs ): self.depends = {} self.constraints = {} self.gamer_names = {} + self.prefix = {} + self.suffix = {} super(ArgumentParser, self).__init__(*args, **kwargs) def add_argument( self, *args, **kwargs ): @@ -85,6 +87,12 @@ def add_argument( self, *args, **kwargs ): if "gamer_name" in kwargs: key = args[0].replace("-", "") self.gamer_names[key] = kwargs.pop("gamer_name") + if "prefix" in kwargs: + key = args[0].replace("-", "") + self.prefix[key] = kwargs.pop("prefix") + if "suffix" in kwargs: + key = args[0].replace("-", "") + self.suffix[key] = kwargs.pop("suffix") super(ArgumentParser, self).add_argument(*args, **kwargs) option = kwargs.copy() @@ -112,7 +120,7 @@ def parse_args( self, args=None, namespace=None ): if arg == '--gpu_arch': msg += "ERROR: <--gpu_arch> is deprecated. Please set in your machine *.config file (see ../configs/template.config).\n" if len(argv) != 0: self.error( msg ) - return args, self.gamer_names, self.depends, self.constraints + return args, self.gamer_names, self.depends, self.constraints, self.prefix, self.suffix def _get_option_tuples(self, option_string): # This function is directly from the source code of `argparse`. @@ -264,15 +272,15 @@ def str2bool( v ): else: raise TypeError("Can not convert <%s> to boolean."%(v)) return -def add_option( opt_str, name, val ): +def add_option( opt_str, name, val, prefix="", suffix="" ): # NOTE: Every -Doption must have a trailing space. if type(val) == type(True): if val: opt_str += "-D%s "%(name) LOGGER.info("%-25s : %r"%(name, val)) elif type(val) == type("str"): if val != NONE_STR: - opt_str += "-D%s=%s "%(name, val) - LOGGER.info("%-25s : %s"%(name, val)) + opt_str += "-D%s=%s "%(name, prefix+val+suffix) + LOGGER.info("%-25s : %s"%(name, prefix+val+suffix)) elif type(val) == type(0): opt_str += "-D%s=%d "%(name, val) LOGGER.info("%-25s : %d"%(name, val)) @@ -447,18 +455,18 @@ def load_arguments(): ) parser.add_argument( "--flux", type=str, metavar="TYPE", gamer_name="RSOLVER", - default=None, choices=["EXACT", "ROE", "HLLE", "HLLC", "HLLD"], + default=None, choices=["EXACT", "ROE", "HLLE", "HLLC", "HLLD", NONE_STR], depend={"model":"HYDRO"}, constraint={ "ROE":{"eos":"GAMMA"}, "EXACT":{"eos":"GAMMA"} }, help="The Riemann solver. Pure hydro: EXACT/ROE/HLLE/HLLC^, MHD: ROE/HLLE/HLLD^, SRHD: HLLE/HLLC^, (^ indicates the recommended and default solvers). Useless for RTVD.\n" ) - parser.add_argument( "--dual", type=str, metavar="TYPE", gamer_name="DUAL_ENERGY", - default=NONE_STR, choices=[NONE_STR, "DE_ENPY", "DE_EINT"], + parser.add_argument( "--dual", type=str, metavar="TYPE", gamer_name="DUAL_ENERGY", prefix="DE_", + default=NONE_STR, choices=[NONE_STR, "ENPY", "EINT"], depend={"model":"HYDRO"}, - constraint={ "DE_ENPY":{"eos":"GAMMA"} }, - help="The dual-energy formalism (DE_ENPY: entropy, DE_EINT: internal energy). DE_EINT is not supported yet. Useless for RTVD.\n" + constraint={ "ENPY":{"eos":"GAMMA"} }, + help="The dual-energy formalism (ENPY: entropy, EINT: internal energy). EINT is not supported yet. Useless for RTVD.\n" ) parser.add_argument( "--mhd", type=str2bool, metavar="BOOLEAN", gamer_name="MHD", @@ -483,7 +491,7 @@ def load_arguments(): help="Enable cosmic rays. Must use <--eos=COSMIC_RAY>.\n" ) - parser.add_argument( "--eos", type=str, metavar="TYPE", gamer_name="EOS", + parser.add_argument( "--eos", type=str, metavar="TYPE", gamer_name="EOS", prefix="EOS_", default=None, choices=["GAMMA", "ISOTHERMAL", "NUCLEAR", "TABULAR", "COSMIC_RAY", "TAUBMATHEWS", "USER"], depend={"model":"HYDRO"}, constraint={ "ISOTHERMAL":{"barotropic":True}, "COSMIC_RAY":{"cosmic_ray":True}, "TAUBMATHEWS":{"srhd":True} }, @@ -498,16 +506,16 @@ def load_arguments(): ) # A.2 ELBDM scheme - parser.add_argument( "--elbdm_scheme", type=str, metavar="TYPE", gamer_name="ELBDM_SCHEME", - default="ELBDM_WAVE", choices=["ELBDM_WAVE", "ELBDM_HYBRID"], + parser.add_argument( "--elbdm_scheme", type=str, metavar="TYPE", gamer_name="ELBDM_SCHEME", prefix="ELBDM_", + default="WAVE", choices=["WAVE", "HYBRID"], depend={"model":"ELBDM"}, - help="Scheme type for <--model=ELBDM> (ELBDM_WAVE: wave-only, ELBDM_HYBRID: fluid-wave-hybrid-scheme).\n" + help="Scheme type for <--model=ELBDM> (WAVE: wave-only, HYBRID: fluid-wave-hybrid-scheme).\n" ) - parser.add_argument( "--wave_scheme", type=str, metavar="TYPE", gamer_name="WAVE_SCHEME", - default="WAVE_FD", choices=["WAVE_FD", "WAVE_GRAMFE"], + parser.add_argument( "--wave_scheme", type=str, metavar="TYPE", gamer_name="WAVE_SCHEME", prefix="WAVE_", + default="FD", choices=["FD", "GRAMFE"], depend={"model":"ELBDM"}, - help="Wave scheme for <--model=ELBDM> (WAVE_FD:finite difference, WAVE_GRAMFE: local spectral method).\n" + help="Wave scheme for <--model=ELBDM> (FD: finite difference, GRAMFE: local spectral method).\n" ) parser.add_argument( "--conserve_mass", type=str2bool, metavar="BOOLEAN", gamer_name="CONSERVE_MASS", @@ -519,21 +527,21 @@ def load_arguments(): parser.add_argument( "--laplacian_four", type=str2bool, metavar="BOOLEAN", gamer_name="LAPLACIAN_4TH", default=None, depend={"model":"ELBDM"}, - constraint={ True:{"wave_scheme":"WAVE_FD"} }, - help="Enable the fourth-order Laplacian for <--model=ELBDM> (for <--wave_scheme=WAVE_FD> only).\n" + constraint={ True:{"wave_scheme":"FD"} }, + help="Enable the fourth-order Laplacian for <--model=ELBDM> (for <--wave_scheme=FD> only).\n" ) - parser.add_argument( "--gramfe_scheme", type=str, metavar="TYPE", gamer_name="GRAMFE_SCHEME", - default="GRAMFE_MATMUL", choices=["GRAMFE_MATMUL", "GRAMFE_FFT"], - depend={"model":"ELBDM", "wave_scheme":"WAVE_GRAMFE"}, - constraint={ "GRAMFE_MATMUL":{"gsl":True} }, - help="GramFE scheme for <--wave_scheme=WAVE_GRAMFE> (GRAMFE_MATMUL: faster for PATCH_SIZE=8, GRAMFE_FFT: faster for larger patch sizes).\n" + parser.add_argument( "--gramfe_scheme", type=str, metavar="TYPE", gamer_name="GRAMFE_SCHEME", prefix="GRAMFE_", + default="MATMUL", choices=["MATMUL", "FFT"], + depend={"model":"ELBDM", "wave_scheme":"GRAMFE"}, + constraint={ "MATMUL":{"gsl":True} }, + help="GramFE scheme for <--wave_scheme=GRAMFE> (MATMUL: faster for PATCH_SIZE=8, FFT: faster for larger patch sizes).\n" ) - parser.add_argument( "--hybrid_scheme", type=str, metavar="TYPE", gamer_name="HYBRID_SCHEME", - default="HYBRID_MUSCL", choices=["HYBRID_UPWIND", "HYBRID_FROMM", "HYBRID_MUSCL"], - depend={"model":"ELBDM", "elbdm_scheme":"ELBDM_HYBRID"}, - help="Fluid scheme for <--elbdm_scheme=ELBDM_HYBRID> (HYBRID_UPWIND: first-order, diffusive, HYBRID_FROMM: second-order, no limiter, unstable for fluid-only simulations, HYBRID_MUSCL: second-order, with limiter, useful for zoom-in and fluid-only simulations).\n" + parser.add_argument( "--hybrid_scheme", type=str, metavar="TYPE", gamer_name="HYBRID_SCHEME", prefix="HYBRID_", + default="MUSCL", choices=["UPWIND", "FROMM", "MUSCL"], + depend={"model":"ELBDM", "elbdm_scheme":"HYBRID"}, + help="Fluid scheme for <--elbdm_scheme=HYBRID> (UPWIND: first-order, diffusive, FROMM: second-order, no limiter, unstable for fluid-only simulations, MUSCL: second-order, with limiter, useful for zoom-in and fluid-only simulations).\n" ) parser.add_argument( "--self_interaction", type=str2bool, metavar="BOOLEAN", gamer_name="QUARTIC_SELF_INTERACTION", @@ -756,7 +764,7 @@ def load_arguments(): help="Enable GPU. Must set in your machine *.config file as well.\n" ) - args, name_table, depends, constraints = parser.parse_args() + args, name_table, depends, constraints, prefix_table, suffix_table = parser.parse_args() args = vars( args ) # 1. Print out a detailed help message then exit. @@ -771,7 +779,7 @@ def load_arguments(): # 2. Conditional default arguments. args = set_conditional_defaults( args ) - return args, name_table, depends, constraints + return args, name_table, depends, constraints, prefix_table, suffix_table def load_config( config ): LOGGER.info("Using %s as the config."%(config)) @@ -816,7 +824,7 @@ def set_conditional_defaults( args ): args["bitwise_reproducibility"] = args["debug"] if args["laplacian_four"] is None: - args["laplacian_four"] = True if args["wave_scheme"] == "WAVE_FD" else False + args["laplacian_four"] = True if args["wave_scheme"] == "FD" else False if args["double_par"] is None: args["double_par"] = args["double"] @@ -870,7 +878,7 @@ def set_gpu( gpus, flags, args ): gpu_opts["MAXRREGCOUNT_FLU"] = "--maxrregcount=128" return gpu_opts -def set_sims( name_table, depends, **kwargs ): +def set_sims( name_table, prefix_table, suffix_table, depends, **kwargs ): opt_str = "" # loop all the simulation options in GAMER. for opt, gamer_name in name_table.items(): @@ -882,10 +890,11 @@ def set_sims( name_table, depends, **kwargs ): if kwargs[depend] not in val: store = False if not store: continue - if opt == "eos": # special string prefix of EOS - opt_str = add_option( opt_str, name=gamer_name, val="EOS_"+kwargs[opt] ) - else: - opt_str = add_option( opt_str, name=gamer_name, val=kwargs[opt] ) + + prefix = prefix_table[opt] if opt in prefix_table else "" + suffix = suffix_table[opt] if opt in suffix_table else "" + + opt_str = add_option( opt_str, name=gamer_name, val=kwargs[opt], prefix=prefix, suffix=suffix ) # hard-code the option of serial. if not kwargs["mpi"]: opt_str = add_option( opt_str, name="SERIAL", val=True ) @@ -905,7 +914,7 @@ def set_compile( paths, compilers, flags, kwargs ): # NOTE: `-G` may cause the GPU Poisson solver to fail if kwargs["debug"]: flags["NVCCFLAG_COM"] += "-g -Xptxas -v" # enable C++ 17 support for ELBDM GPU Gram-Fourier extension scheme - if kwargs["model"] == "ELBDM" and kwargs["wave_scheme"] == "WAVE_GRAMFE" and kwargs["gramfe_scheme"] == "GRAMFE_FFT": + if kwargs["model"] == "ELBDM" and kwargs["wave_scheme"] == "GRAMFE" and kwargs["gramfe_scheme"] == "FFT": flags["NVCCFLAG_COM"] += "-std=c++17" # 4. Write flags to compile option dictionary. @@ -949,7 +958,7 @@ def validation( paths, depends, constraints, **kwargs ): if kwargs["passive"] < 0: LOGGER.error("Passive scalar should not be negative. Current: %d"%kwargs["passive"]) success = False - if kwargs["dual"] not in [NONE_STR, "DE_ENPY"]: + if kwargs["dual"] not in [NONE_STR, "ENPY"]: LOGGER.error("This dual energy form is not supported yet. Current: %s"%kwargs["dual"]) success = False @@ -957,8 +966,8 @@ def validation( paths, depends, constraints, **kwargs ): if kwargs["passive"] < 0: LOGGER.error("Passive scalar should not be negative. Current: %d"%kwargs["passive"]) success = False - if kwargs["gramfe_scheme"] == "GRAMFE_FFT" and not kwargs["gpu"] and kwargs["fftw"] not in ["FFTW2", "FFTW3"]: - LOGGER.error("Must set <--fftw> when adopting <--gramfe_scheme=GRAMFE_FFT> and <--gpu=false>") + if kwargs["gramfe_scheme"] == "FFT" and not kwargs["gpu"] and kwargs["fftw"] not in ["FFTW2", "FFTW3"]: + LOGGER.error("Must set <--fftw> when adopting <--gramfe_scheme=FFT> and <--gpu=false>") success = False if kwargs["spectral_interpolation"] and kwargs["fftw"] == "FFTW2" and not kwargs["double"]: LOGGER.error("Must enable <--double> when adopting <--spectral_interpolation> and <--fftw=FFTW2>") @@ -1024,9 +1033,9 @@ def warning( paths, **kwargs ): if paths.setdefault(p_name, "") != "": continue LOGGER.warning("%-15s is not given in %s.config when setting <--%s=%s>"%(p_name, kwargs["machine"], arg, str(val))) - if kwargs["model"] == "ELBDM" and kwargs["gpu"] and kwargs["wave_scheme"] == "WAVE_GRAMFE" and kwargs["gramfe_scheme"] == "GRAMFE_FFT": + if kwargs["model"] == "ELBDM" and kwargs["gpu"] and kwargs["wave_scheme"] == "GRAMFE" and kwargs["gramfe_scheme"] == "FFT": if paths.setdefault("CUFFTDX_PATH", "") == "": - LOGGER.warning("CUFFTDX_PATH is not given in %s.config when enabling <--gramfe_scheme=GRAMFE_FFT>."%(kwargs["machine"])) + LOGGER.warning("CUFFTDX_PATH is not given in %s.config when enabling <--gramfe_scheme=FFT>."%(kwargs["machine"])) return @@ -1040,7 +1049,7 @@ def warning( paths, **kwargs ): command = " ".join( ["# This makefile is generated by the following command:", "\n#", sys.executable] + sys.argv + ["\n"] ) # 2. Load the input arguments - args, name_table, depends, constraints = load_arguments() + args, name_table, depends, constraints, prefix_table, suffix_table = load_arguments() # 3. Set the logger logging.basicConfig( filename=GAMER_MAKE_OUT+'.log', filemode='w', level=logging.INFO, format=LOG_FORMAT ) @@ -1062,7 +1071,7 @@ def warning( paths, **kwargs ): LOGGER.info("========================================") LOGGER.info("GAMER has the following setting.") LOGGER.info("----------------------------------------") - sims = set_sims( name_table, depends, **args ) + sims = set_sims( name_table, prefix_table, suffix_table, depends, **args ) # 4.4 Set the compiler compiles = set_compile( paths, compilers, flags, args ) From c87ef93726f8886d09af7b5ccd8b7347f9fba69a Mon Sep 17 00:00:00 2001 From: ChunYen-Chen Date: Wed, 11 Dec 2024 22:32:51 +0800 Subject: [PATCH 06/29] Update wiki --- doc/wiki/Installation:-Configure.py.md | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/doc/wiki/Installation:-Configure.py.md b/doc/wiki/Installation:-Configure.py.md index 90affb598b..9ad603741e 100644 --- a/doc/wiki/Installation:-Configure.py.md +++ b/doc/wiki/Installation:-Configure.py.md @@ -173,7 +173,16 @@ Edit `Makefile_base` to add new source files. ) ``` -4. [Optional] Add additional checks in `validation()` and warning messages in `warning()` under `Functions`. +4. [Optional] Add the common prefix/suffix of the simulation options. (Only works for string type) + ```python + parser.add_argument( "--new_argument", type=str, metavar="STRING", gamer_name="NEW_SIMUALTION_OPTION", prefix="YOUR_PREFIX_", suffix="_YOUR_SUFFIX", + default="STR1", choice=["STR1", "STR2", "STR3"], + help="Your help message.\n" + ) + ``` + The simulation option would be concatenated as `YOUR_PREFIX_STR1_YOUR_SUFFIX`. + +5. [Optional] Add additional checks in `validation()` and warning messages in `warning()` under `Functions`. * `validation()` ```python def validation( paths, depends, constraints, **kwargs ): From bc69ce05d51f73c159dd114fc042cfe187bed736 Mon Sep 17 00:00:00 2001 From: ChunYen-Chen Date: Thu, 26 Dec 2024 13:07:21 +0800 Subject: [PATCH 07/29] Support option with `=` autocomplete --- doc/wiki/Installation.md | 4 +- src/configure.py | 18 ++++----- tool/bash/config_autocomplete.sh | 63 +++++++++++++++++++++++++------- 3 files changed, 60 insertions(+), 25 deletions(-) diff --git a/doc/wiki/Installation.md b/doc/wiki/Installation.md index 8024b4a31c..7e3bfd8737 100644 --- a/doc/wiki/Installation.md +++ b/doc/wiki/Installation.md @@ -38,9 +38,9 @@ e.g., `example/test_problem/Hydro/AcousticWave/generate_make.sh`. >
 >    #!/usr/bin/python3
 >    """
->    User and developer guides of this script are provided in the following link.
+>    User guides of this script are provided in the following link.
 >
->    https://github.com/gamer-project/gamer/wiki/Installation%3A-Configure.py
+>    https://github.com/gamer-project/gamer/wiki/Installation
 >
 >    """
 >    
diff --git a/src/configure.py b/src/configure.py index 25e625158b..9eaa38f29e 100755 --- a/src/configure.py +++ b/src/configure.py @@ -1,8 +1,8 @@ #!/usr/bin/python3 """ -User and developer guides of this script are provided in the following link. +User guides of this script are provided in the following link. - https://github.com/gamer-project/gamer/wiki/Installation%3A-Configure.py + https://github.com/gamer-project/gamer/wiki/Installation """ @@ -228,21 +228,21 @@ def print_help( self, *args, **kwargs ): def print_autocomplete( self, target_option, *args, **kwargs ): if target_option == "all": - all_options = [] - for option in self.options: - all_options += option["flags"] + all_options = [ flag+("=" if "type" in option else "") for option in self.options for flag in option["flags"] ] print( " ".join(all_options) ) return - if target_option == "--machine": + if target_option in ["--machine", "--machine="]: all_files = os.listdir( GAMER_CONFIG_DIR ) - config_files = [ f for f in all_files if ".config" in f ] + config_files = [ "%s"%f for f in all_files if ".config" in f ] config_files = list( map( lambda f: f.replace( ".config", "" ), config_files ) ) print( " ".join(config_files) ) return for option in self.options: - if target_option not in option["flags"]: continue + trail_option = "=" if "type" in option else "" + if not any( target_option in [flag+trail_option, flag] for flag in option["flags"] ): + continue # option with choices if "choices" in option: @@ -456,7 +456,7 @@ def load_arguments(): ) parser.add_argument( "--flux", type=str, metavar="TYPE", gamer_name="RSOLVER", - default=None, choices=["EXACT", "ROE", "HLLE", "HLLC", "HLLD", NONE_STR], + default=None, choices=["EXACT", "ROE", "HLLE", "HLLC", "HLLD"], depend={"model":"HYDRO"}, constraint={ "ROE":{"eos":"GAMMA"}, "EXACT":{"eos":"GAMMA"} }, diff --git a/tool/bash/config_autocomplete.sh b/tool/bash/config_autocomplete.sh index ed92d323c9..543f37babf 100755 --- a/tool/bash/config_autocomplete.sh +++ b/tool/bash/config_autocomplete.sh @@ -1,24 +1,59 @@ #!/bin/bash -_gamer_configure_autocomplete() { - local options - local subcommand="${COMP_WORDS[COMP_CWORD-1]}" - all_options=$(./configure.py --autocomplete_info=all) +__gamer_configure_autocomplete() { + + local options option_array option_array2 + local not_set=true + local subsub="${COMP_WORDS[COMP_CWORD-2]}" + local sub="${COMP_WORDS[COMP_CWORD-1]}" + local cur="${COMP_WORDS[COMP_CWORD]}" + local all_options=$(./configure.py --autocomplete_info=all) IFS=' ' read -r -a option_array <<< "${all_options}" - not_set=true + COMPREPLY=() # NOTE: please add a space when ending the option + + # option choices for opt in "${option_array[@]}" do - if [[ "$subcommand" != "$opt" ]]; then continue; fi - - options=$(./configure.py --autocomplete_info="$opt") - not_set=false - break + # --option=xx + if [[ "$opt" == "$subsub=" && "=" == "$sub" ]]; then + options=$(./configure.py --autocomplete_info="$opt") + IFS=' ' read -r -a option_array2 <<< "${options}" + for opt2 in "${option_array2[@]}" + do + if [[ "$opt2" != "$cur"* ]]; then continue;fi + COMPREPLY+=("$opt2 ") + done + not_set=false + break + # --option, --option xxx, or --option= + elif [[ "$opt" == "$sub=" ]]; then + options=$(./configure.py --autocomplete_info="$opt") + IFS=' ' read -r -a option_array2 <<< "${options}" + for opt2 in "${option_array2[@]}" + do + # --option= or --option + if [[ "$cur" == "" || "$cur" == "=" ]]; then + COMPREPLY+=("$opt2 ") + # --option xxx + elif [[ "$opt2" == "$cur"* ]]; then + COMPREPLY+=("$opt2 ") + fi + done + not_set=false + break + # special case without trailing `=` (-h and -lh) + elif [[ "$cur" == "-h" || "$cur" == "-lh" ]]; then + COMPREPLY+=("$cur ") + not_set=false + break + fi done - if ${not_set}; then options=${all_options}; fi + if ${not_set}; then + COMPREPLY=( $(compgen -W "${all_options}" -- "$cur") ) + fi - COMPREPLY=( $(compgen -W "${options}" -- "${COMP_WORDS[COMP_CWORD]}") ) -} +} # __gamer_configure_autocomplete() -complete -F _gamer_configure_autocomplete ./configure.py +complete -o nospace -F __gamer_configure_autocomplete ./configure.py From 958c189375735c41013ed245d043fa59e70ff3db Mon Sep 17 00:00:00 2001 From: ChunYen-Chen Date: Sat, 28 Dec 2024 20:54:51 +0800 Subject: [PATCH 08/29] Support `python configure.py` autocomplete --- tool/bash/config_autocomplete.sh | 63 ++++++++++++++++++++++++++------ 1 file changed, 52 insertions(+), 11 deletions(-) diff --git a/tool/bash/config_autocomplete.sh b/tool/bash/config_autocomplete.sh index 543f37babf..1564d888b9 100755 --- a/tool/bash/config_autocomplete.sh +++ b/tool/bash/config_autocomplete.sh @@ -1,36 +1,75 @@ #!/bin/bash +__gamer_check_gamer_info() { + # Check if the current directory is GAMER and the `configure.py` for generating `Makefile` + # $1 : configure.py filename + + local isGitDir=`git rev-parse --is-inside-work-tree` + [ ! "$isGitDir" = true ] && return 1 + + local firstGAMERCommit=`git rev-list --max-parents=0 HEAD` + [ ! "$firstGAMERCommit" = "2705887745ac1fd254774c512af4a05b0f7f7fb6" ] && return 1 + + local configurePyFirstCommit=`git log --diff-filter=A -- $1 | head -n 1 | awk '{print $2}'` + [ ! "$configurePyFirstCommit" = "a93978a39b4388d169a0f45d1987f55486578fab" ] && return 1 + + return 0 + +} # __gamer_check_gamer_info() + + __gamer_configure_autocomplete() { - local options option_array option_array2 + local all_options sub_options all_option_array sub_option_array configure_filename local not_set=true + local first=${COMP_WORDS[0]} + local second=${COMP_WORDS[1]} local subsub="${COMP_WORDS[COMP_CWORD-2]}" local sub="${COMP_WORDS[COMP_CWORD-1]}" local cur="${COMP_WORDS[COMP_CWORD]}" - local all_options=$(./configure.py --autocomplete_info=all) - IFS=' ' read -r -a option_array <<< "${all_options}" + + if [[ "$first" == "python"* ]]; then + configure_filename=$second + else + configure_filename=$first + fi + + __gamer_check_gamer_info $configure_filename + + # Not the GAEMR `configure.py` + if [ $? -ne 0 ]; then + COMPREPLY=( $( compgen -o default -- ${COMP_WORDS[COMP_CWORD]} ) ) + # add a trailing space since `-o nospace` + for i in "${!COMPREPLY[@]}"; do + COMPREPLY[$i]="${COMPREPLY[$i]} " + done + return 0 + fi + + all_options=$(./configure.py --autocomplete_info=all) + IFS=' ' read -r -a all_option_array <<< "${all_options}" COMPREPLY=() # NOTE: please add a space when ending the option # option choices - for opt in "${option_array[@]}" + for opt in "${all_option_array[@]}" do # --option=xx if [[ "$opt" == "$subsub=" && "=" == "$sub" ]]; then - options=$(./configure.py --autocomplete_info="$opt") - IFS=' ' read -r -a option_array2 <<< "${options}" - for opt2 in "${option_array2[@]}" + sub_options=$(./configure.py --autocomplete_info="$opt") + IFS=' ' read -r -a sub_option_array <<< "${sub_options}" + for opt2 in "${sub_option_array[@]}" do - if [[ "$opt2" != "$cur"* ]]; then continue;fi + if [[ "$opt2" != "$cur"* ]]; then continue; fi COMPREPLY+=("$opt2 ") done not_set=false break # --option, --option xxx, or --option= elif [[ "$opt" == "$sub=" ]]; then - options=$(./configure.py --autocomplete_info="$opt") - IFS=' ' read -r -a option_array2 <<< "${options}" - for opt2 in "${option_array2[@]}" + sub_options=$(./configure.py --autocomplete_info="$opt") + IFS=' ' read -r -a sub_option_array <<< "${sub_options}" + for opt2 in "${sub_option_array[@]}" do # --option= or --option if [[ "$cur" == "" || "$cur" == "=" ]]; then @@ -57,3 +96,5 @@ __gamer_configure_autocomplete() { } # __gamer_configure_autocomplete() complete -o nospace -F __gamer_configure_autocomplete ./configure.py +complete -o nospace -F __gamer_configure_autocomplete python +complete -o nospace -F __gamer_configure_autocomplete python3 From fcfb1bf40794f2bb5431069693a38887b6afd0a9 Mon Sep 17 00:00:00 2001 From: ChunYen-Chen Date: Wed, 15 Jan 2025 10:43:49 +0800 Subject: [PATCH 09/29] Style --- tool/bash/config_autocomplete.sh | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/tool/bash/config_autocomplete.sh b/tool/bash/config_autocomplete.sh index 1564d888b9..e31ba32b21 100755 --- a/tool/bash/config_autocomplete.sh +++ b/tool/bash/config_autocomplete.sh @@ -38,12 +38,12 @@ __gamer_configure_autocomplete() { # Not the GAEMR `configure.py` if [ $? -ne 0 ]; then - COMPREPLY=( $( compgen -o default -- ${COMP_WORDS[COMP_CWORD]} ) ) - # add a trailing space since `-o nospace` - for i in "${!COMPREPLY[@]}"; do - COMPREPLY[$i]="${COMPREPLY[$i]} " - done - return 0 + COMPREPLY=( $( compgen -o default -- ${COMP_WORDS[COMP_CWORD]} ) ) + # add a trailing space since `-o nospace` + for i in "${!COMPREPLY[@]}"; do + COMPREPLY[$i]="${COMPREPLY[$i]} " + done + return 0 fi all_options=$(./configure.py --autocomplete_info=all) From fa8de22536f94efaa462e5a1946a82e0d8c4855d Mon Sep 17 00:00:00 2001 From: ChunYen-Chen Date: Fri, 17 Jan 2025 08:24:47 +0800 Subject: [PATCH 10/29] Bugfix --- tool/bash/config_autocomplete.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tool/bash/config_autocomplete.sh b/tool/bash/config_autocomplete.sh index e31ba32b21..2e7994f567 100755 --- a/tool/bash/config_autocomplete.sh +++ b/tool/bash/config_autocomplete.sh @@ -4,7 +4,7 @@ __gamer_check_gamer_info() { # Check if the current directory is GAMER and the `configure.py` for generating `Makefile` # $1 : configure.py filename - local isGitDir=`git rev-parse --is-inside-work-tree` + local isGitDir=`git rev-parse --is-inside-work-tree 2>/dev/null` [ ! "$isGitDir" = true ] && return 1 local firstGAMERCommit=`git rev-list --max-parents=0 HEAD` From 8c77e4974feab5dba55c4c1da0b943c506cde5f2 Mon Sep 17 00:00:00 2001 From: ChunYen-Chen Date: Fri, 17 Jan 2025 10:11:18 +0800 Subject: [PATCH 11/29] Bugfix --- tool/bash/config_autocomplete.sh | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/tool/bash/config_autocomplete.sh b/tool/bash/config_autocomplete.sh index 2e7994f567..0d0664be9b 100755 --- a/tool/bash/config_autocomplete.sh +++ b/tool/bash/config_autocomplete.sh @@ -38,11 +38,6 @@ __gamer_configure_autocomplete() { # Not the GAEMR `configure.py` if [ $? -ne 0 ]; then - COMPREPLY=( $( compgen -o default -- ${COMP_WORDS[COMP_CWORD]} ) ) - # add a trailing space since `-o nospace` - for i in "${!COMPREPLY[@]}"; do - COMPREPLY[$i]="${COMPREPLY[$i]} " - done return 0 fi @@ -95,6 +90,6 @@ __gamer_configure_autocomplete() { } # __gamer_configure_autocomplete() -complete -o nospace -F __gamer_configure_autocomplete ./configure.py -complete -o nospace -F __gamer_configure_autocomplete python -complete -o nospace -F __gamer_configure_autocomplete python3 +complete -o default -o nospace -F __gamer_configure_autocomplete ./configure.py +complete -o default -o nospace -F __gamer_configure_autocomplete python +complete -o default -o nospace -F __gamer_configure_autocomplete python3 From 78d60fff0c3c983fa95ea8c9973a50f9b9175a7e Mon Sep 17 00:00:00 2001 From: Yuan-Ming Hsu Date: Fri, 17 Jan 2025 18:34:12 +0800 Subject: [PATCH 12/29] Fix fallback issue: add trailing space back --- tool/bash/config_autocomplete.sh | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/tool/bash/config_autocomplete.sh b/tool/bash/config_autocomplete.sh index 0d0664be9b..c8bdc17dca 100755 --- a/tool/bash/config_autocomplete.sh +++ b/tool/bash/config_autocomplete.sh @@ -36,8 +36,9 @@ __gamer_configure_autocomplete() { __gamer_check_gamer_info $configure_filename - # Not the GAEMR `configure.py` + # Not the GAEMR `configure.py`, fallback to default. if [ $? -ne 0 ]; then + compopt -o default +o nospace return 0 fi @@ -90,6 +91,4 @@ __gamer_configure_autocomplete() { } # __gamer_configure_autocomplete() -complete -o default -o nospace -F __gamer_configure_autocomplete ./configure.py -complete -o default -o nospace -F __gamer_configure_autocomplete python -complete -o default -o nospace -F __gamer_configure_autocomplete python3 +complete -o nospace -F __gamer_configure_autocomplete ./configure.py python python3 From ee2b8999e87a2cf0ad0c30acde9774c956b11eba Mon Sep 17 00:00:00 2001 From: ChunYen-Chen Date: Tue, 21 Jan 2025 11:47:16 +0800 Subject: [PATCH 13/29] Move validation to the top of the function --- tool/bash/config_autocomplete.sh | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/tool/bash/config_autocomplete.sh b/tool/bash/config_autocomplete.sh index c8bdc17dca..6e04e005d8 100755 --- a/tool/bash/config_autocomplete.sh +++ b/tool/bash/config_autocomplete.sh @@ -20,18 +20,10 @@ __gamer_check_gamer_info() { __gamer_configure_autocomplete() { - local all_options sub_options all_option_array sub_option_array configure_filename - local not_set=true - local first=${COMP_WORDS[0]} - local second=${COMP_WORDS[1]} - local subsub="${COMP_WORDS[COMP_CWORD-2]}" - local sub="${COMP_WORDS[COMP_CWORD-1]}" - local cur="${COMP_WORDS[COMP_CWORD]}" - - if [[ "$first" == "python"* ]]; then - configure_filename=$second + if [[ "$COMP_WORDS[0]" == "python"* ]]; then + configure_filename=${COMP_WORDS[1]} else - configure_filename=$first + configure_filename=${COMP_WORDS[0]} fi __gamer_check_gamer_info $configure_filename @@ -42,6 +34,12 @@ __gamer_configure_autocomplete() { return 0 fi + local all_options sub_options all_option_array sub_option_array configure_filename + local not_set=true + local subsub="${COMP_WORDS[COMP_CWORD-2]}" + local sub="${COMP_WORDS[COMP_CWORD-1]}" + local cur="${COMP_WORDS[COMP_CWORD]}" + all_options=$(./configure.py --autocomplete_info=all) IFS=' ' read -r -a all_option_array <<< "${all_options}" From 3685e4d129ccd35d4daf514e6e54ccf186f1c95a Mon Sep 17 00:00:00 2001 From: ChunYen-Chen Date: Tue, 21 Jan 2025 11:48:44 +0800 Subject: [PATCH 14/29] Check the filename --- tool/bash/config_autocomplete.sh | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tool/bash/config_autocomplete.sh b/tool/bash/config_autocomplete.sh index 6e04e005d8..ba8fd6d2b5 100755 --- a/tool/bash/config_autocomplete.sh +++ b/tool/bash/config_autocomplete.sh @@ -4,6 +4,8 @@ __gamer_check_gamer_info() { # Check if the current directory is GAMER and the `configure.py` for generating `Makefile` # $1 : configure.py filename + [ ! "$1" = "configure.py" ] && return 1 + local isGitDir=`git rev-parse --is-inside-work-tree 2>/dev/null` [ ! "$isGitDir" = true ] && return 1 From 2b02e3c52806a925bc6b0696231893ef42fbc2b5 Mon Sep 17 00:00:00 2001 From: ChunYen-Chen Date: Tue, 21 Jan 2025 13:24:11 +0800 Subject: [PATCH 15/29] Validate the executed file --- tool/bash/config_autocomplete.sh | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/tool/bash/config_autocomplete.sh b/tool/bash/config_autocomplete.sh index ba8fd6d2b5..0cef1525b0 100755 --- a/tool/bash/config_autocomplete.sh +++ b/tool/bash/config_autocomplete.sh @@ -4,7 +4,7 @@ __gamer_check_gamer_info() { # Check if the current directory is GAMER and the `configure.py` for generating `Makefile` # $1 : configure.py filename - [ ! "$1" = "configure.py" ] && return 1 + if [[ "$1" != *"configure.py" ]]; then return 1; fi local isGitDir=`git rev-parse --is-inside-work-tree 2>/dev/null` [ ! "$isGitDir" = true ] && return 1 @@ -22,10 +22,13 @@ __gamer_check_gamer_info() { __gamer_configure_autocomplete() { - if [[ "$COMP_WORDS[0]" == "python"* ]]; then + local configure_filename configure_command + if [[ "${COMP_WORDS[0]}" == "python"* ]]; then configure_filename=${COMP_WORDS[1]} + configure_command="${COMP_WORDS[0]} ${COMP_WORDS[1]}" else configure_filename=${COMP_WORDS[0]} + configure_command="${COMP_WORDS[0]}" fi __gamer_check_gamer_info $configure_filename @@ -36,13 +39,13 @@ __gamer_configure_autocomplete() { return 0 fi - local all_options sub_options all_option_array sub_option_array configure_filename + local all_options sub_options all_option_array sub_option_array local not_set=true local subsub="${COMP_WORDS[COMP_CWORD-2]}" local sub="${COMP_WORDS[COMP_CWORD-1]}" local cur="${COMP_WORDS[COMP_CWORD]}" - all_options=$(./configure.py --autocomplete_info=all) + all_options=$(${configure_command} --autocomplete_info=all) IFS=' ' read -r -a all_option_array <<< "${all_options}" COMPREPLY=() # NOTE: please add a space when ending the option @@ -52,7 +55,7 @@ __gamer_configure_autocomplete() { do # --option=xx if [[ "$opt" == "$subsub=" && "=" == "$sub" ]]; then - sub_options=$(./configure.py --autocomplete_info="$opt") + sub_options=$(${configure_command} --autocomplete_info="$opt") IFS=' ' read -r -a sub_option_array <<< "${sub_options}" for opt2 in "${sub_option_array[@]}" do @@ -63,7 +66,7 @@ __gamer_configure_autocomplete() { break # --option, --option xxx, or --option= elif [[ "$opt" == "$sub=" ]]; then - sub_options=$(./configure.py --autocomplete_info="$opt") + sub_options=$(${configure_command} --autocomplete_info="$opt") IFS=' ' read -r -a sub_option_array <<< "${sub_options}" for opt2 in "${sub_option_array[@]}" do From 9d9b7df7e714a011dc51acc6da0611fde51098c6 Mon Sep 17 00:00:00 2001 From: ChunYen-Chen Date: Tue, 21 Jan 2025 13:58:35 +0800 Subject: [PATCH 16/29] Avoid long string --- src/configure.py | 91 ++++++++++++++++++++++++++++++++++-------------- 1 file changed, 64 insertions(+), 27 deletions(-) diff --git a/src/configure.py b/src/configure.py index 9eaa38f29e..5ca106c33d 100755 --- a/src/configure.py +++ b/src/configure.py @@ -29,7 +29,9 @@ GAMER_CONFIG_DIR = os.path.join("..", "configs") GAMER_MAKE_BASE = "Makefile_base" GAMER_MAKE_OUT = "Makefile" -GAMER_DESCRIPTION = "Prepare a customized Makefile for GAMER.\nDefault values are marked by '*'.\nUse -lh to show a detailed help message.\n" +GAMER_DESCRIPTION = "Prepare a customized Makefile for GAMER.\n"\ + "Default values are marked by '*'.\n"\ + "Use -lh to show a detailed help message.\n" GAMER_EPILOG = "2023 Computational Astrophysics Lab, NTU. All rights reserved.\n" LOGGER = logging.getLogger() @@ -117,7 +119,9 @@ def parse_args( self, args=None, namespace=None ): msg += 'Unrecognized argument: %s'%(arg) if min_dist <= CLOSE_DIST: msg += ', do you mean: %s ?\n'%(pos_key) msg += '\n' - if arg == '--gpu_arch': msg += "ERROR: <--gpu_arch> is deprecated. Please set in your machine *.config file (see ../configs/template.config).\n" + if arg == '--gpu_arch': + msg += "ERROR: <--gpu_arch> is deprecated. "\ + "Please set in your machine *.config file (see ../configs/template.config).\n" if len(argv) != 0: self.error( msg ) return args, self.gamer_names, self.depends, self.constraints, self.prefix, self.suffix @@ -413,13 +417,15 @@ def load_arguments(): # autocomplete information parser.add_argument( "--autocomplete_info", type=str, metavar="--OPTION", default=None, - help="Print out the autocomplete information. See: ../tool/bash/config_autocomplete.sh\n" + help="Print out the autocomplete information. "\ + "See: ../tool/bash/config_autocomplete.sh\n" ) # machine config setup parser.add_argument( "--machine", type=str, metavar="MACHINE", default="eureka_intel", - help="Select the MACHINE.config file under ../configs directory.\nChoice: [eureka_intel, YOUR_MACHINE_NAME] => " + help="Select the MACHINE.config file under ../configs directory.\n"\ + "Choice: [eureka_intel, YOUR_MACHINE_NAME] => " ) # verbose compilation mode @@ -431,13 +437,16 @@ def load_arguments(): # A. options of diffierent physical models parser.add_argument( "--model", type=str, metavar="TYPE", gamer_name="MODEL", default="HYDRO", choices=["HYDRO", "ELBDM", "PAR_ONLY"], - help="The physical model (HYDRO: hydrodynamics/magnetohydrodynamics, ELBDM: wave dark matter, PAR_ONLY: partivle-only). Must be set in any cases. PAR_ONLY is not supported yet.\n" + help="The physical model (HYDRO: hydrodynamics/magnetohydrodynamics, "\ + "ELBDM: wave dark matter, PAR_ONLY: partivle-only). "\ + "Must be set in any cases. PAR_ONLY is not supported yet.\n" ) parser.add_argument( "--passive", type=int, metavar="INTEGER", gamer_name="NCOMP_PASSIVE_USER", default=0, depend={"model":["HYDRO", "ELBDM"]}, - help="Set the number of user-defined passively advected scalars. Useless for RTVD. <--model=ELBDM> doesn't support passive scalars and only regards them as auxiliary fields.\n" + help="Set the number of user-defined passively advected scalars. Useless for RTVD. "\ + "<--model=ELBDM> doesn't support passive scalars and only regards them as auxiliary fields.\n" ) # A.1 Hydro options @@ -452,7 +461,8 @@ def load_arguments(): parser.add_argument( "--slope", type=str, metavar="TYPE", gamer_name="LR_SCHEME", default="PPM", choices=["PLM", "PPM"], depend={"model":"HYDRO"}, - help="The spatial data reconstruction method (PLM: piecewise-linear, PPM: piecewise-parabolic). Useless for <--flu_scheme=RTVD>.\n" + help="The spatial data reconstruction method (PLM: piecewise-linear, "\ + "PPM: piecewise-parabolic). Useless for <--flu_scheme=RTVD>.\n" ) parser.add_argument( "--flux", type=str, metavar="TYPE", gamer_name="RSOLVER", @@ -460,14 +470,17 @@ def load_arguments(): depend={"model":"HYDRO"}, constraint={ "ROE":{"eos":"GAMMA"}, "EXACT":{"eos":"GAMMA"} }, - help="The Riemann solver. Pure hydro: EXACT/ROE/HLLE/HLLC^, MHD: ROE/HLLE/HLLD^, SRHD: HLLE/HLLC^, (^ indicates the recommended and default solvers). Useless for RTVD.\n" + help="The Riemann solver. Pure hydro: EXACT/ROE/HLLE/HLLC^, "\ + "MHD: ROE/HLLE/HLLD^, SRHD: HLLE/HLLC^, (^ indicates the recommended and default solvers). "\ + "Useless for RTVD.\n" ) parser.add_argument( "--dual", type=str, metavar="TYPE", gamer_name="DUAL_ENERGY", prefix="DE_", default=NONE_STR, choices=[NONE_STR, "ENPY", "EINT"], depend={"model":"HYDRO"}, constraint={ "ENPY":{"eos":"GAMMA"} }, - help="The dual-energy formalism (ENPY: entropy, EINT: internal energy). EINT is not supported yet. Useless for RTVD.\n" + help="The dual-energy formalism (ENPY: entropy, EINT: internal energy). "\ + "EINT is not supported yet. Useless for RTVD.\n" ) parser.add_argument( "--mhd", type=str2bool, metavar="BOOLEAN", gamer_name="MHD", @@ -481,7 +494,8 @@ def load_arguments(): parser.add_argument( "--srhd", type=str2bool, metavar="BOOLEAN", gamer_name="SRHD", default=False, depend={"model":"HYDRO"}, - constraint={ True:{"flu_scheme":["MHM", "MHM_RP"], "flux":["HLLE", "HLLC"], "eos":["TAUBMATHEWS"], "dual":[NONE_STR], "mhd":False, "gravity":False} }, + constraint={ True:{"flu_scheme":["MHM", "MHM_RP"], "flux":["HLLE", "HLLC"], + "eos":["TAUBMATHEWS"], "dual":[NONE_STR], "mhd":False, "gravity":False} }, help="Special Relativistic Hydrodynamics.\n" ) @@ -496,14 +510,16 @@ def load_arguments(): default=None, choices=["GAMMA", "ISOTHERMAL", "NUCLEAR", "TABULAR", "COSMIC_RAY", "TAUBMATHEWS", "USER"], depend={"model":"HYDRO"}, constraint={ "ISOTHERMAL":{"barotropic":True}, "COSMIC_RAY":{"cosmic_ray":True}, "TAUBMATHEWS":{"srhd":True} }, - help="Equation of state. Must be set when <--model=HYDRO>. Must enable <--barotropic> for ISOTHERMAL.\n" + help="Equation of state. Must be set when <--model=HYDRO>. "\ + "Must enable <--barotropic> for ISOTHERMAL.\n" ) parser.add_argument( "--barotropic", type=str2bool, metavar="BOOLEAN", gamer_name="BAROTROPIC_EOS", default=None, depend={"model":"HYDRO"}, constraint={ True:{"eos":["ISOTHERMAL", "TABULAR", "USER"]} }, - help="Whether or not the equation of state set by <--eos> is barotropic. Mandatory for <--eos=ISOTHEMAL>. Optional for <--eos=TABULAR> and <--eos=USER>.\n" + help="Whether or not the equation of state set by <--eos> is barotropic. "\ + "Mandatory for <--eos=ISOTHEMAL>. Optional for <--eos=TABULAR> and <--eos=USER>.\n" ) # A.2 ELBDM scheme @@ -536,20 +552,24 @@ def load_arguments(): default="MATMUL", choices=["MATMUL", "FFT"], depend={"model":"ELBDM", "wave_scheme":"GRAMFE"}, constraint={ "MATMUL":{"gsl":True} }, - help="GramFE scheme for <--wave_scheme=GRAMFE> (MATMUL: faster for PATCH_SIZE=8, FFT: faster for larger patch sizes).\n" + help="GramFE scheme for <--wave_scheme=GRAMFE> "\ + "(MATMUL: faster for PATCH_SIZE=8, FFT: faster for larger patch sizes).\n" ) parser.add_argument( "--hybrid_scheme", type=str, metavar="TYPE", gamer_name="HYBRID_SCHEME", prefix="HYBRID_", default="MUSCL", choices=["UPWIND", "FROMM", "MUSCL"], depend={"model":"ELBDM", "elbdm_scheme":"HYBRID"}, - help="Fluid scheme for <--elbdm_scheme=HYBRID> (UPWIND: first-order, diffusive, FROMM: second-order, no limiter, unstable for fluid-only simulations, MUSCL: second-order, with limiter, useful for zoom-in and fluid-only simulations).\n" + help="Fluid scheme for <--elbdm_scheme=HYBRID> (UPWIND: first-order, diffusive, "\ + "FROMM: second-order, no limiter, unstable for fluid-only simulations, "\ + "MUSCL: second-order, with limiter, useful for zoom-in and fluid-only simulations).\n" ) parser.add_argument( "--self_interaction", type=str2bool, metavar="BOOLEAN", gamer_name="QUARTIC_SELF_INTERACTION", default=False, depend={"model":"ELBDM"}, constraint={ True:{"gravity":True, "comoving":False} }, - help="Include the quartic self-interaction potential for <--model=ELBDM>. Must enable <--gravity>. Does not support <--comoving>.\n" + help="Include the quartic self-interaction potential for <--model=ELBDM>. "\ + "Must enable <--gravity>. Does not support <--comoving>.\n" ) # A.3 gravity @@ -562,20 +582,24 @@ def load_arguments(): parser.add_argument( "--pot_scheme", type=str, metavar="TYPE", gamer_name="POT_SCHEME", default="SOR", choices=["SOR", "MG"], depend={"gravity":True}, - help="Select the Poisson solver. SOR: successive-overrelaxation (recommended), MG: multigrid. Must be set when <--gravity> is enabled.\n" + help="Select the Poisson solver. SOR: successive-overrelaxation (recommended), MG: multigrid. "\ + "Must be set when <--gravity> is enabled.\n" ) parser.add_argument( "--store_pot_ghost", type=str2bool, metavar="BOOLEAN", gamer_name="STORE_POT_GHOST", default=True, depend={"gravity":True}, - help="Store GRA_GHOST_SIZE ghost-zone potential for each patch on each side. Recommended when PARTICLE is enabled for improving accuaracy for particles around the patch boundaries. Must be enabled for <--star_formation> + <--store_par_acc>.\n" + help="Store GRA_GHOST_SIZE ghost-zone potential for each patch on each side. "\ + "Recommended when PARTICLE is enabled for improving accuaracy for particles around the patch boundaries. "\ + "Must be enabled for <--star_formation> + <--store_par_acc>.\n" ) parser.add_argument( "--unsplit_gravity", type=str2bool, metavar="BOOLEAN", gamer_name="UNSPLIT_GRAVITY", default=None, depend={"gravity":True}, constraint={ True:{"model":"HYDRO"} }, - help="Use unsplitting method to couple gravity to the target model (recommended). Supported only for <--model=HYDRO>. When <--model=HYDRO>, the default is True.\n" + help="Use unsplitting method to couple gravity to the target model (recommended). "\ + "Supported only for <--model=HYDRO>. When <--model=HYDRO>, the default is True.\n" ) parser.add_argument( "--comoving", type=str2bool, metavar="BOOLEAN", gamer_name="COMOVING", @@ -605,7 +629,8 @@ def load_arguments(): parser.add_argument( "--star_formation", type=str2bool, metavar="BOOLEAN", gamer_name="STAR_FORMATION", default=False, depend={"particle":True}, - help="Allow creating new particles after initialization. Must trun on <--store_pot_ghost> when <--store_par_acc> is adoped.\n" + help="Allow creating new particles after initialization. " + "Must trun on <--store_pot_ghost> when <--store_par_acc> is adoped.\n" ) parser.add_argument( "--feedback", type=str2bool, metavar="BOOLEAN", gamer_name="FEEDBACK", @@ -629,7 +654,9 @@ def load_arguments(): parser.add_argument( "--grackle", type=str2bool, metavar="BOOLEAN", gamer_name="SUPPORT_GRACKLE", default=False, constraint={ True:{"model":"HYDRO", "eos":["GAMMA", "COSMIC_RAY"], "comoving":False} }, - help="Enable Grackle, a chemistry and radiative cooling library. Must set <--passive> according to the primordial chemistry network set by GRACKLE_PRIMORDIAL. Please enable OpenMP when compiling Grackle (by 'make omp-on').\n" + help="Enable Grackle, a chemistry and radiative cooling library. "\ + "Must set <--passive> according to the primordial chemistry network set by GRACKLE_PRIMORDIAL. "\ + "Please enable OpenMP when compiling Grackle (by 'make omp-on').\n" ) # A.6 microphysics @@ -653,7 +680,8 @@ def load_arguments(): parser.add_argument( "--patch_size", type=int, metavar="INTEGER", gamer_name="PATCH_SIZE", default=8, - help="Set the number of cells along each direction in a single patch. Must be an even number greater than or equal to 8.\n" + help="Set the number of cells along each direction in a single patch. "\ + "Must be an even number greater than or equal to 8.\n" ) parser.add_argument( "--debug", type=str2bool, metavar="BOOLEAN", gamer_name="GAMER_DEBUG", @@ -674,7 +702,9 @@ def load_arguments(): parser.add_argument( "--timing_solver", type=str2bool, metavar="BOOLEAN", gamer_name="TIMING_SOLVER", default=False, constraint={ True:{"timing":True} }, - help="Enable more detailed timing analysis of GPU solvers. This option will disable CPU/GPU overlapping and thus deteriorate performance. Must enable <--timing>.\n" + help="Enable more detailed timing analysis of GPU solvers. "\ + "This option will disable CPU/GPU overlapping and thus deteriorate performance. "\ + "Must enable <--timing>.\n" ) parser.add_argument( "--double", type=str2bool, metavar="BOOLEAN", gamer_name="FLOAT8", @@ -716,31 +746,38 @@ def load_arguments(): parser.add_argument( "--libyt_patchgroup", type=str2bool, metavar="BOOLEAN", gamer_name="LIBYT_USE_PATCH_GROUP", default=True, depend={"libyt":True}, - help="Use patch groups instead of patches as the unit in libyt for better performance (recommended). Must enable <--libyt>.\n" + help="Use patch groups instead of patches as the unit in libyt for better performance (recommended). "\ + "Must enable <--libyt>.\n" ) parser.add_argument( "--libyt_interactive", type=str2bool, metavar="BOOLEAN", gamer_name="LIBYT_INTERACTIVE", default=False, depend={"libyt":True}, - help="Enable the interactive mode of libyt. This activates python prompt and does not shut down a simulation when there are errors in an inline python script. Must compile libyt with INTERACTIVE_MODE. Must enable <--libyt>.\n" + help="Enable the interactive mode of libyt. "\ + "This activates python prompt and does not shut down a simulation when there are errors in an inline python script. "\ + "Must compile libyt with INTERACTIVE_MODE. Must enable <--libyt>.\n" ) parser.add_argument( "--libyt_reload", type=str2bool, metavar="BOOLEAN", gamer_name="LIBYT_RELOAD", default=False, depend={"libyt":True}, - help="Allow for reloading libyt scripts during runtime. Must compile libyt with INTERACTIVE_MODE. Must enable <--libyt>.\n" + help="Allow for reloading libyt scripts during runtime. "\ + "Must compile libyt with INTERACTIVE_MODE. Must enable <--libyt>.\n" ) parser.add_argument( "--libyt_jupyter", type=str2bool, metavar="BOOLEAN", gamer_name="LIBYT_JUPYTER", default=False, depend={"libyt":True}, - help="Allow for in situ analysis using Jupyter Notebook / JupyterLab through libyt. Must compile libyt with JUPYTER_KERNEL. Must enable <--libyt>.\n" + help="Allow for in situ analysis using Jupyter Notebook / JupyterLab through libyt. "\ + "Must compile libyt with JUPYTER_KERNEL. Must enable <--libyt>.\n" ) parser.add_argument( "--rng", type=str, metavar="TYPE", gamer_name="RANDOM_NUMBER", default="RNG_GNU_EXT", choices=["RNG_GNU_EXT", "RNG_CPP11"], - help="Select the random number generator (RNG_GNU_EXT: GNU extension drand48_r, RNG_CPP11: c++11 ).\nRNG_GNU_EXT may not be supported on some macOS.\nFor RNG_CPP11, add -std=c++11 to CXXFLAG in your config file.\n" + help="Select the random number generator (RNG_GNU_EXT: GNU extension drand48_r, RNG_CPP11: c++11 ).\n" + "RNG_GNU_EXT may not be supported on some macOS.\n"\ + "For RNG_CPP11, add -std=c++11 to CXXFLAG in your config file.\n" ) # C. parallelization and flags From 3ee743382f7be98ab182fbcc6d58734b80364bee Mon Sep 17 00:00:00 2001 From: ChunYen-Chen Date: Tue, 21 Jan 2025 14:12:16 +0800 Subject: [PATCH 17/29] Update wiki --- doc/wiki/Installation.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/wiki/Installation.md b/doc/wiki/Installation.md index 7e3bfd8737..2b62b78153 100644 --- a/doc/wiki/Installation.md +++ b/doc/wiki/Installation.md @@ -63,7 +63,7 @@ e.g., `example/test_problem/Hydro/AcousticWave/generate_make.sh`. > source ~/.bashrc > ``` > -> Now, try to type `./configure.py` then press `` twice! +> Now, try to type `./configure.py` then press `` multiple times! 4. Compile the code From 9f880de96568d77a51ea0a7b72dddd7b3c5429a7 Mon Sep 17 00:00:00 2001 From: ChunYen-Chen Date: Tue, 21 Jan 2025 14:40:51 +0800 Subject: [PATCH 18/29] Update wiki --- doc/wiki/Installation.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/doc/wiki/Installation.md b/doc/wiki/Installation.md index 2b62b78153..9c9a412936 100644 --- a/doc/wiki/Installation.md +++ b/doc/wiki/Installation.md @@ -57,6 +57,8 @@ e.g., `example/test_problem/Hydro/AcousticWave/generate_make.sh`. > ```bash > source ~/config_autocomplete.sh > ``` +> NOTE: There are three commands registered in the `config_autocomplete.sh`, `python` `python3` and `./configure.py`. +> If you would like to register your command, please add the command at the bottom of the script. > > 1. Reload `~/.bashrc` to enable the feature > ```bash From c667c4dc6a69b5e5c0e3b26d0c42d53c863754e0 Mon Sep 17 00:00:00 2001 From: ChunYen-Chen Date: Wed, 22 Jan 2025 13:15:55 +0800 Subject: [PATCH 19/29] Fix wrong merge --- src/configure.py | 1 - 1 file changed, 1 deletion(-) diff --git a/src/configure.py b/src/configure.py index 9cb3856b5e..1c60408053 100755 --- a/src/configure.py +++ b/src/configure.py @@ -47,7 +47,6 @@ LOGGER = logging.getLogger() LOG_FORMAT = "%(asctime)s %(levelname)-8s: %(message)s" -logging.basicConfig( filename=GAMER_MAKE_OUT+".log", filemode="w", level=logging.INFO, format=LOG_FORMAT ) From 93a916a8810dbf70caafbe0d6aaf041fce209850 Mon Sep 17 00:00:00 2001 From: ChunYen-Chen Date: Thu, 23 Jan 2025 13:25:17 +0800 Subject: [PATCH 20/29] Fix filename check --- tool/bash/config_autocomplete.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tool/bash/config_autocomplete.sh b/tool/bash/config_autocomplete.sh index 0cef1525b0..9fb0d7defc 100755 --- a/tool/bash/config_autocomplete.sh +++ b/tool/bash/config_autocomplete.sh @@ -4,7 +4,7 @@ __gamer_check_gamer_info() { # Check if the current directory is GAMER and the `configure.py` for generating `Makefile` # $1 : configure.py filename - if [[ "$1" != *"configure.py" ]]; then return 1; fi + if [[ "$1" != "configure.py" && "$1" != "./configure.py" ]]; then return 1; fi local isGitDir=`git rev-parse --is-inside-work-tree 2>/dev/null` [ ! "$isGitDir" = true ] && return 1 From aea74a7f591db54d0250a69da26e2000031e5eed Mon Sep 17 00:00:00 2001 From: ChunYen-Chen Date: Thu, 23 Jan 2025 05:48:47 +0000 Subject: [PATCH 21/29] chore(docs): Sync wiki to doc/wiki [skip-cd] --- doc/wiki/Installation.md | 89 ++++++++++++++++++++-------------------- 1 file changed, 45 insertions(+), 44 deletions(-) diff --git a/doc/wiki/Installation.md b/doc/wiki/Installation.md index 0521397b47..114c946027 100644 --- a/doc/wiki/Installation.md +++ b/doc/wiki/Installation.md @@ -41,45 +41,6 @@ Furthermore, you can override the default setting by passing the [[--machine | I > An example script `generate_make.sh` to generate Makefile can be found in each test problem folder, e.g., `example/test_problem/Hydro/AcousticWave/generate_make.sh`. -> [!TIP] -> Since there are too many options in GAMER, we introduce the autocomplete feature of `configure.py`. You can set the feature by the following steps: -> 1. Update the [shebang](https://en.wikipedia.org/wiki/Shebang_(Unix)) of `configure.py` if needed -> -> For example, replace `#!/usr/bin/python3` with your `python` path. ->
-> top of configure.py ->
->    #!/usr/bin/python3
->    """
->    User guides of this script are provided in the following link.
->
->    https://github.com/gamer-project/gamer/wiki/Installation
->
->    """
->    
->
-> -> 1. Copy the autocomplete shell script to your `/home/usr` (`~`) -> ```bash -> cp tool/bash/config_autocomplete.sh ~/ -> ``` -> -> 1. Update the `~/.bashrc` to load the autocomplete script -> -> Please add the following line to `~/.bashrc`: -> ```bash -> source ~/config_autocomplete.sh -> ``` -> NOTE: There are three commands registered in the `config_autocomplete.sh`, `python` `python3` and `./configure.py`. -> If you would like to register your command, please add the command at the bottom of the script. -> -> 1. Reload `~/.bashrc` to enable the feature -> ```bash -> source ~/.bashrc -> ``` -> -> Now, try to type `./configure.py` then press `` multiple times! - 5. Compile the code ```bash @@ -87,6 +48,12 @@ e.g., `example/test_problem/Hydro/AcousticWave/generate_make.sh`. make ``` + If the compilation succeeds, you will see the following message +
+   Compiling GAMER --> Successful!
+   
+ and get an executable `gamer`, which will be automatically copied to `../bin/gamer`. + > [!TIP] > To reduce the compilation time, you can perform a parallel compilation by `make -j N`, where `N` is the number of compilation @@ -98,8 +65,42 @@ invoke 4 compilation jobs simultaneously: > However, please consult the documentation of your system to avoid violating the usage policy. -If the compilation succeeds, you will see the following message -
-Compiling GAMER --> Successful!
-
-and get an executable `gamer`, which will be automatically copied to `../bin/gamer`. + +6. [Optional] Autocompletion of `configure.py` + + Since there are too many options in GAMER, we introduce the autocomplete feature of `configure.py`. You can set the feature by the following steps: + 1. Update the [shebang](https://en.wikipedia.org/wiki/Shebang_(Unix)) of `configure.py` if needed + + For example, replace `#!/usr/bin/python3` with your `python` path. +
+ top of configure.py +
+      #!/usr/bin/python3
+      """
+      User guides of this script are provided in the following link.
+
+      https://github.com/gamer-project/gamer/wiki/Installation
+      """
+      
+
+ + 2. Copy the autocomplete shell script to your `/home/usr` (`~`) + ```bash + cp tool/bash/config_autocomplete.sh ~/ + ``` + + 2. Update the `~/.bashrc` to load the autocomplete script + + Please add the following line to `~/.bashrc`: + ```bash + source ~/config_autocomplete.sh + ``` + NOTE: There are three commands registered in the `config_autocomplete.sh`, `python` `python3` and `./configure.py`. + If you would like to register your command, please add the command at the bottom of the script. + + 3. Reload `~/.bashrc` to enable the feature + ```bash + source ~/.bashrc + ``` + + Now, try to type `./configure.py` and then press `` multiple times! \ No newline at end of file From eee01be4d89ed14c38c700e072a3a885d200f431 Mon Sep 17 00:00:00 2001 From: Chun-Yen Chen <70311975+ChunYen-Chen@users.noreply.github.com> Date: Tue, 4 Feb 2025 16:11:49 +0800 Subject: [PATCH 22/29] Apply suggestions from code review Co-authored-by: Hsi-Yu Schive --- doc/wiki/Installation.md | 17 +++++++++-------- doc/wiki/configure.py.md | 8 ++++---- src/configure.py | 12 ++++++------ tool/bash/config_autocomplete.sh | 4 ++-- 4 files changed, 21 insertions(+), 20 deletions(-) diff --git a/doc/wiki/Installation.md b/doc/wiki/Installation.md index 114c946027..e50ab4dd90 100644 --- a/doc/wiki/Installation.md +++ b/doc/wiki/Installation.md @@ -68,12 +68,12 @@ violating the usage policy. 6. [Optional] Autocompletion of `configure.py` - Since there are too many options in GAMER, we introduce the autocomplete feature of `configure.py`. You can set the feature by the following steps: - 1. Update the [shebang](https://en.wikipedia.org/wiki/Shebang_(Unix)) of `configure.py` if needed + Since there are many options in GAMER, we have introduced an autocomplete feature for `configure.py`. You can enable this feature by the following steps: + 1. Update the [shebang](https://en.wikipedia.org/wiki/Shebang_(Unix)) of `configure.py` (if needed) - For example, replace `#!/usr/bin/python3` with your `python` path. + For example, replace `#!/usr/bin/python3` with the path to your preferred Python interpreter.
- top of configure.py + Example at the top of configure.py
       #!/usr/bin/python3
       """
@@ -89,16 +89,17 @@ violating the usage policy.
       cp tool/bash/config_autocomplete.sh ~/
       ```
 
-   2. Update the `~/.bashrc` to load the autocomplete script
+   3. Update `~/.bashrc` to load the autocomplete script
 
       Please add the following line to `~/.bashrc`:
       ```bash
       source ~/config_autocomplete.sh
       ```
-      NOTE: There are three commands registered in the `config_autocomplete.sh`, `python` `python3` and `./configure.py`.
-            If you would like to register your command, please add the command at the bottom of the script.
+> [!NOTE]
+> The `config_autocomplete.sh` script registers autocomplete for three commands: `python`, `python3`, and `./configure.py.`.
+If you want to add more commands, simply append them at the bottom of the script.
 
-   3. Reload `~/.bashrc` to enable the feature
+   4. Reload `~/.bashrc` to enable the autocomplete feature
       ```bash
       source ~/.bashrc
       ```
diff --git a/doc/wiki/configure.py.md b/doc/wiki/configure.py.md
index 839c58fcf9..6cd13572dd 100644
--- a/doc/wiki/configure.py.md
+++ b/doc/wiki/configure.py.md
@@ -57,14 +57,14 @@ Edit the section "source files" in the `Makefile_base` to add new source files.
                       )
    ```
 
-4. [Optional] Add the common prefix/suffix of the simulation options. (Only works for string type)
+4. [Optional] Add a common prefix/suffix to the simulation option (only works for the string type).
    ```python
-   parser.add_argument( "--new_argument", type=str, metavar="STRING", gamer_name="NEW_SIMUALTION_OPTION", prefix="YOUR_PREFIX_", suffix="_YOUR_SUFFIX",
-                        default="STR1", choice=["STR1", "STR2", "STR3"],
+   parser.add_argument( "--new_argument", type=str, metavar="STRING", gamer_name="NEW_SIMULATION_OPTION", prefix="YOUR_PREFIX_", suffix="_YOUR_SUFFIX",
+                        default="STR1", choices=["STR1", "STR2", "STR3"],
                         help="Your help message.\n"
                       )
    ```
-   The simulation option would be concatenated as `YOUR_PREFIX_STR1_YOUR_SUFFIX`.
+   The simulation option will be concatenated as `YOUR_PREFIX_STR1_YOUR_SUFFIX`.
 
 5. [Optional] Add additional checks in `validation()` and warning messages in `warning()` under `Functions`.
    * `validation()`
diff --git a/src/configure.py b/src/configure.py
index 615a84e7a1..6321ad6729 100755
--- a/src/configure.py
+++ b/src/configure.py
@@ -225,12 +225,12 @@ def print_autocomplete( self, target_option, *args, **kwargs ):
             if not any( target_option in [flag+trail_option, flag] for flag in option["flags"] ):
                 continue
 
-            # option with choices
+            # options with choices
             if "choices" in option:
                 print( " ".join(option["choices"]) )
                 return
 
-            # help like option
+            # help-like options
             if "type" not in option: return
 
             # boolean type choices
@@ -437,8 +437,8 @@ def load_arguments( sys_setting : SystemSetting ):
     # autocomplete information
     parser.add_argument( "--autocomplete_info", type=str, metavar="--OPTION",
                          default=None,
-                         help="Print out the autocomplete information. "\
-                              "See: ../tool/bash/config_autocomplete.sh\n"
+                         help="Print the autocomplete information "\
+                              "used by the config_autocomplete.sh script.\n"
                        )
 
     # machine config setup
@@ -652,7 +652,7 @@ def load_arguments( sys_setting : SystemSetting ):
                          default=False,
                          depend={"particle":True},
                          help="Allow creating new particles after initialization. "
-                              "Must trun on <--store_pot_ghost> when <--store_par_acc> is adoped.\n"
+                              "Must turn on <--store_pot_ghost> when <--store_par_acc> is adoped.\n"
                        )
 
     parser.add_argument( "--feedback", type=str2bool, metavar="BOOLEAN", gamer_name="FEEDBACK",
@@ -1215,5 +1215,5 @@ def warning( paths, **kwargs ):
 
     LOGGER.info("========================================")
     LOGGER.info("%s is created."%GAMER_MAKE_OUT)
-    if args["verbose_make"]: LOGGER.info("%s is in verbose mode!"%GAMER_MAKE_OUT)
+    if args["verbose_make"]: LOGGER.info("%s is in verbose mode."%GAMER_MAKE_OUT)
     LOGGER.info("========================================")
diff --git a/tool/bash/config_autocomplete.sh b/tool/bash/config_autocomplete.sh
index 9fb0d7defc..ee29f1cec2 100755
--- a/tool/bash/config_autocomplete.sh
+++ b/tool/bash/config_autocomplete.sh
@@ -50,7 +50,7 @@ __gamer_configure_autocomplete() {
 
     COMPREPLY=() # NOTE: please add a space when ending the option
 
-    # option choices
+    # Option choices
     for opt in "${all_option_array[@]}"
     do
         # --option=xx
@@ -80,7 +80,7 @@ __gamer_configure_autocomplete() {
             done
             not_set=false
             break
-        # special case without trailing `=` (-h and -lh)
+        # Special case without trailing `=` (-h and -lh)
         elif [[ "$cur" == "-h" || "$cur" == "-lh" ]]; then
             COMPREPLY+=("$cur ")
             not_set=false

From 97c7c007bee531543aa58a4405b4698dbb65c107 Mon Sep 17 00:00:00 2001
From: ChunYen-Chen 
Date: Tue, 4 Feb 2025 16:23:21 +0800
Subject: [PATCH 23/29] Remove prefix and suffix

---
 example/test_problem/ELBDM/LSS_Hybrid/generate_make.sh          | 2 +-
 example/test_problem/ELBDM/Perturbation/generate_make.sh        | 2 +-
 .../test_problem/ELBDM/VortexPairLinear_Hybrid/generate_make.sh | 2 +-
 .../ELBDM/VortexPairRotating_Hybrid/generate_make.sh            | 2 +-
 .../test_problem/Hydro/AGORA_IsolatedGalaxy/generate_make.sh    | 2 +-
 example/test_problem/Hydro/Bondi/generate_make.sh               | 2 +-
 example/test_problem/Hydro/SphericalCollapse/generate_make.sh   | 2 +-
 example/test_problem/Hydro/Zeldovich/README                     | 2 +-
 example/test_problem/Hydro/Zeldovich/generate_make.sh           | 2 +-
 9 files changed, 9 insertions(+), 9 deletions(-)

diff --git a/example/test_problem/ELBDM/LSS_Hybrid/generate_make.sh b/example/test_problem/ELBDM/LSS_Hybrid/generate_make.sh
index 81c9fba21b..5999ee0eee 100644
--- a/example/test_problem/ELBDM/LSS_Hybrid/generate_make.sh
+++ b/example/test_problem/ELBDM/LSS_Hybrid/generate_make.sh
@@ -3,5 +3,5 @@
 PYTHON=python3
 
 ${PYTHON} configure.py --mpi=true --hdf5=true --fftw=FFTW3 --gpu=true \
-                       --model=ELBDM --elbdm_scheme=ELBDM_HYBRID --wave_scheme=WAVE_GRAMFE --gramfe_scheme=GRAMFE_MATMUL \
+                       --model=ELBDM --elbdm_scheme=HYBRID --wave_scheme=GRAMFE --gramfe_scheme=MATMUL \
                        --gravity=true --comoving=true --gsl=true --spectral_interpolation=true "$@"
diff --git a/example/test_problem/ELBDM/Perturbation/generate_make.sh b/example/test_problem/ELBDM/Perturbation/generate_make.sh
index 382fd3e78a..508b22f1b0 100644
--- a/example/test_problem/ELBDM/Perturbation/generate_make.sh
+++ b/example/test_problem/ELBDM/Perturbation/generate_make.sh
@@ -3,5 +3,5 @@
 PYTHON=python3
 
 ${PYTHON} configure.py --mpi=true --hdf5=true --fftw=FFTW3 --gpu=true \
-                       --model=ELBDM --elbdm_scheme=ELBDM_HYBRID --wave_scheme=WAVE_GRAMFE --gramfe_scheme=GRAMFE_MATMUL \
+                       --model=ELBDM --elbdm_scheme=HYBRID --wave_scheme=GRAMFE --gramfe_scheme=MATMUL \
                        --gravity=true --comoving=false --gsl=true --spectral_interpolation=true "$@"
diff --git a/example/test_problem/ELBDM/VortexPairLinear_Hybrid/generate_make.sh b/example/test_problem/ELBDM/VortexPairLinear_Hybrid/generate_make.sh
index c4f3150c8f..5b71817720 100644
--- a/example/test_problem/ELBDM/VortexPairLinear_Hybrid/generate_make.sh
+++ b/example/test_problem/ELBDM/VortexPairLinear_Hybrid/generate_make.sh
@@ -2,4 +2,4 @@
 
 PYTHON=python3
 
-${PYTHON} configure.py --model=ELBDM --elbdm_scheme=ELBDM_HYBRID --hdf5=true --mpi=true "$@"
+${PYTHON} configure.py --model=ELBDM --elbdm_scheme=HYBRID --hdf5=true --mpi=true "$@"
diff --git a/example/test_problem/ELBDM/VortexPairRotating_Hybrid/generate_make.sh b/example/test_problem/ELBDM/VortexPairRotating_Hybrid/generate_make.sh
index c4f3150c8f..5b71817720 100644
--- a/example/test_problem/ELBDM/VortexPairRotating_Hybrid/generate_make.sh
+++ b/example/test_problem/ELBDM/VortexPairRotating_Hybrid/generate_make.sh
@@ -2,4 +2,4 @@
 
 PYTHON=python3
 
-${PYTHON} configure.py --model=ELBDM --elbdm_scheme=ELBDM_HYBRID --hdf5=true --mpi=true "$@"
+${PYTHON} configure.py --model=ELBDM --elbdm_scheme=HYBRID --hdf5=true --mpi=true "$@"
diff --git a/example/test_problem/Hydro/AGORA_IsolatedGalaxy/generate_make.sh b/example/test_problem/Hydro/AGORA_IsolatedGalaxy/generate_make.sh
index 22c9e42bda..2c9977bd44 100644
--- a/example/test_problem/Hydro/AGORA_IsolatedGalaxy/generate_make.sh
+++ b/example/test_problem/Hydro/AGORA_IsolatedGalaxy/generate_make.sh
@@ -4,4 +4,4 @@ PYTHON=python3
 
 ${PYTHON} configure.py --mpi=true --hdf5=true --fftw=FFTW3 --gpu=true --model=HYDRO \
                        --particle=true --gravity=true --flu_scheme=MHM --flux=HLLC --passive=1 \
-                       --par_attribute_flt=1 --dual=DE_ENPY --star_formation=true --grackle=true "$@"
+                       --par_attribute_flt=1 --dual=ENPY --star_formation=true --grackle=true "$@"
diff --git a/example/test_problem/Hydro/Bondi/generate_make.sh b/example/test_problem/Hydro/Bondi/generate_make.sh
index 70de7de3a3..4424e70fd6 100644
--- a/example/test_problem/Hydro/Bondi/generate_make.sh
+++ b/example/test_problem/Hydro/Bondi/generate_make.sh
@@ -3,4 +3,4 @@
 PYTHON=python3
 
 ${PYTHON} configure.py --hdf5=true --gpu=true --fftw=FFTW3 \
-                       --model=HYDRO --gravity=true --dual=DE_ENPY "$@"
+                       --model=HYDRO --gravity=true --dual=ENPY "$@"
diff --git a/example/test_problem/Hydro/SphericalCollapse/generate_make.sh b/example/test_problem/Hydro/SphericalCollapse/generate_make.sh
index 6398a3fe92..e9106fb4e1 100644
--- a/example/test_problem/Hydro/SphericalCollapse/generate_make.sh
+++ b/example/test_problem/Hydro/SphericalCollapse/generate_make.sh
@@ -3,4 +3,4 @@
 PYTHON=python3
 
 ${PYTHON} configure.py --mpi=true --hdf5=true --fftw=FFTW3 --gpu=true \
-                       --model=HYDRO --gravity=true --comoving=true --dual=DE_ENPY "$@"
+                       --model=HYDRO --gravity=true --comoving=true --dual=ENPY "$@"
diff --git a/example/test_problem/Hydro/Zeldovich/README b/example/test_problem/Hydro/Zeldovich/README
index 64ce058f98..0c5ef227fe 100644
--- a/example/test_problem/Hydro/Zeldovich/README
+++ b/example/test_problem/Hydro/Zeldovich/README
@@ -1,7 +1,7 @@
 Compilation flags:
 ========================================
 Enable : MODEL=HYDRO, GRAVITY, COMOVING, PARTICLE, SUPPORT_GSL, SUPPORT_FFTW, DUAL_ENERGY
-Configure.py: python configure.py --model=HYDRO --gravity=true --comoving=true --particle=true --gsl=true --fftw=FFTW2 --dual=DE_ENPY
+Configure.py: python configure.py --model=HYDRO --gravity=true --comoving=true --particle=true --gsl=true --fftw=FFTW2 --dual=ENPY
 
 
 Default setup:
diff --git a/example/test_problem/Hydro/Zeldovich/generate_make.sh b/example/test_problem/Hydro/Zeldovich/generate_make.sh
index ac3b9a5f8b..f97d355561 100644
--- a/example/test_problem/Hydro/Zeldovich/generate_make.sh
+++ b/example/test_problem/Hydro/Zeldovich/generate_make.sh
@@ -4,4 +4,4 @@ PYTHON=python3
 
 ${PYTHON} configure.py --mpi=true --hdf5=true --fftw=FFTW3 --gpu=true \
                        --gsl=true --double=true --model=HYDRO --gravity=true \
-                       --comoving=true --dual=DE_ENPY --particle=true "$@"
+                       --comoving=true --dual=ENPY --particle=true "$@"

From 530e4e2bf0754f412dee26e88dec30cdb2bc8385 Mon Sep 17 00:00:00 2001
From: ChunYen-Chen 
Date: Tue, 4 Feb 2025 17:06:45 +0800
Subject: [PATCH 24/29] Update wiki

---
 doc/wiki/ELBDM-related/ELBDM-Hybrid-Scheme.md | 18 +++++++-------
 .../ELBDM-related/ELBDM-Spectral-Solver.md    | 24 +++++++++----------
 .../Installation:-Option-List.md              | 16 ++++++-------
 3 files changed, 29 insertions(+), 29 deletions(-)

diff --git a/doc/wiki/ELBDM-related/ELBDM-Hybrid-Scheme.md b/doc/wiki/ELBDM-related/ELBDM-Hybrid-Scheme.md
index 4109c86e14..523f439def 100644
--- a/doc/wiki/ELBDM-related/ELBDM-Hybrid-Scheme.md
+++ b/doc/wiki/ELBDM-related/ELBDM-Hybrid-Scheme.md
@@ -65,7 +65,7 @@ mpirun -map-by ppr:2:socket:pe=8 --report-bindings ./gamer 1>>log 2>&1
    ![Data_000069_PS](https://github.com/gamer-project/gamer/assets/6187378/260649c1-69e7-4a44-8dc9-06ccf6fe798d)
    
-The wave scheme (`GRAMFE_MATMUL`) is used for the dark grey and black grids. +The wave scheme (`MATMUL`) is used for the dark grey and black grids. The relative mass conservation error at $z=0$ with spectral interpolation on is $6.72e-04$. @@ -90,15 +90,15 @@ The hybrid scheme is particularly suited for cosmological simulations where a si The configure.py script is the starting point for setting up a simulation. For the hybrid scheme, ensure the following flags are set: -- `--elbdm_scheme = ELBDM_HYBRID`: Determines the scheme type for ELBDM simulations. There are two options: - - `ELBDM_WAVE`: Wave-only scheme. - - `ELBDM_HYBRID`: Fluid-wave hybrid scheme. +- `--elbdm_scheme = HYBRID`: Determines the scheme type for ELBDM simulations. There are two options: + - `WAVE`: Wave-only scheme. + - `HYBRID`: Fluid-wave hybrid scheme. - `--hybrid_scheme`: This option is specific to the hybrid scheme, defining the fluid dynamics treatment: - - `HYBRID_UPWIND`: First-order upwind scheme. It is diffusive but stable. - - `HYBRID_FROMM`: Second-order Fromm scheme. It has no limiter but can be unstable. - - `HYBRID_MUSCL`: Second-order MUSCL scheme. It includes a limiter, balancing accuracy and stability. + - `UPWIND`: First-order upwind scheme. It is diffusive but stable. + - `FROMM`: Second-order Fromm scheme. It has no limiter but can be unstable. + - `MUSCL`: Second-order MUSCL scheme. It includes a limiter, balancing accuracy and stability. - For zoom-in and fluid-only simulations, use `--hybrid_scheme HYBRID_MUSCL` since unrefined regions may become unstable otherwise. For fully refined simulations use `--hybrid_scheme HYBRID_FROMM` since it is slightly faster and more accurate than `HYBRID_MUSCL`. In case you encounter instabilities, test the more diffusive, first-order scheme `--hybrid_scheme HYBRID_UPWIND`. + For zoom-in and fluid-only simulations, use `--hybrid_scheme MUSCL` since unrefined regions may become unstable otherwise. For fully refined simulations use `--hybrid_scheme FROMM` since it is slightly faster and more accurate than `MUSCL`. In case you encounter instabilities, test the more diffusive, first-order scheme `--hybrid_scheme UPWIND`. ## Configuring the `Input__Parameter` file @@ -225,7 +225,7 @@ $$S(x, t) = \arctan\left(\frac{\Im(\psi(x, t))}{\Re(\psi(x, t)}\right).$$ We must therefore determine the correct phase by requiring continuity at the matching boundary. On a discrete grid, this translates into the requirement that the phase field $S(x, t)$ must not change by more than $2 \pi$ between neighbouring grid points at the matching boundary. In other words, we must resolve the de Broglie wavelength at the matching boundary in order for the reverse boundary matching problem to admit a unique solution. This immediately shows that a useful hybrid scheme based on this approach necessarily requires an AMR algorithm with at least two refinement levels for the phase equation: An outer refinement level where the grids need not resolve the de Broglie wavelength and a second refinement level where the de Broglie wavelength is resolved and the reverse boundary matching problem has a unique solution. ## Implementation -We evolve the continuity equation using a first-order upwind scheme (`HYBRID_UPWIND`), the second-order Fromm scheme without limiter (`HYBRID_FROMM`) or a MUSCL scheme with a linear subgrid model together with the van Albada limiter (`HYBRID_MUSCL`). As for the HJ scheme, we use a finite difference scheme. The convection term is discretised via the Sethian-Osher flux. The velocities at the cell faces are then computed as regular finite differences. We treat the cell averages $\bar{\rho}$ in the finite volume scheme as point values $\rho$ in the discretisation of the quantum pressure term. Technically, we use the MUSCL scheme as a conservative finite-difference method and not as a finite volume scheme. This has the consequence that the maximum order of accuracy we can reach with the linear subgrid MUSCL scheme is second order. The quantum pressure term is discretised as +We evolve the continuity equation using a first-order upwind scheme (`UPWIND`), the second-order Fromm scheme without limiter (`FROMM`) or a MUSCL scheme with a linear subgrid model together with the van Albada limiter (`MUSCL`). As for the HJ scheme, we use a finite difference scheme. The convection term is discretised via the Sethian-Osher flux. The velocities at the cell faces are then computed as regular finite differences. We treat the cell averages $\bar{\rho}$ in the finite volume scheme as point values $\rho$ in the discretisation of the quantum pressure term. Technically, we use the MUSCL scheme as a conservative finite-difference method and not as a finite volume scheme. This has the consequence that the maximum order of accuracy we can reach with the linear subgrid MUSCL scheme is second order. The quantum pressure term is discretised as $$\frac{\Delta \sqrt{\rho}}{\sqrt{\rho}} = \left(\frac{1}{2} \Delta \log(\rho) + \frac{1}{4} \left(\nabla \log(\rho)\right)^2\right)$$ with second-order central finite differences for both the gradient operator and the Laplacian. The resulting semi-discrete scheme is discretised with a third-order RK method. A second-order discretisation also works well, but requires a more stringent CFL condition. diff --git a/doc/wiki/ELBDM-related/ELBDM-Spectral-Solver.md b/doc/wiki/ELBDM-related/ELBDM-Spectral-Solver.md index 47d775733c..a9cdf5cdfb 100644 --- a/doc/wiki/ELBDM-related/ELBDM-Spectral-Solver.md +++ b/doc/wiki/ELBDM-related/ELBDM-Spectral-Solver.md @@ -4,8 +4,8 @@ ### Compilation Options - **Wave Scheme Selection**: To enable the spectral solver, set `WAVE_SCHEME` to `WAVE_GRAMFE` in the Makefile or configure with `--wave_scheme=WAVE_GRAMFE` for the ELBDM model. -- **Spectral Scheme Options**: Choose between `GRAMFE_MATMUL` (faster for `PATCH_SIZE=8`) and `GRAMFE_FFT` (faster for larger patch sizes) by setting `GRAMFE_SCHEME` in the Makefile or configure with `--gramfe_scheme` accordingly. -- **Additional Libraries**: The CPU version requires FFTW 3 for single precision and FFTW 2/3 for double precision. The GPU version of `GRAMFE_FFT` needs the cuFFTDx library. Set `FFTW2_PATH`, `FFTW3_PATH`, and `CUFFTDX_PATH` in the Makefile or configuration files `*.config`. +- **Spectral Scheme Options**: Choose between `MATMUL` (faster for `PATCH_SIZE=8`) and `FFT` (faster for larger patch sizes) by setting `SCHEME` in the Makefile or configure with `--gramfe_scheme` accordingly. +- **Additional Libraries**: The CPU version requires FFTW 3 for single precision and FFTW 2/3 for double precision. The GPU version of `FFT` needs the cuFFTDx library. Set `FFTW2_PATH`, `FFTW3_PATH`, and `CUFFTDX_PATH` in the Makefile or configuration files `*.config`. ### Precision and Performance Options - **Floating Point Precision**: Controlled by `GRAMFE_ENABLE_SINGLE_PRECISION`. The default is double precision. Single precision is not recommended due to stability issues. @@ -68,29 +68,29 @@ 4. **Avoidance of Gibbs Phenomenon**: Smooth extensions largely prevent the Gibbs phenomenon. 5. **Discarding Extended Domain**: After computation, the extended domain is discarded. -## Differences between GRAMFE_MATMUL and GRAMFE_FFT Schemes +## Differences between MATMUL and FFT Schemes ### Overview -Understanding the differences between the `GRAMFE_MATMUL` and `GRAMFE_FFT` schemes in GAMER is crucial for users to choose the appropriate method for their specific simulation needs. Both schemes are based on the Gram-Fourier extension algorithm but differ in their computational approach and performance characteristics. +Understanding the differences between the `MATMUL` and `FFT` schemes in GAMER is crucial for users to choose the appropriate method for their specific simulation needs. Both schemes are based on the Gram-Fourier extension algorithm but differ in their computational approach and performance characteristics. -### GRAMFE_MATMUL Scheme +### MATMUL Scheme #### Description -- **Matrix Multiplication Approach**: In the `GRAMFE_MATMUL` scheme, the entire operation sequence - GramFE extension, FFT, time evolution, IFFT, and discarding of extension data - is precomputed and represented as a single matrix (which is possible because of linearity). +- **Matrix Multiplication Approach**: In the `MATMUL` scheme, the entire operation sequence - GramFE extension, FFT, time evolution, IFFT, and discarding of extension data - is precomputed and represented as a single matrix (which is possible because of linearity). - **Application to Input Vectors**: This precomputed matrix can be directly applied to input vectors, eliminating the need to compute each operation at runtime. #### Advantages -- **Reduced Runtime Computation**: By precomputing the entire operation sequence, the `GRAMFE_MATMUL` scheme minimizes runtime computational overhead. +- **Reduced Runtime Computation**: By precomputing the entire operation sequence, the `MATMUL` scheme minimizes runtime computational overhead. - **Efficiency for Small Patch Sizes**: This scheme is particularly efficient for smaller data sizes where the cost of matrix multiplication is lower. #### Disadvantages - **Memory Usage**: The precomputed matrix, especially for large patch sizes, can consume significant memory resources. - **Precomputation Time**: There is an upfront cost in time to compute and store the matrix, which might be substantial depending on the accuracy used. -### GRAMFE_FFT Scheme +### FFT Scheme #### Description -- **Runtime Computation**: The `GRAMFE_FFT` scheme performs the GramFE extension, FFT, time evolution, IFFT, and discarding of extension data operations at runtime. +- **Runtime Computation**: The `FFT` scheme performs the GramFE extension, FFT, time evolution, IFFT, and discarding of extension data operations at runtime. #### Advantages - **Scalability for Large Patch Sizes**: This scheme is more scalable for larger patch sizes, as it does not require storing large precomputed matrices. @@ -100,10 +100,10 @@ Understanding the differences between the `GRAMFE_MATMUL` and `GRAMFE_FFT` schem - **Dependence on FFT Performance**: The efficiency of the scheme is closely tied to the performance of the FFT algorithm used. ### Conclusion -- **Choice of Scheme**: By default `GRAMFE_MATMUL` should be used. `GRAMFE_FFT` should be considered for larger patch sizes and debugging. +- **Choice of Scheme**: By default `MATMUL` should be used. `FFT` should be considered for larger patch sizes and debugging. ## Performance Metrics -- The performance ratio `Perf_FD / Perf_Spectral` indicates the efficiency compared to the finite-difference scheme. This varies based on patch size (e.g., 4.3 for `PATCH_SIZE=8` and 2.6 for `PATCH_SIZE=16` for `GRAMFE_FFT`; comparable performance of `GRAMFE_MATMUL` and `WAVE_FD` for `PATCH_SIZE=8`). +- The performance ratio `Perf_FD / Perf_Spectral` indicates the efficiency compared to the finite-difference scheme. This varies based on patch size (e.g., 4.3 for `PATCH_SIZE=8` and 2.6 for `PATCH_SIZE=16` for `FFT`; comparable performance of `MATMUL` and `WAVE_FD` for `PATCH_SIZE=8`). ## Issues and Considerations - **Stability with Single Precision**: Using single precision can lead to instability in the scheme. @@ -119,7 +119,7 @@ Understanding the differences between the `GRAMFE_MATMUL` and `GRAMFE_FFT` schem #### Current Precision and Limitations -The calculation of the evolution matrix in the `GRAMFE_MATMUL` scheme currently requires at least 128-bit precision to maintain an error below single precision. The extension matrix has a high condition number, typically around 10^15 or higher, which necessitates this high precision. +The calculation of the evolution matrix in the `MATMUL` scheme currently requires at least 128-bit precision to maintain an error below single precision. The extension matrix has a high condition number, typically around 10^15 or higher, which necessitates this high precision. #### Proposed Enhancements diff --git a/doc/wiki/Installation-related/Installation:-Option-List.md b/doc/wiki/Installation-related/Installation:-Option-List.md index ed1c0aff93..c86b4eacd0 100644 --- a/doc/wiki/Installation-related/Installation:-Option-List.md +++ b/doc/wiki/Installation-related/Installation:-Option-List.md @@ -46,7 +46,7 @@ disabled). See the "Restriction" of each option carefully. | `--flu_scheme` | `RTVD`, `MHM`, `MHM_RP`, `CTU` | `CTU` | Hydro schemes. `RTVD`: relaxing TVD; `MHM`: MUSCL-Hancock; `MHM_RP`: VL scheme; `CTU`: corner transport upwind | `--mhd` only supports `MHM`, `MHM_RP`, and `CTU`; `--srhd` only supports `MHM` and `MHM_RP`; `--cosmic_ray` only supports `MHM_RP` | `FLU_SCHEME` | | `--slope` | `PLM`, `PPM` | `PPM` | Spatial reconstruction. `PLM`: piecewise linear; `PPM`: piecewise parabolic | Useless for `--flu_scheme=RTVD` | `LR_SCHEME` | | `--flux` | `EXACT`, `ROE`, `HLLE`, `HLLC`, `HLLD` | Depend | Riemann solvers | Useless for `--flu_scheme=RTVD`; `EXACT` is experimental; pure hydrodynamics supports `EXACT/ROE/HLLE/HLLC`; `--mhd` supports `ROE/HLLE/HLLD`; `--srhd` and `--cosmic_ray` support `HLLE/HLLC` | `RSOLVER` | -| `--dual` | `OFF`, `DE_ENPY`, `DE_EINT` | `OFF` | Enable dual energy formalism | Not supported for `--flu_scheme=RTVD`. `DE_EINT` is not supported yet. | `DUAL_ENERGY` | +| `--dual` | `OFF`, `ENPY`, `EINT` | `OFF` | Enable dual energy formalism | Not supported for `--flu_scheme=RTVD`. `EINT` is not supported yet. | `DUAL_ENERGY` | | `--mhd` | `true`, `false` | `false` | Magnetohydrodynamics | - | `MHD` | | `--srhd` | `true`, `false` | `false` | Special relativistic hydrodynamics | Must adopt `--eos=TAUBMATHEWS` | `SRHD` | | `--cosmic_ray` | `true`, `false` | `false` | Cosmic rays | Must adopt `--eos=COSMIC_RAY` | `COSMIC_RAY` | @@ -58,13 +58,13 @@ disabled). See the "Restriction" of each option carefully. |                               
Option
                               |           
Value
           |           
Default
           |                                                   
Description
                                                   |                                                   
Restriction
                                                   | Corresponding symbolic constant | |:---:|:---:|:---:|---|---|---| -| `--elbdm_scheme` | `ELBDM_WAVE`, `ELBDM_HYBRID` | `ELBDM_WAVE` | ELBDM schemes. `ELBDM_WAVE`: wave-only; `ELBDM_HYBRID`: fluid-wave hybrid scheme | - | `ELBDM_SCHEME` | -| `--wave_scheme` | `WAVE_FD`, `WAVE_GRAMFE` | `WAVE_FD` | Wave schemes. `WAVE_FD`: finite difference; `WAVE_GRAMFE`: local pseudospectral method based on Fourier continuations with Gram polynomials (hereafter also referred to as the Gram-Fourier extension method; GramFE) | Must set `--model=ELBDM` | `WAVE_SCHEME` | -| `--conserve_mass` | `true`, `false` | `true` | Enforce mass conservation | - | `CONSERVE_MASS` | -| `--laplacian_four` | `true`, `false` | Depend | Adopt the fourth-order Laplacian for `--wave_scheme=WAVE_FD` | Must set `--wave_scheme=WAVE_FD` | `LAPLACIAN_4TH` | -| `--gramfe_scheme` | `GRAMFE_MATMUL`, `GRAMFE_FFT` | `GRAMFE_MATMUL` | GramFE schemes. `GRAMFE_MATMUL`: matrix-multiplication approach, which is faster for `--patch_size=8`; `GRAMFE_FFT`: FFT approach, which is faster for larger patch sizes | Must adopt `--wave_scheme=WAVE_GRAMFE`. Must set `--fftw` when using both `--gramfe_scheme=GRAMFE_FFT` and `--gpu=false` | `GRAMFE_SCHEME` | -| `--hybrid_scheme` | `HYBRID_UPWIND`, `HYBRID_FROMM`, `HYBRID_MUSCL` | `HYBRID_MUSCL` | Fluid schemes supported by the fluid-wave hybrid algorithm. `HYBRID_UPWIND`: first-order, diffusive; `HYBRID_FORMM`: second-order, no limiter, unstable for fluid-only simulations; `HYBRID_MUSCL`: second-order, with limiter, useful for zoom-in and fluid-only simulations | Must adopt `--elbdm_scheme=ELBDM_HYBRID` | `HYBRID_SCHEME` | -| `--self_interaction` | `true`, `false` | `false` | Include the quartic self-interaction potential | Must enable `--gravity`. Does not support `--comoving` | `QUARTIC_SELF_INTERACTION` | +| `--elbdm_scheme` | `WAVE`, `HYBRID` | `WAVE` | ELBDM schemes. `WAVE`: wave-only; `HYBRID`: fluid-wave hybrid scheme | - | `ELBDM_SCHEME` | +| `--wave_scheme` | `FD`, `GRAMFE` | `FD` | Wave schemes. `FD`: finite difference; `GRAMFE`: local pseudospectral method based on Fourier continuations with Gram polynomials (hereafter also referred to as the Gram-Fourier extension method; GramFE) | Must set `--model=ELBDM` | `WAVE_SCHEME` | +| `--conserve_mass` | `true`, `false` | `true` | Enforce mass conservation | - | `CONSERVE_MASS` | +| `--laplacian_four` | `true`, `false` | Depend | Adopt the fourth-order Laplacian for `--wave_scheme=FD` | Must set `--wave_scheme=FD` | `LAPLACIAN_4TH` | +| `--gramfe_scheme` | `MATMUL`, `FFT` | `MATMUL` | GramFE schemes. `MATMUL`: matrix-multiplication approach, which is faster for `--patch_size=8`; `FFT`: FFT approach, which is faster for larger patch sizes | Must adopt `--wave_scheme=GRAMFE`. Must set `--fftw` when using both `--gramfe_scheme=FFT` and `--gpu=false` | `GRAMFE_SCHEME` | +| `--hybrid_scheme` | `UPWIND`, `FROMM`, `MUSCL` | `MUSCL` | Fluid schemes supported by the fluid-wave hybrid algorithm. `UPWIND`: first-order, diffusive; `FORMM`: second-order, no limiter, unstable for fluid-only simulations; `MUSCL`: second-order, with limiter, useful for zoom-in and fluid-only simulations | Must adopt `--elbdm_scheme=ELBDM_HYBRID` | `HYBRID_SCHEME` | +| `--self_interaction` | `true`, `false` | `false` | Include the quartic self-interaction potential | Must enable `--gravity`. Does not support `--comoving` | `QUARTIC_SELF_INTERACTION` | ## Gravity Options -- see [[Gravity]] for the related runtime parameters and other settings; must enable `--gravity=true` From 728fc279c091b29e8f35aed16b256e62c14c3f31 Mon Sep 17 00:00:00 2001 From: ChunYen-Chen Date: Tue, 4 Feb 2025 17:09:55 +0800 Subject: [PATCH 25/29] Update generate_make.sh --- .../ELBDM/Perturbation/generate_make_BaseSpectral.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/example/test_problem/ELBDM/Perturbation/generate_make_BaseSpectral.sh b/example/test_problem/ELBDM/Perturbation/generate_make_BaseSpectral.sh index 18f8a3ea65..0714375ee5 100644 --- a/example/test_problem/ELBDM/Perturbation/generate_make_BaseSpectral.sh +++ b/example/test_problem/ELBDM/Perturbation/generate_make_BaseSpectral.sh @@ -3,5 +3,5 @@ PYTHON=python3 ${PYTHON} configure.py --mpi=true --hdf5=true --fftw=FFTW3 \ - --model=ELBDM --elbdm_scheme=ELBDM_WAVE \ - --gravity=true --comoving=false \ No newline at end of file + --model=ELBDM --elbdm_scheme=WAVE \ + --gravity=true --comoving=false From 2fd68534e805a39c7cb2812bf96b899d4d18629c Mon Sep 17 00:00:00 2001 From: ChunYen-Chen Date: Tue, 4 Feb 2025 17:21:04 +0800 Subject: [PATCH 26/29] Move the script --- tool/{bash => config}/config_autocomplete.sh | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename tool/{bash => config}/config_autocomplete.sh (100%) diff --git a/tool/bash/config_autocomplete.sh b/tool/config/config_autocomplete.sh similarity index 100% rename from tool/bash/config_autocomplete.sh rename to tool/config/config_autocomplete.sh From 3b3d51a66842fb083c7f0d77ed02a1303da2e6ef Mon Sep 17 00:00:00 2001 From: ChunYen-Chen Date: Tue, 4 Feb 2025 17:21:21 +0800 Subject: [PATCH 27/29] Update wiki --- doc/wiki/Installation.md | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/doc/wiki/Installation.md b/doc/wiki/Installation.md index e50ab4dd90..22e9250629 100644 --- a/doc/wiki/Installation.md +++ b/doc/wiki/Installation.md @@ -84,17 +84,19 @@ violating the usage policy. - 2. Copy the autocomplete shell script to your `/home/usr` (`~`) + 2. Copy the autocomplete shell script to `${HOME}/.config/gamer` (`~/.config/gamer/`) ```bash - cp tool/bash/config_autocomplete.sh ~/ + mkdir -p ~/.config/gamer + cp tool/config/config_autocomplete.sh ~/.config/gamer/ ``` 3. Update `~/.bashrc` to load the autocomplete script Please add the following line to `~/.bashrc`: ```bash - source ~/config_autocomplete.sh + source ~/.config/gamer/config_autocomplete.sh ``` + > [!NOTE] > The `config_autocomplete.sh` script registers autocomplete for three commands: `python`, `python3`, and `./configure.py.`. If you want to add more commands, simply append them at the bottom of the script. @@ -104,4 +106,4 @@ If you want to add more commands, simply append them at the bottom of the script source ~/.bashrc ``` - Now, try to type `./configure.py` and then press `` multiple times! \ No newline at end of file + Now, try to type `./configure.py` and then press `` multiple times! From 96fe21982dff319de60dc2e1ae2fd4b141222196 Mon Sep 17 00:00:00 2001 From: ChunYen-Chen Date: Tue, 4 Feb 2025 17:27:31 +0800 Subject: [PATCH 28/29] Update wiki --- doc/wiki/ELBDM-related/ELBDM-Spectral-Solver.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/doc/wiki/ELBDM-related/ELBDM-Spectral-Solver.md b/doc/wiki/ELBDM-related/ELBDM-Spectral-Solver.md index a9cdf5cdfb..274eb5e659 100644 --- a/doc/wiki/ELBDM-related/ELBDM-Spectral-Solver.md +++ b/doc/wiki/ELBDM-related/ELBDM-Spectral-Solver.md @@ -3,7 +3,7 @@ ## Setup and Configuration ### Compilation Options -- **Wave Scheme Selection**: To enable the spectral solver, set `WAVE_SCHEME` to `WAVE_GRAMFE` in the Makefile or configure with `--wave_scheme=WAVE_GRAMFE` for the ELBDM model. +- **Wave Scheme Selection**: To enable the spectral solver, set `WAVE_SCHEME` to `WAVE_GRAMFE` in the Makefile or configure with `--wave_scheme=GRAMFE` for the ELBDM model. - **Spectral Scheme Options**: Choose between `MATMUL` (faster for `PATCH_SIZE=8`) and `FFT` (faster for larger patch sizes) by setting `SCHEME` in the Makefile or configure with `--gramfe_scheme` accordingly. - **Additional Libraries**: The CPU version requires FFTW 3 for single precision and FFTW 2/3 for double precision. The GPU version of `FFT` needs the cuFFTDx library. Set `FFTW2_PATH`, `FFTW3_PATH`, and `CUFFTDX_PATH` in the Makefile or configuration files `*.config`. @@ -103,7 +103,7 @@ Understanding the differences between the `MATMUL` and `FFT` schemes in GAMER is - **Choice of Scheme**: By default `MATMUL` should be used. `FFT` should be considered for larger patch sizes and debugging. ## Performance Metrics -- The performance ratio `Perf_FD / Perf_Spectral` indicates the efficiency compared to the finite-difference scheme. This varies based on patch size (e.g., 4.3 for `PATCH_SIZE=8` and 2.6 for `PATCH_SIZE=16` for `FFT`; comparable performance of `MATMUL` and `WAVE_FD` for `PATCH_SIZE=8`). +- The performance ratio `Perf_FD / Perf_Spectral` indicates the efficiency compared to the finite-difference scheme. This varies based on patch size (e.g., 4.3 for `PATCH_SIZE=8` and 2.6 for `PATCH_SIZE=16` for `FFT`; comparable performance of `MATMUL` and `FD` for `PATCH_SIZE=8`). ## Issues and Considerations - **Stability with Single Precision**: Using single precision can lead to instability in the scheme. From b324df09edb8e9693dad32f2f8e1f1cd2af8e0fb Mon Sep 17 00:00:00 2001 From: ChunYen-Chen Date: Tue, 4 Feb 2025 17:41:54 +0800 Subject: [PATCH 29/29] Minor --- src/configure.py | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/configure.py b/src/configure.py index 6321ad6729..a48495d63c 100755 --- a/src/configure.py +++ b/src/configure.py @@ -574,7 +574,7 @@ def load_arguments( sys_setting : SystemSetting ): depend={"model":"ELBDM", "wave_scheme":"GRAMFE"}, constraint={ "MATMUL":{"gsl":True} }, help="GramFE scheme for <--wave_scheme=GRAMFE> "\ - "(MATMUL: faster for PATCH_SIZE=8, FFT: faster for larger patch sizes).\n" + "(MATMUL: faster for <--patch_size=8>, FFT: faster for larger patch sizes).\n" ) parser.add_argument( "--hybrid_scheme", type=str, metavar="TYPE", gamer_name="HYBRID_SCHEME", prefix="HYBRID_", @@ -1177,13 +1177,17 @@ def warning( paths, **kwargs ): makefile = make_base.read() # 6.2 Replace - LOGGER.info("----------------------------------------") - for key, val in paths.items(): - LOGGER.info("%-25s : %s"%(key, val)) + verbose_mode = "1" if args["verbose_make"] else "0" + makefile, num = re.subn(r"@@@COMPILE_VERBOSE@@@", verbose_mode, makefile) + if num == 0: raise BaseException("The string @@@COMPILE_VERBOSE@@@ is not replaced correctly.") + + for key, val in sims.items(): makefile, num = re.subn(r"@@@%s@@@"%(key), val, makefile) if num == 0: raise BaseException("The string @@@%s@@@ is not replaced correctly."%key) - for key, val in sims.items(): + LOGGER.info("----------------------------------------") + for key, val in paths.items(): + LOGGER.info("%-25s : %s"%(key, val)) makefile, num = re.subn(r"@@@%s@@@"%(key), val, makefile) if num == 0: raise BaseException("The string @@@%s@@@ is not replaced correctly."%key) @@ -1199,10 +1203,6 @@ def warning( paths, **kwargs ): makefile, num = re.subn(r"@@@%s@@@"%(key), val, makefile) if num == 0: raise BaseException("The string @@@%s@@@ is not replaced correctly."%key) - verbose_mode = "1" if args["verbose_make"] else "0" - makefile, num = re.subn(r"@@@COMPILE_VERBOSE@@@", verbose_mode, makefile) - if num == 0: raise BaseException("The string @@@COMPILE_VERBOSE@@@ is not replaced correctly.") - LOGGER.info("----------------------------------------") for key in re.findall(r"@@@(.+?)@@@", makefile): makefile, num = re.subn(r"@@@%s@@@"%key, "", makefile)