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

ENH(OPT,TST): make test_transformations run 7 sec instead of 150 or so #413

Merged
merged 3 commits into from
Mar 21, 2019

Conversation

yarikoptic
Copy link
Collaborator

@yarikoptic yarikoptic commented Mar 5, 2019

  • ENH: do not hardcode numbers
  • use collection only for 2 subjects out of 16 (could even be just 1 may be)
  • cache the collection, i.e. not regenerate in fixture each time (I initially pushed, then killed it, then revived it fixing that side-effect - just always return a clone!)

Also in principle, if tests take proper care about cloning where needed, then no caching would be needed, fixture could get (scope="module") and get called only once - giving even more speed up. But ATM some test(s) do cause inplace modifications of the collection, and I didn't want to just blindly add .clone() everywhere, so added it once in the fixture. The whole test_transformations.py runs 7 sec for me now (instead of 150 originally), but I think even this is too much given that it really doesn't manipulate much of data ;)

@@ -45,6 +62,7 @@ def test_rename(collection):


def test_product(collection):
collection = collection.clone()
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

oh -- leftovers -- will kill now

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

and killed that entire commit for now anyways -- humanity is not ready for it ;)

@yarikoptic yarikoptic force-pushed the enh-test-transformations branch 2 times, most recently from 3458ec6 to 690f78d Compare March 6, 2019 00:03
@tyarkoni
Copy link
Collaborator

tyarkoni commented Mar 6, 2019

Thanks, this is great! Per #320, I eventually want to move away entirely from using the bundled datasets for transformer testing, in favor of synthetic and much smaller data. That would speed things up further while making it much easier to evaluate against ground truth properly. But this PR makes that less urgent. :)

@yarikoptic
Copy link
Collaborator Author

But this PR makes that less urgent. :)

oh - feel free to close without merging to keep the urge! ;)

types=['events'],
scan_length=SCAN_LENGTH,
merge=True,
sampling_rate=10,
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

btw, IIRC interesting "effects" did appear when I set it to 0.31, you get wonderful

_____________________________________________ test_resample_dense ______________________________________________

collection = <bids.variables.kollekshuns.BIDSRunVariableCollection object at 0x7fae82ce3810>

    def test_resample_dense(collection):
        new_sampling_rate = 50
        old_sampling_rate = collection.sampling_rate
        upsampling = float(new_sampling_rate) / old_sampling_rate
    
        collection['RT'] = collection['RT'].to_dense(old_sampling_rate)
        old_rt = collection['RT'].clone()
>       collection.resample(new_sampling_rate, in_place=True)

bids/analysis/tests/test_transformations.py:192: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
bids/variables/kollekshuns.py:279: in resample
    kind=kind)
bids/variables/variables.py:460: in resample
    f = interp1d(x, self.values.values.ravel(), kind=kind)
/usr/lib/python2.7/dist-packages/scipy/interpolate/interpolate.py:433: in __init__
    _Interpolator1D.__init__(self, x, y, axis=axis)
/usr/lib/python2.7/dist-packages/scipy/interpolate/polyint.py:60: in __init__
    self._set_yi(yi, xi=xi, axis=axis)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

self = <scipy.interpolate.interpolate.interp1d object at 0x7fae81d4f050>
yi = array([0.000e+00, 1.793e+00, 1.637e+00, 0.000e+00, 0.000e+00, 0.000e+00,
     ...e+00, 0.000e+00,
       1.440e+00, 0.000e+00, 2.071e+00, 0.000e+00, 0.000e+00])
xi = array([  0,   1,   2,   3,   4,   5,   6,   7,   8,   9,  10,  11,  12,
      ..., 880, 881, 882, 883,
       884, 885, 886, 887, 888, 889, 890, 891, 892, 893])
axis = -1

    def _set_yi(self, yi, xi=None, axis=None):
        if axis is None:
            axis = self._y_axis
        if axis is None:
            raise ValueError("no interpolation axis specified")
    
        yi = np.asarray(yi)
    
        shape = yi.shape
        if shape == ():
            shape = (1,)
        if xi is not None and shape[axis] != len(xi):
>           raise ValueError("x and y arrays must be equal in length along "
                             "interpolation axis.")
E           ValueError: x and y arrays must be equal in length along interpolation axis.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Ah, good catch. Maybe open a separate issue for that.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

isn't it #361?

Copy link
Collaborator

Choose a reason for hiding this comment

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

It is!

Copy link
Collaborator

Choose a reason for hiding this comment

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

@yarikoptic great minds fail alike

@tyarkoni
Copy link
Collaborator

tyarkoni commented Mar 6, 2019

No no no—I'm perfectly happy being lazy and explaining my laziness by saying that your hard work robbed me of my motivation to improve things. :)

Copy link
Collaborator

@tyarkoni tyarkoni left a comment

Choose a reason for hiding this comment

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

LGTM!

@yarikoptic
Copy link
Collaborator Author

forgot about this one . python 3.5 (nothing else) failed with

>       assert len(collection['RT'].values) in [96 * len(SUBJECTS), 3909]
E       assert 499 in [192, 3909]
E        +  where 499 = len(1      1.793\n2      1.637\n3      1.316\n4      1.670\n5      1.232\n6      1.502\n7      1.925\n8      1.061\n9      1.079\n1...289\n505    2.976\n506    1.257\n507    1.199\n508    1.432\n509    1.440\n510    2.071\nName: RT, Length: 499, dtype: float64)
E        +    where 1      1.793\n2      1.637\n3      1.316\n4      1.670\n5      1.232\n6      1.502\n7      1.925\n8      1.061\n9      1.079\n1...289\n505    2.976\n506    1.257\n507    1.199\n508    1.432\n509    1.440\n510    2.071\nName: RT, Length: 499, dtype: float64 = <bids.variables.variables.SparseRunVariable object at 0x7fa90124e978>.values

I will merge master and see if it reproduces

I thought also to decrease number of runs, but then test_split is not behaving,
so decided to stay at this.  Now tests here would run for 25-30 sec in contrast to 150-180
on my laptop
Creating a collection apparently is more expensive.
Clone() is needed since some tests do modification inplace. If they did not
it was possible to declare this fixture as (scope="module"). So we need to return
a clone each time.  This causes full run time of 9 sec vs 30 sec.
@yarikoptic yarikoptic force-pushed the enh-test-transformations branch from a06773a to 9a1c357 Compare March 21, 2019 19:53
@codecov
Copy link

codecov bot commented Mar 21, 2019

Codecov Report

Merging #413 into master will not change coverage.
The diff coverage is n/a.

Impacted file tree graph

@@           Coverage Diff           @@
##           master     #413   +/-   ##
=======================================
  Coverage   62.48%   62.48%           
=======================================
  Files          27       27           
  Lines        4569     4569           
  Branches     1176     1176           
=======================================
  Hits         2855     2855           
  Misses       1429     1429           
  Partials      285      285
Flag Coverage Δ
#unittests 62.48% <ø> (ø) ⬆️

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 838cef8...9a1c357. Read the comment docs.

@yarikoptic
Copy link
Collaborator Author

Ok, seems to be green. Since it was blessed already, I will merge

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.

3 participants