-
Notifications
You must be signed in to change notification settings - Fork 12
/
Makefile
161 lines (130 loc) · 5.43 KB
/
Makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
SHELL := /bin/bash
include docker/Makefile.image_names
include Makefile.data_download
ROOT_DIR:=$(shell dirname $(realpath $(firstword $(MAKEFILE_LIST))))
define BROWSER_PYSCRIPT
import os, webbrowser, sys
try:
from urllib import pathname2url
except:
from urllib.request import pathname2url
webbrowser.open("file://" + pathname2url(os.path.abspath(sys.argv[1])))
endef
export BROWSER_PYSCRIPT
BROWSER := python -c "$$BROWSER_PYSCRIPT"
DOCKER_BUILDKIT=1
SHELL=/bin/bash
CWD=$(shell pwd)
PULL ?=True
DEV ?=y
CHECK_CHANGED_SCRIPT=$(CWD)/changed_from_main.py
CONTAINER_CMD?=docker
SAVEPOINT_SETUP=pip3 list
VOLUMES ?=
BUILD_FLAGS ?=
### Testing variables
RUN_FLAGS ?=--rm
ifeq ("$(CONTAINER_CMD)","")
PACE_PATH?=$(ROOT_DIR)
else
ifeq ("$(CONTAINER_CMD)","srun")
PACE_PATH?=$(ROOT_DIR)
else
PACE_PATH?=/pace
endif
endif
ifeq ("$(CONTAINER_CMD)","")
EXPERIMENT_DATA_RUN=$(EXPERIMENT_DATA)
else
ifeq ("$(CONTAINER_CMD)","srun")
EXPERIMENT_DATA_RUN=$(EXPERIMENT_DATA)
else
EXPERIMENT_DATA_RUN=$(PACE_PATH)/test_data/$(FORTRAN_SERIALIZED_DATA_VERSION)/$(EXPERIMENT)
endif
endif
ifeq ($(DEV),y)
VOLUMES += -v $(ROOT_DIR):/pace
else
VOLUMES += -v $(EXPERIMENT_DATA):$(EXPERIMENT_DATA_RUN)
endif
ifeq ($(CONTAINER_CMD),docker)
CONTAINER_FLAGS=run $(RUN_FLAGS) $(VOLUMES) --env GT_CACHE_ROOT=/pace/.gt_cache $(PACE_IMAGE)
else
CONTAINER_FLAGS=
endif
NUM_RANKS ?=6
MPIRUN_ARGS ?=--oversubscribe --mca btl_vader_single_copy_mechanism none
MPIRUN_CALL ?=mpirun -np $(NUM_RANKS) $(MPIRUN_ARGS)
TEST_ARGS ?=-v
TEST_TYPE=$(word 3, $(subst _, ,$(EXPERIMENT)))
FV3CORE_THRESH_ARGS=--threshold_overrides_file=$(PACE_PATH)/fv3core/tests/savepoint/translate/overrides/$(TEST_TYPE).yaml
PHYSICS_THRESH_ARGS=--threshold_overrides_file=$(PACE_PATH)/physics/tests/savepoint/translate/overrides/$(TEST_TYPE).yaml
###
build:
ifneq ($(findstring docker,$(CONTAINER_CMD)),) # only build if using docker
ifeq ($(DEV),n) # rebuild container if not running in dev mode
$(MAKE) _force_build
else # build even if running in dev mode if there is no environment image
ifeq ($(shell docker images -q us.gcr.io/vcm-ml/pace 2> /dev/null),)
$(MAKE) _force_build
endif
endif
endif
_force_build:
DOCKER_BUILDKIT=1 docker build \
$(BUILD_FLAGS) \
-f $(CWD)/Dockerfile \
-t $(PACE_IMAGE) \
.
enter:
docker run --rm -it \
--network host \
$(VOLUMES) \
$(PACE_IMAGE) bash
dev:
DEV=y $(MAKE) enter
test_util:
if [ $(shell $(CHECK_CHANGED_SCRIPT) util) != false ]; then \
$(MAKE) -C util test; \
fi
savepoint_tests: build ## dycore-only savepoint tests
TARGET=dycore $(MAKE) get_test_data
$(CONTAINER_CMD) $(CONTAINER_FLAGS) bash -c "$(SAVEPOINT_SETUP) && cd $(PACE_PATH) && pytest --data_path=$(EXPERIMENT_DATA_RUN)/dycore/ $(TEST_ARGS) $(FV3CORE_THRESH_ARGS) $(PACE_PATH)/fv3core/tests/savepoint"
savepoint_tests_mpi: build
TARGET=dycore $(MAKE) get_test_data
$(CONTAINER_CMD) $(CONTAINER_FLAGS) bash -c "$(SAVEPOINT_SETUP) && cd $(PACE_PATH) && $(MPIRUN_CALL) python3 -m mpi4py -m pytest --maxfail=1 --data_path=$(EXPERIMENT_DATA_RUN)/dycore/ $(TEST_ARGS) $(FV3CORE_THRESH_ARGS) -m parallel $(PACE_PATH)/fv3core/tests/savepoint"
dependencies.svg: dependencies.dot
dot -Tsvg $< -o $@
.PHONY: constraints.txt
constraints.txt: driver/setup.py dsl/setup.py fv3core/setup.py physics/setup.py util/setup.py stencils/setup.py util/requirements.txt requirements_docs.txt requirements_lint.txt external/gt4py/setup.cfg requirements_dev.txt
pip-compile $^ --output-file constraints.txt
sed -i.bak '/\@ git+https/d' constraints.txt
rm -f constraints.txt.bak
physics_savepoint_tests: build
TARGET=physics $(MAKE) get_test_data
$(CONTAINER_CMD) $(CONTAINER_FLAGS) bash -c "$(SAVEPOINT_SETUP) && cd $(PACE_PATH) && pytest --data_path=$(EXPERIMENT_DATA_RUN)/physics/ $(TEST_ARGS) $(PHYSICS_THRESH_ARGS) $(PACE_PATH)/physics/tests/savepoint"
physics_savepoint_tests_mpi: build
TARGET=physics $(MAKE) get_test_data
$(CONTAINER_CMD) $(CONTAINER_FLAGS) bash -c "$(SAVEPOINT_SETUP) && cd $(PACE_PATH) && $(MPIRUN_CALL) python -m mpi4py -m pytest --maxfail=1 --data_path=$(EXPERIMENT_DATA_RUN)/physics/ $(TEST_ARGS) $(PHYSICS_THRESH_ARGS) -m parallel $(PACE_PATH)/physics/tests/savepoint"
test_main: build
$(CONTAINER_CMD) $(CONTAINER_FLAGS) bash -c "$(SAVEPOINT_SETUP) && cd $(PACE_PATH) && pytest $(TEST_ARGS) $(PACE_PATH)/tests/main"
test_savepoint: ## top level savepoint tests
TARGET=dycore $(MAKE) get_test_data
$(CONTAINER_CMD) $(CONTAINER_FLAGS) bash -c "$(SAVEPOINT_SETUP) && cd $(PACE_PATH) && $(MPIRUN_CALL) python -m pytest --data_path=$(EXPERIMENT_DATA_RUN)/dycore/ $(TEST_ARGS) $(PACE_PATH)/tests/savepoint"
test_notebooks: ## tests for jupyter notebooks, must be run in correct Python environment
pytest --nbmake "examples/notebooks"
test_mpi_54rank:
mpirun -n 54 $(MPIRUN_ARGS) python3 -m mpi4py -m pytest tests/mpi_54rank
driver_savepoint_tests_mpi: build
TARGET=driver $(MAKE) get_test_data
$(CONTAINER_CMD) $(CONTAINER_FLAGS) bash -c "$(SAVEPOINT_SETUP) && cd $(PACE_PATH) && $(MPIRUN_CALL) python -m mpi4py -m pytest --maxfail=1 --data_path=$(EXPERIMENT_DATA_RUN)/driver/ $(TEST_ARGS) $(PHYSICS_THRESH_ARGS) -m parallel $(PACE_PATH)/physics/tests/savepoint"
docs: ## generate Sphinx HTML documentation
$(MAKE) -C docs html
$(BROWSER) docs/_build/html/index.html
doctest: ## run Sphinx doctest
$(MAKE) -C docs doctest
servedocs: docs ## compile the docs watching for changes
watchmedo shell-command -p '*.rst' -c '$(MAKE) -C docs html' -R -D .
lint:
pre-commit run --all-files
.PHONY: docs doctest servedocs build