Repository: tskit-dev/msprime (language: python)

Issue:
Raise error when calculating ARG likelihood on simplified tree seqs
I think it isn't meaningful to run `log_arg_likelihood` on a simplified TS, but it is currently possible to do so. Maybe if there is >1 tree, but no RE nodes in the TS, we should error out when running `log_arg_likelihood`?


Discussion / hints:
Could do easily enough i guess. 

Fix patch:
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 635f5712b..1221c2b6e 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -10,6 +10,10 @@
   are added `SMM`, `TPM`, and `EL2`.  
   ({issue}`2013`, {user}`andrewkern`).
 
+- Raise an error if `log_arg_likelihood` is called on a recombinant tree
+  sequence that has no recombination nodes (({issue}`2123`, {pr}`2124`,
+  {user}`hyanwong`)
+
 ## [1.2.0] - 2022-05-18
 
 **New features**
diff --git a/msprime/likelihood.py b/msprime/likelihood.py
index 6da02f791..aa2b21508 100644
--- a/msprime/likelihood.py
+++ b/msprime/likelihood.py
@@ -145,6 +145,11 @@ def log_arg_likelihood(ts, recombination_rate, Ne=1):
                 " Tree sequences must contain binary mergers only for"
                 " valid likelihood evaluation."
             )
+    if ts.num_trees > 1 and not np.any(ts.nodes_flags & _msprime.NODE_IS_RE_EVENT):
+        raise ValueError(
+            "ARG likelihood only valid for tree sequences where recombinations"
+            " have been recorded via nodes flagged with `NODE_IS_RE_EVENT`."
+        )
 
     # Get the tables into the format we need to interchange with the low-level code.
     lw_tables = _msprime.LightweightTableCollection()


Test patch:
diff --git a/tests/test_likelihood.py b/tests/test_likelihood.py
index 3d0830ed5..813edfa1e 100644
--- a/tests/test_likelihood.py
+++ b/tests/test_likelihood.py
@@ -169,7 +169,7 @@ def test_log_likelihoods(self):
                 msprime.log_mutation_likelihood(arg, t),
             )
 
-    def test_arg_likelihood_error_handling(self):
+    def test_arg_likelihood_polytomy_handling(self):
         tables = tskit.TableCollection(sequence_length=1)
         tables.nodes.add_row(
             flags=tskit.NODE_IS_SAMPLE, population=0, individual=-1, time=0
@@ -196,6 +196,19 @@ def test_arg_likelihood_error_handling(self):
         ):
             msprime.log_arg_likelihood(arg, 1)
 
+    def test_arg_likelihood_no_re_node_handling(self):
+        tables = tskit.TableCollection(sequence_length=1)
+        tables.nodes.add_row(flags=tskit.NODE_IS_SAMPLE, time=0)
+        tables.nodes.add_row(flags=tskit.NODE_IS_SAMPLE, time=0)
+        tables.nodes.add_row(flags=0, time=1)
+        tables.nodes.add_row(flags=0, time=2)
+        tables.edges.add_row(left=0, right=0.5, parent=2, child=0)
+        tables.edges.add_row(left=0.5, right=1, parent=3, child=0)
+        tables.edges.add_row(left=0, right=1, parent=3, child=1)
+        bad_arg = tables.tree_sequence()
+        with pytest.raises(ValueError, match="NODE_IS_RE_EVENT"):
+            msprime.log_arg_likelihood(bad_arg, 1)
+
     def test_multiple_mrcas(self):
         tables = tskit.TableCollection(sequence_length=1)
         tables.nodes.add_row(