Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

compiler: Nested indexification #1789

Merged
merged 1 commit into from
Nov 2, 2021
Merged

compiler: Nested indexification #1789

merged 1 commit into from
Nov 2, 2021

Conversation

mloubout
Copy link
Contributor

@mloubout mloubout commented Nov 1, 2021

Fxes bug that comes with the test (fails to compile on master since the functuion u1 only appear as an index and is never lowered and indexified)

@codecov
Copy link

codecov bot commented Nov 1, 2021

Codecov Report

Merging #1789 (aeff4ce) into master (2d76a50) will decrease coverage by 31.06%.
The diff coverage is 19.04%.

❗ Current head aeff4ce differs from pull request most recent head 7197f81. Consider uploading reports for the commit 7197f81 to get more accurate results
Impacted file tree graph

@@             Coverage Diff             @@
##           master    #1789       +/-   ##
===========================================
- Coverage   89.54%   58.48%   -31.07%     
===========================================
  Files         209      204        -5     
  Lines       34037    33504      -533     
  Branches     4417     4384       -33     
===========================================
- Hits        30480    19594    -10886     
- Misses       3062    13296    +10234     
- Partials      495      614      +119     
Impacted Files Coverage Δ
tests/test_operator.py 12.86% <5.55%> (-84.98%) ⬇️
devito/ir/equations/algorithms.py 96.15% <100.00%> (-3.85%) ⬇️
devito/types/basic.py 85.84% <100.00%> (-9.90%) ⬇️
tests/test_gpu_openmp.py 4.51% <0.00%> (-93.79%) ⬇️
tests/test_buffering.py 6.81% <0.00%> (-91.67%) ⬇️
examples/seismic/viscoacoustic/operators.py 8.43% <0.00%> (-91.57%) ⬇️
examples/seismic/self_adjoint/operators.py 9.23% <0.00%> (-90.77%) ⬇️
tests/test_dimension.py 9.74% <0.00%> (-90.26%) ⬇️
tests/test_fission.py 12.50% <0.00%> (-87.50%) ⬇️
tests/test_dse.py 12.81% <0.00%> (-86.98%) ⬇️
... and 135 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 2d76a50...7197f81. Read the comment docs.

Copy link
Contributor

@georgebisbas georgebisbas left a comment

Choose a reason for hiding this comment

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

In current master you can use directly
eq0 = Eq(u0[u1,y], 2*u0) to get what you want.
instead of subs(x,u1).
But I like adding this as well.

@mloubout
Copy link
Contributor Author

mloubout commented Nov 1, 2021

eq0 = Eq(u0[u1,y], 2*u0) well yeah but it's not very practical when you only care about the first dimension irrespective of the other ones or call subs on the equation directly to avoid multiple subs.

@georgebisbas
Copy link
Contributor

eq0 = Eq(u0[u1,y], 2*u0) well yeah but it's not very practical when you only care about the first dimension irrespective of the other ones or call subs on the equation directly to avoid multiple subs.

I definitely agree. Maybe we should add like a test or two with more complex Eq ?

u0.data[:, :] = 2
u1.data[:, :] = 1

eq0 = Eq(u0._subs(x, u1), 2*u0)
Copy link
Contributor

Choose a reason for hiding this comment

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

why not subs instead of _subs?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh it does the same just quicker through our _subs that bypass some sympy check and stuff, just habit can switch it.

@@ -160,6 +160,10 @@ def lower_exprs(expressions, **kwargs):
mapper.update(dimension_map)
# Add the user-supplied substitutions
mapper.update(subs)
# Apply mapper to itself for nested indexing
mapper = {k: uxreplace(v, mapper) if k.is_Function else v
Copy link
Contributor

Choose a reason for hiding this comment

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

does this work for doubly (or arbitrarily) nested Functions?

should this not become (somewhat) a recursive call?

going through the whole mapper here feels weird

Copy link
Contributor Author

Choose a reason for hiding this comment

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

should this not become (somewhat) a recursive call?

Yeah I think so this will only catch single recursion

@FabioLuporini FabioLuporini changed the title ir: make lower_expr apply the mapper to indices compiler: make lower_expr apply the mapper to indices Nov 1, 2021
@mloubout mloubout force-pushed the func-as-indw branch 3 times, most recently from e8f785b to bb9b307 Compare November 1, 2021 16:04
@mloubout mloubout changed the title compiler: make lower_expr apply the mapper to indices compiler: nested indexification Nov 1, 2021
@mloubout mloubout force-pushed the func-as-indw branch 9 times, most recently from 24f4e0f to 1b47f15 Compare November 1, 2021 21:20
@@ -1078,11 +1078,9 @@ def indexify(self, indices=None, lshift=False, subs=None):
subs = subs or {}
subs = [{**{d.spacing: 1, -d.spacing: -1}, **subs} for d in self.dimensions]

# Add halo shift
shift = self._size_nodomain.left if lshift else tuple([0]*len(self.dimensions))
Copy link
Contributor

Choose a reason for hiding this comment

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

uh? 😮

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Nested lower_expr takes care of it through the indexed part of it

Copy link
Contributor

Choose a reason for hiding this comment

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

awesome!

Copy link
Contributor

Choose a reason for hiding this comment

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

doesn't it apply to subs as well?

Copy link
Contributor Author

@mloubout mloubout Nov 2, 2021

Choose a reason for hiding this comment

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

No subs is needed because of sudomain dimension map in lower_expr, because f.indexe don't have a subdomain

Copy link
Contributor

@FabioLuporini FabioLuporini left a comment

Choose a reason for hiding this comment

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

this is a great change

does it improve or worsen the compilation speed? try with tti so=16?

@FabioLuporini FabioLuporini changed the title compiler: nested indexification compiler: Nested indexification Nov 2, 2021
@mloubout mloubout force-pushed the func-as-indw branch 2 times, most recently from 5167ad5 to 362ec77 Compare November 2, 2021 13:23
@review-notebook-app
Copy link

Check out this pull request on  ReviewNB

See visual diffs & provide feedback on Jupyter Notebooks.


Powered by ReviewNB

@mloubout mloubout force-pushed the func-as-indw branch 5 times, most recently from 44ffa85 to 7197f81 Compare November 2, 2021 15:59
Copy link
Contributor

@FabioLuporini FabioLuporini left a comment

Choose a reason for hiding this comment

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

Thanks, LGTM!

@@ -30,6 +30,7 @@
" import gempy as gp\n",
"except ModuleNotFoundError:\n",
" # Need to install these\n",
" ! pip install aiohttp==3.7.1\n",
Copy link
Contributor

Choose a reason for hiding this comment

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

how does that help?

Copy link
Contributor

Choose a reason for hiding this comment

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

Any chance you checked whether now, we can have working version without installing specific gempy and specific pyvista? @EdCaunt ?

@mloubout mloubout merged commit e264b12 into master Nov 2, 2021
@mloubout mloubout deleted the func-as-indw branch November 2, 2021 17:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants