def test_fv3run_with_mocked_subprocess(runner, config): outdir = os.path.join(TEST_DIR, "outdir") with unittest.mock.patch( "subprocess.check_call") as mock, cleaned_up_directory(outdir): runner(config, outdir) assert mock.called call_args = list(mock.call_args[0]) # ensure test does not depend on # of processors on testing system while "--oversubscribe" in call_args[0]: call_args[0].remove("--oversubscribe") assert call_args == [[ "mpirun", "-n", "6", "--allow-run-as-root", "--use-hwthread-cpus", "--mca", "btl_vader_single_copy_mechanism", "none", "python3", "-m", "mpi4py", "mock_runscript.py", ]] with open(os.path.join(outdir, "fv3config.yml"), "r") as f: written_config = fv3config.load(f) assert written_config == config
def write_run_directory(): args = _parse_write_run_directory_args() with fsspec.open(args.config) as f: config = fv3config.load(f) fv3config.write_run_directory(config, args.rundir)
def test_dump_load(c12_config, diag_table): config = copy.deepcopy(c12_config) config["diag_table"] = diag_table f = io.StringIO() fv3config.dump(config, f) f.seek(0) loaded = fv3config.load(f) assert config == loaded
def enable_restart(): args = _parse_enable_restart_args() with fsspec.open(args.config) as f: config = fv3config.load(f) restart_config = fv3config.enable_restart(config, args.initial_conditions) with fsspec.open(args.config, mode="w") as f: fv3config.dump(restart_config, f)
def enable_nudging(): args = _parse_enable_nudging_args() with fsspec.open(args.config) as f: config = fv3config.load(f) # only update config if nudging is turned on if config["namelist"]["fv_core_nml"].get("nudge", False): updated_config = fv3config.enable_nudging(config) with fsspec.open(args.config, mode="w") as f: fv3config.dump(updated_config, f)
import fv3config import argparse import os if __name__ == "__main__": parser = argparse.ArgumentParser( description="Create a run directory for FV3.") parser.add_argument("configfile", type=str, help="yaml configuration path") parser.add_argument("outdir", type=str, help="output directory") args = parser.parse_args() with open(args.configfile, "r") as f: config = fv3config.load(f) fv3config.write_run_directory(config, args.outdir) with open(os.path.join(args.outdir, "fv3config.yml"), "w") as f: fv3config.dump(config, f)
def read_run_config(run_url): fs = vcm.get_fs(run_url) s = fs.cat(os.path.join(run_url, "fv3config.yml")) return fv3config.load(io.BytesIO(s))
def run_native(fv3config_path: str, rundir: str): """Setup a run-directory and run the model. Used for testing/debugging.""" with open(fv3config_path) as f: config = fv3config.load(f) sys.exit(run_segment(config, rundir))
def create(url: str, fv3config_path: str): """Initialize segmented run at URL given FV3CONFIG_PATH.""" with fsspec.open(fv3config_path) as f: fv3config_dict = fv3config.load(f) api.create(url, fv3config_dict)