OpenMined / PyDP

The Python Differential Privacy Library. Built on top of: https://github.com/google/differential-privacy
Apache License 2.0
500 stars 138 forks source link

Optimize test_bounded_mean test execution #333

Closed alejandrosame closed 3 years ago

alejandrosame commented 3 years ago

Description

Added the possibility to write to file the serialized algorithm data. Currently, we have unit tests that take too much time to run, which hinders quick iteration (mentioned in https://github.com/OpenMined/PyDP/issues/265).

The current PR extends the Summary object to let us save and load protobuf data to a file in order to use it in fixtures. This has the benefit of paying for the creation of "big" setups only once, while the rest of the times the fixture will be loaded from a test data file.

With this approach, we can already see an important improvement for test_bounded_mean, where test execution time drops from ~124s to ~0.04s.

This is just a first step towards test optimization, future steps are:

This PR depends on #332 to be merged first.

Affected Dependencies

No new dependencies added.

How has this been tested?

Checklist

alejandrosame commented 3 years ago

Now that #332 is merged, I can take out the WIP from this PR. If tests are successful, it will be ready for review @chinmayshah99 and @BenjaminDev.

chinmayshah99 commented 3 years ago

I think we need to update all our tests right?

alejandrosame commented 3 years ago

@chinmayshah99 I think they are ok, apart from the distributions test mentioned before (which anyway requires a different serde strategy). We can simply keep track if we add a new test with heavy setup like here. In that case, we can use the same fixture approach to keep test execution fast (and generalize code as we see it fits best).