Repository navigation
Expand file tree
/
Copy pathMakefile
More file actions
107 lines (87 loc) · 3.86 KB
/
Copy pathMakefile
File metadata and controls
107 lines (87 loc) · 3.86 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
# Copyright 2026 Rigetti & Co, LLC.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# GLOBALS
ifeq ($(origin .FEATURES), undefined)
$(error This Makefile requires GNU Make for the purpose of using the .ONESHELL directive.)
endif
# ... we use a single bash shell instance to run all commands in a rule, much like a script
SHELL := bash
.ONESHELL:
.SHELLFLAGS := -eu -o pipefail -c
MAKEFLAGS += --warn-undefined-variables
MAKEFLAGS += --no-builtin-rules
# ... the following are evaluated lazily, and should only be used in rules that check-poetry
PACKAGE = $(shell poetry version | awk '{print $$1;}')
VERSION = $(shell poetry version | awk '{print $$2;}')
INCLUDE = ${PACKAGE//-/_}
# ... the following are evaluated greedily, and form the targets for some rules related to testing
PROJECT_DIR := $(shell dirname $(realpath $(lastword $(MAKEFILE_LIST))))
EXAMPLES_DIR := $(PROJECT_DIR)/docs/examples
EXAMPLE_NOTEBOOKS := $(wildcard $(EXAMPLES_DIR)/*.ipynb)
.PHONY: FORCE # special target you can use to force rebuild of any file; e.g. for testing the examples
# COMMANDS
.DEFAULT := help
.PHONY: help
help:
@awk 'BEGIN { FS=":.*##"; print "Supported Makefile commands:\n" } \
/^[a-zA-Z0-9_-]+:.*##/ { cmd=$$1; desc=$$2; printf " \033[36m%-20s\033[0m %s\n", cmd, desc } \
END { print "" }' $(MAKEFILE_LIST)
.PHONY: build-docs
build-docs: ## Build the project documentation.
cd ${PROJECT_DIR}
JAX_ENABLE_X64=1 LC_ALL=C.UTF-8 poetry run sphinx-build -b html -D project=${PACKAGE} -D version=${VERSION} ./docs ./docs/_build
.PHONY: check-all
check-all: check-format check-types ## Check conformance to code format and typing rules.
.PHONY: check-format
check-format: ## Check conformance to code format rules.
cd ${PROJECT_DIR}
poetry run ruff format src tests examples --diff
poetry run ruff check src tests examples --no-fix
.PHONY: check-types
check-types: ## Check conformance to code typing rules.
cd ${PROJECT_DIR}
poetry run pyright src tests
.PHONY: format
format: ## Make automatic updates to code format and style.
cd ${PROJECT_DIR}
poetry run ruff format src tests examples
poetry run ruff check src tests examples --fix-only
poetry run nbstripout docs/examples/*.ipynb
.PHONY: test-examples
test-examples: ## Test all Jupyter notebooks in "docs/examples" run via papermill.
cd ${PROJECT_DIR}
@for notebook in $(EXAMPLE_NOTEBOOKS); do \
echo "Running $$notebook..."; \
JAX_ENABLE_X64=1 poetry run papermill "$$notebook" /dev/null --cwd $(EXAMPLES_DIR) || exit 1; \
done
@echo "✅ All example notebooks ran successfully."
.PHONY: test-package
test-package: ## Run all unit tests for the package, and report coverage.
cd ${PROJECT_DIR}
poetry run pytest -vv tests/
run-benchmarks: ## Run performance benchmarks
cd ${PROJECT_DIR}
mkdir -p benchmarks/results
JAX_ENABLE_X64=1 poetry run pytest benchmarks/ -v --benchmark-only --benchmark-json=benchmarks/results/results.json
.PHONY: benchmark-report
benchmark-report: ## Generate benchmark report from saved JSON results.
cd ${PROJECT_DIR}
poetry run python benchmarks/analyze.py benchmarks/results/results.json
.PHONY: benchmark
benchmark: run-benchmarks benchmark-report ## Run benchmarks at 64-bit precision and generate report.
# go install github.com/google/addlicense@latest
.PHONY: add-license
add-license: ## Add license headers to all source files.
cd ${PROJECT_DIR}
addlicense -c "Rigetti & Co, LLC." -l "apache" -v .