Comments (2)
Thanks for noticing it, I forgot to update that! And I should make sure to throw a clearer error...
Fundamentally, the reason for that error is that an operator is expecting a keyword parameter called params
.
From the documentation of operator
:
Keyword arguments are defined after the *
in the function signature.
@operator
def my_operator(x: FourierSeries, *, dx: float, params=None):
...
The argument params
is mandatory and it must be a keyword argument. It is used to pass the parameters of the operator, for example the stencil coefficients of a finite difference operator.
The default value of the parameters is specified by the init_params
function, as follows:
def params_initializer(x, *, dx):
return {"stencil": jnp.ones(x.shape) * dx}
@operator(init_params=params_initializer)
def my_operator(x, *, dx, params=None):
b = params["stencil"] / dx
y_params = jnp.convolve(x.params, b, mode="same")
return x.replace_params(y_params)
The default value of params
is not considered during computation. If the operator has no parameters, the init_params
function can be omitted. In this case, the params
value is set to None
.
For constant parameters, the constants
function from jaxdf
can be used:
@operator(init_params=constants({"a": 1, "b": 2.0}))
def my_operator(x, *, params):
return x + params["a"] + params["b"]
For the readme example, the operator needs to be defined as
@operator
def custom_op(u, *, params=None):
grad_u = jops.gradient(u)
diag_jacobian = jops.diag_jacobian(grad_u)
laplacian = jops.sum_over_dims(diag_jacobian)
sin_u = jops.compose(u)(jnp.sin)
return laplacian + sin_u
I will change it in the README now 😄
from jaxdf.
Should be fixed now, but please feel free to reopen if that's not the case
from jaxdf.
Related Issues (15)
- Add named parameters HOT 1
- there are bug in tutorial example HOT 4
- Wrong results on the paper example HOT 1
- Throw a better error when `params` is missing from an operator HOT 1
- Consider moving to equinox modules HOT 1
- Upgrade to plum 2.0 HOT 1
- Code up some examples
- Make a wrapper to hide jaxdf computations
- API for Forwards, Backwards, Central Finite Difference HOT 2
- Simple "Difference" Operator HOT 1
- JVP for Continuous differential operators HOT 1
- Move `Domain.dx` to `OnGrid.dx`
- Remove old version.py HOT 1
- MPI FiniteDifferences
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from jaxdf.