Skip to content

Commit

Permalink
Fixes to examples/ (#1209)
Browse files Browse the repository at this point in the history
* Run divergent optima example in CI.
* Run examples with -We
* Fix deprecated API use in two examples

Closes #1207
  • Loading branch information
molpopgen authored Nov 3, 2023
1 parent 2700d21 commit 08bbfcc
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 12 deletions.
6 changes: 5 additions & 1 deletion .github/workflows/ubuntu.yml
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,11 @@ jobs:
run: |
CPPFLAGS=$CPPFLAGS CC=$CC CXX=$CXX PYTHONPATH=. cmake examples/plugin
make
PYTHONPATH=. python examples/plugin/test_plugin.py
PYTHONPATH=. python -We examples/plugin/test_plugin.py
- name: Run Python divergent optima example
run: |
PYTHONPATH=. python -We examples/gss_divergent_optima/gss_divergent_optima.py 100 0
- name: Validate the sdist
run: |
Expand Down
37 changes: 27 additions & 10 deletions examples/gss_divergent_optima/gss_divergent_optima.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,24 +8,42 @@
N = int(sys.argv[1])
rho = float(sys.argv[2])

moving_optimum_deme_0 = fwdpy11.GSSmo(
[
yaml = f"""
time_units: generations
demes:
- name: alpha
epochs:
- start_size: {N}
- name: beta
epochs:
- start_size: {N}
migrations:
- demes: [alpha, beta]
rate: 1e-2
"""

demography = fwdpy11.ForwardDemesGraph.from_demes(
yaml, burnin=10 * N + 200, burnin_is_exact=True
)

moving_optimum_deme_0 = fwdpy11.GaussianStabilizingSelection.single_trait(
optima=[
fwdpy11.Optimum(when=0, optimum=0.0, VS=1.0),
fwdpy11.Optimum(when=10 * N, optimum=1.0, VS=1.0),
]
],
)
moving_optimum_deme_1 = fwdpy11.GSSmo(
[
moving_optimum_deme_1 = fwdpy11.GaussianStabilizingSelection.single_trait(
optima=[
fwdpy11.Optimum(when=0, optimum=0.0, VS=1.0),
fwdpy11.Optimum(when=10 * N, optimum=-1.0, VS=1.0),
]
],
)

# The covariance matrix for effect sizes.
# The marginal Gaussians will have mean zero and sd = 0.1
# The deviates will be highly positively correlated.
sd = 0.1
covariance_matrix = np.matrix([0.999] * 4).reshape((2, 2))
covariance_matrix = np.array([0.999] * 4).reshape((2, 2))
np.fill_diagonal(covariance_matrix, 1)
covariance_matrix *= np.power(sd, 2)

Expand All @@ -43,9 +61,7 @@
],
"recregions": [fwdpy11.PoissonInterval(0, 1, rho / (4 * N))],
"rates": (0, 1e-3, None),
"demography": fwdpy11.DiscreteDemography(
migmatrix=np.array([0.99, 0.01, 0.01, 0.99]).reshape((2, 2))
),
"demography": demography,
"simlen": 10 * N + 200, # 200 gens past optimum shift
# Specify one gvalue object per deme
"gvalue": [
Expand All @@ -63,6 +79,7 @@
pop = fwdpy11.DiploidPopulation([N, N], 1.0)
rng = fwdpy11.GSLrng(1010)
fwdpy11.evolvets(rng, pop, params, 100)
assert pop.generation == 10 * N + 200
md = np.array(pop.diploid_metadata, copy=False)
df = pd.DataFrame.from_records(md[["deme", "g", "w"]])
g = df.groupby(["deme"])
Expand Down
7 changes: 6 additions & 1 deletion examples/plugin/test_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,12 @@
"sregions": [fwdpy11.GaussianS(0, 1, 1, 0.25)],
"recregions": [fwdpy11.PoissonInterval(0, 1, 5e-3)],
"rates": (0.0, 5e-3, None),
"gvalue": fwdpy11.Additive(2.0, fwdpy11.GSS(VS=1.0, optimum=1.0)),
"gvalue": fwdpy11.Additive(
2.0,
fwdpy11.GaussianStabilizingSelection.single_trait(
optima=[fwdpy11.Optimum(VS=1.0, optimum=1.0, when=0)]
),
),
"prune_selected": False,
}

Expand Down

0 comments on commit 08bbfcc

Please sign in to comment.