Skip to content

REF/TST: add seed to hdrboxplot, Use random order in pytest - #5148

Merged
josef-pkt merged 3 commits into
statsmodels:masterfrom
bashtage:switch-to-random-test-order
Sep 11, 2018
Merged

josef-pkt merged 3 commits into
statsmodels:masterfrom
bashtage:switch-to-random-test-order

Conversation

@bashtage

@bashtage bashtage commented Sep 8, 2018

Copy link
Copy Markdown
Member

Use random order to avoid intertest dependency

Tests show there are some problems with order affecting test success.

@jbrockmendel

Copy link
Copy Markdown
Contributor

Closes #5110

@bashtage

bashtage commented Sep 8, 2018

Copy link
Copy Markdown
Member Author

xref #4965

@josef-pkt

Copy link
Copy Markdown
Member

Is there a way to replicate a specific random order when we need to investigate a failure?

@bashtage

bashtage commented Sep 8, 2018

Copy link
Copy Markdown
Member Author

You can pass the seed argument to reproduce the same order

@josef-pkt

Copy link
Copy Markdown
Member

The first 4 environments on travis that I have checked have only test failures in TestTheilPanel.test_combine_subset_regression and TestTheilPanel.test_regression
I guess that's a bug in code or unit test. I will look into it.

@josef-pkt

josef-pkt commented Sep 8, 2018 •

Copy link
Copy Markdown
Member

Ok, those are mainly regression tests but it doesn't set the seed in random panel.
I'm not sure why it doesn't always fails. I guess some other function sets the seed and the numpy global RandomState before this test (setup_class) is executed.

I will have to redo the regression test numbers because I don't know what seed or random state was used. The unit tests don't fail when I run the entire test module, but fails if I just run the test class.

(half smart: The seed for the random panel is printed out and it uses a specific RandomState instance, but the followups in the test class use again the global random state where we don't know the seed to replicate.)

@josef-pkt

Copy link
Copy Markdown
Member

PR for Theil test is #5149
I will merge that when it's green

@bashtage
bashtage force-pushed the switch-to-random-test-order branch from d687b1e to 540e1d7 Compare September 9, 2018 07:37
@bashtage bashtage changed the title WIP/TST: Use random order [DO NOT MERGE] TST: Use random order Sep 9, 2018
@bashtage

bashtage commented Sep 9, 2018

Copy link
Copy Markdown
Member Author

I think this can be merged after I rebase and it gets green. I added a fix that only seems to affect appveyor.

@bashtage
bashtage force-pushed the switch-to-random-test-order branch from 767049d to 96fe3ab Compare September 9, 2018 14:49
@coveralls

coveralls commented Sep 9, 2018 •

Copy link
Copy Markdown

Coverage Status

Coverage decreased (-0.04%) to 83.896% when pulling 0876cc7 on bashtage:switch-to-random-test-order into 1a0d703 on statsmodels:master.

@bashtage
bashtage force-pushed the switch-to-random-test-order branch from 96fe3ab to 91a29da Compare September 9, 2018 16:13
@codecov

codecov Bot commented Sep 9, 2018 •

Copy link
Copy Markdown

Codecov Report

Merging #5148 into master will increase coverage by <.01%.
The diff coverage is 88.88%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #5148      +/-   ##
==========================================
+ Coverage   81.42%   81.42%   +<.01%     
==========================================
  Files         581      581              
  Lines       90273    90277       +4     
  Branches    10099    10101       +2     
==========================================
+ Hits        73508    73512       +4     
  Misses      14479    14479              
  Partials     2286     2286
Impacted Files Coverage Δ
statsmodels/graphics/tests/test_functional.py 98.03% <100%> (+0.01%) ⬆️
statsmodels/tsa/tests/test_stattools.py 98.59% <100%> (-0.01%) ⬇️
statsmodels/tsa/stattools.py 86.3% <100%> (ø) ⬆️
statsmodels/graphics/functional.py 78.12% <77.77%> (+0.6%) ⬆️
statsmodels/tsa/arima_model.py 86.51% <0%> (-0.04%) ⬇️
...smodels/genmod/generalized_estimating_equations.py 83.15% <0%> (ø) ⬆️
statsmodels/base/tests/test_generic_methods.py 96.42% <0%> (ø) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 1a0d703...0876cc7. Read the comment docs.

@bashtage
bashtage force-pushed the switch-to-random-test-order branch 3 times, most recently from 9e03aca to 845e039 Compare September 9, 2018 23:21
#for ii, yy in enumerate([y1, y2, y3, y4]):
# fig = plt.figure()
# ax = fig.add_subplot(111)
# for ii, yy in enumerate([y1, y2, y3, y4]):

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Are these worth keeping as comments? Or actually just defunct code? If it's the latter then second-best (after deleting) is to keep them pep8-invalid so they don't fall through the cracks.

Use random order to avoid intertest dependency
Ensure correct warning type is issued
@bashtage
bashtage force-pushed the switch-to-random-test-order branch 2 times, most recently from 890adbb to c5bf4a6 Compare September 10, 2018 08:33
@bashtage

Copy link
Copy Markdown
Member Author

@josef-pkt This is ready now. The changes to HDR are all backward compat and are both good practice and helpful in testing.

data = zip(range(dim), itertools.repeat((band, pca,
bounds, ks_gaussian)))
bounds, ks_gaussian,
seed, use_brute)))

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Doesn't this use the same seed in each call/repeat?
causing perfect correlation across dim

(I never tried to understand the details here.)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

seed is just used for differential evolution, so maybe/likely it doesn't matter.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

No, it ultimately calls

def _curve_constrained(x, idx, sign, band, pca, ks_gaussian):

which takes idx as a parameter (which comes from range).

I'm not trying to fix anything other than to allow it to be deterministic.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

But AFAICS it changes the differential evolution behavior.
Before it was using the global random state which continuous the random chain with each call.
Now it uses the same seed in each call to differential_evolution.

I don't think anymore that it matters in this case, but in general using identical seed would be incorrect, e.g. in bootstrap or parallel randomized optimization for the same function. The latter is the case that I thought about initially.

Allow seed to be set in differential evolution
Allow end user to choose algorithm
Set seed in all tests for reproducible results
Small cleanups for style
@bashtage
bashtage force-pushed the switch-to-random-test-order branch from c5bf4a6 to 0876cc7 Compare September 10, 2018 14:07
@josef-pkt josef-pkt added this to the 0.10 milestone Sep 10, 2018
@josef-pkt josef-pkt changed the title TST: Use random order REF/TST: add seed to hdrboxplot, Use random order in pytest Sep 10, 2018
@josef-pkt

Copy link
Copy Markdown
Member

I changed the title and added labels to indicate it includes now also a REF/ENH in graphics.

@bashtage

Copy link
Copy Markdown
Member Author

If seed=None then the global is still used everywhere.

@josef-pkt

Copy link
Copy Markdown
Member

If seed=None then the global is still used everywhere.

Good, thanks for pointing it out. I skimmed the docstrings too fast, and didn't think about this.

@josef-pkt

Copy link
Copy Markdown
Member

ETA for appveyor looks like 12 hours.

merge when green

@jbrockmendel jbrockmendel mentioned this pull request Sep 10, 2018
31 of 32 tasks
@jbrockmendel

Copy link
Copy Markdown
Contributor

@josef-pkt defacto green

@josef-pkt

Copy link
Copy Markdown
Member

as green as it gets, merging

@bashtage Thank you

@josef-pkt
josef-pkt merged commit 4b57473 into statsmodels:master Sep 11, 2018
@bashtage
bashtage deleted the switch-to-random-test-order branch September 11, 2018 06:38
@bashtage
bashtage restored the switch-to-random-test-order branch September 11, 2018 07:14
@bashtage
bashtage deleted the switch-to-random-test-order branch September 11, 2018 07:18
@jbrockmendel jbrockmendel mentioned this pull request May 14, 2019
8 of 15 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants