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

api: Always make subsampling factor symbolic #2259

Merged
merged 1 commit into from
Nov 10, 2023
Merged

Conversation

mloubout
Copy link
Contributor

@mloubout mloubout commented Nov 6, 2023

Fix issue with overwrties with different factor

@mloubout mloubout added the API api (symbolics, types, ...) label Nov 6, 2023
Copy link

codecov bot commented Nov 6, 2023

Codecov Report

Merging #2259 (6c62e3a) into master (7c155e0) will increase coverage by 0.00%.
The diff coverage is 100.00%.

@@           Coverage Diff           @@
##           master    #2259   +/-   ##
=======================================
  Coverage   86.95%   86.95%           
=======================================
  Files         229      229           
  Lines       41939    41970   +31     
  Branches     7748     7752    +4     
=======================================
+ Hits        36466    36495   +29     
- Misses       4836     4838    +2     
  Partials      637      637           
Files Coverage Δ
devito/symbolics/extended_sympy.py 96.08% <100.00%> (ø)
devito/types/dense.py 93.88% <100.00%> (ø)
devito/types/dimension.py 92.29% <100.00%> (-0.19%) ⬇️
devito/types/grid.py 92.66% <100.00%> (ø)
tests/test_dimension.py 100.00% <100.00%> (ø)

@@ -793,8 +793,8 @@ def _arg_defaults(self, alias=None):
args = ReducerMap({key.name: self._data_buffer})

# Collect default dimension arguments from all indices
for i, s in zip(self.dimensions, self.shape):
args.update(i._arg_defaults(_min=0, size=s))
for a, i, s in zip(key.dimensions, self.dimensions, self.shape):
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@FabioLuporini quite surprised this never broke anything

Copy link
Contributor

Choose a reason for hiding this comment

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

I'm now confused.

Shouldn't it be key._data_buffer?
Shouldn't it be key.shape?

Might just be early morning sleepy brain

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No:

  • key/alias is the object and names used to build the operator, i.e the "key" of key-value pairs
  • self is the runtime argument with the runtime shapes/values/data/....

So you want to return the {key: self} key-pair values

Copy link
Contributor

Choose a reason for hiding this comment

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

ah yes you're right of course

@@ -793,8 +793,8 @@ def _arg_defaults(self, alias=None):
args = ReducerMap({key.name: self._data_buffer})

# Collect default dimension arguments from all indices
for i, s in zip(self.dimensions, self.shape):
args.update(i._arg_defaults(_min=0, size=s))
for a, i, s in zip(key.dimensions, self.dimensions, self.shape):
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm now confused.

Shouldn't it be key._data_buffer?
Shouldn't it be key.shape?

Might just be early morning sleepy brain

@@ -890,7 +900,7 @@ def _arg_defaults(self, _min=None, size=None, alias=None):
return defaults
try:
# Is it a symbolic factor?
factor = defaults[dim._factor.name] = dim._factor.data
factor = defaults[dim._factor.name] = self._factor.data
Copy link
Contributor

Choose a reason for hiding this comment

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

why?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

same as above, self is the runtime argument with the value for the operator, dim is the name of the dimension used to build the operator and argument name

@@ -848,13 +849,22 @@ def __init_finalize__(self, name, parent=None, factor=None, condition=None,

super().__init_finalize__(name, parent)

self._factor = factor
# Always make the factor symbolic to allow overrides with different factor.
Copy link
Contributor

Choose a reason for hiding this comment

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

We totally sure we don't want to leave this to the user?

Probably yes for the principle of least surprise right? the underlying issue is when you pass an override with a TimeFunction with a different factor -- correct?

A symbolic factor will make the generated code a bit more verbose (thinking about when it's used in tandem with lazy streaming), but yeah, it sounds safer...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think it's safer to make it symbolic. It makes it a little it more verbose yes but at the price of avoiding bad surprises.

@FabioLuporini FabioLuporini changed the title api: always make subsampling factor symbolic api: Always make subsampling factor symbolic Nov 7, 2023
self._factor = None
elif is_integer(factor):
self._factor = Constant(name="%sf" % name, value=factor, dtype=np.int32)
elif factor.is_Constant and is_integer(factor.data):
Copy link
Contributor

Choose a reason for hiding this comment

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

issubclass(factor, np.integer)

slightly cleaner

@@ -793,8 +793,8 @@ def _arg_defaults(self, alias=None):
args = ReducerMap({key.name: self._data_buffer})

# Collect default dimension arguments from all indices
for i, s in zip(self.dimensions, self.shape):
args.update(i._arg_defaults(_min=0, size=s))
for a, i, s in zip(key.dimensions, self.dimensions, self.shape):
Copy link
Contributor

Choose a reason for hiding this comment

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

ah yes you're right of course

@mloubout mloubout merged commit e707027 into master Nov 10, 2023
32 checks passed
@mloubout mloubout deleted the symbolic-factpr branch November 10, 2023 13:18
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