{ "info": { "author": "", "author_email": "", "bugtrack_url": null, "classifiers": [ "Development Status :: 3 - Alpha", "Intended Audience :: Developers", "Intended Audience :: Science/Research", "License :: OSI Approved :: BSD License", "Programming Language :: Python :: 3", "Programming Language :: Python :: 3.6", "Programming Language :: Python :: 3.7", "Programming Language :: Python :: 3 :: Only" ], "description": "[![Build Status](https://travis-ci.org/Quansight-Labs/python-moa.svg?branch=master)](https://travis-ci.org/Quansight-Labs/python-moa)\n[![Documentation Status](https://readthedocs.org/projects/python-moa/badge/?version=latest)](https://python-moa.readthedocs.io/en/latest/?badge=latest)\n[![Binder](https://mybinder.org/badge_logo.svg)](https://mybinder.org/v2/gh/Quansight-Labs/python-moa/master)\n\n\n# Mathematics of Arrays (MOA)\n\nMOA is a mathematically rigorous approach to dealing with arrays that\nwas developed by [Lenore\nMullins](https://www.albany.edu/ceas/lenore-mullin.php). MOA is guided\nby the following principles.\n\n1. Everything is an array and has a shape. Scalars. Vectors. NDArray.\n\n2. What is the shape of the computation at each step of the calculation?\n\nAnswering this guarentees no out of bounds indexing and a valid\nrunning program.\n\n3. What are the indicies and operations required to produce a given\n index in the result?\n\nOnce we have solved this step we have a minimal representation of the\ncomputation that has the [Church\nRosser](https://en.wikipedia.org/wiki/Church%E2%80%93Rosser_theorem)\nproperty. Allowing us to truely compare algorithms, analyze\nalgorithms, and finally map to algorithm to a low level\nimplementation. For further questions see the\n[documentation](https://python-moa.readthedocs.io/en/latest/?badge=latest). The\ndocumentation provides the theory, implementation details, and a\nguide.\n\nImportant questions that will guide development:\n\n - [X] Is a simple implementation of moa possible with only knowing the dimension?\n - [X] Can we represent complex operations and einsum math: requires `+red, transpose`?\n - [ ] What is the interface for arrays? (shape, indexing function)\n - [ ] How does one wrap pre-existing numerical routines?\n\n# Installation\n\n```shell\npip install python-moa\n```\n \n# Documentation\n\nDocumentation is available on\n[python-moa.readthedocs.org](https://python-moa.readthedocs.io/en/latest/?badge=latest). The\ndocumentation provides the theory, implementation details, and a\nguide for development and usage of `python-moa`.\n\n# Example\n\nA few well maintained jupyter notebooks are available for\nexperimentation with\n[binder](https://mybinder.org/v2/gh/Quansight-Labs/python-moa/master)\n\n## Python Frontend AST Generation\n\n```python\nfrom moa.frontend import LazyArray\n\nA = LazyArray(name='A', shape=(2, 3))\nB = LazyArray(name='B', shape=(2, 3))\n\nexpression = ((A + B).T)[0]\nexpression.visualize(as_text=True)\n```\n\n```\npsi(\u03a8)\n\u251c\u2500\u2500 Array _a2: <1> (0)\n\u2514\u2500\u2500 transpose(\u00d8)\n \u2514\u2500\u2500 +\n \u251c\u2500\u2500 Array A: <2 3>\n \u2514\u2500\u2500 Array B: <2 3>\n```\n\n## Shape Calculation\n\n```python\nexpression.visualize(stage='shape', as_text=True)\n```\n\n```\npsi(\u03a8): <2>\n\u251c\u2500\u2500 Array _a2: <1> (0)\n\u2514\u2500\u2500 transpose(\u00d8): <3 2>\n \u2514\u2500\u2500 +: <2 3>\n \u251c\u2500\u2500 Array A: <2 3>\n \u2514\u2500\u2500 Array B: <2 3>\n```\n\n## Reduction to DNF\n\n```python\nexpression.visualize(stage='dnf', as_text=True)\n```\n\n```\n+: <2>\n\u251c\u2500\u2500 psi(\u03a8): <2>\n\u2502 \u251c\u2500\u2500 Array _a6: <2> (_i3 0)\n\u2502 \u2514\u2500\u2500 Array A: <2 3>\n\u2514\u2500\u2500 psi(\u03a8): <2>\n \u251c\u2500\u2500 Array _a6: <2> (_i3 0)\n \u2514\u2500\u2500 Array B: <2 3>\n```\n\n## Reduction to ONF\n\n```python\nexpression.visualize(stage='onf', as_text=True)\n```\n\n```\nfunction: <2> (A B) -> _a17\n\u251c\u2500\u2500 if (not ((len(B.shape) == 2) and (len(A.shape) == 2)))\n\u2502 \u2514\u2500\u2500 error arguments have invalid dimension\n\u251c\u2500\u2500 if (not ((3 == B.shape[1]) and ((2 == B.shape[0]) and ((3 == A.shape[1]) and (2 == A.shape[0])))))\n\u2502 \u2514\u2500\u2500 error arguments have invalid shape\n\u251c\u2500\u2500 initialize: <2> _a17\n\u2514\u2500\u2500 loop: <2> _i3\n \u2514\u2500\u2500 assign: <2>\n \u251c\u2500\u2500 psi(\u03a8): <2>\n \u2502 \u251c\u2500\u2500 Array _a18: <1> (_i3)\n \u2502 \u2514\u2500\u2500 Array _a17: <2>\n \u2514\u2500\u2500 +: <2>\n \u251c\u2500\u2500 psi(\u03a8): <2>\n \u2502 \u251c\u2500\u2500 Array _a6: <2> (_i3 0)\n \u2502 \u2514\u2500\u2500 Array A: <2 3>\n \u2514\u2500\u2500 psi(\u03a8): <2>\n \u251c\u2500\u2500 Array _a6: <2> (_i3 0)\n \u2514\u2500\u2500 Array B: <2 3>\n```\n\n## Generate Python Source\n\n```python\nprint(expression.compile(backend='python', use_numba=True))\n```\n\n```python\n@numba.jit\ndef f(A, B):\n \n if (not ((len(B.shape) == 2) and (len(A.shape) == 2))):\n \n raise Exception('arguments have invalid dimension')\n \n if (not ((3 == B.shape[1]) and ((2 == B.shape[0]) and ((3 == A.shape[1]) and (2 == A.shape[0]))))):\n \n raise Exception('arguments have invalid shape')\n \n _a17 = numpy.zeros((2,))\n \n for _i3 in range(0, 2):\n \n _a17[(_i3,)] = (A[(_i3, 0)] + B[(_i3, 0)])\n return _a17\n```\n\n# Development\n\nDownload [nix](https://nixos.org/nix/download.html). No other\ndependencies and all builds will be identical on Linux and OSX.\n\n## Demoing\n\n`jupyter` environment\n\n```\nnix-shell dev.nix -A jupyter-shell\n```\n\n`ipython` environment\n\n```\nnix-shell dev.nix -A ipython-shell\n```\n\n## Testing\n\n```\nnix-build dev.nix -A python-moa\n```\n\nTo include benchmarks (numba, numpy, pytorch, tensorflow)\n\n```\nnix-build dev.nix -A python-moa --arg benchmark true\n```\n\n## Documentation\n\n```\nnix-build dev.nix -A docs\nfirefox result/index.html\n```\n\n## Docker\n\n```\nnix-build moa.nix -A docker\ndocker load < result\n```\n\n# Development Philosophy\n\nThis is a proof of concept which should be guided by assumptions and\ngoals.\n\n1. Assumes that dimension is each operation is known. This condition\n with not much work can be relaxed to knowing an upper bound.\n\n2. The MOA compiler is designed to be modular with clear separations:\n parsing, shape calculation, dnf reduction, onf reduction, and code\n generation.\n\n3. All code is written with the idea that the logic can ported to any\n low level language (C for example). This means no object oriented\n design and using simple data structures. Dictionaries should be the\n highest level data structure used.\n\n4. Performance is not a huge concern instead readability should be\n preferred. The goal of this code is to serve as documentation for\n beginners in MOA. Remember that tests are often great forms of\n documentation as well.\n\n5. Runtime dependencies should be avoided. Testing (pytest, hypothesis)\n and Visualization (graphviz) are examples of suitable exceptions.\n\n# Contributing\n\nContributions are welcome! For bug reports or requests please submit an issue.\n\n# Authors\n\nThe original author is [Christopher\nOstrouchov](https://github.com/costrouc). The funding that made this\nproject possible came from [Quansight\nLLC](https://www.quansight.com/).", "description_content_type": "text/markdown", "docs_url": null, "download_url": "", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/Quansight-Labs/python-moa", "keywords": "tensor,compiler,moa", "license": "BSD 3-Clause License (Revised)", "maintainer": "Christopher Ostrouchov", "maintainer_email": "costrouchov@quansight.com", "name": "python-moa", "package_url": "https://pypi.org/project/python-moa/", "platform": "", "project_url": "https://pypi.org/project/python-moa/", "project_urls": { "Bug Reports": "https://github.com/Quansight-Labs/python-moa/issues", "Documentation": "https://python-moa.readthedocs.io", "Homepage": "https://github.com/Quansight-Labs/python-moa", "Source": "https://github.com/Quansight-Labs/python-moa/sampleproject/" }, "release_url": "https://pypi.org/project/python-moa/0.5.1/", "requires_dist": null, "requires_python": ">=3.6", "summary": "Python Mathematics of Arrays (MOA)", "version": "0.5.1" }, "last_serial": 5134695, "releases": { "0.5.0": [ { "comment_text": "", "digests": { "md5": "a46023a928fdf24f3718d700babdefda", "sha256": "5167d5cff4d0b34efc94fecf9117e11f56e4ecb56567d292ad85c68011886eb0" }, "downloads": -1, "filename": "python-moa-0.5.0.tar.gz", "has_sig": false, "md5_digest": "a46023a928fdf24f3718d700babdefda", "packagetype": "sdist", "python_version": "source", "requires_python": ">=3.6", "size": 32640, "upload_time": "2019-04-11T21:42:20", "url": "https://files.pythonhosted.org/packages/b7/be/48317d5d1b34513c046e91391ed5d386af9f2427bcac357e77e359b4dd43/python-moa-0.5.0.tar.gz" } ], "0.5.1": [ { "comment_text": "", "digests": { "md5": "59cc94fea114d0914ab15e11760343c4", "sha256": "006c7477d6a507b62497fa18c2af46d56c85f83c0fa0e6f129e6fe673aa48c7a" }, "downloads": -1, "filename": "python-moa-0.5.1.tar.gz", "has_sig": false, "md5_digest": "59cc94fea114d0914ab15e11760343c4", "packagetype": "sdist", "python_version": "source", "requires_python": ">=3.6", "size": 33669, "upload_time": "2019-04-12T16:11:28", "url": "https://files.pythonhosted.org/packages/3b/cd/349176401c49ca749f3b2c6bc9523d4ce7486be5a6765979066bf1d582c4/python-moa-0.5.1.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "59cc94fea114d0914ab15e11760343c4", "sha256": "006c7477d6a507b62497fa18c2af46d56c85f83c0fa0e6f129e6fe673aa48c7a" }, "downloads": -1, "filename": "python-moa-0.5.1.tar.gz", "has_sig": false, "md5_digest": "59cc94fea114d0914ab15e11760343c4", "packagetype": "sdist", "python_version": "source", "requires_python": ">=3.6", "size": 33669, "upload_time": "2019-04-12T16:11:28", "url": "https://files.pythonhosted.org/packages/3b/cd/349176401c49ca749f3b2c6bc9523d4ce7486be5a6765979066bf1d582c4/python-moa-0.5.1.tar.gz" } ] }