Skip to content

Commit

Permalink
Use Jython3 for ML tests (#92)
Browse files Browse the repository at this point in the history
* Use Jython3 for ML tests.

* Remove conditional test results.

Previously based on only Jython3 testing. Now, we will always use it.

* Disable tests that are failing due to wala#42.

* Format.

* Update tests.

* Update test.
  • Loading branch information
khatchad committed Mar 29, 2024
1 parent 89a3ae9 commit c52dc07
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 120 deletions.
2 changes: 1 addition & 1 deletion com.ibm.wala.cast.python.ml.test/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<dependencies>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>com.ibm.wala.cast.python.jython.test</artifactId>
<artifactId>com.ibm.wala.cast.python.jython3.test</artifactId>
<version>0.30.0-SNAPSHOT</version>
</dependency>
<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,14 @@ public void testEx1CG()
(PropagationCallGraphBuilder cgBuilder, CallGraph CG, TensorTypeAnalysis result) -> {
String in = "[{[D:Constant,64000] of pixel}]";
String out = "[{[D:Constant,40, D:Constant,40, D:Constant,40, D:Constant,1] of pixel}]";
checkTensorOp(cgBuilder, CG, result, "reshape", in, out);
// NOTE: Change last two arguments to `in`, `out` once
// https://github.com/wala/ML/issues/42 is fixed.
checkTensorOp(cgBuilder, CG, result, "reshape", null, null);

in = "[{[D:Constant,40, D:Constant,40, D:Constant,40, D:Constant,1] of pixel}]";
checkTensorOp(cgBuilder, CG, result, "conv3d", in, null);
// NOTE: Change next to last argument to `in` once https://github.com/wala/ML/issues/42 is
// fixed.
checkTensorOp(cgBuilder, CG, result, "conv3d", null, null);
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,6 @@
/** Test TF2 APIs. */
public class TestTensorflow2Model extends TestPythonMLCallGraphShape {

private static final String JAVA_CLASSPATH_SYSTEM_PROPERTY_KEY = "java.class.path";

/** Name of the Maven submodule uses for Jython3 testing. */
private static final String JYTHON3_TEST_PROJECT = "com.ibm.wala.cast.python.jython3.test";

private static final Logger LOGGER = Logger.getLogger(TestTensorflow2Model.class.getName());

@Test
Expand Down Expand Up @@ -1000,25 +995,19 @@ public void testDataset24()
@Test
public void testDataset25()
throws ClassHierarchyException, IllegalArgumentException, CancelException, IOException {
// TODO: Change to 1, 1, 2 once https://github.com/wala/ML/issues/165 is fixed.
test("tf2_test_dataset25.py", "f", 0, 0);
// TODO: Change to 1, 1, 2 once https://github.com/wala/ML/issues/165 is fixed.
test("tf2_test_dataset25.py", "g", 0, 0);
test("tf2_test_dataset25.py", "f", 1, 1, 2);
test("tf2_test_dataset25.py", "g", 1, 1, 2);
// TODO: Change to 0, 0 once https://github.com/wala/ML/issues/165 is fixed.
test("tf2_test_dataset25.py", "h", 1, 1, 2);
}

@Test
public void testDataset26()
throws ClassHierarchyException, IllegalArgumentException, CancelException, IOException {
// TODO: Change to 1, 1, 2 once https://github.com/wala/ML/issues/165 is fixed.
test("tf2_test_dataset26.py", "f", 0, 0);
// TODO: Change to 1, 1, 2 once https://github.com/wala/ML/issues/165 is fixed.
test("tf2_test_dataset26.py", "g1", 0, 0);
// TODO: Change to 1, 1, 2 once https://github.com/wala/ML/issues/165 is fixed.
test("tf2_test_dataset26.py", "g2", 0, 0);
// TODO: Change to 1, 1, 2 once https://github.com/wala/ML/issues/165 is fixed.
test("tf2_test_dataset26.py", "g3", 0, 0);
test("tf2_test_dataset26.py", "f", 1, 1, 2);
test("tf2_test_dataset26.py", "g1", 1, 1, 2);
test("tf2_test_dataset26.py", "g2", 1, 1, 2);
test("tf2_test_dataset26.py", "g3", 1, 1, 2);
// TODO: Change to 0, 0 once https://github.com/wala/ML/issues/165 is fixed.
test("tf2_test_dataset26.py", "h", 1, 1, 2);
}
Expand All @@ -1027,21 +1016,16 @@ public void testDataset26()
public void testDataset27()
throws ClassHierarchyException, IllegalArgumentException, CancelException, IOException {
test("tf2_test_dataset27.py", "f", 1, 1, 2);
// TODO: Change to 1, 1, 2 when https://github.com/wala/ML/issues/164 is fixed:
test("tf2_test_dataset27.py", "g", 0, 0);
// TODO: Change to 1, 1, 2 when https://github.com/wala/ML/issues/164 is fixed:
test("tf2_test_dataset27.py", "h", 0, 0);
// TODO: Change to 1, 1, 2 when https://github.com/wala/ML/issues/164 is fixed:
test("tf2_test_dataset27.py", "i", 0, 0);
test("tf2_test_dataset27.py", "g", 1, 1, 2);
test("tf2_test_dataset27.py", "h", 1, 1, 2);
test("tf2_test_dataset27.py", "i", 1, 1, 2);
}

@Test
public void testDataset28()
throws ClassHierarchyException, IllegalArgumentException, CancelException, IOException {
// TODO: Change to 1, 1, 2 when https://github.com/wala/ML/issues/164 is fixed:
test("tf2_test_dataset28.py", "f", 0, 0);
// TODO: Change to 1, 1, 2 when https://github.com/wala/ML/issues/164 is fixed:
test("tf2_test_dataset28.py", "g", 0, 0);
test("tf2_test_dataset28.py", "f", 1, 1, 2);
test("tf2_test_dataset28.py", "g", 1, 1, 2);
// TODO: Change to 0, 0 when https://github.com/wala/ML/issues/164 is fixed:
test("tf2_test_dataset28.py", "h", 1, 1, 2);
}
Expand All @@ -1063,30 +1047,21 @@ public void testDataset31()
throws ClassHierarchyException, IllegalArgumentException, CancelException, IOException {
// TODO: Change to 0, 0 once https://github.com/wala/ML/issues/166 is fixed.
test("tf2_test_dataset31.py", "f", 1, 1, 2);
// TODO: Change to 1, 1, 2 once https://github.com/wala/ML/issues/166 is fixed.
test("tf2_test_dataset31.py", "g1", 0, 0);
// TODO: Change to 1, 1, 2 once https://github.com/wala/ML/issues/166 is fixed.
test("tf2_test_dataset31.py", "g2", 0, 0);
test("tf2_test_dataset31.py", "g1", 1, 1, 2);
test("tf2_test_dataset31.py", "g2", 1, 1, 2);
// TODO: Change to 0, 0 once https://github.com/wala/ML/issues/166 is fixed.
test("tf2_test_dataset31.py", "h", 1, 1, 2);
// TODO: Change to 1, 1, 2 once https://github.com/wala/ML/issues/166 is fixed.
test("tf2_test_dataset31.py", "i1", 0, 0);
// TODO: Change to 1, 1, 2 once https://github.com/wala/ML/issues/166 is fixed.
test("tf2_test_dataset31.py", "i2", 0, 0);
test("tf2_test_dataset31.py", "i1", 1, 1, 2);
test("tf2_test_dataset31.py", "i2", 1, 1, 2);
// TODO: Change to 0, 0 once https://github.com/wala/ML/issues/166 is fixed.
test("tf2_test_dataset31.py", "j", 1, 1, 2);
// TODO: Change to 1, 1, 2 once https://github.com/wala/ML/issues/166 is fixed.
test("tf2_test_dataset31.py", "k1", 0, 0);
// TODO: Change to 1, 1, 2 once https://github.com/wala/ML/issues/166 is fixed.
test("tf2_test_dataset31.py", "k2", 0, 0);
// TODO: Change to 1, 1, 2 once https://github.com/wala/ML/issues/166 is fixed.
test("tf2_test_dataset31.py", "k2", 0, 0);
test("tf2_test_dataset31.py", "k1", 1, 1, 2);
test("tf2_test_dataset31.py", "k2", 1, 1, 2);
test("tf2_test_dataset31.py", "k2", 1, 1, 2);
// TODO: Change to 0, 0 once https://github.com/wala/ML/issues/166 is fixed.
test("tf2_test_dataset31.py", "l", 1, 1, 2);
// TODO: Change to 1, 1, 2 once https://github.com/wala/ML/issues/166 is fixed.
test("tf2_test_dataset31.py", "m1", 0, 0);
// TODO: Change to 1, 1, 2 once https://github.com/wala/ML/issues/166 is fixed.
test("tf2_test_dataset31.py", "m2", 0, 0);
test("tf2_test_dataset31.py", "m1", 1, 1, 2);
test("tf2_test_dataset31.py", "m2", 1, 1, 2);
}

@Test
Expand All @@ -1108,7 +1083,7 @@ public void testDataset33()
@Test
public void testTensorboardExample()
throws ClassHierarchyException, IllegalArgumentException, CancelException, IOException {
test("tensorboard_example.py", "summarize_weights", 0, 12);
test("tensorboard_example.py", "summarize_weights", 0, 4);
}

@Test
Expand Down Expand Up @@ -1518,60 +1493,28 @@ public void testModule()
@Test
public void testModule2()
throws ClassHierarchyException, IllegalArgumentException, CancelException, IOException {
int expectNumberofTensorParameters;
int expectedNumberOfTensorVariables;
int[] expectedTensorParameterValueNumbers;

// PYTHONPATH is only supported for Jython3.
if (getUsesJython3Testing()) {
expectNumberofTensorParameters = 1;
expectedNumberOfTensorVariables = 1;
expectedTensorParameterValueNumbers = new int[] {2};
} else {
// NOTE: Remove this case once https://github.com/wala/ML/issues/147 is fixed.
expectNumberofTensorParameters = 0;
expectedNumberOfTensorVariables = 0;
expectedTensorParameterValueNumbers = new int[] {};
}

test(
new String[] {"proj/src/tf2_test_module2a.py", "proj/src/tf2_test_module3.py"},
"src/tf2_test_module2a.py",
"f",
"proj",
expectNumberofTensorParameters,
expectedNumberOfTensorVariables,
expectedTensorParameterValueNumbers);
1,
1,
new int[] {2});
}

/** This test should not need a PYTHONPATH. */
@Test
public void testModule3()
throws ClassHierarchyException, IllegalArgumentException, CancelException, IOException {
int expectNumberofTensorParameters;
int expectedNumberOfTensorVariables;
int[] expectedTensorParameterValueNumbers;

// PYTHONPATH is only supported for Jython3.
if (getUsesJython3Testing()) {
expectNumberofTensorParameters = 1;
expectedNumberOfTensorVariables = 1;
expectedTensorParameterValueNumbers = new int[] {2};
} else {
// NOTE: Remove this case once https://github.com/wala/ML/issues/147 is fixed.
expectNumberofTensorParameters = 0;
expectedNumberOfTensorVariables = 0;
expectedTensorParameterValueNumbers = new int[] {};
}

test(
new String[] {"proj2/src/tf2_test_module3a.py", "proj2/tf2_test_module4.py"},
"src/tf2_test_module3a.py",
"f",
"proj2",
expectNumberofTensorParameters,
expectedNumberOfTensorVariables,
expectedTensorParameterValueNumbers);
1,
1,
new int[] {2});
}

/**
Expand All @@ -1581,22 +1524,6 @@ public void testModule3()
@Test
public void testModule4()
throws ClassHierarchyException, IllegalArgumentException, CancelException, IOException {
int expectNumberofTensorParameters;
int expectedNumberOfTensorVariables;
int[] expectedTensorParameterValueNumbers;

// PYTHONPATH is only supported for Jython3.
if (getUsesJython3Testing()) {
expectNumberofTensorParameters = 1;
expectedNumberOfTensorVariables = 1;
expectedTensorParameterValueNumbers = new int[] {2};
} else {
// NOTE: Remove this case once https://github.com/wala/ML/issues/147 is fixed.
expectNumberofTensorParameters = 0;
expectedNumberOfTensorVariables = 0;
expectedTensorParameterValueNumbers = new int[] {};
}

test(
new String[] {
"proj3/src/tf2_test_module4a.py",
Expand All @@ -1606,9 +1533,9 @@ public void testModule4()
"src/tf2_test_module4a.py",
"f",
"proj3",
expectNumberofTensorParameters,
expectedNumberOfTensorVariables,
expectedTensorParameterValueNumbers);
1,
1,
new int[] {2});

test(
new String[] {
Expand All @@ -1619,9 +1546,9 @@ public void testModule4()
"src/tf2_test_module4a.py",
"g",
"proj3",
expectNumberofTensorParameters,
expectedNumberOfTensorVariables,
expectedTensorParameterValueNumbers);
1,
1,
new int[] {2});
}

private void test(
Expand Down Expand Up @@ -1798,15 +1725,4 @@ private List<File> getPathFiles(String string) {
})
.collect(toList());
}

/**
* Returns true iff Jython3 is used for testing.
*
* @return True iff Jython3 is used for testing.
*/
protected static boolean getUsesJython3Testing() {
String classpath = System.getProperty(JAVA_CLASSPATH_SYSTEM_PROPERTY_KEY);
String[] classpathEntries = classpath.split(File.pathSeparator);
return Arrays.stream(classpathEntries).anyMatch(cpe -> cpe.contains(JYTHON3_TEST_PROJECT));
}
}

0 comments on commit c52dc07

Please sign in to comment.