Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BinomialPoint has missing attributes #1153

Closed
hanbin973 opened this issue Jul 31, 2023 · 7 comments
Closed

BinomialPoint has missing attributes #1153

hanbin973 opened this issue Jul 31, 2023 · 7 comments
Labels

Comments

@hanbin973
Copy link

Hi, thank you for developing a great library.

I came up with the following error while using BinomialPoint for recregion.
I ran

fwdpy11.evolvets(rng, pop, params, simplification_interval=100)

and got

File ~/mambaforge/envs/ptrans/lib/python3.10/site-packages/fwdpy11/_evolvets.py:194, in evolvets(rng, pop, params, simplification_interval, recorder, post_simplification_recorder, suppress_table_indexing, record_gvalue_matrix, stopping_criterion, track_mutation_counts, remove_extinct_variants, preserve_first_generation)
    189 for r in params.recregions:
    190     assert isinstance(r, fwdpy11._fwdpy11.PoissonCrossoverGenerator) or \
    191         isinstance(
    192             r, fwdpy11._fwdpy11.NonPoissonCrossoverGenerator) or \
    193         isinstance(r, fwdpy11.Region), f"{type(r)}"
--> 194     if r.beg < 0:
    195         raise ValueError(f"{r} has begin value < 0.0")
    196     if r.end > pop.tables.genome_length:

AttributeError: 'BinomialPoint' object has no attribute 'beg'

The full code is

# recombination
# https://molpopgen.github.io/fwdpy11/short_vignettes/geneticmaps_vignette.html
# four regions (chrs) = 0,1,2,3
recregions = [
    fwdpy11.BinomialPoint(position=10, probability=0.5),
    fwdpy11.BinomialPoint(position=20, probability=0.5),
    fwdpy11.BinomialPoint(position=30, probability=0.5)
]
# neutral variants
# https://molpopgen.github.io/fwdpy11/short_vignettes/neutralmuts_vignette.html
# simulate neutral variants bc to gettemporal frequencies 
nregions = [
    fwdpy11.Region(beg=0, end=4, weight=1)
]
nrate = 1e-4

pdict = {
    "nregions": nregions,
    "rates": (nrate, 0, None), # rates of neutral mut, selected mut, recomb
    "recregions": recregions,
    "demography": demography,
    "sregions": [],
    "gvalue": [fwdpy11.Multiplicative(scaling=0)], # no selection?
    "simlen": pop.N
}

params = fwdpy11.ModelParams(**pdict)

Unlike PoissonInterval, BinomialPoint does not have an attribute beg and end which is causing the problem.

The only page in the current documentation containing a code with BinomialPoint is this link. Copy-and-pasting the code here to execute evolvets returns the same error above.

@molpopgen
Copy link
Owner

Thanks for the message @hanbin973. I am unable to reproduce the bug with the current version, which is identical to the GitHub main branch:

mkdir ~/tmp/test_bug
cd ~/tmp/test_bug
python -m venv venv
source venv/bin/activate
python -m pip install --upgrade pip
python -m pip install --no-cache fwdpy11

Making minor modifications to your code so that it is standalone:

import fwdpy11

# recombination
# https://molpopgen.github.io/fwdpy11/short_vignettes/geneticmaps_vignette.html
# four regions (chrs) = 0,1,2,3
recregions = [
    fwdpy11.BinomialPoint(position=10, probability=0.5),
    fwdpy11.BinomialPoint(position=20, probability=0.5),
    fwdpy11.BinomialPoint(position=30, probability=0.5)
]
# neutral variants
# https://molpopgen.github.io/fwdpy11/short_vignettes/neutralmuts_vignette.html
# simulate neutral variants bc to gettemporal frequencies 
nregions = [
    fwdpy11.Region(beg=0, end=4, weight=1)
]
nrate = 1e-4

pdict = {
    "nregions": nregions,
    "rates": (nrate, 0, None), # rates of neutral mut, selected mut, recomb
    "recregions": recregions,
    "demography": None,
    "sregions": [],
    "gvalue": [fwdpy11.Multiplicative(scaling=2)], # no selection?
    "simlen": 1000
}

params = fwdpy11.ModelParams(**pdict)

Everything runs just fine.

The current version is:

>>> import fwdpy11
>>> fwdpy11.__version__
'0.20.0'

Further,

  • The link to the docs shows code that is run during testing. So if the code doesn't work, the manual cannot build.
  • BinomialPoint is also tested here for every change to the library.

I'm guessing you have an installation issue. Perhaps one of the alpha releases of the current version and not the latest version itself?

One other point:

The scaling argument to Multiplicative is not correct! See here. The way to have "no selection" is to not add "sregions" to the model.

@hanbin973
Copy link
Author

Thank you for the check. I've reinstalled the environment and still have the error.

I've installed fwdpy11 in two separate envs using conda and pip. Both are version 0.20.0 (output of fwdpy11.__version__). The error is reproduced in both envs.

No error occurs until running

params = fwdpy11.ModelParams(**pdict)

Everything is fine until I run the actual simulation.

The initially reported error

AttributeError                            Traceback (most recent call last)
Cell In[10], line 1
----> 1 fwdpy11.evolvets(rng, pop, params, simplification_interval=100)

File ~/mambaforge/envs/tskit/lib/python3.11/site-packages/fwdpy11/_evolvets.py:194, in evolvets(rng, pop, params, simplification_interval, recorder, post_simplification_recorder, suppress_table_indexing, record_gvalue_matrix, stopping_criterion, track_mutation_counts, remove_extinct_variants, preserve_first_generation)
    189 for r in params.recregions:
    190     assert isinstance(r, fwdpy11._fwdpy11.PoissonCrossoverGenerator) or \
    191         isinstance(
    192             r, fwdpy11._fwdpy11.NonPoissonCrossoverGenerator) or \
    193         isinstance(r, fwdpy11.Region), f"{type(r)}"
--> 194     if r.beg < 0:
    195         raise ValueError(f"{r} has begin value < 0.0")
    196     if r.end > pop.tables.genome_length:

AttributeError: 'BinomialPoint' object has no attribute 'beg'

occurs when running

fwdpy11.evolvets(rng, pop, params, simplification_interval=100)

I think there was a mistake on my side. The full code I was referring to in the original issue was actually 'the full code except for the fwdpy11.evolvets() command`. Sorry for this.

@molpopgen
Copy link
Owner

I am now able to reproduce the issue. Your previous example was not complete, which is why I was unable to reproduce. In the future, please provide code that does reproduce bugs. It is really important for any project. You said that you code was complete except for evolvets, but that wasn't true. It was missing the fwdpy11 import, missing the demography variable, etc.. Thus it could not run.

Reproducible example:

import fwdpy11

# recombination
# https://molpopgen.github.io/fwdpy11/short_vignettes/geneticmaps_vignette.html
# four regions (chrs) = 0,1,2,3
recregions = [
    fwdpy11.BinomialPoint(position=10, probability=0.5),
    fwdpy11.BinomialPoint(position=20, probability=0.5),
    fwdpy11.BinomialPoint(position=30, probability=0.5)
]
# neutral variants
# https://molpopgen.github.io/fwdpy11/short_vignettes/neutralmuts_vignette.html
# simulate neutral variants bc to gettemporal frequencies 
nregions = [
    fwdpy11.Region(beg=0, end=4, weight=1)
]
nrate = 1e-4

pdict = {
    "nregions": nregions,
    "rates": (nrate, 0, None), # rates of neutral mut, selected mut, recomb
    "recregions": recregions,
    "demography": None,
    "sregions": [],
    "gvalue": [fwdpy11.Multiplicative(scaling=2)], # no selection?
    "simlen": 1000
}

params = fwdpy11.ModelParams(**pdict)

pop = fwdpy11.DiploidPopulation(100, 40)

rng = fwdpy11.GSLrng(5)

fwdpy11.evolvets(rng, pop, params, 100)

@molpopgen molpopgen added the bug label Aug 1, 2023
@molpopgen
Copy link
Owner

I'll get a fix out for this shortly.

@molpopgen
Copy link
Owner

This may be held up by #1154.

@molpopgen
Copy link
Owner

@hanbin973, I have a fix in #1155. Testing via GitHub takes a while, but I expect to merge soon and push a release. Pushing a release will trigger automatic builds and pushes to PyPi. bioconda will take longer and may need manual intervention from me.

@molpopgen
Copy link
Owner

The new version is on PyPi now with pre-built packages for Linux and macOS/x86. macos/x86 is currently failing over on bioconda for unknown reasons. So that side of things will take a while.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants