def inference(args, model_xml, model_bin, inputs, outputs): from openvino.inference_engine import IENetwork from openvino.inference_engine import IEPlugin plugin = IEPlugin(device=args.device, plugin_dirs=args.plugin_dir) if args.cpu_extension and 'CPU' in args.device: plugin.add_cpu_extension(args.cpu_extension) log.info('Loading network files:\n\t{}\n\t{}'.format(model_xml, model_bin)) net = IENetwork(model=model_xml, weights=model_bin) if plugin.device == 'CPU': supported_layers = plugin.get_supported_layers(net) not_supported_layers = [ l for l in net.layers.keys() if l not in supported_layers ] if not_supported_layers: log.error('Folowing layers are not supported by the plugin for ' 'specified device {}:\n {}'.format( plugin.device, ', '.join(not_supported_layers))) log.error('Please try to specify cpu extensions library path in ' 'sample\'s command line parameters using ' '--cpu-extension command line argument') sys.exis(1) assert len(net.inputs) == len(inputs) ie_inputs = {} for item in inputs: assert item[0] in set(net.inputs.keys()) ie_inputs[item[0]] = item[1] log.info('Loading model to the plugin') exec_net = plugin.load(network=net) res = exec_net.infer(inputs=ie_inputs) assert len(res) == len(outputs) for name, output in outputs: assert name in res actual_output = res[name] np.testing.assert_allclose(output, actual_output, rtol=1e-3, atol=1e-4) log.info('{}: OK'.format(name)) log.info('ALL OK') def compute(): exec_net.infer(inputs=ie_inputs) return run_onnx_util.run_benchmark(compute, args.iterations)
def end(self): click.clear() sys.exis(0)
def main(argv): if len(argv) != 3: sys.exis('Input arguments must be year, month, day!') year = argv[0] month = argv[1] day = argv[2] home_dir = '/mnt/lab_45d1/database/Sc_group/' '''Input a date''' date = pd.date_range(year + '-' + month + '-' + day + ' 12:00', year + '-' + month + '-' + day + ' 12:00')[0] caseName = 'NKX_' + date.strftime('%Y%m%d') try: os.makedirs(home_dir + 'uclales_output/' + caseName) os.makedirs(home_dir + 'uclales_output/' + caseName + '/hr_1_3_60min_with_spinup') os.makedirs(home_dir + 'uclales_output/' + caseName + '/hr_3_4_1min') os.makedirs(home_dir + 'uclales_output/' + caseName + '/hr_4_18_60min') except OSError: if not os.path.isdir('./uclales_output/' + caseName): raise '''Hour minus 2 to 3, saving hourly data''' os.chdir(home_dir + 'uclales_output/' + caseName + '/hr_1_3_60min_with_spinup') '''Make sound_in file''' IC, uwind, vwind, z = prep_les.make_sound_in_file(home_dir, date) '''Make backrad_in file''' ### no need for backrad_in file for rad type 2 # prep_les.make_backrad_in_file(home_dir,date,IC,z) '''Make zm_grid and zt_grid files''' domain_H = np.max([IC['z_inv_base'] * 3, 1500.]) zm, zt = prep_les.write_z_grid_relax_transition(IC['z_inv_base'], domain_H) '''Make NAMELIST''' prep_les.write_NAMELIST(nzp=len(zm),timmax=18000.,runtype='INITIAL',frqanl=3600.,\ filprf=caseName,hfilin=caseName+'.rst',strtim=float(date.dayofyear),\ dthcon=IC['SHF'],drtcon=IC['LHF'],\ th00=IC['eq_thetalBL'],umean=uwind.mean(),vmean=vwind.mean(),div=IC['D_SEAarea'],fr0=IC['F0'],fr1=IC['F1'],xka=IC['xka_bestfit']) '''Run UCLALES''' os.system('ln -s /home/elw014/radtyp2/uclales/build/uclales .') os.system('ln -s /home/elw014/radtyp2/uclales/bin/datafiles .') os.system('mpiexec -n 8 ./uclales > log') '''Hour 3 - 4, saving minute data''' os.chdir(home_dir + 'uclales_output/' + caseName + '/hr_3_4_1min') prep_les.write_NAMELIST(nzp=len(zm),timmax=21600.,runtype='HISTORY',frqanl=60.,\ filprf=caseName,hfilin=caseName+'.rst',strtim=float(date.dayofyear),\ dthcon=IC['SHF'],drtcon=IC['LHF'],\ th00=IC['eq_thetalBL'],umean=uwind.mean(),vmean=vwind.mean(),div=IC['D_SEAarea'],fr0=IC['F0'],fr1=IC['F1'],xka=IC['xka_bestfit']) os.system('cp ../hr_1_3_60min_with_spinup/zm_grid_in .') os.system('cp ../hr_1_3_60min_with_spinup/zt_grid_in .') os.system('cp ../hr_1_3_60min_with_spinup/sound_in .') # os.system('cp ../hr_1_3_60min_with_spinup/backrad_in .') os.system('cp ../hr_1_3_60min_with_spinup/*.rst .') os.system('ln -s /home/elw014/radtyp2/uclales/build/uclales .') os.system('ln -s /home/elw014/radtyp2/uclales/bin/datafiles .') os.system('mpiexec -n 8 ./uclales > log') prep_les.SEND_ALERT_EMAIL(caseName, ' Hour 3 - 4') '''Hour 4 - 18, saving hourly data''' os.chdir(home_dir + 'uclales_output/' + caseName + '/hr_4_18_60min') prep_les.write_NAMELIST(nzp=len(zm),timmax=72000.,runtype='HISTORY',frqanl=3600.,\ filprf=caseName,hfilin=caseName+'.rst',strtim=float(date.dayofyear),\ dthcon=IC['SHF'],drtcon=IC['LHF'],\ th00=IC['eq_thetalBL'],umean=uwind.mean(),vmean=vwind.mean(),div=IC['D_SEAarea'],fr0=IC['F0'],fr1=IC['F1'],xka=IC['xka_bestfit']) os.system('cp ../hr_3_4_1min/zm_grid_in .') os.system('cp ../hr_3_4_1min/zt_grid_in .') os.system('cp ../hr_3_4_1min/sound_in .') # os.system('cp ../hr_3_4_1min/backrad_in .') os.system('cp ../hr_3_4_1min/*.rst .') os.system('ln -s /home/elw014/radtyp2/uclales/build/uclales .') os.system('ln -s /home/elw014/radtyp2/uclales/bin/datafiles .') os.system('mpiexec -n 8 ./uclales > log') prep_les.SEND_ALERT_EMAIL(caseName, ' Hour 4 - 18')