Skip to content

Changing Argo float kernels to use boolean masking#2632

Merged
erikvansebille merged 3 commits into
Parcels-code:mainfrom
erikvansebille:argo_boolean_indexing
Jun 23, 2026
Merged

Changing Argo float kernels to use boolean masking#2632
erikvansebille merged 3 commits into
Parcels-code:mainfrom
erikvansebille:argo_boolean_indexing

Conversation

@erikvansebille

Copy link
Copy Markdown
Member

This PR changes the Kernels in the Argo tutorial to use boolean masking, which is easier to read than the np.where() clauses used before.

I'll create a script in the benchmarking repo so that we can test performance between the two types of vectorised if-statements (see also #2197)

Description

Checklist

AI Disclosure

  • This PR contains AI-generated content.
    • I have tested any AI-generated content in my PR.
    • I take responsibility for any AI-generated content in my PR.
    • Describe how you used it (e.g., by pasting your prompt):

Which is easier to read than the np.where() clauses used before

Performance can be tested in the benchmarking suite
@erikvansebille

Copy link
Copy Markdown
Member Author

To inform the difference between np.where() and boolean masking in this Kernel, I created Parcels-code/elphe-hackathon#11

Short summary: they are virtually the same speed. I therefore propose to change the tutorial to use this simpler/more-intuitive kernel

Below is the output for the (old) kernel using np.where(). cumtime is 0.229 seconds

(boolean_masking_profiling) erik ~/Codes/elphe-hackathon/boolean_masking_profiling % python argo_kernel_profiling.py --argo-kernel npwhere
/Users/erik/Codes/elphe-hackathon/boolean_masking_profiling/argo_kernel_profiling.py:9: UserWarning: This is an alpha version of Parcels v4. The API is not stable and may change without deprecation warnings.
  import parcels
INFO: Output files are stored in output_argo.parquet
Integration time: 2024-07-06T22:00:00 100%|█████████████████████████████████████████████████| [00:12<00:00, 40740.27it/s]
         8916903 function calls (8782721 primitive calls) in 16.386 seconds

   Random listing order was used
   List reduced from 4024 to 3 due to restriction <'run_simulation|particleset\\.py:\\d+\\(execute\\)|ArgoVerticalMovement'>

   ncalls  tottime  percall  cumtime  percall filename:lineno(function)
      576    0.043    0.000    0.229    0.000 /Users/erik/Codes/elphe-hackathon/boolean_masking_profiling/argo_kernel_profiling.py:34(ArgoVerticalMovement_npwhere)
      2/1    0.000    0.000   12.726   12.726 /Users/erik/Codes/elphe-hackathon/boolean_masking_profiling/argo_kernel_profiling.py:127(run_simulation)

And below is the output for the (new) kernel using boolean masking. cumtime is 0.227 seconds

(boolean_masking_profiling) erik ~/Codes/elphe-hackathon/boolean_masking_profiling % python argo_kernel_profiling.py --argo-kernel boolean
/Users/erik/Codes/elphe-hackathon/boolean_masking_profiling/argo_kernel_profiling.py:9: UserWarning: This is an alpha version of Parcels v4. The API is not stable and may change without deprecation warnings.
  import parcels
INFO: Output files are stored in output_argo.parquet
Integration time: 2024-07-06T22:00:00 100%|█████████████████████████████████████████████████| [00:12<00:00, 42156.98it/s]
         8964778 function calls (8830591 primitive calls) in 16.681 seconds

   Random listing order was used
   List reduced from 4026 to 3 due to restriction <'run_simulation|particleset\\.py:\\d+\\(execute\\)|ArgoVerticalMovement'>

   ncalls  tottime  percall  cumtime  percall filename:lineno(function)
      576    0.021    0.000    0.227    0.000 /Users/erik/Codes/elphe-hackathon/boolean_masking_profiling/argo_kernel_profiling.py:85(ArgoVerticalMovement_boolean)
      2/1    0.000    0.000   12.299   12.299 /Users/erik/Codes/elphe-hackathon/boolean_masking_profiling/argo_kernel_profiling.py:127(run_simulation)

@erikvansebille erikvansebille marked this pull request as ready for review June 19, 2026 12:34

@VeckoTheGecko VeckoTheGecko left a comment

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.

Looks good!

@erikvansebille erikvansebille enabled auto-merge (squash) June 23, 2026 16:21
@erikvansebille erikvansebille merged commit 6141a5b into Parcels-code:main Jun 23, 2026
15 of 16 checks passed
@github-project-automation github-project-automation Bot moved this from Backlog to Done in Parcels development Jun 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

2 participants