javiche
================
<!-- WARNING: THIS FILE WAS AUTOGENERATED! DO NOT EDIT! -->
Small package to enable using ceviche with a JAX optimizer easily.
## Install
*This package is not yet published. As soon as it is install with:*
``` sh
pip install javiche
```
or
``` sh
conda install javiche
```
## How to use
Import the decorator
``` python
from javiche import jaxit
```
decorate your function (will be differentiated using ceviches jacobian
-\> HIPS autograd)
``` python
@jaxit()
def square(A):
"""squares number/array"""
return A**2
```
Now you can use jax as usual:
``` python
grad_fn = jax.grad(square)
```
``` python
grad_fn(2.0)
```
Array(4., dtype=float32, weak_type=True)
In this toy example that was already possible without the `jaxit()`
decorator. However `jaxit()` decorated functions can contain autograd
operators (but no jax operators):
``` python
import autograd.numpy as npa
```
``` python
def sin(A):
"""computes sin of number/array using autograds numpy"""
return npa.sin(A)
```
``` python
grad_sin = jax.grad(sin)
try:
print(grad_sin(0.0))
except Exception as e:
print(e)
```
The numpy.ndarray conversion method __array__() was called on the JAX Tracer object Traced<ConcreteArray(0.0, dtype=float32, weak_type=True)>with<JVPTrace(level=2/0)> with
primal = 0.0
tangent = Traced<ShapedArray(float32[], weak_type=True)>with<JaxprTrace(level=1/0)> with
pval = (ShapedArray(float32[], weak_type=True), None)
recipe = LambdaBinding()
See https://jax.readthedocs.io/en/latest/errors.html#jax.errors.TracerArrayConversionError
``` python
@jaxit()
def cos(A):
"""computes sin of number/array using autograds numpy"""
return npa.cos(A)
grad_cos = jax.grad(cos)
try:
print(grad_cos(0.0))
except Exception as e:
print(e)
```
-0.0
## Usecase
This library is intended for use with ceviche, while running a JAX
optimization stack as demonstated in the [inverse design
example](03_test_inverse_design.ipynb)
Raw data
{
"_id": null,
"home_page": "https://github.com/Jan-David-Black/javiche",
"name": "javiche",
"maintainer": "",
"docs_url": null,
"requires_python": ">=3.7",
"maintainer_email": "",
"keywords": "nbdev jupyter notebook python ceviche fdtd inverse-design",
"author": "Jan David Fischbach",
"author_email": "jan-david.fischbach@blacksemicon.de",
"download_url": "https://files.pythonhosted.org/packages/55/2e/2f9b5a30129894743ea116982a4d1984ba09e2d6d5d5ad24ededea1355d5/javiche-0.0.6.tar.gz",
"platform": null,
"description": "javiche\n================\n\n<!-- WARNING: THIS FILE WAS AUTOGENERATED! DO NOT EDIT! -->\n\nSmall package to enable using ceviche with a JAX optimizer easily.\n\n## Install\n\n*This package is not yet published. As soon as it is install with:*\n\n``` sh\npip install javiche\n```\n\nor\n\n``` sh\nconda install javiche\n```\n\n## How to use\n\nImport the decorator\n\n``` python\nfrom javiche import jaxit\n```\n\ndecorate your function (will be differentiated using ceviches jacobian\n-\\> HIPS autograd)\n\n``` python\n@jaxit()\ndef square(A):\n \"\"\"squares number/array\"\"\"\n return A**2\n```\n\nNow you can use jax as usual:\n\n``` python\ngrad_fn = jax.grad(square)\n```\n\n``` python\ngrad_fn(2.0)\n```\n\n Array(4., dtype=float32, weak_type=True)\n\nIn this toy example that was already possible without the `jaxit()`\ndecorator. However `jaxit()` decorated functions can contain autograd\noperators (but no jax operators):\n\n``` python\nimport autograd.numpy as npa\n```\n\n``` python\ndef sin(A):\n \"\"\"computes sin of number/array using autograds numpy\"\"\"\n return npa.sin(A)\n```\n\n``` python\ngrad_sin = jax.grad(sin)\ntry:\n print(grad_sin(0.0))\nexcept Exception as e:\n print(e)\n```\n\n The numpy.ndarray conversion method __array__() was called on the JAX Tracer object Traced<ConcreteArray(0.0, dtype=float32, weak_type=True)>with<JVPTrace(level=2/0)> with\n primal = 0.0\n tangent = Traced<ShapedArray(float32[], weak_type=True)>with<JaxprTrace(level=1/0)> with\n pval = (ShapedArray(float32[], weak_type=True), None)\n recipe = LambdaBinding()\n See https://jax.readthedocs.io/en/latest/errors.html#jax.errors.TracerArrayConversionError\n\n``` python\n@jaxit()\ndef cos(A):\n \"\"\"computes sin of number/array using autograds numpy\"\"\"\n return npa.cos(A)\n\ngrad_cos = jax.grad(cos)\ntry:\n print(grad_cos(0.0))\nexcept Exception as e:\n print(e)\n```\n\n -0.0\n\n## Usecase\n\nThis library is intended for use with ceviche, while running a JAX\noptimization stack as demonstated in the [inverse design\nexample](03_test_inverse_design.ipynb)\n",
"bugtrack_url": null,
"license": "Apache Software License 2.0",
"summary": "A JAX wrapper around ceviche to make interoperability easier. In the future it might make sense to update ceviche itself to use JAX internally.",
"version": "0.0.6",
"split_keywords": [
"nbdev",
"jupyter",
"notebook",
"python",
"ceviche",
"fdtd",
"inverse-design"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "1f1fadd69e214fcef83cd74aaf10ded79a9e367ed551c5a8732e665809c8ee60",
"md5": "d874ce8c1a5e07e8c0cb7f75f0461723",
"sha256": "79b29842e01c0befe13e10e2c262a5454525f843160fb7f15b4d8e155cbc90bd"
},
"downloads": -1,
"filename": "javiche-0.0.6-py3-none-any.whl",
"has_sig": false,
"md5_digest": "d874ce8c1a5e07e8c0cb7f75f0461723",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.7",
"size": 9884,
"upload_time": "2023-02-09T23:44:49",
"upload_time_iso_8601": "2023-02-09T23:44:49.086648Z",
"url": "https://files.pythonhosted.org/packages/1f/1f/add69e214fcef83cd74aaf10ded79a9e367ed551c5a8732e665809c8ee60/javiche-0.0.6-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "552e2f9b5a30129894743ea116982a4d1984ba09e2d6d5d5ad24ededea1355d5",
"md5": "24a29b8421a963144ca0d3dac979ee21",
"sha256": "b429dbbede453ef3bd5d0b5fb52fb516bb3e5c3249fbc4b8a8cd15280974bc4f"
},
"downloads": -1,
"filename": "javiche-0.0.6.tar.gz",
"has_sig": false,
"md5_digest": "24a29b8421a963144ca0d3dac979ee21",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.7",
"size": 10083,
"upload_time": "2023-02-09T23:44:51",
"upload_time_iso_8601": "2023-02-09T23:44:51.020106Z",
"url": "https://files.pythonhosted.org/packages/55/2e/2f9b5a30129894743ea116982a4d1984ba09e2d6d5d5ad24ededea1355d5/javiche-0.0.6.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2023-02-09 23:44:51",
"github": true,
"gitlab": false,
"bitbucket": false,
"github_user": "Jan-David-Black",
"github_project": "javiche",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"lcname": "javiche"
}