question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Feature request: Support python control flow in `custom_transforms` functions

See original GitHub issue

For fitting parameter values for ODEs a la the adjoint sensitivity method, we might want to override the gradient computation for the forward ODE solve. More concretely, we might have an integrator function odeint that takes in a gradient field f, initial state y0, and a sequence of times ts to be evaluated at.

One specific use case where supporting control-flow in custom_transforms will be useful is for the backward integration (which might involve adaptive solvers, hence non-trivial control-flow). Ideally, we would like to write code as follows

@custom_transforms
def odeint(y0, ts):
  pass  # Some procedure integrating the vector field `f`.

def vjp_y0(g, ans, y0, ts):
  pass # A while loop and some if statements used to determine integration step size.

defvjp(odeint, vjp_y0, None)

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

5reactions
mattjjcommented, Nov 4, 2019

We’re working on this. The reason it isn’t as simple as it was for Autograd is that JAX uses a new autodiff design in which we only have forward mode and derive reverse mode automatically (composing forward mode with other transformations). That confers several advantages, but a disadvantage is that since the system itself doesn’t work in terms of VJPs, supporting custom VJPs is tricky. (You can write custom JVPs, ie forward-mode rules, with arbitrary Python control flow now.)

3reactions
mattjjcommented, Mar 22, 2020

#2026 finally landed and added support for Python control flow in custom derivative rules! (The API also changed, so take a look at the tutorial notebook.)

Read more comments on GitHub >

github_iconTop Results From Across the Web

PEP 42 – Feature Requests - Python Enhancement Proposals
Introduction. This PEP contains a list of feature requests that may be considered for future versions of Python. Large feature requests should ...
Read more >
Python's Requests Library (Guide)
In this tutorial on Python's "requests" library, you'll see some of the most useful features that requests has to offer as well as...
Read more >
Advanced Usage — Requests 2.28.1 documentation
This document covers some of Requests more advanced features. Session Objects¶. The Session object allows you to persist certain parameters across requests. It ......
Read more >
Custom Transforms in Lab Automation
Custom Transforms are a way to inject arbitrary logic into Lab Automation's processing pipeline. The user will upload a file to a Run's...
Read more >
Creating a Custom Data Transformer using Scikit-Learn
In this article, we will learn how to build the custom data transformers using Scikit-Learn and look at an example to implement the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found