Skip to content

Commit

Permalink
Adding example for callbacks. Better documentation of callbacks.
Browse files Browse the repository at this point in the history
  • Loading branch information
Wrzlprmft committed Jun 27, 2020
1 parent 9adeb09 commit 2cebe2a
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
2 changes: 1 addition & 1 deletion docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ The following is a list of example scripts that may help you with specific probl

* `Simple Neutral <https://github.com/neurophysik/jitcdde/blob/master/examples/simple_neutral.py>`_ and `Neutral <https://github.com/neurophysik/jitcdde/blob/master/examples/simple_neutral.py>`_ show how to implement neutral DDES. The latter additionally shows how to optimise a DDE with many redundant delay requests, making it considerably faster.
* If you want to have input that cannot be expressed in a simple function, you can use `jitcdde_input <https://jitcdde.rtfd.io#input>`_ or use a callback (see the next point). `This example <https://github.com/neurophysik/jitcdde/blob/master/examples/input_data.py>`_ demonstrates how to use this.
* If you want to call a Python function within the derivative, use the `callback_functions` argument.
* If you want to call a Python function within the derivative, use the `callback_functions` argument. `This example <https://github.com/neurophysik/jitcdde/blob/master/examples/sunflower_callback.py>`_ demonstrates how to use this.

Command reference
-----------------
Expand Down
4 changes: 3 additions & 1 deletion jitcdde/_jitcdde.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,8 +157,10 @@ class jitcdde(jitcxde):
Python functions that should be called at integration time (callback) when evaluating the derivative. Each element of the iterable represents one callback function as a tuple containing (in that order):
* A SymEngine function object used in `f_sym` to represent the function call. If you want to use any JiTCDDE features that need the derivative, this must have a properly defined `f_diff` method with the derivative being another callback function (or constant).
* The Python function to be called. This function will receive the state array (`y`) as the first argument. All further arguments are whatever you use as arguments of the SymEngine function in `f_sym`. These must be floats. The return value must also be a float (or something castable to float). It is your responsibility to ensure that this function is deterministic and sufficiently smooth with respect to time and state.
* The Python function to be called. This function will receive the state array (`y`) as the first argument. All further arguments are whatever you use as arguments of the SymEngine function in `f_sym`. These can be any expression that you might use in the definition of the derivative and contain, e.g., dynamical variables (current or delayed), time, control parameters, and helpers. The only restriction is that the arguments are floats (and not vectors, anchors or similar). The return value must also be a float (or something castable to float). It is your responsibility to ensure that this function adheres to these criteria, is deterministic and sufficiently smooth with respect its arguments; expect nasty errors otherwise.
* The number of arguments, **excluding** the state array as mandatory first argument. This means if you have a variadic Python function, you cannot just call it with different numbers of arguments in `f_sym`, but you have to define separate callbacks for each of numer of arguments.
See `this example <https://github.com/neurophysik/jitcdde/blob/master/examples/sunflower_callback.py>`_ for how to use this.
verbose : boolean
Whether JiTCDDE shall give progress reports on the processing steps.
Expand Down

0 comments on commit 2cebe2a

Please sign in to comment.