Skip to content

Commit b615801

Browse files
Add warning if jsbeutifier not installed, set default for h5 in inference, fix import (#237)
Co-authored-by: Mohammad Amin Nabian <[email protected]>
1 parent 4028d0c commit b615801

File tree

3 files changed

+23
-5
lines changed

3 files changed

+23
-5
lines changed

modulus/experimental/sfno/inference.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
parser.add_argument("--cuda_graph_mode", default='none', type=str, choices=["none", "fwdbwd", "step"], help="Specify which parts to capture under cuda graph")
4646
parser.add_argument("--enable_benchy", action='store_true')
4747
parser.add_argument("--disable_ddp", action='store_true')
48+
parser.add_argument("--enable_odirect", action='store_true')
4849
parser.add_argument("--enable_nhwc", action='store_true')
4950
parser.add_argument("--checkpointing_level", default=0, type=int, help="How aggressively checkpointing is used")
5051
parser.add_argument("--epsilon_factor", default = 0, type = float)
@@ -58,6 +59,11 @@
5859
# parse
5960
args = parser.parse_args()
6061

62+
# check whether the right h5py package is installed
63+
odirect_env_var_name = "ENABLE_H5PY_ODIRECT"
64+
if args.enable_odirect and os.environ.get(odirect_env_var_name, "False").lower() != "true":
65+
raise RuntimeError(f"Error, {odirect_env_var_name} h5py with MPI support is not installed. Please refer to README for instructions on how to install it.")
66+
6167
# parse parameters
6268
params = YParams(os.path.abspath(args.yaml_config), args.config)
6369
params['epsilon_factor'] = args.epsilon_factor
@@ -122,6 +128,7 @@
122128
params['cuda_graph_mode'] = args.cuda_graph_mode
123129
params['enable_benchy'] = args.enable_benchy
124130
params['disable_ddp'] = args.disable_ddp
131+
params['enable_odirect'] = args.enable_odirect
125132
params['enable_nhwc'] = args.enable_nhwc
126133
params['checkpointing'] = args.checkpointing_level
127134
params['enable_synthetic_data'] = args.enable_synthetic_data

modulus/experimental/sfno/networks/model_package.py

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,14 @@
2929

3030
import logging
3131

32+
import warnings
33+
3234
try:
3335
import jsbeautifier
36+
use_jsbeautifier = True
3437
except ImportError:
35-
raise ImportError('jsbeautifier is not installed. Please install it with "pip install jsbeautifier"')
38+
warnings.warn('jsbeautifier is not installed. Please install it with "pip install jsbeautifier"')
39+
use_jsbeautifier = False
3640

3741
class LocalPackage:
3842
"""
@@ -101,11 +105,15 @@ def save_model_package(params):
101105
"""
102106
# save out the current state of the parameters, make it human readable
103107
config_path = os.path.join(params.experiment_dir, "config.json")
104-
jsopts = jsbeautifier.default_options()
105-
jsopts.indent_size = 2
108+
109+
msg = json.dumps(params.to_dict())
110+
if use_jsbeautifier:
111+
jsopts = jsbeautifier.default_options()
112+
jsopts.indent_size = 2
113+
114+
msg = jsbeautifier.beautify(msg, jsopts)
106115

107116
with open(config_path, "w") as f:
108-
msg = jsbeautifier.beautify(json.dumps(params.to_dict()), jsopts)
109117
f.write(msg)
110118

111119
if hasattr(params, "add_orography") and params.add_orography:
@@ -131,7 +139,9 @@ def save_model_package(params):
131139
"entrypoint": {"name": "networks.model_package:load_time_loop"},
132140
}
133141
with open(os.path.join(params.experiment_dir, "metadata.json"), "w") as f:
134-
msg = jsbeautifier.beautify(json.dumps(fcn_mip_data), jsopts)
142+
msg = json.dumps(fcn_mip_data)
143+
if use_jsbeautifier:
144+
msg = jsbeautifier.beautify(msg, jsopts)
135145
f.write(msg)
136146

137147

modulus/experimental/sfno/utils/visualize.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
import io
1616
import numpy as np
17+
import os
1718
import concurrent.futures as cf
1819
from PIL import Image
1920
from moviepy.editor import ImageSequenceClip

0 commit comments

Comments
 (0)