Skip to content

Instantly share code, notes, and snippets.

@JPDSousa
Created November 26, 2018 15:13
Show Gist options
  • Save JPDSousa/176fca384aed7f4b56ae2ca21bc51530 to your computer and use it in GitHub Desktop.
Save JPDSousa/176fca384aed7f4b56ae2ca21bc51530 to your computer and use it in GitHub Desktop.
Race condition debuging in OpenML H2O Provider
@Test
public void testParallelScoring() throws ModelLoadingException, ExecutionException, InterruptedException {
final ExecutorService executor = Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors() + 1);
final ClassificationH2OModel firstModel = getFirstModel();
final Instance oneInstance = getDummyInstance();
final Instance anotherInstance = getDummyInstanceDifferentResult();
//The expected values -> scored in the same thread.
final double[] oneExpected = firstModel.getClassDistribution(oneInstance);
final double[] otherExpected = firstModel.getClassDistribution(anotherInstance);
// The actual scoring function
final Future<double[]> oneResult = executor.submit(() -> firstModel.getClassDistribution(oneInstance));
final Future<double[]> anotherResult = executor.submit(() -> firstModel.getClassDistribution(anotherInstance));
final SoftAssertions assertions = new SoftAssertions();
assertions.assertThat(oneResult.get())
.usingComparatorWithPrecision(0.001)
.isEqualTo(oneExpected);
//The expected result for 'oneInstance' -> {0.954432234028561, 0.04556776597143899}
assertions.assertThat(anotherResult.get())
.usingComparatorWithPrecision(0.001)
.isEqualTo(otherExpected);
//The expected result for 'anotherInstance' -> {0.9556366865683105, 0.044363313431689616}
assertions.assertAll();
executor.shutdown();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment