Skip to content

Commit

Permalink
Privacy on Beam test refactoring, Java export rule fix, Go update.
Browse files Browse the repository at this point in the history
Privacy on Beam:
- Simplify tests by moving error handling to (Approx)Equal functions.
- Fix some tests in public_partitions_test.go not being run due to missing ptest.Run calls.

Java DP:
- Update Rules JVM External to version 6.0 to fix an issue with the
`java_export` rule.

Go DP:
- Update Go version in GitHub actions.

Change-Id: If97cda7886ef336b1e6811c9c29e2ca58a0cba7a
GitOrigin-RevId: 87b7873d498db4332b0f5b08f80e272be84a1135
  • Loading branch information
Differential Privacy Team authored and dibakch committed Feb 9, 2024
1 parent 7b02d98 commit 26b4436
Show file tree
Hide file tree
Showing 14 changed files with 158 additions and 368 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ jobs:
- name: Set up Go
uses: actions/setup-go@v2
with:
go-version: 1.19
go-version: 1.21

- name: Build go
run: go build -mod=mod -v ./...
Expand Down
4 changes: 2 additions & 2 deletions java/dp_java_deps_preload.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ def dp_java_deps_prework():
This must be called before the rest of the dependencies are loaded.
"""
RULES_JVM_EXTERNAL_TAG = "5.1"
RULES_JVM_EXTERNAL_SHA = "8c3b207722e5f97f1c83311582a6c11df99226e65e2471086e296561e57cc954"
RULES_JVM_EXTERNAL_TAG = "6.0"
RULES_JVM_EXTERNAL_SHA = "85fd6bad58ac76cc3a27c8e051e4255ff9ccd8c92ba879670d195622e7c0a9b7"
BAZEL_COMMON_TAG = "a9e1d8efd54cbf27249695b23775b75ca65bb59d"
BAZEL_COMMON_SHA = "17ea98149586dff60aa741c67fbd9a010fbb1507df90e741c50403bf5228bea3"
http_archive(
Expand Down
2 changes: 1 addition & 1 deletion java/maven_install.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"__AUTOGENERATED_FILE_DO_NOT_MODIFY_THIS_FILE_MANUALLY": "THERE_IS_NO_DATA_ONLY_ZUUL",
"__INPUT_ARTIFACTS_HASH": -131666651,
"__INPUT_ARTIFACTS_HASH": -131668409,
"__RESOLVED_ARTIFACTS_HASH": -1554454602,
"artifacts": {
"com.google.auto.value:auto-value": {
Expand Down
28 changes: 7 additions & 21 deletions privacy-on-beam/pbeam/count_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,7 @@ func TestCountNoNoise(t *testing.T) {
pcol := MakePrivate(s, col, NewPrivacySpec(2*epsilon, delta))
got := Count(s, pcol, CountParams{MaxValue: 2, MaxPartitionsContributed: 1, NoiseKind: LaplaceNoise{}})
want = beam.ParDo(s, testutils.PairII64ToKV, want)
if err := testutils.ApproxEqualsKVInt64(s, got, want, testutils.RoundedLaplaceTolerance(k, l1Sensitivity, epsilon)); err != nil {
t.Fatalf("TestCountNoNoise: %v", err)
}
testutils.ApproxEqualsKVInt64(t, s, got, want, testutils.RoundedLaplaceTolerance(k, l1Sensitivity, epsilon))
if err := ptest.Run(p); err != nil {
t.Errorf("TestCountNoNoise: Count(%v) = %v, expected %v: %v", col, got, want, err)
}
Expand Down Expand Up @@ -112,9 +110,7 @@ func TestCountWithPartitionsNoNoise(t *testing.T) {

got := Count(s, pcol, countParams)
want = beam.ParDo(s, testutils.PairII64ToKV, want)
if err := testutils.ApproxEqualsKVInt64(s, got, want, testutils.RoundedLaplaceTolerance(k, l1Sensitivity, epsilon)); err != nil {
t.Fatalf("TestCountWithPartitionsNoNoise in-memory=%t: %v", tc.inMemory, err)
}
testutils.ApproxEqualsKVInt64(t, s, got, want, testutils.RoundedLaplaceTolerance(k, l1Sensitivity, epsilon))
if err := ptest.Run(p); err != nil {
t.Errorf("TestCountWithPartitionsNoNoise in-memory=%t: Count(%v) = %v, expected %v: %v", tc.inMemory, col, got, want, err)
}
Expand Down Expand Up @@ -381,9 +377,7 @@ func TestCountCrossPartitionContributionBounding(t *testing.T) {
sumOverPartitions := stats.Sum(s, counts)
got = beam.AddFixedKey(s, sumOverPartitions) // Adds a fixed key of 0.
want = beam.ParDo(s, testutils.PairII64ToKV, want)
if err := testutils.ApproxEqualsKVInt64(s, got, want, testutils.RoundedLaplaceTolerance(k, l1Sensitivity, epsilon)); err != nil {
t.Fatalf("TestCountCrossPartitionContributionBounding: %v", err)
}
testutils.ApproxEqualsKVInt64(t, s, got, want, testutils.RoundedLaplaceTolerance(k, l1Sensitivity, epsilon))
if err := ptest.Run(p); err != nil {
t.Errorf("TestCountCrossPartitionContributionBounding: Metric(%v) = %v, expected elements to sum to 150: %v", col, got, err)
}
Expand Down Expand Up @@ -430,9 +424,7 @@ func TestCountWithPartitionsCrossPartitionContributionBounding(t *testing.T) {
sumOverPartitions := stats.Sum(s, counts)
got = beam.AddFixedKey(s, sumOverPartitions) // Adds a fixed key of 0.
want = beam.ParDo(s, testutils.PairII64ToKV, want)
if err := testutils.ApproxEqualsKVInt64(s, got, want, testutils.RoundedLaplaceTolerance(k, l1Sensitivity, epsilon)); err != nil {
t.Fatalf("TestCountWithPartitionsCrossPartitionContributionBounding in-memory=%t: %v", tc.inMemory, err)
}
testutils.ApproxEqualsKVInt64(t, s, got, want, testutils.RoundedLaplaceTolerance(k, l1Sensitivity, epsilon))
if err := ptest.Run(p); err != nil {
t.Errorf("TestCountWithPartitionsCrossPartitionContributionBounding in-memory=%t: Metric(%v) = %v, expected elements to sum to 150: %v", tc.inMemory, col, got, err)
}
Expand Down Expand Up @@ -872,9 +864,7 @@ func TestCountNoNoiseTemp(t *testing.T) {
pcol := MakePrivate(s, col, spec)
got := Count(s, pcol, CountParams{MaxValue: 2, MaxPartitionsContributed: 1, NoiseKind: LaplaceNoise{}})
want = beam.ParDo(s, testutils.PairII64ToKV, want)
if err := testutils.ApproxEqualsKVInt64(s, got, want, testutils.RoundedLaplaceTolerance(k, l1Sensitivity, epsilon)); err != nil {
t.Fatalf("TestCountNoNoiseTemp: %v", err)
}
testutils.ApproxEqualsKVInt64(t, s, got, want, testutils.RoundedLaplaceTolerance(k, l1Sensitivity, epsilon))
if err := ptest.Run(p); err != nil {
t.Errorf("TestCountNoNoiseTemp: Count(%v) = %v, expected %v: %v", col, got, want, err)
}
Expand Down Expand Up @@ -923,9 +913,7 @@ func TestCountWithPartitionsNoNoiseTemp(t *testing.T) {

got := Count(s, pcol, countParams)
want = beam.ParDo(s, testutils.PairII64ToKV, want)
if err := testutils.ApproxEqualsKVInt64(s, got, want, testutils.RoundedLaplaceTolerance(k, l1Sensitivity, epsilon)); err != nil {
t.Fatalf("TestCountWithPartitionsNoNoiseTemp in-memory=%t: %v", tc.inMemory, err)
}
testutils.ApproxEqualsKVInt64(t, s, got, want, testutils.RoundedLaplaceTolerance(k, l1Sensitivity, epsilon))
if err := ptest.Run(p); err != nil {
t.Errorf("TestCountWithPartitionsNoNoiseTemp in-memory=%t: Count(%v) = %v, expected %v: %v", tc.inMemory, col, got, want, err)
}
Expand Down Expand Up @@ -966,9 +954,7 @@ func TestCountPreThresholding(t *testing.T) {
pcol := MakePrivate(s, col, spec)
got := Count(s, pcol, CountParams{MaxValue: int64(l1Sensitivity), MaxPartitionsContributed: 1, NoiseKind: LaplaceNoise{}})
want = beam.ParDo(s, testutils.PairII64ToKV, want)
if err := testutils.ApproxEqualsKVInt64(s, got, want, testutils.RoundedLaplaceTolerance(k, l1Sensitivity, epsilon)); err != nil {
t.Fatalf("TestCountPreThresholding: %v", err)
}
testutils.ApproxEqualsKVInt64(t, s, got, want, testutils.RoundedLaplaceTolerance(k, l1Sensitivity, epsilon))
if err := ptest.Run(p); err != nil {
t.Errorf("TestCountPreThresholding: Count(%v) = %v, expected %v: %v", col, got, want, err)
}
Expand Down
32 changes: 8 additions & 24 deletions privacy-on-beam/pbeam/distinct_id_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,7 @@ func TestDistinctPrivacyIDNoNoise(t *testing.T) {
pcol := MakePrivate(s, col, NewPrivacySpec(epsilon, delta))
got := DistinctPrivacyID(s, pcol, DistinctPrivacyIDParams{MaxPartitionsContributed: 4, NoiseKind: LaplaceNoise{}})
want = beam.ParDo(s, testutils.PairII64ToKV, want)
if err := testutils.ApproxEqualsKVInt64(s, got, want, testutils.RoundedLaplaceTolerance(k, l1Sensitivity, epsilon)); err != nil {
t.Fatalf("TestDistinctPrivacyIDNoNoise: %v", err)
}
testutils.ApproxEqualsKVInt64(t, s, got, want, testutils.RoundedLaplaceTolerance(k, l1Sensitivity, epsilon))
if err := ptest.Run(p); err != nil {
t.Errorf("TestDistinctPrivacyIDNoNoise: DistinctPrivacyID(%v) = %v, expected %v: %v", col, got, want, err)
}
Expand Down Expand Up @@ -141,9 +139,7 @@ func TestDistinctPrivacyIDWithPartitionsNoNoise(t *testing.T) {
distinctPrivacyIDParams := DistinctPrivacyIDParams{MaxPartitionsContributed: 4, NoiseKind: LaplaceNoise{}, PublicPartitions: publicPartitions}
got := DistinctPrivacyID(s, pcol, distinctPrivacyIDParams)
want = beam.ParDo(s, testutils.PairII64ToKV, want)
if err := testutils.ApproxEqualsKVInt64(s, got, want, testutils.RoundedLaplaceTolerance(k, l1Sensitivity, epsilon)); err != nil {
t.Fatalf("TestDistinctPrivacyIDWithPartitionsNoNoise in-memory=%t: %v", tc.inMemory, err)
}
testutils.ApproxEqualsKVInt64(t, s, got, want, testutils.RoundedLaplaceTolerance(k, l1Sensitivity, epsilon))
if err := ptest.Run(p); err != nil {
t.Errorf("TestDistinctPrivacyIDWithPartitionsNoNoise in-memory=%t: DistinctPrivacyID(%v) = %v, expected %v: %v", tc.inMemory, col, got, want, err)
}
Expand Down Expand Up @@ -426,9 +422,7 @@ func TestDistinctPrivacyIDCrossPartitionContributionBounding(t *testing.T) {
sumOverPartitions := stats.Sum(s, counts)
got = beam.AddFixedKey(s, sumOverPartitions) // Adds a fixed key of 0.
want = beam.ParDo(s, testutils.PairII64ToKV, want)
if err := testutils.ApproxEqualsKVInt64(s, got, want, testutils.RoundedLaplaceTolerance(k, l1Sensitivity, epsilon)); err != nil {
t.Fatalf("TestDistinctPrivacyIDCrossPartitionContributionBounding: %v", err)
}
testutils.ApproxEqualsKVInt64(t, s, got, want, testutils.RoundedLaplaceTolerance(k, l1Sensitivity, epsilon))
if err := ptest.Run(p); err != nil {
t.Errorf("TestDistinctPrivacyIDCrossPartitionContributionBounding: DistinctPrivacyID(%v) = %v, expected elements to sum to 150: %v", col, got, err)
}
Expand Down Expand Up @@ -476,9 +470,7 @@ func TestDistinctPrivacyIDWithPartitionsCrossPartitionContributionBounding(t *te
sumOverPartitions := stats.Sum(s, counts)
got = beam.AddFixedKey(s, sumOverPartitions) // Adds a fixed key of 0.
want = beam.ParDo(s, testutils.PairII64ToKV, want)
if err := testutils.ApproxEqualsKVInt64(s, got, want, testutils.RoundedLaplaceTolerance(k, l1Sensitivity, epsilon)); err != nil {
t.Fatalf("TestDistinctPrivacyIDWithPartitionsCrossPartitionContributionBounding in-memory=%t: %v", tc.inMemory, err)
}
testutils.ApproxEqualsKVInt64(t, s, got, want, testutils.RoundedLaplaceTolerance(k, l1Sensitivity, epsilon))
if err := ptest.Run(p); err != nil {
t.Errorf("TestDistinctPrivacyIDWithPartitionsCrossPartitionContributionBounding in-memory=%t: DistinctPrivacyID(%v) = %v, expected elements to sum to 150: %v", tc.inMemory, col, got, err)
}
Expand Down Expand Up @@ -579,9 +571,7 @@ func TestDistinctPrivacyIDOptimizedContrib(t *testing.T) {
pcol := MakePrivate(s, col, NewPrivacySpec(epsilon, delta))
got := DistinctPrivacyID(s, pcol, DistinctPrivacyIDParams{MaxPartitionsContributed: 4, NoiseKind: LaplaceNoise{}})
want = beam.ParDo(s, testutils.PairII64ToKV, want)
if err := testutils.ApproxEqualsKVInt64(s, got, want, testutils.RoundedLaplaceTolerance(k, l1Sensitivity, epsilon)); err != nil {
t.Fatalf("TestDistinctPrivacyIDOptimizedContrib: %v", err)
}
testutils.ApproxEqualsKVInt64(t, s, got, want, testutils.RoundedLaplaceTolerance(k, l1Sensitivity, epsilon))
if err := ptest.Run(p); err != nil {
t.Errorf("TestDistinctPrivacyIDOptimizedContrib: DistinctPrivacyID(%v) = %v, expected %v: %v", col, got, want, err)
}
Expand Down Expand Up @@ -1116,9 +1106,7 @@ func TestDistinctPrivacyIDNoNoiseTemp(t *testing.T) {
pcol := MakePrivate(s, col, spec)
got := DistinctPrivacyID(s, pcol, DistinctPrivacyIDParams{MaxPartitionsContributed: 4, NoiseKind: LaplaceNoise{}})
want = beam.ParDo(s, testutils.PairII64ToKV, want)
if err := testutils.ApproxEqualsKVInt64(s, got, want, testutils.RoundedLaplaceTolerance(k, l1Sensitivity, epsilon)); err != nil {
t.Fatalf("TestDistinctPrivacyIDNoNoiseTemp: %v", err)
}
testutils.ApproxEqualsKVInt64(t, s, got, want, testutils.RoundedLaplaceTolerance(k, l1Sensitivity, epsilon))
if err := ptest.Run(p); err != nil {
t.Errorf("TestDistinctPrivacyIDNoNoiseTemp: DistinctPrivacyID(%v) = %v, expected %v: %v", col, got, want, err)
}
Expand Down Expand Up @@ -1172,9 +1160,7 @@ func TestDistinctPrivacyIDWithPartitionsNoNoiseTemp(t *testing.T) {
distinctPrivacyIDParams := DistinctPrivacyIDParams{MaxPartitionsContributed: 4, NoiseKind: LaplaceNoise{}, PublicPartitions: publicPartitions}
got := DistinctPrivacyID(s, pcol, distinctPrivacyIDParams)
want = beam.ParDo(s, testutils.PairII64ToKV, want)
if err := testutils.ApproxEqualsKVInt64(s, got, want, testutils.RoundedLaplaceTolerance(k, l1Sensitivity, epsilon)); err != nil {
t.Fatalf("TestDistinctPrivacyIDWithPartitionsNoNoiseTemp in-memory=%t: %v", tc.inMemory, err)
}
testutils.ApproxEqualsKVInt64(t, s, got, want, testutils.RoundedLaplaceTolerance(k, l1Sensitivity, epsilon))
if err := ptest.Run(p); err != nil {
t.Errorf("TestDistinctPrivacyIDWithPartitionsNoNoiseTemp in-memory=%t: DistinctPrivacyID(%v) = %v, expected %v: %v", tc.inMemory, col, got, want, err)
}
Expand Down Expand Up @@ -1214,9 +1200,7 @@ func TestDistinctPrivacyIDPreThresholding(t *testing.T) {
pcol := MakePrivate(s, col, spec)
got := DistinctPrivacyID(s, pcol, DistinctPrivacyIDParams{MaxPartitionsContributed: 1, NoiseKind: LaplaceNoise{}})
want = beam.ParDo(s, testutils.PairII64ToKV, want)
if err := testutils.ApproxEqualsKVInt64(s, got, want, testutils.RoundedLaplaceTolerance(k, l1Sensitivity, epsilon)); err != nil {
t.Fatalf("TestDistinctPrivacyIDPreThresholding: %v", err)
}
testutils.ApproxEqualsKVInt64(t, s, got, want, testutils.RoundedLaplaceTolerance(k, l1Sensitivity, epsilon))
if err := ptest.Run(p); err != nil {
t.Errorf("TestDistinctPrivacyIDPreThresholding: Count(%v) = %v, expected %v: %v", col, got, want, err)
}
Expand Down
Loading

0 comments on commit 26b4436

Please sign in to comment.