Repository: popsim-consortium/stdpopsim (language: python)

Issue:
When msprime 1.0 is released, we should use discrete recombination maps
Also for the slim engine, see #438 and #439.


Discussion / hints:
hey, it turns out I'm running into this issue right now. any ideas how to deal with this?
How are you running into the issue @mufernando?
We chatted about this on Slack, and it seems @mufernando had introduced the same change in #644 that was reverted to fix #439. I.e. doing recapitation with a recombination map. The solution is to either specify a recombination rate (rather than providing a map, uniform or otherwise), or to rely on msprime 1.0 features and recapitate with discrete=True. I think @mufernando is going to do the latter?
> or to rely on msprime 1.0 features and recapitate with discrete=True. I think @mufernando is going to do the latter?

Yes, that's the way to go all right. It would be best to start using [sim_ancestry](https://tskit-dev.github.io/msprime-docs/main/ancestry.html#msprime.sim_ancestry), as this has the discrete_genome=True as the default and we'll want to transition stdpopsim to using this when 1.0 is available.
#764 almost closes this, but I think we can only close when we've updated the SLiM engine recaptitate step.
The slim engine is using sim_ancestry() and sim_mutations() now. Anything specific we need to do to close out this issue? @jeromekelleher @mufernando 

https://github.com/popsim-consortium/stdpopsim/blob/de8c2150b4f569b6a3ed1bd7d6d9d2e12b02ba82/stdpopsim/slim_engine.py#L1296-L1325
Well, (a) `msprime.simulate` only appears in testing code, and (b) the phrase `discrete_genome` doesn't appear in the repository, and we'd need to set `discrete_genome=False` to get sim_ancestry to be continuous. So I think we're good (although we should probably change the testing code, and also there is [this note](https://github.com/popsim-consortium/stdpopsim/blob/de8c2150b4f569b6a3ed1bd7d6d9d2e12b02ba82/stdpopsim/slim_engine.py#L1296)).
Thanks @petrelharp. Looks like the test code is using msprime.simulate in quite reasonable ways (checking functions that do things with tree sequences), so I don't think we need to do anything there.

Fix patch:
diff --git a/stdpopsim/genomes.py b/stdpopsim/genomes.py
index 3bf69fb91..5f4d7307f 100644
--- a/stdpopsim/genomes.py
+++ b/stdpopsim/genomes.py
@@ -258,7 +258,7 @@ def species_contig(
             )
         if chromosome is None:
             if genetic_map is not None:
-                raise ValueError("Cannot use genetic map with generic contic")
+                raise ValueError("Cannot use genetic map with generic contig")
             if length_multiplier != 1:
                 raise ValueError("Cannot use length multiplier for generic contig")
             if inclusion_mask is not None or exclusion_mask is not None:
diff --git a/stdpopsim/slim_engine.py b/stdpopsim/slim_engine.py
index 7735582b5..108df89ad 100644
--- a/stdpopsim/slim_engine.py
+++ b/stdpopsim/slim_engine.py
@@ -1293,11 +1293,10 @@ def _recap_and_rescale(
             migration_matrix=recap_epoch.migration_matrix,
         )
 
-        # TODO: using recombination map in recapitate. maps should be discrete.
         ts = msprime.sim_ancestry(
             initial_state=ts,
             demography=demography,
-            recombination_rate=contig.recombination_map.mean_rate,
+            recombination_rate=contig.recombination_map,
             random_seed=s1,
         )
 


Test patch:
diff --git a/tests/test_slim_engine.py b/tests/test_slim_engine.py
index 045e5513c..d018bcb92 100644
--- a/tests/test_slim_engine.py
+++ b/tests/test_slim_engine.py
@@ -119,18 +119,19 @@ def test_script_generation(self):
         )
         assert "sim.registerLateEvent" in out
 
+    @pytest.mark.filterwarnings("ignore::msprime.IncompletePopulationMetadataWarning")
     @pytest.mark.filterwarnings("ignore:Recombination map has length:UserWarning")
     def test_recombination_map(self):
         engine = stdpopsim.get_engine("slim")
         species = stdpopsim.get_species("HomSap")
         contig = species.get_contig("chr1", genetic_map="HapMapII_GRCh37")
-        model = stdpopsim.PiecewiseConstantSize(species.population_size)
+        model = stdpopsim.PiecewiseConstantSize(100)
         samples = model.get_samples(10)
         engine.simulate(
             demographic_model=model,
             contig=contig,
             samples=samples,
-            dry_run=True,
+            slim_burn_in=0.1,
         )
 
     @pytest.mark.filterwarnings("ignore::msprime.IncompletePopulationMetadataWarning")