mggg / GerryChain

Use MCMC to analyze districting plans and gerrymanders
https://mggg.github.io/GerryChain/
Other
132 stars 74 forks source link

Add option to disable cut_edges updater with use_cut_edges flag #375

Closed InnovativeInventor closed 2 years ago

InnovativeInventor commented 2 years ago

This is a PR broken out from #372 to ease the code review process.

As noted in #368, the cut_edges updater is forcibly enabled by default for every Partition object. However, the user has no way of opting out of this expensive updater. Prior to pcompress, this wasn't a big deal. However, now that GerryChain runs are replayable (and since most analysis is now done with replayable chains), it doesn't make sense to force every partition to calculate the cut_edges updater.

As an example case where this would be useful, let's say that we want to draw election histograms or simply export a few sample maps in a recorded chain run (a fairly common occurrence). In this case, there would be no need to calculate the cut_edges and disabling the updater by providing the use_cut_edges flag would result in a significant speedup.

Note that this PR is backwards compatible. By default, cut_edges are calculated (use_cut_edges defaults to True and is an optional argument).

Fixes #368

InnovativeInventor commented 2 years ago

For some context, my replay speeds are roughly 1260 it/s (3-4x speedup) with this flag set to False. I'm open to renaming the flag name, if it seems unwieldy.