From 253e8d2680e11c80cb99af3ef703c0a04b1dda34 Mon Sep 17 00:00:00 2001 From: "Jason.Eu" Date: Thu, 17 Oct 2019 20:45:23 +0800 Subject: [PATCH] Docs draft and outlines of plumpy documentation (#112) Skeleton setup of docs for plumpy: * readthedocs setup * docs structure and style, add some API docs * add nitpick-exceptions * travis add dos-test option -nWT --- .readthedocs.yml | 26 ++ .travis.yml | 9 + docs/Makefile | 176 +---------- docs/make.bat | 225 +------------- docs/source/.gitignore | 1 + docs/source/advanced/plumpyAPIfsm.rst | 12 + docs/source/advanced/plumpyAPIprocess.rst | 8 + docs/source/advanced/plumpyAPIworkchain.rst | 8 + docs/source/advanced/process.rst | 10 + docs/source/advanced/workchain.rst | 12 + docs/source/apidoc/modules.rst | 7 - docs/source/apidoc/plum.engine.rst | 46 --- docs/source/apidoc/plum.rst | 165 ---------- docs/source/basic/concepts.rst | 53 ++++ docs/source/basic/introduction.rst | 8 + docs/source/basic/process.rst | 20 ++ docs/source/basic/workchain.rst | 11 + docs/source/conf.py | 320 +++++++++----------- docs/source/gettingStarted/install.rst | 54 ++++ docs/source/gettingStarted/quickStart.rst | 41 +++ docs/source/index.rst | 48 ++- docs/source/nitpick-exceptions | 44 +++ examples/process_helloworld.py | 28 ++ examples/process_waitAndResume.py | 45 +++ examples/workchain_simple.py | 31 ++ plumpy/__init__.py | 2 +- plumpy/process_comms.py | 31 +- plumpy/processes.py | 28 +- plumpy/workchains.py | 2 +- setup.py | 8 +- 30 files changed, 666 insertions(+), 813 deletions(-) create mode 100644 .readthedocs.yml create mode 100644 docs/source/.gitignore create mode 100644 docs/source/advanced/plumpyAPIfsm.rst create mode 100644 docs/source/advanced/plumpyAPIprocess.rst create mode 100644 docs/source/advanced/plumpyAPIworkchain.rst create mode 100644 docs/source/advanced/process.rst create mode 100644 docs/source/advanced/workchain.rst delete mode 100644 docs/source/apidoc/modules.rst delete mode 100644 docs/source/apidoc/plum.engine.rst delete mode 100644 docs/source/apidoc/plum.rst create mode 100644 docs/source/basic/concepts.rst create mode 100644 docs/source/basic/introduction.rst create mode 100644 docs/source/basic/process.rst create mode 100644 docs/source/basic/workchain.rst create mode 100644 docs/source/gettingStarted/install.rst create mode 100644 docs/source/gettingStarted/quickStart.rst create mode 100644 docs/source/nitpick-exceptions create mode 100644 examples/process_helloworld.py create mode 100644 examples/process_waitAndResume.py create mode 100644 examples/workchain_simple.py diff --git a/.readthedocs.yml b/.readthedocs.yml new file mode 100644 index 00000000..4dc22d40 --- /dev/null +++ b/.readthedocs.yml @@ -0,0 +1,26 @@ +# .readthedocs.yml +# Read the Docs configuration file +# See https://docs.readthedocs.io/en/stable/config-file/v2.html for details + +# Required +version: 2 + +# Build documentation in the docs/ directory with Sphinx +sphinx: + configuration: docs/source/conf.py + +# Build documentation with MkDocs +#mkdocs: +# configuration: mkdocs.yml + +# Optionally build your docs in additional formats such as PDF and ePub +formats: [] + +# Optionally set the version of Python and requirements required to build your docs +python: + version: 3.6 + install: + - method: pip + path: . + extra_requirements: + - docs diff --git a/.travis.yml b/.travis.yml index 42d13246..99a0c373 100644 --- a/.travis.yml +++ b/.travis.yml @@ -22,3 +22,12 @@ install: script: - py.test + +jobs: + include: + - stage: docs-test + python: 3.6 + install: + - pip install .[dev,docs] + script: + - sphinx-build -nT -b dummy docs/source build/html diff --git a/docs/Makefile b/docs/Makefile index 8cbde6ea..69fe55ec 100644 --- a/docs/Makefile +++ b/docs/Makefile @@ -1,177 +1,19 @@ -# Makefile for Sphinx documentation +# Minimal makefile for Sphinx documentation # # You can set these variables from the command line. SPHINXOPTS = SPHINXBUILD = sphinx-build -PAPER = +SOURCEDIR = source BUILDDIR = build -# 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 - +# Put it first so that "make" without argument is like "make 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 " 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/plum.qhcp" - @echo "To view the help file:" - @echo "# assistant -collectionFile $(BUILDDIR)/qthelp/plum.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/plum" - @echo "# ln -s $(BUILDDIR)/devhelp $$HOME/.local/share/devhelp/plum" - @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." + @$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O) -xml: - $(SPHINXBUILD) -b xml $(ALLSPHINXOPTS) $(BUILDDIR)/xml - @echo - @echo "Build finished. The XML files are in $(BUILDDIR)/xml." +.PHONY: help Makefile -pseudoxml: - $(SPHINXBUILD) -b pseudoxml $(ALLSPHINXOPTS) $(BUILDDIR)/pseudoxml - @echo - @echo "Build finished. The pseudo-XML files are in $(BUILDDIR)/pseudoxml." +# 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) \ No newline at end of file diff --git a/docs/make.bat b/docs/make.bat index c9f589ca..543c6b13 100644 --- a/docs/make.bat +++ b/docs/make.bat @@ -1,53 +1,18 @@ @ECHO OFF +pushd %~dp0 + REM Command file for Sphinx documentation if "%SPHINXBUILD%" == "" ( set SPHINXBUILD=sphinx-build ) +set SOURCEDIR=source set BUILDDIR=build -set ALLSPHINXOPTS=-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 +%SPHINXBUILD% >NUL 2>NUL if errorlevel 9009 ( echo. echo.The 'sphinx-build' command was not found. Make sure you have Sphinx @@ -60,183 +25,11 @@ if errorlevel 9009 ( 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\plum.qhcp - echo.To view the help file: - echo.^> assistant -collectionFile %BUILDDIR%\qthelp\plum.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 -) +%SPHINXBUILD% -M %1 %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% +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 -) +:help +%SPHINXBUILD% -M help %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% :end +popd diff --git a/docs/source/.gitignore b/docs/source/.gitignore new file mode 100644 index 00000000..73f85073 --- /dev/null +++ b/docs/source/.gitignore @@ -0,0 +1 @@ +apidoc diff --git a/docs/source/advanced/plumpyAPIfsm.rst b/docs/source/advanced/plumpyAPIfsm.rst new file mode 100644 index 00000000..c74fa1f5 --- /dev/null +++ b/docs/source/advanced/plumpyAPIfsm.rst @@ -0,0 +1,12 @@ +Finite State Machine API +======================== + + Implement this API to support a new state machine. + + .. autoclass:: plumpy.base.state_machine::State + :members: + :noindex: + + .. autoclass:: plumpy.base.state_machine::StateMachine + :members: + :noindex: diff --git a/docs/source/advanced/plumpyAPIprocess.rst b/docs/source/advanced/plumpyAPIprocess.rst new file mode 100644 index 00000000..80f9eb24 --- /dev/null +++ b/docs/source/advanced/plumpyAPIprocess.rst @@ -0,0 +1,8 @@ +Process API +=========== + + Implement this API to support a new Process. + + .. autoclass:: plumpy.processes::Process + :members: + :noindex: diff --git a/docs/source/advanced/plumpyAPIworkchain.rst b/docs/source/advanced/plumpyAPIworkchain.rst new file mode 100644 index 00000000..a97284ef --- /dev/null +++ b/docs/source/advanced/plumpyAPIworkchain.rst @@ -0,0 +1,8 @@ +WorkChain API +============= + + Implement this API to support a new WorkChain. + + .. autoclass:: plumpy.workchains::WorkChain + :members: + :noindex: diff --git a/docs/source/advanced/process.rst b/docs/source/advanced/process.rst new file mode 100644 index 00000000..0d08e513 --- /dev/null +++ b/docs/source/advanced/process.rst @@ -0,0 +1,10 @@ +.. _develop_process: + +Writing Process +===================== + +About how to construct own process. + +namespace + +events diff --git a/docs/source/advanced/workchain.rst b/docs/source/advanced/workchain.rst new file mode 100644 index 00000000..99d66330 --- /dev/null +++ b/docs/source/advanced/workchain.rst @@ -0,0 +1,12 @@ +.. _develop_workchain: + +Writing WorkChain +======================= + +About how to construct a specific use workchain + +define + +outline + +context diff --git a/docs/source/apidoc/modules.rst b/docs/source/apidoc/modules.rst deleted file mode 100644 index dd4951fa..00000000 --- a/docs/source/apidoc/modules.rst +++ /dev/null @@ -1,7 +0,0 @@ -plum -==== - -.. toctree:: - :maxdepth: 4 - - plum diff --git a/docs/source/apidoc/plum.engine.rst b/docs/source/apidoc/plum.engine.rst deleted file mode 100644 index 508e9f6b..00000000 --- a/docs/source/apidoc/plum.engine.rst +++ /dev/null @@ -1,46 +0,0 @@ -plum.engine package -=================== - -Submodules ----------- - -plum.engine.execution_engine module ------------------------------------ - -.. automodule:: plum.engine.execution_engine - :members: - :undoc-members: - :show-inheritance: - -plum.engine.parallel module ---------------------------- - -.. automodule:: plum.engine.parallel - :members: - :undoc-members: - :show-inheritance: - -plum.engine.serial module -------------------------- - -.. automodule:: plum.engine.serial - :members: - :undoc-members: - :show-inheritance: - -plum.engine.ticking module --------------------------- - -.. automodule:: plum.engine.ticking - :members: - :undoc-members: - :show-inheritance: - - -Module contents ---------------- - -.. automodule:: plum.engine - :members: - :undoc-members: - :show-inheritance: diff --git a/docs/source/apidoc/plum.rst b/docs/source/apidoc/plum.rst deleted file mode 100644 index 1592dc5b..00000000 --- a/docs/source/apidoc/plum.rst +++ /dev/null @@ -1,165 +0,0 @@ -plum package -============ - -Subpackages ------------ - -.. toctree:: - - plum.engine - -Submodules ----------- - -plum.class_loader module ------------------------- - -.. automodule:: plum.class_loader - :members: - :undoc-members: - :show-inheritance: - -plum.error module ------------------ - -.. automodule:: plum.error - :members: - :undoc-members: - :show-inheritance: - -plum.exceptions module ----------------------- - -.. automodule:: plum.exceptions - :members: - :undoc-members: - :show-inheritance: - -plum.in_memory_database module ------------------------------- - -.. automodule:: plum.in_memory_database - :members: - :undoc-members: - :show-inheritance: - -plum.knowledge_base module --------------------------- - -.. automodule:: plum.knowledge_base - :members: - :undoc-members: - :show-inheritance: - -plum.knowledge_provider module ------------------------------- - -.. automodule:: plum.knowledge_provider - :members: - :undoc-members: - :show-inheritance: - -plum.lang module ----------------- - -.. automodule:: plum.lang - :members: - :undoc-members: - :show-inheritance: - -plum.port module ----------------- - -.. automodule:: plum.port - :members: - :undoc-members: - :show-inheritance: - -plum.process module -------------------- - -.. automodule:: plum.process - :members: - :undoc-members: - :show-inheritance: - -plum.process_listener module ----------------------------- - -.. automodule:: plum.process_listener - :members: - :undoc-members: - :show-inheritance: - -plum.process_monitor module ---------------------------- - -.. automodule:: plum.process_monitor - :members: - :undoc-members: - :show-inheritance: - -plum.process_spec module ------------------------- - -.. automodule:: plum.process_spec - :members: - :undoc-members: - :show-inheritance: - -plum.settings module --------------------- - -.. automodule:: plum.settings - :members: - :undoc-members: - :show-inheritance: - -plum.test_utils module ----------------------- - -.. automodule:: plum.test_utils - :members: - :undoc-members: - :show-inheritance: - -plum.util module ----------------- - -.. automodule:: plum.util - :members: - :undoc-members: - :show-inheritance: - -plum.wait module ----------------- - -.. automodule:: plum.wait - :members: - :undoc-members: - :show-inheritance: - -plum.wait_ons module --------------------- - -.. automodule:: plum.wait_ons - :members: - :undoc-members: - :show-inheritance: - -plum.workflow module --------------------- - -.. automodule:: plum.workflow - :members: - :undoc-members: - :show-inheritance: - - -Module contents ---------------- - -.. automodule:: plum - :members: - :undoc-members: - :show-inheritance: diff --git a/docs/source/basic/concepts.rst b/docs/source/basic/concepts.rst new file mode 100644 index 00000000..d6eedb46 --- /dev/null +++ b/docs/source/basic/concepts.rst @@ -0,0 +1,53 @@ +.. _concepts: + +Concepts +======== + +Process +------- + +The probably most basic concept in plumpy is the process. A process is an asynchronously running component that is typically defined as a static, "long-running" part of the workflow. + +... + +State Machine +~~~~~~~~~~~~~ + + +A process can be in one of the following states: + +* CREATED +* RUNNING +* WAITING +* FINISHED +* EXCEPTED +* KILLED + +as defined in the :class:`ProcessState` enum. + +:: + + ___ + | v + CREATED (x) --- RUNNING (x) --- FINISHED (o) + | ^ / + v | / + WAITING (x) -- + | ^ + --- + + * -- EXCEPTED (o) + * -- KILLED (o) + +* (o): terminal state +* (x): non terminal state + +Workchain +--------- + +`WorkChain` is `Process`, however, not only the `Process`. + +A WorkChain is a series of instructions carried out with the ability to save state in between. + +The `outline` can give a succinct summary of the logical steps that the workchain will perform. +WorkChain supporting using `If_` and `While_` to control the state flow of certain processes. diff --git a/docs/source/basic/introduction.rst b/docs/source/basic/introduction.rst new file mode 100644 index 00000000..7bd58da3 --- /dev/null +++ b/docs/source/basic/introduction.rst @@ -0,0 +1,8 @@ +Introduction +============ + +Assumuing readers are: + + 1. Users from aiida-core + 2. (?)Users who want to create tools like aiida but on other research field + 3. Programmers who are searching for the python workflow tools integrated with finite state machine. diff --git a/docs/source/basic/process.rst b/docs/source/basic/process.rst new file mode 100644 index 00000000..34b9982f --- /dev/null +++ b/docs/source/basic/process.rst @@ -0,0 +1,20 @@ +Process +======= + +Persistence +----------- + +checkpoint + +how to save and reserve from checkpoint + +State machine +------------- + +How state transition +-------------------- + +Remote Controller +-------------------- + +control remote process (designate by pid) diff --git a/docs/source/basic/workchain.rst b/docs/source/basic/workchain.rst new file mode 100644 index 00000000..436e04c2 --- /dev/null +++ b/docs/source/basic/workchain.rst @@ -0,0 +1,11 @@ +WorkChain +========= + +Context +------- + +Strung processes or workchains in a WorkChain +------------------------------------------------ + +Control flow statement in workchain +----------------------------------- diff --git a/docs/source/conf.py b/docs/source/conf.py index c9afdce6..42f9ec9c 100644 --- a/docs/source/conf.py +++ b/docs/source/conf.py @@ -1,264 +1,238 @@ # -*- coding: utf-8 -*- # -# plum documentation build configuration file, created by -# sphinx-quickstart on Fri Dec 9 09:51:36 2016. +# Configuration file for the Sphinx documentation builder. # -# 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. +# This file does only contain a selection of the most common options. For a +# full list see the documentation: +# http://www.sphinx-doc.org/en/master/config -import sys -import os +# -- Path setup -------------------------------------------------------------- # 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. -#sys.path.insert(0, os.path.abspath('.')) +# +# import os +# import sys +# sys.path.insert(0, os.path.abspath('.')) + +from __future__ import division +from __future__ import print_function +from __future__ import absolute_import + +import os +import sys -# -- General configuration ------------------------------------------------ +import plumpy + +# -- Project information ----------------------------------------------------- + +project = 'plumpy' +copyright = '2019, Martin Uhrin' +author = 'Martin Uhrin' + +# The short X.Y version. +version = '.'.join(plumpy.__version__.split('.')[:2]) +# The full version, including alpha/beta/rc tags. +release = plumpy.__version__ + + +# -- General configuration --------------------------------------------------- # If your documentation needs a minimal Sphinx version, state it here. -#needs_sphinx = '1.0' +# +# 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.autodoc', 'sphinx.ext.doctest', - 'sphinx.ext.todo', - 'sphinx.ext.coverage', 'sphinx.ext.viewcode', ] - # Add any paths that contain templates here, relative to this directory. -templates_path = ['_templates'] -# The suffix of source filenames. +# The suffix(es) of source filenames. +# You can specify multiple suffix as a list of string: +# +# source_suffix = ['.rst', '.md'] 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 = u'plum' -copyright = u'2016, Martin Uhrin' - -# 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. -# -# The short X.Y version. -version = '0.7' -# The full version, including alpha/beta/rc tags. -release = '0.7.2' - # 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' +# +# This is also used if you do content translation via gettext catalogs. +# Usually you set "language" from the command line for these cases. +language = None # 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' - -# A list of ignored prefixes for module index sorting. -#modindex_common_prefix = [] +pygments_style = None -# If true, keep warnings as "system message" paragraphs in the built documents. -#keep_warnings = False - -# -- Options for HTML output ---------------------------------------------- +# -- 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 = 'default' +# +html_theme = 'sphinx_rtd_theme' # 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 +# +# html_theme_options = {} # 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 = {} - -# 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 +# html_static_path = ['_static'] -# 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 +# Custom sidebar templates, must be a dictionary that maps document names +# to template names. +# +# The default sidebars (for documents that don't match any pattern) are +# defined by theme itself. Builtin themes are using these templates by +# default: ``['localtoc.html', 'relations.html', 'sourcelink.html', +# 'searchbox.html']``. +# +# html_sidebars = {} -# 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 +# -- Options for HTMLHelp output --------------------------------------------- # Output file base name for HTML help builder. -htmlhelp_basename = 'plumdoc' +htmlhelp_basename = 'plumpydoc' -# -- Options for LaTeX output --------------------------------------------- +# -- Options for LaTeX output ------------------------------------------------ latex_elements = { -# The paper size ('letterpaper' or 'a4paper'). -#'papersize': 'letterpaper', + # The paper size ('letterpaper' or 'a4paper'). + # + # 'papersize': 'letterpaper', -# The font size ('10pt', '11pt' or '12pt'). -#'pointsize': '10pt', + # The font size ('10pt', '11pt' or '12pt'). + # + # 'pointsize': '10pt', -# Additional stuff for the LaTeX preamble. -#'preamble': '', + # Additional stuff for the LaTeX preamble. + # + # 'preamble': '', + + # Latex figure (float) alignment + # + # 'figure_align': 'htbp', } # 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', 'plum.tex', u'plum Documentation', - u'Martin Uhrin', 'manual'), + (master_doc, 'plumpy.tex', 'plumpy Documentation', + 'Martin Uhrin', 'manual'), ] -# The name of an image file (relative to this directory) to place at the top of -# the title page. -#latex_logo = None +def run_apidoc(_): + """Runs sphinx-apidoc when building the documentation. + + Needs to be done in conf.py in order to include the APIdoc in the + build on readthedocs. -# For "manual" documents, if this is true, then toplevel headings are parts, -# not chapters. -#latex_use_parts = False + See also https://github.com/rtfd/readthedocs.org/issues/1139 + """ + source_dir = os.path.abspath(os.path.dirname(__file__)) + apidoc_dir = os.path.join(source_dir, 'apidoc') + package_dir = os.path.join(source_dir, os.pardir, os.pardir, 'plumpy') -# If true, show page references after internal links. -#latex_show_pagerefs = False + # In #1139, they suggest the route below, but for me this ended up + # calling sphinx-build, not sphinx-apidoc + #from sphinx.apidoc import main + #main([None, '-e', '-o', apidoc_dir, package_dir, '--force']) -# If true, show URL addresses after external links. -#latex_show_urls = False + import subprocess + cmd_path = 'sphinx-apidoc' + if hasattr(sys, 'real_prefix'): # Check to see if we are in a virtualenv + # If we are, assemble the path manually + cmd_path = os.path.abspath(os.path.join(sys.prefix, 'bin', 'sphinx-apidoc')) -# Documents to append as an appendix to all manuals. -#latex_appendices = [] + options = [ + '-o', apidoc_dir, package_dir, + '--private', + '--force', + '--no-headings', + '--module-first', + '--no-toc', + '--maxdepth', '4', + ] -# If false, no module index is generated. -#latex_domain_indices = True + # See https://stackoverflow.com/a/30144019 + env = os.environ.copy() + env["SPHINX_APIDOC_OPTIONS"] = 'members,special-members,private-members,undoc-members,show-inheritance' + subprocess.check_call([cmd_path] + options, env=env) +def setup(app): + app.connect('builder-inited', run_apidoc) -# -- Options for manual page output --------------------------------------- + +# -- Options for manual page output ------------------------------------------ # One entry per manual page. List of tuples # (source start file, name, description, authors, manual section). man_pages = [ - ('index', 'plum', u'plum Documentation', - [u'Martin Uhrin'], 1) + (master_doc, 'plumpy', 'plumpy Documentation', + [author], 1) ] -# If true, show URL addresses after external links. -#man_show_urls = False - -# -- Options for Texinfo output ------------------------------------------- +# -- 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', 'plum', u'plum Documentation', - u'Martin Uhrin', 'plum', 'One line description of project.', - 'Miscellaneous'), + (master_doc, 'plumpy', 'plumpy Documentation', + author, 'plumpy', '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 +# -- Options for Epub output ------------------------------------------------- + +# Bibliographic Dublin Core info. +epub_title = project + +# The unique identifier of the text. This can be a ISBN number +# or the project homepage. +# +# epub_identifier = '' + +# A unique identification for the text. +# +# epub_uid = '' + +# A list of files that should not be packed into the epub file. +epub_exclude_files = ['search.html'] + + +# -- Extension configuration ------------------------------------------------- -# How to display URL addresses: 'footnote', 'no', or 'inline'. -#texinfo_show_urls = 'footnote' +# Warnings to ignore when using the -n (nitpicky) option +# We should ignore any python built-in exception, for instance +nitpick_ignore = [('py:class','Warning'), ('py:class', 'exceptions.Warning')] -# If true, do not generate a @detailmenu in the "Top" node's menu. -#texinfo_no_detailmenu = False +for line in open('nitpick-exceptions'): + if line.strip() == "" or line.startswith("#"): + continue + dtype, target = line.split(None, 1) + target = target.strip() + nitpick_ignore.append((dtype, target)) diff --git a/docs/source/gettingStarted/install.rst b/docs/source/gettingStarted/install.rst new file mode 100644 index 00000000..f7e90fc2 --- /dev/null +++ b/docs/source/gettingStarted/install.rst @@ -0,0 +1,54 @@ +.. _installation: + +.. highlight:: console + +Installation +============ + +This document describes how to prepare for and install plumpy. Note that plumpy better requires that the user use the package +inside of a Python `virtualenv`_. Instructions for installing and creating a Python virtual environment are provided +below. + +.. _virtualenv: https://virtualenv.pypa.io/en/stable/ + +Preparing Your Python Runtime Environment +----------------------------------------- + +Plumpy currently requires a virtualenv to be active to install. + +If not already present, please install the latest Python ``virtualenv`` using pip_:: + + $ sudo pip install virtualenv + +And create a virtual environment called ``venv`` in your home directory:: + + $ virtualenv ~/venv + +.. _pip: https://pip.readthedocs.io/en/latest/installing/ + +Now that you've created your virtualenv, activate your virtual environment:: + + $ source ~/venv/bin/activate + +Basic Installation +------------------ + + $ pip install plumpy + +Now you're ready to run :ref:`your first plumpy process and workchain `! + +Building from Source +-------------------- + +If developing with plumpy, you will need to build from source. This allows changes you +make to plumpy to be reflected immediately in your runtime environment. + +First, clone the source:: + + $ git clone https://github.com/aiidateam/plumpy.git + +Then, create and activate a virtualenv:: + + $ virtualenv venv + $ . venv/bin/activate + $ pip install "plumpy[dev,docs]" diff --git a/docs/source/gettingStarted/quickStart.rst b/docs/source/gettingStarted/quickStart.rst new file mode 100644 index 00000000..a5bab5db --- /dev/null +++ b/docs/source/gettingStarted/quickStart.rst @@ -0,0 +1,41 @@ +.. _quickstart: + +Quickstart Examples +=================== + +Creating and running basis Process +------------------------------------ + +A Plumpy process can be create and run with: + +1. Copy and paste the following code block into a new file called ``helloWorld.py``: + +.. literalinclude:: ../../../examples/process_helloworld.py + +2. run the process:: + + (venv) $ python helloWorld.py + +Process can wait, pause, play and resume +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +The example below shows how process state transition with different action: + +.. literalinclude:: ../../../examples/process_waitAndResume.py + +Remote controled process +~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +process start. + +script to kill that process + +Creating and running basis WorkChain +-------------------------------------- + +The WorkChain is a special process that can strung different small function +together into a independent process. + +See the example below: + +.. literalinclude:: ../../../examples/workchain_simple.py diff --git a/docs/source/index.rst b/docs/source/index.rst index 2773fd48..a4f18f89 100644 --- a/docs/source/index.rst +++ b/docs/source/index.rst @@ -1,24 +1,56 @@ -.. plum documentation master file, created by - sphinx-quickstart on Fri Dec 9 09:51:36 2016. +.. plumpy documentation master file, created by + sphinx-quickstart on Tue May 14 13:41:41 2019. You can adapt this file completely to your liking, but it should at least contain the root `toctree` directive. -Welcome to plum's documentation! -================================ +Welcome to plumpy's documentation! +================================== -Contents: +A python workflows library that supports writing Processes with a well defined set of inputs and outputs that can be strung together. + +RabbitMQ is used to queue up, control and monitor running processes via the kiwipy library. + +Features: + +- Process can be remotely controlled by sending messages over RabbitMQ all from a simple interface +- Process can be saved between steps and continued later +- Optional explicit specification of inputs and outputs including their types, validation functions, help strings, etc. + + * To install plumpy follow the instructions in the :ref:`installation section` + * After you have successfully installed plumpy, you can find some tips in the :ref:`user guide section` to help you on your way + * The design concepts behind plumpy can be found in :ref:`concepts section` + * If you want to develop your process and workchain, you'll find :ref:`Develop Process section` and :ref:`Develop WorkChain section` useful. + * Use the complete :doc:`API reference`, the :ref:`modindex` or the :ref:`genindex` to find code you're looking for .. toctree:: + :caption: Getting Started :maxdepth: 2 - apidoc/modules.rst + gettingStarted/install + gettingStarted/quickStart +.. toctree:: + :caption: Basic + :maxdepth: 2 + basic/introduction + basic/concepts + basic/process + basic/workchain + +.. toctree:: + :caption: Advanced + :maxdepth: 2 + + advanced/process + advanced/workchain + advanced/plumpyAPIprocess + advanced/plumpyAPIworkchain + advanced/plumpyAPIfsm + apidoc/plumpy Indices and tables ================== * :ref:`genindex` -* :ref:`modindex` * :ref:`search` - diff --git a/docs/source/nitpick-exceptions b/docs/source/nitpick-exceptions new file mode 100644 index 00000000..d49c338f --- /dev/null +++ b/docs/source/nitpick-exceptions @@ -0,0 +1,44 @@ +py:class Exception +py:class ProcessState +py:class persistence.LoadSaveContext +py:class Bundle +py:class Process +py:class PersistedPickle +py:class StateMachine + +py:class kiwipy.Communicator +py:class kiwipy.Future + +py:class dict +py:class str +py:class object +py:class bool +py:class type +py:class tuple + +py:class builtins.dict + +py:obj str + +py:class logging.Logger +py:class enum.Enum +py:class typing.Optional +py:class typing.Tuple +py:class typing.Any +py:class typing.Callable +py:class ValidationError + +py:class plumpy.InterruptException +py:class plumpy.CancellableAction +py:class plumpy.process_states.Command +py:class plumpy.process_states.State +py:class plumpy.LoopCommunicator +py:class plumpy.ports.PortNamespace + +py:func save_instance_state +py:func load_instance_state + +py:class tornado.concurrent.Future +py:class tornado.ioloop.IOLoop + +py:class concurrent.futures._base.Error diff --git a/examples/process_helloworld.py b/examples/process_helloworld.py new file mode 100644 index 00000000..5dad69de --- /dev/null +++ b/examples/process_helloworld.py @@ -0,0 +1,28 @@ +import plumpy + +class HelloWorld(plumpy.Process): + + @classmethod + def define(cls, spec): + super(HelloWorld, cls).define(spec) + spec.input('name', default='World', required=True) + spec.output("greeting", valid_type=str) + + def run(self, **kwargs): + s = "Hello {:}!".format(self.inputs.name) + self.out("greeting", s) + return plumpy.Stop(None, True) + +if __name__ == "__main__": + p = HelloWorld(inputs={'name': 'foobar'}) + print("Process State: {:}".format(p.state)) + + p.execute() + + print("Process State: {:}".format(p.state)) + print("{:}".format(p.outputs['greeting'])) + + # default inputs + p = HelloWorld() + p.execute() + print("{:}".format(p.outputs['greeting'])) diff --git a/examples/process_waitAndResume.py b/examples/process_waitAndResume.py new file mode 100644 index 00000000..ba352d44 --- /dev/null +++ b/examples/process_waitAndResume.py @@ -0,0 +1,45 @@ +import plumpy +import threading +from kiwipy import rmq +from tornado import ioloop, gen + +class WaitForResumeProc(plumpy.Process): + + def run(self, **kwargs): + print("Now I am running: {:}".format(self.state)) + return plumpy.Wait(self.after_resume_and_exec) + + def after_resume_and_exec(self): + print("After resume from watting state: {:}".format(self.state)) + + +if __name__ == "__main__": + message_exchange = "{}.{}".format("WaitForResume", "uuid-0") + task_exchange = "{}.{}".format("WaitForResume", "uuid-0") + task_queue = "{}.{}".format("WaitForResume", "uuid-0") + + kwargs = { + 'connection_params': {'url': 'amqp://guest:guest@127.0.0.1:5672/'}, + 'message_exchange': message_exchange, + 'task_exchange': task_exchange, + 'task_queue': task_queue, + } + try: + with rmq.RmqThreadCommunicator.connect(**kwargs) as communicator: + proc = WaitForResumeProc(communicator=communicator) + process_controller = plumpy.RemoteProcessThreadController(communicator) + + status_future = process_controller.get_status(proc.pid) + print(status_future.result()) # pause: False + + process_controller.pause_process(proc.pid) + status_future = process_controller.get_status(proc.pid) + print(status_future.result()) # pause: True + + process_controller.play_process(proc.pid) + status_future = process_controller.get_status(proc.pid) + print(status_future.result()) # pause: False + + + except KeyboardInterrupt: + pass diff --git a/examples/workchain_simple.py b/examples/workchain_simple.py new file mode 100644 index 00000000..47a83d90 --- /dev/null +++ b/examples/workchain_simple.py @@ -0,0 +1,31 @@ +import plumpy + +class AddAndMulWF(plumpy.WorkChain): + + @classmethod + def define(cls, spec): + super(AddAndMulWF, cls).define(spec) + spec.input("ini", valid_type=float, default=1.0) + spec.input("add", valid_type=int, required=True) + spec.input("mul", valid_type=int,required=True) + spec.output("result", valid_type=float) + spec.outline( + cls.add, + cls.mul, + ) + + def add(self): + self.ctx.addresult = self.inputs.ini + self.inputs.add + + def mul(self): + r = self.ctx.addresult * self.inputs.mul + self.out("result", r) + + +if __name__ == "__main__": + wf = AddAndMulWF(inputs={"ini": 10.0, "add": 1, "mul": 2}) + wf.execute() + + print(wf.outputs["result"]) + # output: + # 22.0 diff --git a/plumpy/__init__.py b/plumpy/__init__.py index f2e68198..1d360344 100644 --- a/plumpy/__init__.py +++ b/plumpy/__init__.py @@ -18,7 +18,7 @@ from .workchains import * __all__ = (events.__all__ + exceptions.__all__ + processes.__all__ + utils.__all__ + futures.__all__ + mixins.__all__ + - persistence.__all__ + communications.__all__ + process_comms.__all__ + version.__all__, + persistence.__all__ + communications.__all__ + process_comms.__all__ + version.__all__ + process_listener.__all__ + workchains.__all__ + loaders.__all__ + ports.__all__ + process_states.__all__) diff --git a/plumpy/process_comms.py b/plumpy/process_comms.py index c053f558..cae09df8 100644 --- a/plumpy/process_comms.py +++ b/plumpy/process_comms.py @@ -448,21 +448,24 @@ class ProcessLauncher(object): # pylint: disable=useless-object-inheritance Takes incoming task messages and uses them to launch processes. Expected format of task: - For launch: - { - 'task': [LAUNCH_TASK] - 'process_class': [Process class to launch] - 'args': [tuple of positional args for process constructor] - 'kwargs': [dict of keyword args for process constructor]. - 'nowait': True or False - } - For continue - { - 'task': [CONTINUE_TASK] - 'pid': [Process ID] - 'nowait': True or False - } + For launch:: + + { + 'task': + 'process_class': + 'args': + 'kwargs': . + 'nowait': True or False + } + + For continue:: + + { + 'task': + 'pid': + 'nowait': True or False + } """ def __init__(self, loop=None, persister=None, load_context=None, loader=None): diff --git a/plumpy/processes.py b/plumpy/processes.py index f2876496..aa728bd0 100644 --- a/plumpy/processes.py +++ b/plumpy/processes.py @@ -109,20 +109,20 @@ class Process(StateMachine, persistence.Savable): :: - ___ - | v - CREATED --- RUNNING --- FINISHED (o) - | ^ / - v | / - WAITING-- - | ^ - ---- - - - * -- EXCEPTED (o) - * -- KILLED (o) - - * = any non terminal state + ___ + | v + CREATED (x) --- RUNNING (x) --- FINISHED (o) + | ^ / + v | / + WAITING (x) -- + | ^ + --- + + * -- EXCEPTED (o) + * -- KILLED (o) + + * (o): terminal state + * (x): non terminal state When a Process enters a state is always gets a corresponding message, e.g. on entering RUNNING it will receive the on_run message. These are diff --git a/plumpy/workchains.py b/plumpy/workchains.py index 79bdc649..c0f10a67 100644 --- a/plumpy/workchains.py +++ b/plumpy/workchains.py @@ -657,7 +657,7 @@ def while_(condition): return_ ) -or +or:: if_(cls.conditional)( return_(EXIT_CODE) diff --git a/setup.py b/setup.py index cc0ca426..1d5e767d 100644 --- a/setup.py +++ b/setup.py @@ -52,7 +52,13 @@ 'prospector', 'pylint<2; python_version<"3"', 'pylint; python_version>="3"', - ] + ], + "docs": [ + "Sphinx==1.8.4", + "Pygments==2.3.1", + "docutils==0.14", + "sphinx-rtd-theme==0.4.3", + ], }, packages=['plumpy', 'plumpy/base'], test_suite='test')