Skip to content

Commit

Permalink
feat(frontend-python): Makefile working without compiler
Browse files Browse the repository at this point in the history
  • Loading branch information
rudy-6-4 authored and BourgerieQuentin committed Aug 1, 2024
1 parent 3adf658 commit 1630611
Showing 1 changed file with 31 additions and 21 deletions.
52 changes: 31 additions & 21 deletions frontends/concrete-python/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,14 @@ PYTHON=python
PIP=$(PYTHON) -m pip

COMPILER_BUILD_DIRECTORY ?= $(PWD)/../../compilers/concrete-compiler/compiler/build
NEW_PYTHON_PATH="${COMPILER_BUILD_DIRECTORY}/tools/concretelang/python_packages/concretelang_core/:$(PWD)"
BINDINGS_DIRECTORY=${COMPILER_BUILD_DIRECTORY}/tools/concretelang/python_packages/concretelang_core/
RUNTIME_LIBRARY=${COMPILER_BUILD_DIRECTORY}/lib/libConcretelangRuntime.so

CONCRETE_VERSION?="" # empty mean latest
# E.g. to use a previous version: `make CONCRETE_VERSION="<2.7.0" venv`
# E.g. to use a nightly: `make CONCRETE_VERSION="==2.7.0dev20240801`
# see https://pypi.zama.ai/cpu/concrete-python/index.html for available versions

.ONESHELL:
.PHONY:
.SILENT:
Expand All @@ -16,7 +21,9 @@ RUNTIME_LIBRARY=${COMPILER_BUILD_DIRECTORY}/lib/libConcretelangRuntime.so
venv:
$(PYTHON) -m venv .venv
. .venv/bin/activate

ifeq (,$(wildcard ${RUNTIME_LIBRARY}))
$(PIP) install --extra-index-url https://pypi.zama.ai/cpu "concrete-python$(CONCRETE_VERSION)"
endif
$(PIP) install -r requirements.dev.txt
$(PIP) install -r requirements.extra-full.txt
$(PIP) install -r requirements.txt
Expand All @@ -26,11 +33,17 @@ venv:
@echo "You can have the same activation in a terminal using:"
@echo 'eval $$(make cp_activate)'

cp_activate:
cp_activate: silent_cp_activate
@echo "echo 'Activating virtual env and local concrete-python and local compiler bindings' ;"

silent_cp_activate:
@echo "export PATH=$(PWD)/.venv/bin:$$PATH;"
ifeq (,$(wildcard ${RUNTIME_LIBRARY}))
@echo "export PYTHONPATH=$(PWD);"
else
@echo "export LD_PRELOAD=$(RUNTIME_LIBRARY);"
@echo "export PYTHONPATH=$(NEW_PYTHON_PATH);"
@echo "export PYTHONPATH=${BINDINGS_DIRECTORY}:$(PWD);"
endif

licenses:
bash scripts/versioning/summary.sh
Expand All @@ -42,8 +55,7 @@ licenses:
pytest: pytest-default

pytest-default:
export LD_PRELOAD=$(RUNTIME_LIBRARY)
export PYTHONPATH=$(NEW_PYTHON_PATH)
eval $(shell make silent_cp_activate)
pytest tests -svv -n auto \
--cov=concrete.fhe \
--cov-fail-under=95 \
Expand All @@ -52,9 +64,7 @@ pytest-default:
-m "${PYTEST_MARKERS}"

pytest-single:
export LD_PRELOAD=$(RUNTIME_LIBRARY)
export PYTHONPATH=$(NEW_PYTHON_PATH)

eval $(shell make silent_cp_activate)
# test single precision, mono params
pytest tests -svv -n auto \
--precision=single \
Expand All @@ -63,9 +73,7 @@ pytest-single:
-m "${PYTEST_MARKERS}"

pytest-multi:
export LD_PRELOAD=$(RUNTIME_LIBRARY)
export PYTHONPATH=$(NEW_PYTHON_PATH)

eval $(shell make silent_cp_activate)
# test multi precision, multi params
pytest tests -svv -n auto \
--precision=multi \
Expand All @@ -77,9 +85,7 @@ pytest-multi:
-m "${PYTEST_MARKERS}"

pytest-gpu:
export LD_PRELOAD=$(RUNTIME_LIBRARY)
export PYTHONPATH=$(NEW_PYTHON_PATH)

eval $(shell make silent_cp_activate)
# test single precision
pytest tests -svv -n0 --use_gpu \
--key-cache "${KEY_CACHE_DIRECTORY}" \
Expand All @@ -95,19 +101,15 @@ pytest-gpu:
-m "${PYTEST_MARKERS}"

benchmark:
export LD_PRELOAD=$(RUNTIME_LIBRARY)
export PYTHONPATH=$(NEW_PYTHON_PATH)

eval $(shell make silent_cp_activate)
export PROGRESS_SAMPLES=3
export PROGRESS_OUTPUT_INDENT=2

rm -rf progress.json
find ./benchmarks/ -name "*.py" | xargs python

process-benchmark-results-for-grafana:
export LD_PRELOAD=$(RUNTIME_LIBRARY)
export PYTHONPATH=$(NEW_PYTHON_PATH)

eval $(shell make silent_cp_activate)
python scripts/benchmark/postprocessor.py \
--source progress.json \
--target progress.processed.json \
Expand All @@ -118,6 +120,7 @@ process-benchmark-results-for-grafana:
# ==========

format:
eval $(shell make silent_cp_activate)
bash scripts/format/formatter.sh \
--dir concrete \
--dir examples \
Expand All @@ -126,6 +129,7 @@ format:
--dir benchmarks

sanitize-notebooks:
eval $(shell make silent_cp_activate)
$(PYTHON) scripts/notebook/sanitizer.py docs

conformance: format sanitize-notebooks
Expand All @@ -135,6 +139,7 @@ conformance: format sanitize-notebooks
# =======

check-format:
eval $(shell make silent_cp_activate)
bash scripts/format/formatter.sh --check \
--dir concrete \
--dir examples \
Expand All @@ -143,22 +148,27 @@ check-format:
--dir benchmarks

check-sanitize-notebooks:
eval $(shell make silent_cp_activate)
$(PYTHON) scripts/notebook/sanitizer.py docs --check

mypy:
eval $(shell make silent_cp_activate)
mypy concrete examples scripts tests benchmarks --ignore-missing-imports

pydocstyle:
eval $(shell make silent_cp_activate)
pydocstyle concrete --convention google --add-ignore=D1,D200,D202,D212,D402 --add-select=D401

pylint:
eval $(shell make silent_cp_activate)
pylint --rcfile=.pylintrc concrete
pylint --rcfile=.pylintrc examples --disable=C0103,C0114,C0115,C0116,E0401,R1721
pylint --rcfile=.pylintrc scripts
pylint --rcfile=.pylintrc tests --disable=C0301,W0108
pylint --rcfile=.pylintrc benchmarks

ruff:
eval $(shell make silent_cp_activate)
ruff concrete/ examples/ scripts/ tests/ benchmarks/

pcc: check-format check-sanitize-notebooks mypy pydocstyle pylint ruff
Expand Down

0 comments on commit 1630611

Please sign in to comment.