docs: autogenerate the list of supported functions

closes #410
This commit is contained in:
Benoit Chevallier-Mames
2021-10-15 15:40:02 +02:00
committed by Benoit Chevallier
parent 9571ad8e78
commit a8aafcb70a
3 changed files with 180 additions and 34 deletions

View File

@@ -63,7 +63,7 @@ flake8:
python_linting: pylint flake8
.PHONY: python_linting
conformance: finalize_nb python_format
conformance: finalize_nb python_format supported_functions
.PHONY: conformance
pcc:
@@ -72,7 +72,7 @@ pcc:
.PHONY: pcc
PCC_DEPS := check_python_format check_finalize_nb python_linting mypy_ci pydocstyle shell_lint
PCC_DEPS += check_version_coherence
PCC_DEPS += check_version_coherence check_supported_functions
pcc_internal: $(PCC_DEPS)
.PHONY: pcc_internal
@@ -158,7 +158,7 @@ docker_publish_measurements: docker_build
/bin/bash ./script/progress_tracker_utils/benchmark_and_publish_findings_in_docker.sh
.PHONY: docker_publish_measurements
docs: clean_docs
docs: clean_docs supported_functions
@# Generate the auto summary of documentations
poetry run sphinx-apidoc -o docs/_apidoc $(SRC_DIR)
@@ -257,3 +257,12 @@ todo:
--pylintrc-path pylintrc);\
grep -rInH --exclude-dir='.[^.]*' --exclude=pylintrc --exclude='*.ipynb' "$${NOTES_ARGS}" .
.PHONY: todo
# Update docs with supported functions
supported_functions:
poetry run python script/doc_utils/gen_supported_ufuncs.py docs/user/tutorial/WORKING_WITH_FLOATING_POINTS.md
.PHONY: supported_functions
check_supported_functions:
poetry run python script/doc_utils/gen_supported_ufuncs.py docs/user/tutorial/WORKING_WITH_FLOATING_POINTS.md --check
.PHONY: check_supported_functions

View File

@@ -27,37 +27,89 @@ circuit.run(60) == 58
The following operations are supported in the latest release, and we'll add more operations in the upcoming releases.
- np.arccos
- np.arccosh
- np.arcsin
- np.arcsinh
- np.arctan
- np.arctanh
- np.cbrt
- np.ceil
- np.cos
- np.cosh
- np.deg2rad
- np.degrees
- np.exp
- np.exp2
- np.expm1
- np.fabs
- np.floor
- np.log
- np.log10
- np.log1p
- np.log2
- np.rad2deg
- np.radians
- np.rint
- np.sin
- np.sinh
- np.spacing
- np.sqrt
- np.tan
- np.tanh
- np.trunc
<!--- gen_supported_ufuncs.py: inject supported operations [BEGIN] -->
<!--- do not edit, auto generated part by `python3 gen_supported_ufuncs.py` in docker -->
List of supported unary functions:
- absolute
- arccos
- arccosh
- arcsin
- arcsinh
- arctan
- arctanh
- cbrt
- ceil
- cos
- cosh
- deg2rad
- degrees
- exp
- exp2
- expm1
- fabs
- floor
- invert
- isfinite
- isinf
- isnan
- log
- log10
- log1p
- log2
- logical_not
- negative
- positive
- rad2deg
- radians
- reciprocal
- rint
- sign
- signbit
- sin
- sinh
- spacing
- sqrt
- square
- tan
- tanh
- trunc
List of supported binary functions if one of the two operators is a constant scalar:
- arctan2
- bitwise_and
- bitwise_or
- bitwise_xor
- copysign
- equal
- float_power
- floor_divide
- fmax
- fmin
- fmod
- gcd
- greater
- greater_equal
- heaviside
- hypot
- lcm
- ldexp
- left_shift
- less
- less_equal
- logaddexp
- logaddexp2
- logical_and
- logical_or
- logical_xor
- maximum
- minimum
- nextafter
- not_equal
- power
- remainder
- right_shift
- true_divide
<!--- gen_supported_ufuncs.py: inject supported operations [END] -->
## Limitations

View File

@@ -0,0 +1,85 @@
"""Update list of supported functions in the doc."""
import argparse
from concrete.numpy import tracing
def main(file_to_update):
"""Update list of supported functions in file_to_update"""
supported_unary_ufunc = sorted(
f.__name__ for f in tracing.NPTracer.LIST_OF_SUPPORTED_UFUNC if f.nin == 1
)
supported_binary_ufunc = sorted(
f.__name__ for f in tracing.NPTracer.LIST_OF_SUPPORTED_UFUNC if f.nin == 2
)
with open(file_to_update, "r", encoding="utf-8") as file:
lines = file.readlines()
newlines = []
keep_line = True
for line in lines:
if line.startswith(
"<!--- gen_supported_ufuncs.py: inject supported operations [BEGIN] -->"
):
keep_line = False
newlines.append(line)
newlines.append(
"<!--- do not edit, auto generated part by "
"`python3 gen_supported_ufuncs.py` in docker -->\n"
)
elif line.startswith(
"<!--- do not edit, auto generated part by "
"`python3 gen_supported_ufuncs.py` in docker -->"
):
pass
elif line.startswith(
"<!--- gen_supported_ufuncs.py: inject supported operations [END] -->"
):
keep_line = True
# Inject the supported functions
newlines.append("List of supported unary functions:\n")
newlines.extend(f"- {f}\n" for f in supported_unary_ufunc)
newlines.append("\n")
newlines.append(
"List of supported binary functions if one of the "
"two operators is a constant scalar:\n"
)
newlines.extend(f"- {f}\n" for f in supported_binary_ufunc)
newlines.append(line)
else:
assert "gen_supported_ufuncs.py" not in line, (
f"Error: not expected to have 'gen_supported_ufuncs.py' at line {line} "
f"of {file_to_update}"
)
if keep_line:
newlines.append(line)
if args.check:
with open(file_to_update, "r", encoding="utf-8") as file:
oldlines = file.readlines()
assert (
oldlines == newlines
), "List of supported functions is not up to date. Please run `make supported_functions`."
else:
with open(file_to_update, "w", encoding="utf-8") as file:
file.writelines(newlines)
if __name__ == "__main__":
parser = argparse.ArgumentParser(description="Update list of supported functions in the doc")
parser.add_argument("--check", action="store_true", help="flag to enable just checking mode")
parser.add_argument("file_to_update", type=str, help=".md file to update")
args = parser.parse_args()
main(args.file_to_update)