From 10ff0de4164490df3ad1aa16929adb5ae47438b2 Mon Sep 17 00:00:00 2001 From: Luca Ferranti <49938764+lucaferranti@users.noreply.github.com> Date: Mon, 25 Mar 2024 18:51:15 +0200 Subject: [PATCH] update to 2.0 (#14) * start upgrading to 1.33 * debugging info when running tests * add .readthedocs.yaml * update readthedocs yaml * try fix the docs * fix lambda deprecation * install requirements * try update sphinx * try now * update conf file * add author text field * try add theme to requirements * fixes for 2.0 * try updating CI * Revert "try updating CI" This reverts commit 289ee56015f124c1b9c8531ccf96c0398e4f01d8. * try fix version for brew * debug statement for brew * hups * what about now? * Update .github/workflows/CI.yml * comment out macos workflow * update documentation for new lambdas syntax --- .github/workflows/CI.yml | 22 +-- .readthedocs.yaml | 35 ++++ Mason.toml | 4 +- docs/Makefile | 183 ++++++++++++++++-- docs/make.bat | 277 ++++++++++++++++++++++++---- docs/requirements.txt | 3 +- docs/source/_static/empty | 1 + docs/source/_templates/empty | 1 + docs/source/_templates/page.html | 16 ++ docs/source/api/differentiation.rst | 6 +- docs/source/conf.py | 268 ++++++++++++++++++++++++--- docs/source/tutorial.rst | 10 +- example/example1d.chpl | 12 +- src/differentiation.chpl | 10 +- src/dualtype.chpl | 8 +- src/transcendental.chpl | 8 +- test/test_differentiation.chpl | 10 +- test/test_dual_algebra.chpl | 12 +- test/test_multidual_algebra.chpl | 10 +- 19 files changed, 767 insertions(+), 129 deletions(-) create mode 100644 .readthedocs.yaml create mode 100644 docs/source/_static/empty create mode 100644 docs/source/_templates/empty create mode 100644 docs/source/_templates/page.html diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml index c89bbf8..07933b8 100644 --- a/.github/workflows/CI.yml +++ b/.github/workflows/CI.yml @@ -28,14 +28,14 @@ jobs: # Runs a single command using the runners shell - name: Run tests run: | - mason test - mac-test: - runs-on: macos-latest - steps: - - uses: actions/checkout@v3 - - name: Install dependencies - run: | - brew install chapel - - name: Run test - run: | - mason test + mason test --show + # mac-test: + # runs-on: macos-latest + # steps: + # - uses: actions/checkout@v3 + # - name: Install dependencies + # run: | + # brew install chapel + # - name: Run test + # run: | + # mason test --show diff --git a/.readthedocs.yaml b/.readthedocs.yaml new file mode 100644 index 0000000..fe73f99 --- /dev/null +++ b/.readthedocs.yaml @@ -0,0 +1,35 @@ +# Read the Docs configuration file for Sphinx projects +# See https://docs.readthedocs.io/en/stable/config-file/v2.html for details + +# Required +version: 2 + +# Set the OS, Python version and other tools you might need +build: + os: ubuntu-22.04 + tools: + python: "3.12" + # You can also specify other tool versions: + # nodejs: "20" + # rust: "1.70" + # golang: "1.20" + +# Build documentation in the "docs/" directory with Sphinx +sphinx: + configuration: docs/source/conf.py + # You can configure Sphinx to use a different builder, for instance use the dirhtml builder for simpler URLs + # builder: "dirhtml" + # Fail on all warnings to avoid broken references + # fail_on_warning: true + +# Optionally build your docs in additional formats such as PDF and ePub +# formats: +# - pdf +# - epub + +# Optional but recommended, declare the Python requirements required +# to build your documentation +# See https://docs.readthedocs.io/en/stable/guides/reproducible-builds.html +python: + install: + - requirements: docs/requirements.txt diff --git a/Mason.toml b/Mason.toml index e773edc..9ec57d8 100644 --- a/Mason.toml +++ b/Mason.toml @@ -1,10 +1,10 @@ [brick] authors = "Luca Ferranti" -chplVersion = "1.28.0" +chplVersion = "2.0.0" license = "MIT" name = "ForwardModeAD" -version = "0.1.0" +version = "0.2.0" type="library" [dependencies] diff --git a/docs/Makefile b/docs/Makefile index d0c3cbf..c0dc64b 100644 --- a/docs/Makefile +++ b/docs/Makefile @@ -1,20 +1,177 @@ -# Minimal makefile for Sphinx documentation +# Makefile for Sphinx documentation # -# You can set these variables from the command line, and also -# from the environment for the first two. -SPHINXOPTS ?= -SPHINXBUILD ?= sphinx-build -SOURCEDIR = source +# You can set these variables from the command line. +SPHINXOPTS = -W +SPHINXBUILD = sphinx-build +PAPER = BUILDDIR = build -# Put it first so that "make" without argument is like "make help". +# User-friendly check for sphinx-build +ifeq ($(shell which $(SPHINXBUILD) >/dev/null 2>&1; echo $$?), 1) +$(error The '$(SPHINXBUILD)' command was not found. Make sure you have Sphinx installed, then set the SPHINXBUILD environment variable to point to the full path of the '$(SPHINXBUILD)' executable. Alternatively you can add the directory with the executable to your PATH. If you don't have Sphinx installed, grab it from http://sphinx-doc.org/) +endif + +# Internal variables. +PAPEROPT_a4 = -D latex_paper_size=a4 +PAPEROPT_letter = -D latex_paper_size=letter +ALLSPHINXOPTS = -d $(BUILDDIR)/doctrees $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) source +# the i18n builder cannot share the environment and doctrees with the others +I18NSPHINXOPTS = $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) source + +.PHONY: help clean html dirhtml singlehtml pickle json htmlhelp qthelp devhelp epub latex latexpdf text man changes linkcheck doctest gettext + help: - @$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O) + @echo "Please use \`make ' where is one of" + @echo " html to make standalone HTML files" + @echo " dirhtml to make HTML files named index.html in directories" + @echo " singlehtml to make a single large HTML file" + @echo " pickle to make pickle files" + @echo " json to make JSON files" + @echo " htmlhelp to make HTML files and a HTML help project" + @echo " qthelp to make HTML files and a qthelp project" + @echo " devhelp to make HTML files and a Devhelp project" + @echo " epub to make an epub" + @echo " latex to make LaTeX files, you can set PAPER=a4 or PAPER=letter" + @echo " latexpdf to make LaTeX files and run them through pdflatex" + @echo " latexpdfja to make LaTeX files and run them through platex/dvipdfmx" + @echo " text to make text files" + @echo " man to make manual pages" + @echo " texinfo to make Texinfo files" + @echo " info to make Texinfo files and run them through makeinfo" + @echo " gettext to make PO message catalogs" + @echo " changes to make an overview of all changed/added/deprecated items" + @echo " xml to make Docutils-native XML files" + @echo " pseudoxml to make pseudoxml-XML files for display purposes" + @echo " linkcheck to check all external links for integrity" + @echo " doctest to run all doctests embedded in the documentation (if enabled)" + +clean: + rm -rf $(BUILDDIR)/* + +html: + $(SPHINXBUILD) -b html $(ALLSPHINXOPTS) $(BUILDDIR)/html + @echo + @echo "Build finished. The HTML pages are in $(BUILDDIR)/html." + +dirhtml: + $(SPHINXBUILD) -b dirhtml $(ALLSPHINXOPTS) $(BUILDDIR)/dirhtml + @echo + @echo "Build finished. The HTML pages are in $(BUILDDIR)/dirhtml." + +singlehtml: + $(SPHINXBUILD) -b singlehtml $(ALLSPHINXOPTS) $(BUILDDIR)/singlehtml + @echo + @echo "Build finished. The HTML page is in $(BUILDDIR)/singlehtml." + +pickle: + $(SPHINXBUILD) -b pickle $(ALLSPHINXOPTS) $(BUILDDIR)/pickle + @echo + @echo "Build finished; now you can process the pickle files." + +json: + $(SPHINXBUILD) -b json $(ALLSPHINXOPTS) $(BUILDDIR)/json + @echo + @echo "Build finished; now you can process the JSON files." + +htmlhelp: + $(SPHINXBUILD) -b htmlhelp $(ALLSPHINXOPTS) $(BUILDDIR)/htmlhelp + @echo + @echo "Build finished; now you can run HTML Help Workshop with the" \ + ".hhp project file in $(BUILDDIR)/htmlhelp." + +qthelp: + $(SPHINXBUILD) -b qthelp $(ALLSPHINXOPTS) $(BUILDDIR)/qthelp + @echo + @echo "Build finished; now you can run "qcollectiongenerator" with the" \ + ".qhcp project file in $(BUILDDIR)/qthelp, like this:" + @echo "# qcollectiongenerator $(BUILDDIR)/qthelp/chpldoc.qhcp" + @echo "To view the help file:" + @echo "# assistant -collectionFile $(BUILDDIR)/qthelp/chpldoc.qhc" + +devhelp: + $(SPHINXBUILD) -b devhelp $(ALLSPHINXOPTS) $(BUILDDIR)/devhelp + @echo + @echo "Build finished." + @echo "To view the help file:" + @echo "# mkdir -p $$HOME/.local/share/devhelp/chpldoc" + @echo "# ln -s $(BUILDDIR)/devhelp $$HOME/.local/share/devhelp/chpldoc" + @echo "# devhelp" + +epub: + $(SPHINXBUILD) -b epub $(ALLSPHINXOPTS) $(BUILDDIR)/epub + @echo + @echo "Build finished. The epub file is in $(BUILDDIR)/epub." + +latex: + $(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex + @echo + @echo "Build finished; the LaTeX files are in $(BUILDDIR)/latex." + @echo "Run \`make' in that directory to run these through (pdf)latex" \ + "(use \`make latexpdf' here to do that automatically)." + +latexpdf: + $(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex + @echo "Running LaTeX files through pdflatex..." + $(MAKE) -C $(BUILDDIR)/latex all-pdf + @echo "pdflatex finished; the PDF files are in $(BUILDDIR)/latex." + +latexpdfja: + $(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex + @echo "Running LaTeX files through platex and dvipdfmx..." + $(MAKE) -C $(BUILDDIR)/latex all-pdf-ja + @echo "pdflatex finished; the PDF files are in $(BUILDDIR)/latex." + +text: + $(SPHINXBUILD) -b text $(ALLSPHINXOPTS) $(BUILDDIR)/text + @echo + @echo "Build finished. The text files are in $(BUILDDIR)/text." + +man: + $(SPHINXBUILD) -b man $(ALLSPHINXOPTS) $(BUILDDIR)/man + @echo + @echo "Build finished. The manual pages are in $(BUILDDIR)/man." + +texinfo: + $(SPHINXBUILD) -b texinfo $(ALLSPHINXOPTS) $(BUILDDIR)/texinfo + @echo + @echo "Build finished. The Texinfo files are in $(BUILDDIR)/texinfo." + @echo "Run \`make' in that directory to run these through makeinfo" \ + "(use \`make info' here to do that automatically)." + +info: + $(SPHINXBUILD) -b texinfo $(ALLSPHINXOPTS) $(BUILDDIR)/texinfo + @echo "Running Texinfo files through makeinfo..." + make -C $(BUILDDIR)/texinfo info + @echo "makeinfo finished; the Info files are in $(BUILDDIR)/texinfo." + +gettext: + $(SPHINXBUILD) -b gettext $(I18NSPHINXOPTS) $(BUILDDIR)/locale + @echo + @echo "Build finished. The message catalogs are in $(BUILDDIR)/locale." + +changes: + $(SPHINXBUILD) -b changes $(ALLSPHINXOPTS) $(BUILDDIR)/changes + @echo + @echo "The overview file is in $(BUILDDIR)/changes." + +linkcheck: + $(SPHINXBUILD) -b linkcheck $(ALLSPHINXOPTS) $(BUILDDIR)/linkcheck + @echo + @echo "Link check complete; look for any errors in the above output " \ + "or in $(BUILDDIR)/linkcheck/output.txt." + +doctest: + $(SPHINXBUILD) -b doctest $(ALLSPHINXOPTS) $(BUILDDIR)/doctest + @echo "Testing of doctests in the sources finished, look at the " \ + "results in $(BUILDDIR)/doctest/output.txt." -.PHONY: help Makefile +xml: + $(SPHINXBUILD) -b xml $(ALLSPHINXOPTS) $(BUILDDIR)/xml + @echo + @echo "Build finished. The XML files are in $(BUILDDIR)/xml." -# Catch-all target: route all unknown targets to Sphinx using the new -# "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS). -%: Makefile - @$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O) +pseudoxml: + $(SPHINXBUILD) -b pseudoxml $(ALLSPHINXOPTS) $(BUILDDIR)/pseudoxml + @echo + @echo "Build finished. The pseudo-XML files are in $(BUILDDIR)/pseudoxml." diff --git a/docs/make.bat b/docs/make.bat index 747ffb7..c551fd7 100644 --- a/docs/make.bat +++ b/docs/make.bat @@ -1,35 +1,242 @@ -@ECHO OFF - -pushd %~dp0 - -REM Command file for Sphinx documentation - -if "%SPHINXBUILD%" == "" ( - set SPHINXBUILD=sphinx-build -) -set SOURCEDIR=source -set BUILDDIR=build - -%SPHINXBUILD% >NUL 2>NUL -if errorlevel 9009 ( - echo. - echo.The 'sphinx-build' command was not found. Make sure you have Sphinx - echo.installed, then set the SPHINXBUILD environment variable to point - echo.to the full path of the 'sphinx-build' executable. Alternatively you - echo.may add the Sphinx directory to PATH. - echo. - echo.If you don't have Sphinx installed, grab it from - echo.https://www.sphinx-doc.org/ - exit /b 1 -) - -if "%1" == "" goto help - -%SPHINXBUILD% -M %1 %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O% -goto end - -:help -%SPHINXBUILD% -M help %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O% - -:end -popd +@ECHO OFF + +REM Command file for Sphinx documentation + +if "%SPHINXBUILD%" == "" ( + set SPHINXBUILD=sphinx-build +) +set BUILDDIR=build +set ALLSPHINXOPTS=-W -d %BUILDDIR%/doctrees %SPHINXOPTS% source +set I18NSPHINXOPTS=%SPHINXOPTS% source +if NOT "%PAPER%" == "" ( + set ALLSPHINXOPTS=-D latex_paper_size=%PAPER% %ALLSPHINXOPTS% + set I18NSPHINXOPTS=-D latex_paper_size=%PAPER% %I18NSPHINXOPTS% +) + +if "%1" == "" goto help + +if "%1" == "help" ( + :help + echo.Please use `make ^` where ^ is one of + echo. html to make standalone HTML files + echo. dirhtml to make HTML files named index.html in directories + echo. singlehtml to make a single large HTML file + echo. pickle to make pickle files + echo. json to make JSON files + echo. htmlhelp to make HTML files and a HTML help project + echo. qthelp to make HTML files and a qthelp project + echo. devhelp to make HTML files and a Devhelp project + echo. epub to make an epub + echo. latex to make LaTeX files, you can set PAPER=a4 or PAPER=letter + echo. text to make text files + echo. man to make manual pages + echo. texinfo to make Texinfo files + echo. gettext to make PO message catalogs + echo. changes to make an overview over all changed/added/deprecated items + echo. xml to make Docutils-native XML files + echo. pseudoxml to make pseudoxml-XML files for display purposes + echo. linkcheck to check all external links for integrity + echo. doctest to run all doctests embedded in the documentation if enabled + goto end +) + +if "%1" == "clean" ( + for /d %%i in (%BUILDDIR%\*) do rmdir /q /s %%i + del /q /s %BUILDDIR%\* + goto end +) + + +%SPHINXBUILD% 2> nul +if errorlevel 9009 ( + echo. + echo.The 'sphinx-build' command was not found. Make sure you have Sphinx + echo.installed, then set the SPHINXBUILD environment variable to point + echo.to the full path of the 'sphinx-build' executable. Alternatively you + echo.may add the Sphinx directory to PATH. + echo. + echo.If you don't have Sphinx installed, grab it from + echo.http://sphinx-doc.org/ + exit /b 1 +) + +if "%1" == "html" ( + %SPHINXBUILD% -b html %ALLSPHINXOPTS% %BUILDDIR%/html + if errorlevel 1 exit /b 1 + echo. + echo.Build finished. The HTML pages are in %BUILDDIR%/html. + goto end +) + +if "%1" == "dirhtml" ( + %SPHINXBUILD% -b dirhtml %ALLSPHINXOPTS% %BUILDDIR%/dirhtml + if errorlevel 1 exit /b 1 + echo. + echo.Build finished. The HTML pages are in %BUILDDIR%/dirhtml. + goto end +) + +if "%1" == "singlehtml" ( + %SPHINXBUILD% -b singlehtml %ALLSPHINXOPTS% %BUILDDIR%/singlehtml + if errorlevel 1 exit /b 1 + echo. + echo.Build finished. The HTML pages are in %BUILDDIR%/singlehtml. + goto end +) + +if "%1" == "pickle" ( + %SPHINXBUILD% -b pickle %ALLSPHINXOPTS% %BUILDDIR%/pickle + if errorlevel 1 exit /b 1 + echo. + echo.Build finished; now you can process the pickle files. + goto end +) + +if "%1" == "json" ( + %SPHINXBUILD% -b json %ALLSPHINXOPTS% %BUILDDIR%/json + if errorlevel 1 exit /b 1 + echo. + echo.Build finished; now you can process the JSON files. + goto end +) + +if "%1" == "htmlhelp" ( + %SPHINXBUILD% -b htmlhelp %ALLSPHINXOPTS% %BUILDDIR%/htmlhelp + if errorlevel 1 exit /b 1 + echo. + echo.Build finished; now you can run HTML Help Workshop with the ^ +.hhp project file in %BUILDDIR%/htmlhelp. + goto end +) + +if "%1" == "qthelp" ( + %SPHINXBUILD% -b qthelp %ALLSPHINXOPTS% %BUILDDIR%/qthelp + if errorlevel 1 exit /b 1 + echo. + echo.Build finished; now you can run "qcollectiongenerator" with the ^ +.qhcp project file in %BUILDDIR%/qthelp, like this: + echo.^> qcollectiongenerator %BUILDDIR%\qthelp\chpldoc.qhcp + echo.To view the help file: + echo.^> assistant -collectionFile %BUILDDIR%\qthelp\chpldoc.ghc + goto end +) + +if "%1" == "devhelp" ( + %SPHINXBUILD% -b devhelp %ALLSPHINXOPTS% %BUILDDIR%/devhelp + if errorlevel 1 exit /b 1 + echo. + echo.Build finished. + goto end +) + +if "%1" == "epub" ( + %SPHINXBUILD% -b epub %ALLSPHINXOPTS% %BUILDDIR%/epub + if errorlevel 1 exit /b 1 + echo. + echo.Build finished. The epub file is in %BUILDDIR%/epub. + goto end +) + +if "%1" == "latex" ( + %SPHINXBUILD% -b latex %ALLSPHINXOPTS% %BUILDDIR%/latex + if errorlevel 1 exit /b 1 + echo. + echo.Build finished; the LaTeX files are in %BUILDDIR%/latex. + goto end +) + +if "%1" == "latexpdf" ( + %SPHINXBUILD% -b latex %ALLSPHINXOPTS% %BUILDDIR%/latex + cd %BUILDDIR%/latex + make all-pdf + cd %BUILDDIR%/.. + echo. + echo.Build finished; the PDF files are in %BUILDDIR%/latex. + goto end +) + +if "%1" == "latexpdfja" ( + %SPHINXBUILD% -b latex %ALLSPHINXOPTS% %BUILDDIR%/latex + cd %BUILDDIR%/latex + make all-pdf-ja + cd %BUILDDIR%/.. + echo. + echo.Build finished; the PDF files are in %BUILDDIR%/latex. + goto end +) + +if "%1" == "text" ( + %SPHINXBUILD% -b text %ALLSPHINXOPTS% %BUILDDIR%/text + if errorlevel 1 exit /b 1 + echo. + echo.Build finished. The text files are in %BUILDDIR%/text. + goto end +) + +if "%1" == "man" ( + %SPHINXBUILD% -b man %ALLSPHINXOPTS% %BUILDDIR%/man + if errorlevel 1 exit /b 1 + echo. + echo.Build finished. The manual pages are in %BUILDDIR%/man. + goto end +) + +if "%1" == "texinfo" ( + %SPHINXBUILD% -b texinfo %ALLSPHINXOPTS% %BUILDDIR%/texinfo + if errorlevel 1 exit /b 1 + echo. + echo.Build finished. The Texinfo files are in %BUILDDIR%/texinfo. + goto end +) + +if "%1" == "gettext" ( + %SPHINXBUILD% -b gettext %I18NSPHINXOPTS% %BUILDDIR%/locale + if errorlevel 1 exit /b 1 + echo. + echo.Build finished. The message catalogs are in %BUILDDIR%/locale. + goto end +) + +if "%1" == "changes" ( + %SPHINXBUILD% -b changes %ALLSPHINXOPTS% %BUILDDIR%/changes + if errorlevel 1 exit /b 1 + echo. + echo.The overview file is in %BUILDDIR%/changes. + goto end +) + +if "%1" == "linkcheck" ( + %SPHINXBUILD% -b linkcheck %ALLSPHINXOPTS% %BUILDDIR%/linkcheck + if errorlevel 1 exit /b 1 + echo. + echo.Link check complete; look for any errors in the above output ^ +or in %BUILDDIR%/linkcheck/output.txt. + goto end +) + +if "%1" == "doctest" ( + %SPHINXBUILD% -b doctest %ALLSPHINXOPTS% %BUILDDIR%/doctest + if errorlevel 1 exit /b 1 + echo. + echo.Testing of doctests in the sources finished, look at the ^ +results in %BUILDDIR%/doctest/output.txt. + goto end +) + +if "%1" == "xml" ( + %SPHINXBUILD% -b xml %ALLSPHINXOPTS% %BUILDDIR%/xml + if errorlevel 1 exit /b 1 + echo. + echo.Build finished. The XML files are in %BUILDDIR%/xml. + goto end +) + +if "%1" == "pseudoxml" ( + %SPHINXBUILD% -b pseudoxml %ALLSPHINXOPTS% %BUILDDIR%/pseudoxml + if errorlevel 1 exit /b 1 + echo. + echo.Build finished. The pseudo-XML files are in %BUILDDIR%/pseudoxml. + goto end +) + +:end diff --git a/docs/requirements.txt b/docs/requirements.txt index 2444e5a..252f32e 100644 --- a/docs/requirements.txt +++ b/docs/requirements.txt @@ -1 +1,2 @@ -sphinxcontrib-chapeldomain \ No newline at end of file +sphinxcontrib-chapeldomain +sphinx_rtd_theme diff --git a/docs/source/_static/empty b/docs/source/_static/empty new file mode 100644 index 0000000..4134791 --- /dev/null +++ b/docs/source/_static/empty @@ -0,0 +1 @@ +This directory is empty. diff --git a/docs/source/_templates/empty b/docs/source/_templates/empty new file mode 100644 index 0000000..4134791 --- /dev/null +++ b/docs/source/_templates/empty @@ -0,0 +1 @@ +This directory is empty. diff --git a/docs/source/_templates/page.html b/docs/source/_templates/page.html new file mode 100644 index 0000000..d604afd --- /dev/null +++ b/docs/source/_templates/page.html @@ -0,0 +1,16 @@ +{% extends "!page.html" %} +{% block footer %} +{{ super() }} +{% if theme_analytics_id %} + +{% endif %} +{% endblock %} diff --git a/docs/source/api/differentiation.rst b/docs/source/api/differentiation.rst index cb5fc0c..9bab663 100644 --- a/docs/source/api/differentiation.rst +++ b/docs/source/api/differentiation.rst @@ -53,7 +53,7 @@ Functions for differentiation return x**2 + 2*x + 1; } - var dfx = derivative(lambda(x : dual){return f(x);}, 1.0); + var dfx = derivative(proc(x : dual){return f(x);}, 1.0); //outputs //4.0 @@ -86,7 +86,7 @@ Functions for differentiation type D = [0..#2] multidual; // domain for the lambda function - var dh = gradient(lambda(x : D){return h(x);}, [1.0, 2.0]); + var dh = gradient(proc(x : D){return h(x);}, [1.0, 2.0]); //outputs //8.0 3.0 @@ -119,7 +119,7 @@ Functions for differentiation type D = [0..#2] multidual; // domain for the lambda function - var Jf = jacobian(lambda(x : D){return F(x);}, [1.0, 2.0]); + var Jf = jacobian(proc(x : D){return F(x);}, [1.0, 2.0]); writeln(Jf, "\n"); //outputs diff --git a/docs/source/conf.py b/docs/source/conf.py index 8753549..3fbe5f1 100644 --- a/docs/source/conf.py +++ b/docs/source/conf.py @@ -1,60 +1,280 @@ -# Configuration file for the Sphinx documentation builder. +# -*- coding: utf-8 -*- # -# This file only contains a selection of the most common options. For a full -# list see the documentation: -# https://www.sphinx-doc.org/en/master/usage/configuration.html +# chpldoc documentation build configuration file, created by +# sphinx-quickstart on Thu Jan 29 08:44:44 2015. +# +# This file is execfile()d with the current directory set to its +# containing dir. +# +# Note that not all possible configuration values are present in this +# autogenerated file. +# +# All configuration values have a default; values that are commented out +# serve to show the default. -# -- Path setup -------------------------------------------------------------- +import sys +import os + +on_rtd = os.environ.get('READTHEDOCS', None) == 'True' # If extensions (or modules to document with autodoc) are in another directory, # add these directories to sys.path here. If the directory is relative to the # documentation root, use os.path.abspath to make it absolute, like shown here. -# -# import os -# import sys -# sys.path.insert(0, os.path.abspath('.')) - - -# -- Project information ----------------------------------------------------- - -project = 'ForwardModeAD' -copyright = '2022, Luca Ferranti' -author = 'Luca Ferranti' - -# The full version, including alpha/beta/rc tags -release = '0.1.0' +#sys.path.insert(0, os.path.abspath('.')) +# -- General configuration ------------------------------------------------ -# -- General configuration --------------------------------------------------- +# If your documentation needs a minimal Sphinx version, state it here. +needs_sphinx = '1.0' # Add any Sphinx extension module names here, as strings. They can be # extensions coming with Sphinx (named 'sphinx.ext.*') or your custom # ones. -extensions = ['sphinx.ext.mathjax', 'sphinxcontrib.chapeldomain'] +extensions = [ + 'sphinx.ext.todo', + 'sphinxcontrib.chapeldomain', + 'sphinx.ext.mathjax', +] # Add any paths that contain templates here, relative to this directory. templates_path = ['_templates'] +# The suffix of source filenames. +source_suffix = '.rst' + +# The encoding of source files. +#source_encoding = 'utf-8-sig' + +# The master toctree document. +master_doc = 'index' + +# General information about the project. +project = 'ForwardModeAD' +copyright = '2022 - 2024 Luca Ferranti' +author_text = 'Luca Ferranti' + + +# The version info for the project you're documenting, acts as replacement for +# |version| and |release|, also used in various other places throughout the +# built documents. +# +release = '0.1.0' + +# The language for content autogenerated by Sphinx. Refer to documentation +# for a list of supported languages. +#language = None + +# There are two options for replacing |today|: either, you set today to some +# non-false value, then it is used: +#today = '' +# Else, today_fmt is used as the format for a strftime call. +#today_fmt = '%B %d, %Y' + # List of patterns, relative to source directory, that match files and # directories to ignore when looking for source files. -# This pattern also affects html_static_path and html_extra_path. exclude_patterns = [] +# The reST default role (used for this markup: `text`) to use for all +# documents. +#default_role = None + +# If true, '()' will be appended to :func: etc. cross-reference text. +#add_function_parentheses = True + +# If true, the current module name will be prepended to all description +# unit titles (such as .. function::). +#add_module_names = True + +# If true, sectionauthor and moduleauthor directives will be shown in the +# output. They are ignored by default. +#show_authors = False + +# The name of the Pygments (syntax highlighting) style to use. +pygments_style = 'sphinx' -# -- Options for HTML output ------------------------------------------------- +# A list of ignored prefixes for module index sorting. +#modindex_common_prefix = [] + +# If true, keep warnings as "system message" paragraphs in the built documents. +#keep_warnings = False + + +# -- Options for HTML output ---------------------------------------------- # The theme to use for HTML and HTML Help pages. See the documentation for # a list of builtin themes. -# html_theme = 'sphinx_rtd_theme' +if not on_rtd: + import sphinx_rtd_theme + html_theme = 'sphinx_rtd_theme' + html_theme_path = [sphinx_rtd_theme.get_html_theme_path()] + + html_theme_options = { + 'sticky_navigation': True, + } + + analytics_id = os.environ.get('CHPLDOC_ANALYTICS_ID') + if analytics_id: + html_theme_options['analytics_id'] = analytics_id + + +# Theme options are theme-specific and customize the look and feel of a theme +# further. For a list of options available for each theme, see the +# documentation. +#html_theme_options = {} + +# Add any paths that contain custom themes here, relative to this directory. +#html_theme_path = [] + +# The name for this set of Sphinx documents. If None, it defaults to +# " v documentation". +#html_title = None + +# A shorter title for the navigation bar. Default is the same as html_title. +#html_short_title = None + +# The name of an image file (relative to this directory) to place at the top +# of the sidebar. +#html_logo = None + +# The name of an image file (within the static path) to use as favicon of the +# docs. This file should be a Windows icon file (.ico) being 16x16 or 32x32 +# pixels large. +#html_favicon = None # Add any paths that contain custom static files (such as style sheets) here, # relative to this directory. They are copied after the builtin static files, # so a file named "default.css" will overwrite the builtin "default.css". html_static_path = ['_static'] +# Add any extra paths that contain custom files (such as robots.txt or +# .htaccess) here, relative to this directory. These files are copied +# directly to the root of the documentation. +#html_extra_path = [] + +# If not '', a 'Last updated on:' timestamp is inserted at every page bottom, +# using the given strftime format. +#html_last_updated_fmt = '%b %d, %Y' + +# If true, SmartyPants will be used to convert quotes and dashes to +# typographically correct entities. +#html_use_smartypants = True + +# Custom sidebar templates, maps document names to template names. html_sidebars = { '**': [ 'globaltoc.html', ] } + +# Additional templates that should be rendered to pages, maps page names to +# template names. +#html_additional_pages = {} + +# If false, no module index is generated. +#html_domain_indices = True + +# If false, no index is generated. +#html_use_index = True + +# If true, the index is split into individual pages for each letter. +#html_split_index = False + +# If true, links to the reST sources are added to the pages. +#html_show_sourcelink = True + +# If true, "Created using Sphinx" is shown in the HTML footer. Default is True. +#html_show_sphinx = True + +# If true, "(C) Copyright ..." is shown in the HTML footer. Default is True. +#html_show_copyright = True + +# If true, an OpenSearch description file will be output, and all pages will +# contain a tag referring to it. The value of this option must be the +# base URL from which the finished HTML is served. +#html_use_opensearch = '' + +# This is the file name suffix for HTML files (e.g. ".xhtml"). +#html_file_suffix = None + +# Output file base name for HTML help builder. +htmlhelp_basename = 'chpldocdoc' + + +# -- Options for LaTeX output --------------------------------------------- + +latex_elements = { +# The paper size ('letterpaper' or 'a4paper'). +#'papersize': 'letterpaper', + +# The font size ('10pt', '11pt' or '12pt'). +#'pointsize': '10pt', + +# Additional stuff for the LaTeX preamble. +#'preamble': '', +} + +# Grouping the document tree into LaTeX files. List of tuples +# (source start file, target name, title, +# author, documentclass [howto, manual, or own class]). +latex_documents = [ + ('index', 'chpldoc.tex', u'chpldoc Documentation', + author_text, 'manual'), +] + +# The name of an image file (relative to this directory) to place at the top of +# the title page. +#latex_logo = None + +# For "manual" documents, if this is true, then toplevel headings are parts, +# not chapters. +#latex_use_parts = False + +# If true, show page references after internal links. +#latex_show_pagerefs = False + +# If true, show URL addresses after external links. +#latex_show_urls = False + +# Documents to append as an appendix to all manuals. +#latex_appendices = [] + +# If false, no module index is generated. +#latex_domain_indices = True + + +# -- Options for manual page output --------------------------------------- + +# One entry per manual page. List of tuples +# (source start file, name, description, authors, manual section). +man_pages = [ + ('index', 'chpldoc', u'chpldoc Documentation', + [author_text], 1) +] + +# If true, show URL addresses after external links. +#man_show_urls = False + + +# -- Options for Texinfo output ------------------------------------------- + +# Grouping the document tree into Texinfo files. List of tuples +# (source start file, target name, title, author, +# dir menu entry, description, category) +texinfo_documents = [ + ('index', 'chpldoc', u'chpldoc Documentation', + author_text, 'chpldoc', 'One line description of project.', + 'Miscellaneous'), +] + +# Documents to append as an appendix to all manuals. +#texinfo_appendices = [] + +# If false, no module index is generated. +#texinfo_domain_indices = True + +# How to display URL addresses: 'footnote', 'no', or 'inline'. +#texinfo_show_urls = 'footnote' + +# If true, do not generate a @detailmenu in the "Top" node's menu. +#texinfo_no_detailmenu = False diff --git a/docs/source/tutorial.rst b/docs/source/tutorial.rst index 72e30ba..d1ea206 100644 --- a/docs/source/tutorial.rst +++ b/docs/source/tutorial.rst @@ -86,7 +86,7 @@ achieve this passing a lambda function, as the example below demonstrates. .. code-block:: chapel - var dfx0 = derivative(lambda(x : dual) {return f(x);}, 0.0); + var dfx0 = derivative(proc(x : dual) {return f(x);}, 0.0); writeln(dfx0); .. code-block:: @@ -128,7 +128,7 @@ Next, we can compute the gradient similarly to before .. code-block:: chapel - var dh = gradient(lambda(x : D){return h(x);}, [1.0, 2.0]); + var dh = gradient(proc(x : D){return h(x);}, [1.0, 2.0]); writeln(dh); .. code-block:: @@ -174,7 +174,7 @@ Using the example function above type D = [0..#2] multidual - var J = jacobian(lambda(x : D){return F(x);}, [1.0, 2.0]); + var J = jacobian(proc(x : D){return F(x);}, [1.0, 2.0]); writeln(J); .. code-block:: @@ -233,8 +233,8 @@ Similarly to ``gradient`` and ``jacobian``, the function passed cannot be generi type D = [0..#2] dual; - var dirder = directionalDerivative(lambda(x: D) {return f(x);}, [1, 2], [0.5, 2.0]); - Jv = jvp(lambda(x: D) {return F(x);}, [1, 2], [0.5, 2.0]); + var dirder = directionalDerivative(proc(x: D) {return f(x);}, [1, 2], [0.5, 2.0]); + Jv = jvp(proc(x: D) {return F(x);}, [1, 2], [0.5, 2.0]); writeln(dirder, "\n"); writeln(Jv); diff --git a/example/example1d.chpl b/example/example1d.chpl index 41a7f7c..084b117 100644 --- a/example/example1d.chpl +++ b/example/example1d.chpl @@ -5,14 +5,14 @@ proc f(x) { } -var df = derivative(lambda(x : dual) {return f(x);}, 1.0); +var df = derivative(proc(x : dual) {return f(x);}, 1.0); writeln(df, "\n"); var df1 = derivative(f(initdual(1.0))); writeln(df1, "\n"); // proc df(x) { -// return derivative(lambda(t : dual) {return f(t);}, x); +// return derivative(proc(t : dual) {return f(t);}, x); // } // var z = df(1.0); @@ -23,14 +23,14 @@ proc g(x) { type D = [0..#2] multidual; -var dg = gradient(lambda(x : D) {return g(x);}, [1.0, 2.0]); +var dg = gradient(proc(x : D) {return g(x);}, [1.0, 2.0]); writeln(dg, "\n"); proc h(x) { return x[0] ** 2 + 3 * x[0] * x[1]; } -var dh = gradient(lambda(x : D){return h(x);}, [1.0, 2.0]); +var dh = gradient(proc(x : D){return h(x);}, [1.0, 2.0]); writeln(dh, "\n"); var dh1 = gradient(h(initdual([1.0, 2.0]))); @@ -40,7 +40,7 @@ proc F(x) { return [x[0] ** 2 + x[1] + 1, x[0] + x[1] ** 2 + x[0] * x[1]]; } -var Jf = jacobian(lambda(x : D){return F(x);}, [1.0, 2.0]); +var Jf = jacobian(proc(x : D){return F(x);}, [1.0, 2.0]); writeln(Jf, "\n"); var valjac = F(initdual([1.0, 2.0])); @@ -49,5 +49,5 @@ writeln(jacobian(valjac), "\n"); proc G(x) {return [1, 2, 3];} -var Jg = jacobian(lambda(x : D) {return G(x);}, [1.0, 2.0]); +var Jg = jacobian(proc(x : D) {return G(x);}, [1.0, 2.0]); writeln(Jg, "\n"); diff --git a/src/differentiation.chpl b/src/differentiation.chpl index aa6d7e9..252b34e 100644 --- a/src/differentiation.chpl +++ b/src/differentiation.chpl @@ -15,7 +15,7 @@ module differentiation { return new dual(x, 1.0); } - pragma "no doc" + @chpldoc.nodoc proc initdual(x : [?D] ?t) { var x0 : [D] multidual; forall i in D { @@ -63,7 +63,7 @@ module differentiation { return x**2 + 2*x + 1; } - var dfx = derivative(lambda(x : dual){return f(x);}, 1.0); + var dfx = derivative(proc(x : dual){return f(x);}, 1.0); //outputs //4.0 */ @@ -74,7 +74,7 @@ module differentiation { /* Extracts the derivative from a dual number. */ proc derivative(x: dual) {return dualPart(x);} - pragma "no doc" + @chpldoc.nodoc proc derivative(x: real) {return 0.0;} /* @@ -98,7 +98,7 @@ module differentiation { } type D = [0..#2] multidual; // domain for the lambda function - var dh = gradient(lambda(x : D){return h(x);}, [1.0, 2.0]); + var dh = gradient(proc(x : D){return h(x);}, [1.0, 2.0]); //outputs //8.0 3.0 */ @@ -133,7 +133,7 @@ module differentiation { type D = [0..#2] multidual; // domain for the lambda function - var Jf = jacobian(lambda(x : D){return F(x);}, [1.0, 2.0]); + var Jf = jacobian(proc(x : D){return F(x);}, [1.0, 2.0]); writeln(Jf, "\n"); //outputs diff --git a/src/dualtype.chpl b/src/dualtype.chpl index fc8ce5e..a2c6f91 100644 --- a/src/dualtype.chpl +++ b/src/dualtype.chpl @@ -35,10 +35,10 @@ module dualtype { /* Converts a real number and array of reals to a multidual number. */ proc todual(val : real, grad : [?D]) {return new multidual(D, val, [g in grad] g : real);} - pragma "no doc" + @chpldoc.nodoc proc isDualType(type t : dual) param {return true;} - pragma "no doc" + @chpldoc.nodoc proc isDualType(type t : multidual) param {return true;} /* Returns ``true`` if ``t`` is ``dual`` or ``multidual``. */ @@ -69,10 +69,10 @@ module dualtype { return [ai in a] dualPart(ai); } - pragma "no doc" + @chpldoc.nodoc proc primalPart(a) {return a;} - pragma "no doc" + @chpldoc.nodoc proc dualPart(a) {return 0.0;} proc isclose(a, b, rtol=1e-5, atol=0.0) where isEitherDualType(a.type, b.type) { diff --git a/src/transcendental.chpl b/src/transcendental.chpl index 9e19132..36d2941 100644 --- a/src/transcendental.chpl +++ b/src/transcendental.chpl @@ -22,7 +22,7 @@ module transcendental { proc exp2(a) where isDualType(a.type) { var f = exp2(primalPart(a)), - df = ln_2 * exp2(primalPart(a)) * dualPart(a); + df = ln2 * exp2(primalPart(a)) * dualPart(a); return todual(f, df); } @@ -40,13 +40,13 @@ module transcendental { proc log2(a) where isDualType(a.type) { var f = log2(primalPart(a)), - df = dualPart(a)/(primalPart(a) * ln_2); + df = dualPart(a)/(primalPart(a) * ln2); return todual(f, df); } proc log10(a) where isDualType(a.type) { var f = log10(primalPart(a)), - df = dualPart(a) / (primalPart(a) * ln_10); + df = dualPart(a) / (primalPart(a) * ln10); return todual(f, df); } @@ -55,4 +55,4 @@ module transcendental { df = dualPart(a) / (primalPart(a) + 1); return todual(f, df); } -} \ No newline at end of file +} diff --git a/test/test_differentiation.chpl b/test/test_differentiation.chpl index 121bfd9..05ba8b3 100644 --- a/test/test_differentiation.chpl +++ b/test/test_differentiation.chpl @@ -9,7 +9,7 @@ proc testUnivariateFunctions(test: borrowed Test) throws { return x ** 2 + 2 * x + 1; } - var df = derivative(lambda(x : dual) {return f(x);}, 1); + var df = derivative(proc(x : dual) {return f(x);}, 1); test.assertEqual(df, 4.0); var valder = f(initdual(1)); @@ -22,7 +22,7 @@ proc testGradient(test: borrowed Test) throws { return 2.0; } - var dg = gradient(lambda(x : D) {return g(x);}, [1.0, 2.0]); + var dg = gradient(proc(x : D) {return g(x);}, [1.0, 2.0]); test.assertEqual(dg, [0.0, 0.0]); proc h(x) { @@ -47,7 +47,7 @@ proc testJacobian(test: borrowed Test) throws { proc G(x) {return [1, 2, 3];} - var Jg = jacobian(lambda(x : D) {return G(x);}, [1.0, 2.0]), + var Jg = jacobian(proc(x : D) {return G(x);}, [1.0, 2.0]), _Jg: [0..2, 0..1] real; test.assertEqual(Jg, _Jg); @@ -63,7 +63,7 @@ proc testDirectionalAndJvp(test: borrowed Test) throws { test.assertEqual(value(valdirder), 7); test.assertEqual(directionalDerivative(valdirder), 10); - var dirder = directionalDerivative(lambda(x: D2) {return f(x);}, [1, 2], [0.5, 2.0]); + var dirder = directionalDerivative(proc(x: D2) {return f(x);}, [1, 2], [0.5, 2.0]); test.assertEqual(dirder, 10); proc F(x) { @@ -74,7 +74,7 @@ proc testDirectionalAndJvp(test: borrowed Test) throws { test.assertEqual(value(valjvp), [4.0, 7.0]); test.assertEqual(jvp(valjvp), [3.0, 11.5]); - var Jv = jvp(lambda(x: D2) {return F(x);}, [1, 2], [0.5, 2.0]); + var Jv = jvp(proc(x: D2) {return F(x);}, [1, 2], [0.5, 2.0]); test.assertEqual(Jv, [3.0, 11.5]); } diff --git a/test/test_dual_algebra.chpl b/test/test_dual_algebra.chpl index 321cb1b..9b5e397 100644 --- a/test/test_dual_algebra.chpl +++ b/test/test_dual_algebra.chpl @@ -38,7 +38,7 @@ proc test_arithmetic_operations(test : borrowed Test) throws { proc test_trigonometric_operations(test : borrowed Test) throws { var x = new dual(pi, 1); - var y = new dual(half_pi, 1); + var y = new dual(halfPi, 1); var z = new dual(sqrt(2) / 2.0, 2); // TODO: use isclose with e.g. atol=1e-10 and rtol=1e-5 @@ -55,19 +55,19 @@ proc test_trigonometric_operations(test : borrowed Test) throws { proc test_transcendental_functions(test : borrowed Test) throws { var x = new dual(2, 3); - test.assertEqual(2 ** x, new dual(4, 12 * ln_2)); + test.assertEqual(2 ** x, new dual(4, 12 * ln2)); - test.assertEqual(x ** x, new dual(4, 12 * (ln_2 + 1))); + test.assertEqual(x ** x, new dual(4, 12 * (ln2 + 1))); test.assertEqual(exp(x), new dual(exp(2), 3 * exp(2))); - test.assertEqual(exp2(x), new dual(4, 12 * ln_2)); + test.assertEqual(exp2(x), new dual(4, 12 * ln2)); test.assertEqual(expm1(x), new dual(expm1(2), 3 * exp(2))); - test.assertEqual(log(x), new dual(ln_2, 1.5)); + test.assertEqual(log(x), new dual(ln2, 1.5)); - test.assertEqual(log2(x), new dual(1, 1.5 / ln_2)); + test.assertEqual(log2(x), new dual(1, 1.5 / ln2)); test.assertEqual(log1p(x), new dual(log1p(2), 1)); } diff --git a/test/test_multidual_algebra.chpl b/test/test_multidual_algebra.chpl index 3e7bef4..8fafba9 100644 --- a/test/test_multidual_algebra.chpl +++ b/test/test_multidual_algebra.chpl @@ -51,19 +51,19 @@ proc test_trigonometric_operations(test : borrowed Test) throws { proc test_transcendental_functions(test : borrowed Test) throws { var x = todual(2, [2, 3]); - test.assertEqual(2 ** x, todual(4, [8 * ln_2, 12 * ln_2])); + test.assertEqual(2 ** x, todual(4, [8 * ln2, 12 * ln2])); - test.assertEqual(x ** x, todual(4, [8 * (ln_2 + 1), 12 * (ln_2 + 1)])); + test.assertEqual(x ** x, todual(4, [8 * (ln2 + 1), 12 * (ln2 + 1)])); test.assertEqual(exp(x), todual(exp(2), [2 * exp(2), 3 * exp(2)])); - test.assertEqual(exp2(x), todual(4, [8 * ln_2, 12 * ln_2])); + test.assertEqual(exp2(x), todual(4, [8 * ln2, 12 * ln2])); test.assertEqual(expm1(x), todual(expm1(2), [2 * exp(2), 3 * exp(2)])); - test.assertEqual(log(x), todual(ln_2, [1.0, 1.5])); + test.assertEqual(log(x), todual(ln2, [1.0, 1.5])); - test.assertEqual(log2(x), todual(1, [1.0 / ln_2, 1.5 / ln_2])); + test.assertEqual(log2(x), todual(1, [1.0 / ln2, 1.5 / ln2])); test.assertEqual(log1p(x), todual(log1p(2), [2.0 / 3.0, 1.0])); }