Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add docs #35

Merged
merged 10 commits into from
Feb 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
93 changes: 93 additions & 0 deletions .github/workflows/build-docs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
name: Build mkl_random documentation
on:
pull_request:
push:
branches: [master]

permissions: read-all

jobs:
build-and-deploy:
name: Build and Deploy Documentation
runs-on: ubuntu-latest
permissions:
contents: write
pull-requests: write
steps:
- name: Cancel Previous Runs
uses: styfle/[email protected]
with:
access_token: ${{ github.token }}
- name: Add Intel repository
if: ${{ !github.event.pull_request || github.event.action != 'closed' }}
run: |
wget https://apt.repos.intel.com/intel-gpg-keys/GPG-PUB-KEY-INTEL-SW-PRODUCTS-2023.PUB
sudo apt-key add GPG-PUB-KEY-INTEL-SW-PRODUCTS-2023.PUB
rm GPG-PUB-KEY-INTEL-SW-PRODUCTS-2023.PUB
sudo add-apt-repository "deb https://apt.repos.intel.com/oneapi all main"
sudo apt-get update
- name: Install Intel OneAPI
if: ${{ !github.event.pull_request || github.event.action != 'closed' }}
run: |
sudo apt-get install intel-oneapi-compiler-dpcpp-cpp intel-oneapi-mkl-devel
- name: Setup Python
if: ${{ !github.event.pull_request || github.event.action != 'closed' }}
uses: actions/setup-python@v5
with:
python-version: '3.11'
architecture: x64
- name: Install sphinx dependencies
if: ${{ !github.event.pull_request || github.event.action != 'closed' }}
shell: bash -l {0}
run: |
pip install numpy cython setuptools scikit-build cmake sphinx sphinx_rtd_theme furo pydot graphviz sphinxcontrib-programoutput sphinxcontrib-googleanalytics sphinx_design
- name: Checkout repo
uses: actions/[email protected]
with:
fetch-depth: 0
persist-credentials: false
- name: Build mkl_random+docs
if: ${{ !github.event.pull_request || github.event.action != 'closed' }}
shell: bash -l {0}
run: |
# Ensure that SYCL libraries are on LD_LIBRARY_PATH
source /opt/intel/oneapi/setvars.sh
python setup.py develop
python -c "import mkl_random; print(mkl_random.__version__)" || exit 1
sphinx-build -M html docs/source docs/build
mkdir -p ~/rendered_docs
cp -r docs/build/html/* ~/rendered_docs/
git clean -dfx
- name: Save built docs as an artifact
if: ${{ github.event.pull_request && github.event.action != 'closed'}}
uses: actions/upload-artifact@v4
with:
name: ${{ env.PACKAGE_NAME }} rendered documentation
path: ~/rendered_docs
- name: Configure git
if: ${{ !github.event.pull_request && github.event.action != 'closed'}}
run: |
git config --local user.email "[email protected]"
git config --local user.name "mkl_random-doc-bot"
timeout-minutes: 5
- name: Checkout gh-pages
if: ${{ !github.event.pull_request && github.event.action != 'closed'}}
run: |
git fetch --all
git checkout gh-pages
- name: 'Copy build to root'
if: ${{ !github.event.pull_request && github.event.action != 'closed'}}
run: |
cp -R ~/rendered_docs/* .
timeout-minutes: 10
- name: 'Commit changes'
if: ${{ !github.event.pull_request && github.event.action != 'closed'}}
run: |
git add . && git commit -m "Deploy: ${{ github.sha }}"
continue-on-error: true
timeout-minutes: 10
- name: Publish changes
if: ${{ success() && !github.event.pull_request && github.event.action != 'closed'}}
run: |
git push origin gh-pages
timeout-minutes: 10
7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
*~
build/
mkl_random/__pycache__/
mkl_random/tests/__pycache__/
mkl_random/mklrand.cpp
mkl_random/mklrand.cpython*.so
mkl_random.egg-info/
20 changes: 20 additions & 0 deletions docs/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Minimal 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
BUILDDIR = build

# Put it first so that "make" without argument is like "make help".
help:
@$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)

.PHONY: help Makefile

# 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)
35 changes: 35 additions & 0 deletions docs/make.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
@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
41 changes: 41 additions & 0 deletions docs/source/conf.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# Configuration file for the Sphinx documentation builder.
#
# For the full list of built-in configuration values, see the documentation:
# https://www.sphinx-doc.org/en/master/usage/configuration.html

# -- Project information -----------------------------------------------------
# https://www.sphinx-doc.org/en/master/usage/configuration.html#project-information

project = 'mkl_random'
copyright = '2017-2024, Intel Corp.'
author = 'Intel Corp.'
release = '1.2.5'

# -- General configuration ---------------------------------------------------
# https://www.sphinx-doc.org/en/master/usage/configuration.html#general-configuration

extensions = [
"sphinx.ext.autodoc",
"sphinx.ext.autosummary",
"sphinx.ext.coverage",
"sphinx.ext.extlinks",
"sphinx.ext.intersphinx",
"sphinx.ext.githubpages",
"sphinx.ext.napoleon",
"sphinx.ext.todo",
"sphinx.ext.viewcode",
"sphinxcontrib.programoutput",
# "sphinxcontrib.googleanalytics",
'sphinx_design',
]

templates_path = ['_templates']
exclude_patterns = []



# -- Options for HTML output -------------------------------------------------
# https://www.sphinx-doc.org/en/master/usage/configuration.html#options-for-html-output

html_theme = 'furo'
html_static_path = ['_static']
4 changes: 4 additions & 0 deletions docs/source/how_to.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
How-to Guides
=============

To be written.
73 changes: 73 additions & 0 deletions docs/source/index.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
Random sampling powered by Intel(R) Math Kernel Library
=======================================================

:mod:`mkl_random` is Python package exposing pseudo-random and non-deterministic random
number generators with continuous and discrete distribution available in
Intel(R) Math Kernel Library (MKL).

.. grid:: 2
:gutter: 3

.. grid-item-card:: Beginner Guides

New to :mod:`mkl_random`? Check out the Tutorials.
They are a hands-on introduction for beginners.

+++

.. button-ref:: tutorials
:expand:
:color: secondary
:click-parent:

To the beginner guides

.. grid-item-card:: User Guides

The user guides are recipes for key tasks and common problems.

+++

.. button-ref:: how_to
:expand:
:color: secondary
:click-parent:

To the user guides

.. grid-item-card:: Reference Guide

The reference guide contains a detailed description of class :class:`mkl_random.RandomState` and its methods.

+++

.. button-ref:: reference/index
:expand:
:color: secondary
:click-parent:

To the reference guide

.. grid-item-card:: Contributor Guides

Want to add to the codebase?
The contributing guidelines will guide you through the
process of improving :mod:`mkl_random`.

+++

.. button-ref:: maintenance/index
:expand:
:color: secondary
:click-parent:

To the contributor guides


.. toctree::
:hidden:

tutorials
how_to
reference/index
maintenance/index
50 changes: 50 additions & 0 deletions docs/source/maintenance/index.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
Contributing
============

:mod:`mkl_random` is an free and open source project.
We welcome and appreciate your contributions.

To contribute, fork the repo https://github.com/IntelPython/mkl_random.git,
clone it:

.. code-block::
:caption: How to clone the repo

git clone https://github.com/<fork-org>/mkl_random.git


A working compiler is needed build :mod:`mkl_random`.
Both Gnu :code:`g++` and Intel LLVM :code:`icpx` are supported.

Make sure to install Python packages required to build :mod:`mkl_random`:

* :mod:`python`
* :mod:`numpy`
* :mod:`cython`
* :mod:`setuptools`

You would also need Intel(R) MKL library and its headers. Set :code:`MKLROOT` environment
variable so that :code:`${MKLROOT}/include/mkl.h` and :code:`${MKLROOT}/lib/libmkl_rt.so`
can be found.

.. code-block:: bash
:caption: Building mkl_random

$ export MKLROOT=</path/to/mkl>
python setup.py develop

To run test suite, install :mod:`pytest`, and run

.. code-block:: bash
:caption: Running mkl_random test suite

python -m pytest mkl_random/tests

To build documentation, install dependencies and running

.. code-block:: bash
:caption: Building mkl_random documentation

$ sphinx-build -M html docs/source docs/build

Rendered documentation can be found in "docs/build/html".
7 changes: 7 additions & 0 deletions docs/source/reference/api.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
.. _fullapi:

Class RandomState
=================

.. autoclass:: mkl_random.RandomState
:members:
37 changes: 37 additions & 0 deletions docs/source/reference/ars5.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
ARS5 brng
=========

The ARS5 counter-based pseudorandom number generator based on AES encryption algorithm can be
initialized with either an integral seed, a list of integral seeds, or automatically.

.. code-block:: python
:caption: Construction for ARS5 basic random number generator with scalar seed

import mkl_random
rs = mkl_random.RandomState(1234, brng="ars5")

# Use random state instance to generate 1000 random numbers from
# Uniform(0, 1) distribution
esample = rs.uniform(0, 1, size=1000)

.. code-block:: python
:caption: Construction for ARS5 basic random number generator with vector seed

import mkl_random
rs_vec = mkl_random.RandomState([1234, 567, 89, 0], brng="ars5")

# Use random state instance to generate 1000 random numbers from
# Gamma(3, 1) distibution
gsample = rs_vec.gamma(3, 1, size=1000)

When seed is not specified, the generator is initialized using system clock, e.g.:

.. code-block:: python
:caption: Construction for ARS5 basic random number generator automatic seed

import mkl_random
rs_def = mkl_random.RandomState(brng="ars5")

# Use random state instance to generate 1000 random numbers
# from discrete uniform distribution [1, 6]
isample = rs_def.randint(1, 6 + 1, size=1000)
Loading