Skip to content

dsl: Fix up functions on subdomains staggered derivs and cross derivs with halo=0 - #3103

Open
EdCaunt wants to merge 6 commits into
mainfrom
subdomain-xderiv
Open

EdCaunt wants to merge 6 commits into
mainfrom
subdomain-xderiv

Conversation

@EdCaunt

@EdCaunt EdCaunt commented Nov 4, 2026

Copy link
Copy Markdown
Contributor

No description provided.

@EdCaunt
EdCaunt requested a review from mloubout November 4, 2026 12:24
Comment thread tests/test_subdomains.py Outdated
Eq(gd, Derivative(g, d), subdomain=mid)])()

assert np.any(fd.data != 0)
assert np.allclose(fd.data, gd.data)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At least with so 4, that shouldn't be the case, g.dx reaches into the zeros of g where f isn't zero so they should have different values.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But f is defined on the subdomain, so it will be reaching into the zeros for both f and g no?

Comment thread tests/test_subdomains.py Resolved
Comment thread devito/finite_differences/tools.py Outdated
# Evaluation point relative to the expression's grid, which may be indexed by a
# SubDimension of `dim` (e.g., a Function on a SubDomain)
rel = x0 - expr.indices_ref[dim]
mid = rel.subs({**{i: 0 for i in rel.free_symbols

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Going through free_symbols seems quite brutal just to handle subdims. Also not sure why it just pops up now SubDimension work fine.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agree that this seems quite brutal. Took half a look at fixing before I got distracted. I was surprised by this one as well, but the test below definitely fails on current main with TypeError: Error while computing finite-difference for expr=f(ix, y): Cannot convert expression to float

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking at this more,rel.free_symbols is pretty tiny, so it's less bad than it looks. It seems the issue only appears when you have a staggered evaluation with a function on the grid on the LHS and a function on a subdomain on the RHS

@EdCaunt EdCaunt Nov 4, 2026 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Digging into this did lead me to a bug - it looks like staggered=x gets dropped on the floor for functions on subdomains (you need to use staggered=ix instead, but this isn't necessarily intuitive). Patching currently so that staggering gets normalised

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I mean this just seems to be that indices_ref returns the subdim instead of the root dim

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, it does, but seems to me to be what it should intuitively return? However, x0 should probably be normalised to match the dimensions of the expression

@codecov

codecov Bot commented Nov 4, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 84.50%. Comparing base (f7350b6) to head (c804e06).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3103      +/-   ##
==========================================
- Coverage   84.51%   84.50%   -0.02%     
==========================================
  Files         260      260              
  Lines       58493    58533      +40     
  Branches     4962     4963       +1     
==========================================
+ Hits        49438    49461      +23     
- Misses       8226     8242      +16     
- Partials      829      830       +1     
Flag Coverage Δ
pytest-gpu-aomp-amdgpuX 68.43% <66.66%> (+<0.01%) ⬆️
pytest-gpu-gcc- 79.23% <100.00%> (-0.01%) ⬇️
pytest-gpu-icx- 79.16% <100.00%> (+<0.01%) ⬆️
pytest-gpu-nvc-nvidiaX 69.11% <66.66%> (-0.01%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Comment thread devito/types/dense.py Resolved
@mloubout mloubout added the API api (symbolics, types, ...) label Nov 5, 2026
Comment thread devito/finite_differences/tools.py Outdated

# Express `x0` in the same Dimension as the indices, or the FD weights retain
# e.g. `iy - y` and are not reduced to numbers
x0 = expr.indices_ref[dim] + mid * dim.spacing

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Modifying x0 like that seems quite dangerous

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed. Fixing

@EdCaunt
EdCaunt requested a review from mloubout November 6, 2026 13:14
@mloubout

mloubout commented Nov 7, 2026

Copy link
Copy Markdown
Contributor

Rebase and gtg

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

API api (symbolics, types, ...)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants