-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
180 lines (151 loc) · 5.65 KB
/
Copy pathMakefile
File metadata and controls
180 lines (151 loc) · 5.65 KB
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
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
IMAGE_NAME = vqe-mpi-gpu
NP ?= 2 #override with - make run NP=4
ifneq (,$(wildcard .env))
include .env
export
endif
GPU_AVAILABLE := $(shell docker run --rm --gpus all nvidia/cuda:12.2.0-base-ubuntu22.04 nvidia-smi > /dev/null 2>&1 && echo yes || echo no)
ifeq ($(GPU_AVAILABLE),yes)
GPU_FLAG = --gpus all
$(info [Make] GPU detected — CUDA acceleration enabled.)
else
GPU_FLAG =
$(info [Make] No GPU detected — falling back to CPU mode.)
endif
.PHONY: build trial run run-ibm scaling baseline clean shell
build:
@echo "[Make] Building Docker image '$(IMAGE_NAME)' ..."
docker build -t $(IMAGE_NAME) .
@echo "[Make] Build complete."
# DIAGNOSTIC - tests the 6 layers on simulator
trial:
@echo "[Make] Running diagnostic trial (simulator, $(NP) ranks) ..."
docker run --rm \
$(GPU_FLAG) \
-e BACKEND=simulator \
-e USE_GPU=$(GPU_AVAILABLE) \
-v "$$(pwd)/checkpoints:/workspace/checkpoints" \
$(IMAGE_NAME) \
mpirun --allow-run-as-root -np $(NP) python3 tests/test_layers_run.py
# RUN TEMPLATE SCRIPT
example:
@echo "[Make] Running template (simulator, $(NP) ranks) ..."
docker run --rm \
$(GPU_FLAG) \
-e BACKEND=simulator \
-e USE_GPU=$(GPU_AVAILABLE) \
-v "$$(pwd)/results:/workspace/results" \
-v "$$(pwd)/checkpoints:/workspace/checkpoints" \
$(IMAGE_NAME) \
mpirun --allow-run-as-root -np $(NP) python3 template.py
# FULL BENCHMARK - simualtor only
run:
@echo "[Make] Running full benchmark (simulator, $(NP) ranks) ..."
docker run --rm \
$(GPU_FLAG) \
-e BACKEND=simulator \
-e USE_GPU=$(GPU_AVAILABLE) \
-v "$$(pwd)/checkpoints:/workspace/checkpoints" \
-v "$$(pwd)/results:/workspace/results" \
$(IMAGE_NAME) \
mpirun --allow-run-as-root -np $(NP) python3 benchmarks/local_test_run.py
# # FULL BENCHMARK - IBM quantum QPU
run-ibm:
@[ -n "$(IBM_QUANTUM_TOKEN)" ] || (echo "ERROR: IBM_QUANTUM_TOKEN not set in .env"; exit 1)
@[ -n "$(IBM_QUANTUM_INSTANCE)" ] || (echo "ERROR: IBM_QUANTUM_INSTANCE not set in .env"; exit 1)
@echo "[Make] Running $(NP) ranks -> IBM Quantum ($(IBM_QUANTUM_BACKEND)) ..."
docker run --rm \
$(GPU_FLAG) \
-e BACKEND=ibm_cloud \
-e USE_GPU=$(GPU_AVAILABLE) \
-e IBM_QUANTUM_TOKEN="$(IBM_QUANTUM_TOKEN)" \
-e IBM_QUANTUM_INSTANCE="$(IBM_QUANTUM_INSTANCE)" \
-e IBM_QUANTUM_BACKEND="$(IBM_QUANTUM_BACKEND)" \
-e IBM_QUANTUM_REGION="$(IBM_QUANTUM_REGION)" \
-v "$$(pwd)/checkpoints:/workspace/checkpoints" \
-v "$$(pwd)/results:/workspace/results" \
$(IMAGE_NAME) \
mpirun --allow-run-as-root -np $(NP) python3 benchmarks/ibm_test_run.py
# STRONG SCALAING SWEEP - simulator
scaling:
@echo "[Make] Starting strong scaling analysis ..."
@mkdir -p results/scaling
@for p in 1 2 4 8; do \
echo " Running P=$$p ..."; \
docker run --rm \
$(GPU_FLAG) \
-e BACKEND=simulator \
-e USE_GPU=$(GPU_AVAILABLE) \
-v "$$(pwd)/results/scaling:/workspace/results/scaling" \
$(IMAGE_NAME) \
mpirun --allow-run-as-root -np $$p python3 benchmarks/local_test_run.py \
> results/scaling/scaling_p$$p.log 2>&1; \
echo " P=$$p done."; \
done
@echo "[Make] Scaling logs saved to results/scaling/. Check T_total and M-metric."
# WEAK SCALING SWEEP - problem size grows with P
weak-scaling:
@echo "[Make] Starting weak scaling analysis ..."
@mkdir -p results/scaling
@for p in 1 2 4 8; do \
echo " Running P=$$p (weak scaling) ..."; \
docker run --rm \
$(GPU_FLAG) \
-e BACKEND=simulator \
-e USE_GPU=$(GPU_AVAILABLE) \
-v "$$(pwd)/results/scaling:/workspace/results/scaling" \
-v "$$(pwd)/checkpoints:/workspace/checkpoints" \
$(IMAGE_NAME) \
mpirun --allow-run-as-root -np $$p python3 -c \
"import sys,os; sys.path.insert(0,'.'); sys.path.insert(0,'build'); \
from src.api.interface import HPCHybridStack; \
from benchmarks.local_test_run import run_weak_scaling; \
stack = HPCHybridStack(use_gpu=os.environ.get('USE_GPU','no')=='yes', backend='simulator'); \
run_weak_scaling(stack); stack.finalize()" \
> results/scaling/weak_scaling_p$$p.log 2>&1; \
echo " P=$$p done."; \
done
@echo "[Make] Weak scaling results saved to results/scaling/."
# SERIAL BASELINE - single-core Qiskit VQE for comparison (no MPI)
baseline:
@echo "[Make] Running serial Qiskit baseline (no MPI, no GPU) ..."
docker run --rm \
-e USE_GPU=no \
-v "$$(pwd)/results:/workspace/results" \
$(IMAGE_NAME) \
python3 benchmarks/serial_baseline.py
@echo "[Make] Serial baseline complete."
# RUN ALL TESTS- resolver + layer diagnostic
test:
@echo "[Make] Running test suite ..."
# python3 tests/test_resolver.py
python3 tests/test_molecules_run.py
docker run --rm \
$(GPU_FLAG) \
-e BACKEND=simulator \
-e USE_GPU=$(GPU_AVAILABLE) \
-v "$$(pwd)/checkpoints:/workspace/checkpoints" \
$(IMAGE_NAME) \
mpirun --allow-run-as-root -np 2 python3 tests/test_layers_run.py
@echo "[Make] All tests complete."
# LIST AVAILABLE MOLECULES - from the live registry
molecules:
@docker run --rm $(IMAGE_NAME) python3 -c "\
from src.api.problems import MOLECULE_REGISTRY; \
print('Available molecules:'); \
print(f'{\"Name\":<8} {\"Qubits\":<8} {\"FCI (Ha)\":<14} {\"Description\"}'); \
print('-' * 60); \
[print(f'{k:<8} {\"--\":<8} {v[\"fci_energy\"]:<14.4f} {v[\"description\"]}') for k, v in MOLECULE_REGISTRY.items()]"
shell:
docker run --rm -it \
$(GPU_FLAG) \
-e BACKEND=simulator \
-e USE_GPU=$(GPU_AVAILABLE) \
-v "$$(pwd)/checkpoints:/workspace/checkpoints" \
$(IMAGE_NAME) \
/bin/bash
clean:
docker rmi $(IMAGE_NAME) || true
rm -rf results/scaling/
rm -f *.log *.npy
find checkpoints/ -name "*.npy" -delete 2>/dev/null || true