Skip to content

Commit

Permalink
Fix all NRPy+ modules to use sys.exit() instead of exit()
Browse files Browse the repository at this point in the history
  • Loading branch information
zachetienne committed Jul 17, 2019
1 parent b34924b commit 5b81c17
Show file tree
Hide file tree
Showing 14 changed files with 79 additions and 116 deletions.
5 changes: 0 additions & 5 deletions MoLtimestepping/RK_Allocate_Memory.h

This file was deleted.

5 changes: 0 additions & 5 deletions MoLtimestepping/RK_Free_Memory.h

This file was deleted.

36 changes: 0 additions & 36 deletions MoLtimestepping/RK_MoL.h

This file was deleted.

25 changes: 13 additions & 12 deletions NRPy_param_funcs.py
Expand Up @@ -3,6 +3,7 @@
from collections import namedtuple
glb_param = namedtuple('glb_param', 'type module parname defaultval')
import sympy as sp
import sys

def initialize_param(input):
if get_params_idx(input) == -1:
Expand All @@ -25,15 +26,15 @@ def get_params_idx(input):
else:
if len(list) > 1:
print("Error: Found multiple parameters matching "+str(input))
exit(1)
sys.exit(1)
return list.pop() # pop() returns the index

def get_params_value(input):
idx = get_params_idx(input)
if idx < 0:
print("Error: could not find a parameter matching:",input)
print("Full list of modules:\n",glb_params_list)
exit(1)
sys.exit(1)
else:
return glb_paramsvals_list[idx]

Expand All @@ -51,10 +52,10 @@ def idx_from_str(varname,modname=""):
list = [i for i, v in enumerate(glb_params_list) if (v[1] == modname and v[2] == varname)]
if list == []:
print("Error: Could not find a parameter matching \""+varname+"\" in ",glb_params_list)
exit(1)
sys.exit(1)
if len(list) > 1:
print("Error: Found more than one parameter named \""+varname+"\". Use get_params_value() instead.")
exit(1)
sys.exit(1)
return list.pop()

def parval_from_str(string):
Expand Down Expand Up @@ -99,7 +100,7 @@ def set_paramsvals_value(line,filename="", FindMainModuleMode=False):
else:
print("Error: the command-line argument " + stripped_line_of_text + " is not in the form")
print("\"module::variable=value\" <-- NOTICE NO SPACES ALLOWED!")
exit(1)
sys.exit(1)

# Next remove all leading/trailing whitespace from single_param_def
for i in range(len(single_param_def)):
Expand All @@ -116,7 +117,7 @@ def set_paramsvals_value(line,filename="", FindMainModuleMode=False):
else:
print("Error: when parsing command-line argument \"" + stripped_line_of_text + "\":")
print("\t\tcould not find parameter \""+ single_param_def[1] + "\" in \""+single_param_def[0]+"\" module.")
exit(1)
sys.exit(1)
# If parameter is found at index idx, set paramsval[idx] to the value specified in the file.
if glb_params_list[idx].defaultval != "RUNTIME":
partype = glb_params_list[idx].type
Expand All @@ -127,7 +128,7 @@ def set_paramsvals_value(line,filename="", FindMainModuleMode=False):
glb_paramsvals_list[idx] = False
else:
print("Error: \"bool\" type can only take values of \"True\" or \"False\"")
exit(1)
sys.exit(1)
elif partype == "INT":
glb_paramsvals_list[idx] = int(single_param_def[2])
elif partype == "REAL" or \
Expand All @@ -138,21 +139,21 @@ def set_paramsvals_value(line,filename="", FindMainModuleMode=False):
else:
print("Error: type \""+partype+"\" on variable \""+ glb_params_list[idx].parname +"\" is unsupported.")
print("Supported types include: bool, INT, REAL, REALARRAY, char, and char *")
exit(1)
sys.exit(1)
# glb_paramsvals_list[idx] = single_param_def[2]
else:
print("Error: Tried to set the parameter "
+ single_param_def[0] + "::" + single_param_def[1] +
" with default value RUNTIME")
print("Such a parameter is defined by NRPy+, but must be "
"set at C code runtime. Go fix your C code parameter file!")
exit(1)
sys.exit(1)
elif FindMainModuleMode == True and MainModuleFound == False:
if single_param_def[0] == "NRPy" and single_param_def[1] == "MainModule":
idx = get_params_idx(glb_param("ignoretype", single_param_def[0], single_param_def[1], "ignoredefval"))
if idx == -1:
print("Critical error: NRPy::MainModule is uninitialized!")
exit(1)
sys.exit(1)
glb_paramsvals_list[idx] = single_param_def[2]

def Cparameters(type,module,names,assumption="Real"):
Expand All @@ -169,7 +170,7 @@ def Cparameters(type,module,names,assumption="Real"):
tmp = sp.Symbol(names[i], real=True, positive=True) # Assumes all Cparameters are real and positive.
else:
print("Error: assumption "+str(assumption)+" not supported.")
exit(1)
sys.exit(1)
output.append(tmp)
if len(names) == 1:
return output[0]
Expand All @@ -185,7 +186,7 @@ def Ccode__declare_params(filename):
partype != "REAL":
print("Error: parameter "+glb_params_list[i].module+"::"+glb_params_list[i].parname+" has unsupported type: \""
+ glb_params_list[i].type + "\"")
exit(1)
sys.exit(1)
if partype == "char":
Ctype = "char *"
else:
Expand Down
7 changes: 4 additions & 3 deletions SIMD.py
@@ -1,6 +1,7 @@
from sympy import Integer,Symbol,symbols,simplify,Rational,sign,Function,srepr,sin,cos,exp,log,Abs,Add,Mul,Pow,preorder_traversal,N,Float,S,var,sympify
import NRPy_param_funcs as par
import re
import sys

# For debugging purposes, Part 1:
# Basic arithmetic operations
Expand Down Expand Up @@ -269,7 +270,7 @@ def expr_convert_to_SIMD_intrins(expr, SIMD_const_varnms,SIMD_const_values,debu
# E.g., doesn't make sense to have -1/-3. SymPy should have simplified this.
print("Found a weird Rational(a,b) expression, where a<0 and b<0. Report to SymPy devels")
print("Specifically, found that a="+str(item.args[0])+" and b="+str(item.args[1]))
exit(1)
sys.exit(1)
# Set variable value, to 34 digits of precision
SIMD_const_values.extend([str(N(Float(item.args[0],34)/Float(item.args[1],34),34))])
elif item.func == IntegerTMP:
Expand All @@ -293,7 +294,7 @@ def expr_convert_to_SIMD_intrins(expr, SIMD_const_varnms,SIMD_const_values,debu
# E.g., doesn't make sense to have -1/-3. SymPy should have simplified this.
print("Found a weird Rational(a,b) expression, where a<0 and b<0. Report to SymPy devels")
print("Specifically, found that a=" + str(item.args[0]) + " and b=" + str(item.args[1]))
exit(1)
sys.exit(1)
elif item.func == IntegerTMP:
if item.args[0] < 0:
tempitem = var("_Integer_m" + str(-item.args[0]))
Expand All @@ -306,7 +307,7 @@ def lookup_name_output_idx(name, list_of_names):
if list_of_names[i] == name:
return i
print("I SHOULDN'T BE HERE!",name,list_of_names)
exit(1)
sys.exit(1)

if debug=="True":
expr_check = expr
Expand Down
10 changes: 5 additions & 5 deletions Tutorial-Coutput__Parameter_Interface.ipynb
Expand Up @@ -490,21 +490,21 @@
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"display_name": "Python 2",
"language": "python",
"name": "python3"
"name": "python2"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
"version": 2
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.6.7"
"pygments_lexer": "ipython2",
"version": "2.7.13"
}
},
"nbformat": 4,
Expand Down
16 changes: 8 additions & 8 deletions Tutorial-Start_to_Finish-BSSNCurvilinear-Two_BHs_Collide.ipynb
Expand Up @@ -228,7 +228,7 @@
"initialize_param() minor warning: Did nothing; already initialized parameter reference_metric::M_SQRT1_2\n",
"initialize_param() minor warning: Did nothing; already initialized parameter reference_metric::RMAX\n",
"Generating C code for BSSN RHSs in Spherical coordinates.\n",
"Finished in 50.1745619774 seconds.\n"
"Finished in 48.8268458843 seconds.\n"
]
}
],
Expand Down Expand Up @@ -314,7 +314,7 @@
"initialize_param() minor warning: Did nothing; already initialized parameter reference_metric::M_SQRT1_2\n",
"initialize_param() minor warning: Did nothing; already initialized parameter reference_metric::RMAX\n",
"Generating optimized C code for Hamiltonian constraint. May take a while, depending on CoordSystem.\n",
"Finished in 11.5362100601 seconds.\n",
"Finished in 12.5775399208 seconds.\n",
"Output C implementation of Hamiltonian constraint to BSSN/Hamiltonian.h\n"
]
}
Expand Down Expand Up @@ -786,14 +786,14 @@
"text": [
"Compiling executable...\n",
"Executing `gcc -Ofast -fopenmp -march=native BSSN/BrillLindquist_Playground.c -o BrillLindquist_Playground -lm`...\n",
"Finished executing in 10.0649590492 seconds.\n",
"Finished executing in 9.47643899918 seconds.\n",
"Finished compilation.\n",
"Executing `taskset -c 0,1 ./BrillLindquist_Playground 72 12 2 1.0`...\n",
"\u001b[2KIt: 550 t=7.50 dt=1.36e-02 | 100.0%; ETA 0 s | t/h 3997.47 | gp/s 5.63e+05\n",
"Finished executing in 6.91102099419 seconds.\n",
"\u001b[2KIt: 550 t=7.50 dt=1.36e-02 | 100.0%; ETA 0 s | t/h 4322.62 | gp/s 6.09e+05\n",
"Finished executing in 6.46167302132 seconds.\n",
"Executing `taskset -c 0,1 ./BrillLindquist_Playground 96 16 2 1.0`...\n",
"\u001b[2KIt: 970 t=7.44 dt=7.67e-03 | 99.2%; ETA 0 s | t/h 1397.61 | gp/s 6.22e+055\n",
"Finished executing in 19.5423519611 seconds.\n",
"\u001b[2KIt: 970 t=7.44 dt=7.67e-03 | 99.2%; ETA 0 s | t/h 1441.96 | gp/s 6.42e+055\n",
"Finished executing in 18.8283128738 seconds.\n",
"Finished this code cell.\n"
]
}
Expand Down Expand Up @@ -1177,7 +1177,7 @@
"output_type": "stream",
"text": [
"[NbConvertApp] Converting notebook Tutorial-Start_to_Finish-BSSNCurvilinear-Two_BHs_Collide.ipynb to latex\n",
"[NbConvertApp] Writing 107046 bytes to Tutorial-Start_to_Finish-BSSNCurvilinear-Two_BHs_Collide.tex\n",
"[NbConvertApp] Writing 109227 bytes to Tutorial-Start_to_Finish-BSSNCurvilinear-Two_BHs_Collide.tex\n",
"This is pdfTeX, Version 3.14159265-2.6-1.40.18 (TeX Live 2017/Debian) (preloaded format=pdflatex)\n",
" restricted \\write18 enabled.\n",
"entering extended mode\n",
Expand Down
17 changes: 9 additions & 8 deletions finite_difference.py
Expand Up @@ -6,6 +6,7 @@

import grid as gri
import re
import sys
from outputC import *

from operator import itemgetter
Expand Down Expand Up @@ -71,7 +72,7 @@ def FD_outputC(filename,sympyexpr_list, params="", upwindcontrolvec=""):
print("in NRPy+ as either a gridfunction or Cparameter, by calling")
print(str(var)+" = register_gridfunctions...() (in ixp/grid) if \""+str(var)+"\" is a gridfunction, or")
print(str(var)+" = Cparameters() (in par) otherwise (e.g., if it is a free parameter set at C runtime).")
exit(1)
sys.exit(1)
list_of_deriv_vars_with_duplicates.append(var)
# elif vartype == "gridfunction":
# list_of_deriv_vars_with_duplicates.append(var)
Expand Down Expand Up @@ -129,7 +130,7 @@ def FD_outputC(filename,sympyexpr_list, params="", upwindcontrolvec=""):
print("Error: "+varstr+" has "+str(num_UDs)+" U's and D's, but ")
print(str(num_digits)+" integers at the end. These must be equal.")
print("Please rename your gridfunction.")
exit(1)
sys.exit(1)
# Step 2a.2: Based on the variable name, find the rank of
# the underlying gridfunction of which we're
# trying to take the derivative.
Expand Down Expand Up @@ -169,7 +170,7 @@ def FD_outputC(filename,sympyexpr_list, params="", upwindcontrolvec=""):
if not is_gf:
print("Error: Attempting to take the derivative of "+basegf+", which is not a registered gridfunction.")
print(" Make sure your gridfunction name does not have any underscores in it!")
exit(1)
sys.exit(1)

# Step 2c:
# Check each derivative operator to make sure it is
Expand All @@ -181,7 +182,7 @@ def FD_outputC(filename,sympyexpr_list, params="", upwindcontrolvec=""):
found_derivID = True
if not found_derivID:
print("Error: Valid derivative operator in "+deriv__operator[i]+" not found.")
exit(1)
sys.exit(1)

# Step 2d (Upwinded derivatives algorithm, part 1):
# If an upwinding control vector is specified, determine
Expand All @@ -200,7 +201,7 @@ def FD_outputC(filename,sympyexpr_list, params="", upwindcontrolvec=""):
upwind_directions_unsorted_withdups.append(dirn)
else:
print("Error: Derivative operator "+deriv_op+" does not contain a direction")
exit(1)
sys.exit(1)
upwind_directions = []
if len(upwind_directions_unsorted_withdups)>0:
upwind_directions = superfast_uniq(upwind_directions_unsorted_withdups)
Expand Down Expand Up @@ -298,7 +299,7 @@ def unique_idx(idx4):
return str(int(idx4[3])+os + sz*( (int(idx4[2])+os) + sz*( (int(idx4[1])+os) + sz*( int(idx4[0])+os ) ) ))
else:
print("Error: MemAllocStyle = "+par.parval_from_str("MemAllocStyle")+" unsupported.")
exit(1)
sys.exit(1)

# Step 4d.ii: For each gridfunction and
# point read from memory, call unique_idx,
Expand Down Expand Up @@ -463,7 +464,7 @@ def indent_Ccode(Ccode):
exprs[i] *= invdx[dirn1]*invdx[dirn2]
else:
print("Error: was unable to parse derivative operator: ",deriv__operator[i])
exit(1)
sys.exit(1)
# Step 5b.ii: If upwind control vector is specified,
# add upwind control vectors to the
# derivative expression list, so its
Expand Down Expand Up @@ -674,7 +675,7 @@ def compute_fdcoeffs_fdstencl(derivstring,FDORDER=-1):
if "DDD" in derivstring:
print("Error: Only derivatives up to second order currently supported.")
print(" Feel free to contribute to NRPy+ to extend its functionality!")
exit(1)
sys.exit(1)
elif "DD" in derivstring:

if derivstring[len(derivstring)-1] == derivstring[len(derivstring)-2]:
Expand Down

0 comments on commit 5b81c17

Please sign in to comment.