Skip to content

Commit

Permalink
Assorted changes to MethodGrackle
Browse files Browse the repository at this point in the history
This commit consists of 3 main changesets that:

1. update the reference results for the single precision test

2. addressed some deprecation notices in tools/field_summary.py for modern versions of yt (while maintaining backwards compatability)
   - when passing a field to yt, we now a tuple including the fluid type (previously we just passed a single string, which caused some confusion)
   - the script now has yt compute the "weighted_standard_deviation" quantity instead of the "weighted_variance" quantity, when possible. In older versions of yt it falls back to having yt compute the "weighted_variance" quantity (which was incorrectly named - it always returned the weighted standard deviation).

3. tweaked the commands related to running the general_grackle test. Now the report is printed to stdout to make it obvious whether there where issues and exactly what they are
  • Loading branch information
mabruzzo committed Mar 12, 2022
1 parent 579b742 commit 0fd58a0
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 48 deletions.
30 changes: 19 additions & 11 deletions test/MethodGrackle/SConscript
Original file line number Diff line number Diff line change
Expand Up @@ -34,24 +34,32 @@ if grackle_data_dir != '' and use_grackle:
_script_path = os.path.abspath(
os.path.join(os.getcwd(), '../../tools/gen_grackle_testing_file.py')
)
_cmd_template = ("python {_script_path} $SOURCE "
"-d {grackle_data_dir}/CloudyData_UVB=HM2012_shielded.h5 "
"--use-abs-paths -o $TARGET")
make_grackle_input = Builder(
action = _cmd_template.format(_script_path = _script_path,
grackle_data_dir = grackle_data_dir)
)
_cmd = (
"python {_script_path} $SOURCE "
" -d {grackle_data_dir}/CloudyData_UVB=HM2012_shielded.h5 "
" --use-abs-paths "
" -o $TARGET"
).format(_script_path = _script_path, grackle_data_dir = grackle_data_dir)
make_grackle_input = Builder(action = _cmd)


# now prepare the builder that executes tools/field_summary.py (the script
# actually performs the test)
_script_path = os.path.abspath(
os.path.join(os.getcwd(), '../../tools/field_summary.py')
)
_cmd = ("python {_script_path} cmp $SOURCE --ref $REF_TABLE "
"--report $TARGET --rtol $RTOL --atol $ATOL "
"> $LOG_FILE").format(_script_path = _script_path)
compare_field_summary = Builder(action = _cmd)
_cmd = (
"rm --force $TARGET; "
"python {_script_path} cmp $SOURCE "
" --ref $REF_TABLE "
" --report $TARGET "
" --rtol $RTOL --atol $ATOL "
" > $LOG_FILE"
).format(_script_path = _script_path)

compare_field_summary = Builder(
action = _cmd + "; awk '{ print \" \", $0 }' $TARGET"
)

# now add these builders to the environment and clone the environment
env.Append(BUILDERS = {'MakeGrackleInput' : make_grackle_input,
Expand Down
2 changes: 1 addition & 1 deletion test/MethodGrackle/ref_general_grackle-double.csv
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# {"code unit definitions": {"code_length": [3.086e+16, "cm"], "code_mass": [4.9157019637146824e+25, "g"], "code_density": [1.6726219e-24, "g/cm**3"], "code_specific_energy": [956277.4378779504, "erg/g"], "code_time": [31557600000000.0, "s"], "code_magnetic": [4.483279099741026e-09, "G"], "code_temperature": [1.0, "K"], "code_pressure": [1.5994905850705492e-18, "dyn/cm**2"], "code_velocity": [977.8943899409335, "cm/s"], "code_metallicity": [1.0, "dimensionless"]}, "field units": {"pressure": "dimensionless", "temperature": "code_temperature", "cooling_time": "dimensionless"}}
#
# name,min,min_xloc,min_yloc,min_zloc,max,max_xloc,max_yloc,max_zloc,mean,variance
# name,min,min_xloc,min_yloc,min_zloc,max,max_xloc,max_yloc,max_zloc,mean,standard_deviation
pressure,1.520195901060065e+02,7.812500000000000e-02,1.718750000000000e-01,1.562500000000000e-02,2.753947492701502e+06,7.812500000000000e-02,2.343750000000000e-01,1.562500000000000e-02,6.675724774669249e+04,3.557197556605695e+05
temperature,3.549497639185964e+00,2.343750000000000e-01,1.718750000000000e-01,1.562500000000000e-02,6.376232820587005e+06,1.562500000000000e-02,2.343750000000000e-01,1.562500000000000e-02,2.417771901546382e+05,1.115430124658054e+06
cooling_time,-6.450617403727277e+04,1.562500000000000e-02,2.343750000000000e-01,1.562500000000000e-02,3.866436169424824e+03,1.093750000000000e-01,1.093750000000000e-01,1.562500000000000e-02,-1.578969463027807e+03,8.485129947191494e+03
8 changes: 4 additions & 4 deletions test/MethodGrackle/ref_general_grackle-single.csv
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# {"code unit definitions": {"code_length": [3.086e+16, "cm"], "code_mass": [4.9157019637146824e+25, "g"], "code_density": [1.6726219e-24, "g/cm**3"], "code_specific_energy": [956277.4378779504, "erg/g"], "code_time": [31557600000000.0, "s"], "code_magnetic": [4.483279099741026e-09, "G"], "code_temperature": [1.0, "K"], "code_pressure": [1.5994905850705492e-18, "dyn/cm**2"], "code_velocity": [977.8943899409335, "cm/s"], "code_metallicity": [1.0, "dimensionless"]}, "field units": {"pressure": "dimensionless", "temperature": "code_temperature", "cooling_time": "dimensionless"}}
#
# name,min,min_xloc,min_yloc,min_zloc,max,max_xloc,max_yloc,max_zloc,mean,variance
pressure,1.415744883541061e+02,7.812500000000000e-02,2.031250000000000e-01,1.562500000000000e-02,2.754013931249404e+06,7.812500000000000e-02,2.343750000000000e-01,1.562500000000000e-02,6.630586095298077e+04,3.557600421338977e+05
temperature,3.165577650070190e+00,2.343750000000000e-01,2.031250000000000e-01,1.562500000000000e-02,6.376238000000000e+06,1.562500000000000e-02,2.343750000000000e-01,1.562500000000000e-02,2.417755864369683e+05,1.115433533961514e+06
cooling_time,-6.450620312500000e+04,1.562500000000000e-02,2.343750000000000e-01,1.562500000000000e-02,1.856560791015625e+03,4.687500000000000e-02,7.812500000000000e-02,1.562500000000000e-02,-1.275470950921066e+03,8.076624362662475e+03
# name,min,min_xloc,min_yloc,min_zloc,max,max_xloc,max_yloc,max_zloc,mean,standard_deviation
pressure,1.448596228495553e+02,7.812500000000000e-02,2.031250000000000e-01,1.562500000000000e-02,2.754013931249404e+06,7.812500000000000e-02,2.343750000000000e-01,1.562500000000000e-02,6.668474451175868e+04,3.557327613678277e+05
temperature,3.444945335388184e+00,2.343750000000000e-01,2.031250000000000e-01,1.562500000000000e-02,6.376238000000000e+06,1.562500000000000e-02,2.343750000000000e-01,1.562500000000000e-02,2.417772680167406e+05,1.115433169502840e+06
cooling_time,-6.450619921875000e+04,1.562500000000000e-02,2.343750000000000e-01,1.562500000000000e-02,1.856555786132812e+03,4.687500000000000e-02,7.812500000000000e-02,1.562500000000000e-02,-1.300657236445695e+03,8.072030883837461e+03
48 changes: 16 additions & 32 deletions tools/field_summary.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@
from l1_error_norm import StoreCommaListAction
from test_report import create_test_report, create_dummy_report

if 'enzo_p' in yt.frontends.__dict__.keys():
_ENZOE_FLUID_TYPE = 'enzop' # for older versions of yt
else:
_ENZOE_FLUID_TYPE = 'enzoe'

_TABLE_DTYPE_ARGS = [
('name', object),
('min', 'f8'),
Expand All @@ -19,7 +24,7 @@
('max_yloc', 'f8'),
('max_zloc', 'f8'),
('mean', 'f8'),
('variance', 'f8')
('standard_deviation', 'f8')
]

_FIXED_COL_UNITS = dict((col, 'code_length') for col,_ in _TABLE_DTYPE_ARGS \
Expand All @@ -29,7 +34,7 @@
_QUANTITY_ENTRY_SETS = [
('min_location', ('min', 'min_xloc', 'min_yloc', 'min_zloc'), {}),
('max_location', ('max', 'max_xloc', 'max_yloc', 'max_zloc'), {}),
('weighted_variance', ('variance', 'mean'),
('weighted_standard_deviation', ('standard_deviation', 'mean'),
{'weight' : ("gas", "cell_volume")}),
]

Expand All @@ -54,17 +59,11 @@ def _get_sim_props(ds, field_names):
code_unit_defs[unit] = [float(converted.v), str(converted.units)]

# determine the default units of each field
fluid_type = None
for elem in ds.fluid_types:
if elem in ['enzoe','enzop']:
assert fluid_type is None
fluid_type = elem
assert fluid_type is not None

ds.field_list # this is necessary for initializing ds.field_info
field_units = {}
for field in field_names:
dflt_units = ds.field_info[(fluid_type,field)].units
dflt_units = ds.field_info[_ENZOE_FLUID_TYPE,field].units
# it may not be necessary to complete the following line
converted = str(ds.quan(1.0, dflt_units).in_base('code').units)
field_units[field] = converted
Expand All @@ -88,9 +87,16 @@ def measure_field_summary(target_path, field_names):
assert colname not in computed_cols # sanity check
computed_cols.add(colname)

if ((derived_quantity == 'weighted_standard_deviation') and
(not hasattr(ad.quantities, derived_quantity))):
# in older versions of yt, this quantity was mis-named (it still
# computes that weighted standard deviation)
derived_quantity = 'weighted_variance'

func = getattr(ad.quantities,derived_quantity)
for row_ind, field_name in enumerate(field_names):
rslt = func(field_name, **kwargs)
full_field_name = (_ENZOE_FLUID_TYPE, field_name)
rslt = func(full_field_name, **kwargs)
for i,val in enumerate(rslt):
colname = colnames[i]
if colnames in _FIXED_COL_UNITS:
Expand Down Expand Up @@ -336,25 +342,3 @@ def _add_target_path_arg(parser):
args = parser.parse_args()
main_func = args.func
main_func(args)

"""
#print(colnames)
old_field_table = measure_field_summary(
'./GRACKLE_TEST_000/GRACKLE_TEST_000.block_list', field_names
)
print("Constructing Field Summary Table:")
field_table = measure_field_summary(
'./GRACKLE_TEST_010/GRACKLE_TEST_010.block_list', field_names
)
print(old_field_table == field_table)
#print(field_table)
#print(field_table['min','max'])
print("Comparing Field Summary Table:")
with create_test_report('my_report.unit', clobber = True) as tr:
test_rslt = test_equivalent_field_tables(old_field_table,field_table,
atol = 1e-15, rtol = 1e-14,
test_report = tr)
"""

0 comments on commit 0fd58a0

Please sign in to comment.