Skip to content

Remove dummy_exchange_with_bound_dim#1177

Merged
msimberg merged 5 commits intomainfrom
copilot/deduplicate-dummy-exchange-definition
May 8, 2026
Merged

Remove dummy_exchange_with_bound_dim#1177
msimberg merged 5 commits intomainfrom
copilot/deduplicate-dummy-exchange-definition

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Mar 30, 2026

Instead just use the already existing SingleNodeExchange which is a noop. This also fixes the mismatch in function parameters where exchange: Callable[...] = single_node_exchange is wrong, with single_node_exchange not being the correct type of callable.

@jenkins-apn
Copy link
Copy Markdown

Hi there, this is jenkins continuous integration...
Do you want me to verify this patch?

1 similar comment
@jenkins-apn
Copy link
Copy Markdown

Hi there, this is jenkins continuous integration...
Do you want me to verify this patch?

Copilot AI linked an issue Mar 30, 2026 that may be closed by this pull request
…NodeExchange.exchange

Remove the standalone dummy_exchange_with_bound_dim function and replace it with
noop_exchange = functools.partial(single_node_default.exchange, dims.CellDim),
which relies on the exchange objects directly as suggested in the issue.
SingleNodeExchange.exchange is inherently a noop, making this a proper
replacement. Updated all 9 test files that referenced the old function.

Agent-Logs-Url: https://github.com/C2SM/icon4py/sessions/4b7a4e7b-4b0b-474f-b345-1d9cae17543d

Co-authored-by: jcanton <5622559+jcanton@users.noreply.github.com>
Copilot AI changed the title [WIP] Deduplicate dummy_exchange definition Replace dummy_exchange_with_bound_dim with noop derived from SingleNodeExchange Mar 30, 2026
Copilot AI requested a review from jcanton March 30, 2026 09:46
@havogt
Copy link
Copy Markdown
Contributor

havogt commented Apr 1, 2026

This change doesn't make sense...

@havogt
Copy link
Copy Markdown
Contributor

havogt commented Apr 1, 2026

But probably because I already did the deduplication in a previous PR and it didn't understand that there is nothing to do... Now it's more or less a rename but not for the better.

@msimberg
Copy link
Copy Markdown
Contributor

But probably because I already did the deduplication in a previous PR and it didn't understand that there is nothing to do... Now it's more or less a rename but not for the better.

Agree on the current changes not being an improvement. What I'd like to see is the dummy exchange removed, and all places where an exchange callable with a bound Dimension is expected be changed to that they take a plain ExchangeRuntime and the factory/whatever can supply the Dimension instead (I think it makes anyway more sense that the caller doesn't have to know which Dimension is going to get exchanged).

Probably even better: do #1136 first. If and only if there are still numpy functions that need to do the exchange internally, do the change I suggest above.

@msimberg
Copy link
Copy Markdown
Contributor

Work on #1136 is ongoing in #1195. Let's resolve that first before continuing here.

@msimberg msimberg changed the title Replace dummy_exchange_with_bound_dim with noop derived from SingleNodeExchange Remove dummy_exchange_with_bound_dim May 6, 2026
msimberg added 2 commits May 6, 2026 15:09
…ummy-exchange-definition

# Conflicts:
#	model/common/tests/common/grid/unit_tests/test_topography.py
#	model/common/tests/common/grid/unit_tests/test_vertical.py
#	model/common/tests/common/interpolation/unit_tests/test_interpolation_fields.py
#	model/common/tests/common/interpolation/unit_tests/test_rbf_interpolation.py
#	model/common/tests/common/metrics/unit_tests/test_compute_coeff_gradekin.py
#	model/common/tests/common/metrics/unit_tests/test_compute_weight_factors.py
#	model/common/tests/common/metrics/unit_tests/test_compute_zdiff_gradp.py
#	model/common/tests/common/metrics/unit_tests/test_metric_fields.py
@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 6, 2026

Mandatory Tests

Please make sure you run these tests via comment before you merge!

  • cscs-ci run default
  • cscs-ci run distributed

Optional Tests

To run benchmarks you can use:

  • cscs-ci run benchmark-bencher

To run tests and benchmarks with the DaCe backend you can use:

  • cscs-ci run dace

To run test levels ignored by the default test suite (mostly simple datatest for static fields computations) you can use:

  • cscs-ci run extra

For more detailed information please look at CI in the EXCLAIM universe.

@msimberg msimberg marked this pull request as ready for review May 6, 2026 15:27
@msimberg
Copy link
Copy Markdown
Contributor

msimberg commented May 7, 2026

cscs-ci run default

@msimberg
Copy link
Copy Markdown
Contributor

msimberg commented May 7, 2026

cscs-ci run distributed

n_edges: int,
nlev: int,
exchange: Callable[[data_alloc.NDArray], None],
exchange: decomposition.ExchangeRuntime,
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.

Can I know why only this one does not need the default single node exchange?

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 don't know the original reason, I just didn't want to change it.

But now that you bring this up, I'd probably remove the default in all the other cases as well?

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 commented above for another function which does nto have teh single exchange as default. Probably we didn't set it here because we missed it, but I do prefer that we set up the single node as default everywhere

Copy link
Copy Markdown
Contributor

@OngChia OngChia May 7, 2026

Choose a reason for hiding this comment

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

Hmm. I think that I will also vote for removing the default, because users should specify the exchange that they want to avoid unexpected results.

Copy link
Copy Markdown
Contributor

@msimberg msimberg May 7, 2026

Choose a reason for hiding this comment

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

I'd propose to not make that decision in this PR since that's orthogonal to the main purpose of this PR which is to remove the dummy_exchange helper. I'm happy to follow up with another PR based on what we discuss here.

I agree with @OngChia. Using the current "default" is almost always a mistake in user code. There the decision should be explicit. Additionally, having single node exchange as the default for convenience in tests is I think adding convenience for the wrong target audience. If one has to choose between a good API for users and a good API for testing/development, the good API for users should always have precedence. (If one can satisfy both that's even better, but I think in this case helping users avoid making the mistake of not specifying the type of exchange has precedence).

It should possibly not even be a choice which type of exchange to do. The SingleNodeExchange is IMO an implementation detail that exists to avoid loading mpi4py. GHEX will happily not do an exchange if there's only one rank. So I think we could do a better job abstracting this away. Additionally, I'm toying with the idea of passing a ProcessProps in places like this instead, which is in the end used to decide whether an exchange should be done. But these two last points are definitely not for now, let's focus on default/no default.

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.

@OngChia @nfarabullini are you ok with me resolving this comment? I'll open a separate PR for removing the default exchange and for the rest we need a bit more thinking...

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.

Yes, I agree. Let's do it in another PR.

horizontal_start: gtx.int32,
horizontal_start_1: gtx.int32,
exchange: Callable[[data_alloc.NDArray], None],
exchange: decomposition.ExchangeRuntime,
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.

this one too

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.

+1

Copy link
Copy Markdown
Contributor

@nfarabullini nfarabullini left a comment

Choose a reason for hiding this comment

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

I agree with the changes. I just left some comments here and there.

Comment thread model/common/src/icon4py/model/common/grid/vertical.py
n_edges: int,
nlev: int,
exchange: Callable[[data_alloc.NDArray], None],
exchange: decomposition.ExchangeRuntime,
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 commented above for another function which does nto have teh single exchange as default. Probably we didn't set it here because we missed it, but I do prefer that we set up the single node as default everywhere

horizontal_start: gtx.int32,
horizontal_start_1: gtx.int32,
exchange: Callable[[data_alloc.NDArray], None],
exchange: decomposition.ExchangeRuntime,
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.

+1

Comment thread model/testing/src/icon4py/model/testing/exchange_utils.py
@msimberg msimberg requested a review from OngChia May 7, 2026 14:30
@msimberg msimberg requested a review from nfarabullini May 7, 2026 14:30
@msimberg msimberg changed the title Remove dummy_exchange_with_bound_dim Remove dummy_exchange_with_bound_dim May 7, 2026
Copy link
Copy Markdown
Contributor

@OngChia OngChia left a comment

Choose a reason for hiding this comment

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

LGTM.

@msimberg msimberg merged commit c0649fa into main May 8, 2026
54 checks passed
@msimberg msimberg deleted the copilot/deduplicate-dummy-exchange-definition branch May 8, 2026 14:41
jcanton added a commit that referenced this pull request May 8, 2026
* main:
  Remove `dummy_exchange_with_bound_dim` (#1177)
  py2fgen: all_bindings generate .f90 and .c separately (#1253)
  Update Plottingscripts (#1239)
  Fix default nox sessions (#1243)
  Improve return code handling in py2fgen generated code (#1245)
jcanton added a commit that referenced this pull request May 8, 2026
* save_json_nml_serialization:
  pre-commit
  small review
  Remove `dummy_exchange_with_bound_dim` (#1177)
  py2fgen: all_bindings generate .f90 and .c separately (#1253)
  Update Plottingscripts (#1239)
  Fix default nox sessions (#1243)
  Improve return code handling in py2fgen generated code (#1245)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Deduplicate dummy_exchange definition

7 participants