Skip to content

Commit d6d8cfb

Browse files
alxmrsclaude
andcommitted
Differentiate grad() as a SQL rewrite, dropping the Substrait bridge
Make grad()/jvp()/vjp() work inside any query shape (recursive CTEs, DML, subqueries) by rewriting the calls as SQL text before planning, rather than round-tripping the logical plan through Substrait (which could not represent those shapes). Closes the gap tracked in #197. XarrayContext.sql() now hands a query containing a marker to the native rewrite_grad_sql, which parses the statement with sqlparser, differentiates each marker call with the existing engine, and renders the derivative back into the SQL in place. Because it runs before planning, every query shape the parser accepts is supported, and the result is ordinary SQL the stock datafusion-python context plans and executes directly. This removes the Substrait round-trip entirely: the datafusion-substrait and prost dependencies, the grad_rewrite/_sql_with_autograd/_table_schemas plumbing, the marker-UDF registration, and the protoc steps in CI. Unlike the FFI alternative, it needs no datafusion fork and no custom datafusion-python wheel. The grad surface is unchanged (same SQL, same results); marker arguments use unqualified column names, matching existing usage, since differentiation is syntactic and runs before binding. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
1 parent 27c02d4 commit d6d8cfb

10 files changed

Lines changed: 257 additions & 543 deletions

File tree

.github/workflows/ci-build.yml

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,6 @@ jobs:
3131

3232
- uses: dtolnay/rust-toolchain@stable
3333

34-
# The `substrait` crate (a datafusion-substrait dependency) generates
35-
# code from .proto files at build time and requires protoc.
36-
- name: Install Protoc
37-
uses: arduino/setup-protoc@v3
38-
with:
39-
repo-token: ${{ secrets.GITHUB_TOKEN }}
40-
4134
- name: Setup sccache
4235
uses: mozilla-actions/sccache-action@v0.0.9
4336

.github/workflows/ci-rust.yml

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,6 @@ jobs:
2727
with:
2828
components: clippy
2929

30-
# The `substrait` crate (a datafusion-substrait dependency) generates
31-
# code from .proto files at build time and requires protoc.
32-
- name: Install Protoc
33-
uses: arduino/setup-protoc@v3
34-
with:
35-
repo-token: ${{ secrets.GITHUB_TOKEN }}
36-
3730
- name: Setup sccache
3831
uses: mozilla-actions/sccache-action@v0.0.9
3932

.github/workflows/ci.yml

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -43,13 +43,6 @@ jobs:
4343

4444
- uses: dtolnay/rust-toolchain@stable
4545

46-
# The `substrait` crate (a datafusion-substrait dependency) generates
47-
# code from .proto files at build time and requires protoc.
48-
- name: Install Protoc
49-
uses: arduino/setup-protoc@v3
50-
with:
51-
repo-token: ${{ secrets.GITHUB_TOKEN }}
52-
5346
- name: Setup sccache
5447
uses: mozilla-actions/sccache-action@v0.0.9
5548

.github/workflows/publish.yml

Lines changed: 0 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -54,13 +54,6 @@ jobs:
5454

5555
- uses: dtolnay/rust-toolchain@stable
5656

57-
# The `substrait` crate (a datafusion-substrait dependency) generates
58-
# code from .proto files at build time and requires protoc.
59-
- name: Install Protoc
60-
uses: arduino/setup-protoc@v3
61-
with:
62-
repo-token: ${{ secrets.GITHUB_TOKEN }}
63-
6457
- name: Setup sccache
6558
uses: mozilla-actions/sccache-action@v0.0.9
6659

@@ -98,18 +91,6 @@ jobs:
9891
manylinux: 2_28
9992
rustup-components: rust-std rustfmt
10093
sccache: 'true'
101-
# protoc is required by the substrait crate build and must be
102-
# installed inside the manylinux container.
103-
before-script-linux: |
104-
PROTOC_VERSION=29.3
105-
case "$(uname -m)" in
106-
x86_64) PROTOC_ARCH=x86_64 ;;
107-
aarch64) PROTOC_ARCH=aarch_64 ;;
108-
*) echo "unsupported arch $(uname -m)"; exit 1 ;;
109-
esac
110-
curl -L -o /tmp/protoc.zip "https://github.com/protocolbuffers/protobuf/releases/download/v${PROTOC_VERSION}/protoc-${PROTOC_VERSION}-linux-${PROTOC_ARCH}.zip"
111-
unzip -o /tmp/protoc.zip -d /usr/local bin/protoc 'include/*'
112-
protoc --version
11394
args: --release --strip --out dist -i python3.10 python3.11 python3.12 python3.13
11495

11596
- uses: actions/upload-artifact@v6
@@ -132,18 +113,6 @@ jobs:
132113
manylinux: 2_28
133114
rustup-components: rust-std rustfmt
134115
sccache: 'true'
135-
# protoc is required by the substrait crate build and must be
136-
# installed inside the manylinux container.
137-
before-script-linux: |
138-
PROTOC_VERSION=29.3
139-
case "$(uname -m)" in
140-
x86_64) PROTOC_ARCH=x86_64 ;;
141-
aarch64) PROTOC_ARCH=aarch_64 ;;
142-
*) echo "unsupported arch $(uname -m)"; exit 1 ;;
143-
esac
144-
curl -L -o /tmp/protoc.zip "https://github.com/protocolbuffers/protobuf/releases/download/v${PROTOC_VERSION}/protoc-${PROTOC_VERSION}-linux-${PROTOC_ARCH}.zip"
145-
unzip -o /tmp/protoc.zip -d /usr/local bin/protoc 'include/*'
146-
protoc --version
147116
args: --release --strip --out dist -i python3.10 python3.11 python3.12 python3.13
148117

149118
- uses: actions/upload-artifact@v6

0 commit comments

Comments
 (0)