Skip to content

Drop smck hull_offset defaults#2445

Merged
jeromekelleher merged 1 commit intotskit-dev:mainfrom
hossam26644:feat/drop-smck-hulloffset-default-2443
Dec 15, 2025
Merged

Drop smck hull_offset defaults#2445
jeromekelleher merged 1 commit intotskit-dev:mainfrom
hossam26644:feat/drop-smck-hulloffset-default-2443

Conversation

@hossam26644
Copy link
Contributor

closes #2443

@hossam26644
Copy link
Contributor Author

@jeromekelleher
Please check this: the test test_gaps in test models fails for the smc_prime (now mapped to smc(k=1)). This tests overlapping segments in a non-discrete genome. I think smc(k=1) is not equavelent to the smc_prim in the case of a non-discrete genome. What do you think?

Copy link
Member

@jeromekelleher jeromekelleher left a comment

Choose a reason for hiding this comment

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

See comment above - that should make it less painful


# We have to define an __init__ to enforce keyword-only behaviour
def __init__(self, *, duration=None, hull_offset=0.0):
def __init__(self, *, duration=None, hull_offset):
Copy link
Member

Choose a reason for hiding this comment

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

I think we should make hull offset a required positional arg, like

def __init__(self, hull_offset, *, duration=None):
    ...

I don't think we put much thought into this when it was going in initially, just put something in to get things working.

(unless this breaks other things?)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

it does not break other things 👍

@jeromekelleher
Copy link
Member

Please check this: the test test_gaps in test models fails for the smc_prime (now mapped to smc(k=1)). This tests overlapping segments in a non-discrete genome. I think smc(k=1) is not equavelent to the smc_prim in the case of a non-discrete genome. What do you think?

Ooh - that's a nasty one! Can you confirm by making k=1.00001 and rerunning?

@hossam26644
Copy link
Contributor Author

ts = msprime.simulate(
                sample_size=sample_size,
                recombination_rate=recombination_rate,
                random_seed=random_seed,
                model=msprime.SmcKApproxCoalescent(hull_offset=1.00001),
            )
            edgesets = sorted(ts.edgesets(), key=lambda e: (e.parent, e.left))
            num_found = 0
            for j in range(1, len(edgesets)):
                r = edgesets[j - 1]
                s = edgesets[j]
                if r.right != s.left and r.parent == s.parent:
                    num_found += 1
            assert num_found == 0 #fails

hull_offset=1.00001 gives similar results to 1. both fail the test

@hossam26644 hossam26644 force-pushed the feat/drop-smck-hulloffset-default-2443 branch 2 times, most recently from 85155aa to 1fb660c Compare December 12, 2025 15:08
@jeromekelleher
Copy link
Member

Hmm, good catch. We'll have to think about that.

@jeromekelleher
Copy link
Member

Ah right, the problem is k is too big. Here, the genome is one unit long, so k=1 means we allow all possible overlaps. If we put k=0.00001 in this example we get the right answer.

Now, I'm not entirely sure what the right value of the smc_prime is in a continuous genome model. I guess it's a very small number? It's an annoying one.

@hossam26644
Copy link
Contributor Author

In a math term, it should be when k -> 0. I am not sure if we set it to the smallest float that could be stored, it would be a sustainable universal solution. Also, we would have to set the k value differently for discrete genomes (k=1).

@jeromekelleher
Copy link
Member

Let's try a small value like 1e-14 or something so as the default, and see if that does the right thing for the discrete genome case. Having a different mapping for discrete genome and not would be quite tricky, as we'd have to pass the discrete_genome parameter around a lot, and it would be confusing to document anyway.

Using very small values like flt_min or whatever could have unexpected consequences, so I think a reasonable like 1e-14 is less likely overall to bite us.

@hossam26644
Copy link
Contributor Author

It does not break unit tests, and I am checking the stats verifications. Verifications does not look ok though. Check below the number of trees between msprime.SmcKApproxCoalescent(hull_offset=1e-14) and msprime.SmcPrimeApproxCoalescent()

for: the test_smck_vs_smckapprox_recomb_discrete_hotspots

recombination_map = msprime.RateMap(
           position=[0, 100, 500, 900, 1200, 1500, 2000],
           rate=[0.00001, 0, 0.0002, 0.00005, 0, 0.001],
       )
       self._run(
           samples=10,
           population_size=1000,
           recombination_rate=recombination_map,
           num_replicates=300,
           discrete_genome=True,
       )
num_trees

What about we restrict the smc_prime model to discrete genome from the interface?

@jeromekelleher
Copy link
Member

What about we restrict the smc_prime model to discrete genome from the interface?

I considered this, but it's not trivial because of the complex structure of the model argument and also it will likely break code.

Hmm, this is annoying.

OK, let's drop the remapping of the strings for now, and keep the reparameterisation of smck to require the parameter. At least this excecise has shown us that a default of 1 was definitely not the right thing to do...

It may be simpler to just do this in a different PR or update this one, it's up to you.

@hossam26644 hossam26644 force-pushed the feat/drop-smck-hulloffset-default-2443 branch from 1fb660c to edbb3ce Compare December 15, 2025 13:25
@hossam26644 hossam26644 changed the title Drop smck hull_offset defaults and remap the strings smc and smc_prime to the smck model (k=0&k=1) Drop smck hull_offset defaults Dec 15, 2025
@hossam26644 hossam26644 force-pushed the feat/drop-smck-hulloffset-default-2443 branch 2 times, most recently from ded178c to 0b6bf90 Compare December 15, 2025 13:35
@hossam26644 hossam26644 marked this pull request as ready for review December 15, 2025 13:44
@codecov
Copy link

codecov bot commented Dec 15, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 91.22%. Comparing base (1526582) to head (902179d).
⚠️ Report is 2 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #2445   +/-   ##
=======================================
  Coverage   91.22%   91.22%           
=======================================
  Files          20       20           
  Lines       11847    11847           
  Branches     2300     2300           
=======================================
  Hits        10807    10807           
  Misses        569      569           
  Partials      471      471           
Flag Coverage Δ
C 91.22% <100.00%> (ø)
python 98.63% <100.00%> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link
Member

@jeromekelleher jeromekelleher left a comment

Choose a reason for hiding this comment

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

Looks good. Spotted one thing.

We can probably get rid of the hull_offset named argument in new code as well and just use SmcKApproxCoalescent(0) etc.

msprime.SweepGenicSelection(1)

def test_smck_coalescent(self):
model = msprime.SmcKApproxCoalescent()
Copy link
Member

Choose a reason for hiding this comment

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

Should resinstate this test to check that it raises a TypeError (or whatever it is)

# mandatory positional argument
with pytest.raises(TypeError):
        msprime.SmcKApproxCoalescent()

@hossam26644 hossam26644 force-pushed the feat/drop-smck-hulloffset-default-2443 branch from 0b6bf90 to 185a1a8 Compare December 15, 2025 14:30
@hossam26644
Copy link
Contributor Author

check now. Also check the recommendation in the documentation: for smc_prime the documentation recommends smck(1) for discrete and smck(1e-14) for continuous genomes

@jeromekelleher
Copy link
Member

Docstring is malformed, that's why the docs build is failing

update documentation and float k values

hull offset a required positional arg

remove string remapping

fix verifications

added lost test

not remove named argument and add a test

fix test

fix doc
@hossam26644 hossam26644 force-pushed the feat/drop-smck-hulloffset-default-2443 branch from 8de716c to 902179d Compare December 15, 2025 16:01
@hossam26644
Copy link
Contributor Author

yes, should be fixed now

@hossam26644
Copy link
Contributor Author

@jeromekelleher Can be merged

@jeromekelleher jeromekelleher added this pull request to the merge queue Dec 15, 2025
Merged via the queue into tskit-dev:main with commit 939a0e9 Dec 15, 2025
13 checks passed
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.

Drop the default Hull offset of the SMCK model

2 participants