Skip to content

Don't specialize on build, take 2 - #2652

Merged
visr merged 5 commits into
mainfrom
special-ice
Oct 20, 2025
Merged

visr merged 5 commits into
mainfrom
special-ice

Conversation

@visr

@visr visr commented Oct 17, 2025

Copy link
Copy Markdown
Member

Replaces #2643

@visr

visr commented Oct 18, 2025 •

Copy link
Copy Markdown
Member Author

Some stats. Currently we do FullSpecialize. I give the wall time , the time it takes ribasim.exe as reported in my shell, and the computation time as reported by Ribasim. The computation time often includes compilation for the first timestep, especially for FullSpecialize it seems.

# this small test model is in our precompilation workload, so not representative
basic FullSpecialize: 20s total, Computation time: 5 seconds
basic NoSpecialize: 2s total, Computation time: 42 milliseconds

# other small test model
tabulated_rating_curve_control FullSpecialize: 28s total, Computation time: 5 seconds
tabulated_rating_curve_control NoSpecialize: 10s total, Computation time: 21 milliseconds

# large 3100 node model
Noorderzijlvest_2025_10_3 FullSpecialize: 1m59s total, Computation time: 1 minute, 32 seconds
Noorderzijlvest_2025_10_3 NoSpecialize: 1m40s total, Computation time: 1 minute, 26 seconds

I'm somewhat surprised to see a speedup on NoSpecialize for all cases, even a large model. It could be that for the full LHM this will still go the other way but probably not by much.

For users working with small models the 28s to 10s speedup will be great, so I'm inclined to disable specialization. Rather than changing the setting we can also just rip out the Preferences setting specialize.

EDIT: this needs a better check, but it seems at LHM scale this does negatively affect performance of possibly up to 2x longer ETA. We could also add a solver option for this, and use NoSpecialize by default. We could also still check AutoSpecialize. And it might be wise to do these checks on top of #2624.

@evetion

evetion commented Oct 20, 2025 •

Copy link
Copy Markdown
Member

There's a finetuning option as well, most of the specialize time comes from introducing a chunk-like number (forgot the exact name), that is determined automatically based on the size of the problem. We could hardcode it for all/specific models? Would be good to print that number for different problem sizes.

Not sure if this is all that specialize influences, but this is the chunksize argument: https://github.com/Deltares/Ribasim/pull/2114/files#diff-50a3f887d6d4b8517e8faf1ceaddb02c23149fe7bf4b9199c8f56d52bed6c6f2R303

@visr

visr commented Oct 20, 2025

Copy link
Copy Markdown
Member Author

Yeah that is a good point. I don't have time to look into chunksizes right now, so we can keep the specialize argument to the solver which also controls the chunk size. I made a separate issue for chunksize.

@visr
visr force-pushed the special-ice branch 2 times, most recently from 4bb93c4 to 59efa04 Compare October 20, 2025 12:00
Replaces #2643

Make specialize configurable from TOML
@visr
visr marked this pull request as ready for review October 20, 2025 12:02
Comment thread core/test/docs.toml Outdated
sparse = true # optional, default true
autodiff = true # optional, default true
evaporate_mass = true # optional, default true to simulate a correct mass balance
specialize = false # optional, default true

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

= true

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Thanks, fixed. To be clear, the comment on the default was wrong.

Comment thread docs/reference/usage.qmd Outdated
The `evaporate_mass = true` setting determines whether mass is lost due to evaporation in water quality calculations, by default set to true.
While physically incorrect, it is useful for a first correctness check on a model in terms of mass balance (Continuity tracer should always have a concentration of 1). To simulate increasing concentrations (e.g. salinity) due to evaporation, change the setting to `false`.

Finally there's `specialize = false`. By default it is turned off to reduce the time it takes to initialize fully. It can be enabled for long-running simulations, trading initialization speed for simulation speed. Concretely, enabling it will set the [specialization level](https://docs.sciml.ai/SciMLBase/stable/interfaces/Problems/#Specialization-Levels) to NoSpecialize for false, and FullSpecialize for true. Additionally setting it to true also fixes the [autodiff chunk size](https://juliadiff.org/ForwardDiff.jl/stable/user/advanced/#Configuring-Chunk-Size) to 1, making a similar tradeoff as the specialization level.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Enabling it => setting it
And the chunk size is 1 when specialize is false, not true.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Sharp.

@visr
visr merged commit efa1e2c into main Oct 20, 2025
18 of 19 checks passed
@visr
visr deleted the special-ice branch October 20, 2025 14:11
@visr

visr commented Oct 21, 2025

Copy link
Copy Markdown
Member Author

Nice, Test Ribasim Binaries went from 15 to 8 minutes on Linux, and a similar improvement on Windows.

visr added a commit that referenced this pull request Oct 25, 2025
…" (#2667)

This reverts commit e179af0.

#2624 provides a great performance speedup for very large models, but I
now see this is too much at the expense of small models.

For instance after
#2652 (comment) we
got down to an acceptable 10s wall time for
`tabulated_rating_curve_control` from ribasim.exe. It seems #2624 brings
that up to 1m11s. This can be reduced by setting the number of threads
to 1, though only partially.

```
tabulated_rating_curve_control NoSpecialize: 10s total, Computation time: 21 milliseconds
tabulated_rating_curve_control NoSpecialize+2624: 1m11s total, Computation time: 10 seconds
tabulated_rating_curve_control NoSpecialize+2624-t1: 46s total, Computation time: 10 seconds
```

Since for the upcoming courses no-one is going to be running the LHM I
feel we should revert this now, giving us time to find ways to make
#2624 quicker to start.
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.

2 participants