Skip to content

Commit

Permalink
Migrate Java to the API that accepts double delta, fix bugs in C++
Browse files Browse the repository at this point in the history
Overall:
- Update Bazel to 6.4.0

C++:
- Remove incorrect assumptions about the default capacity of hashtables. With small buffer optimization in swisstable, default capacity is no longer guaranteed to be 0
- Fix a typo in algorithm.h
- Fix use of uninitialized value
- Update boringssl dependency
- Update external absl dependency

Java:
- Use the new DP lib aggregations API that accepts double delta
- Use the new Noise.addNoise() methods that accept double delta. The methods that accept @nullable Double delta were deprecated

Change-Id: I289fc97e33c964b78af0013b52c267ba7e73ef52
GitOrigin-RevId: 2da05a4be29a39fc0c55a006365d31c31e93a7f5
  • Loading branch information
Differential Privacy Team authored and miracvbasaran committed Nov 13, 2023
1 parent 91b4ece commit 53b4c6a
Show file tree
Hide file tree
Showing 31 changed files with 219 additions and 198 deletions.
2 changes: 1 addition & 1 deletion .bazelversion
Original file line number Diff line number Diff line change
@@ -1 +1 @@
6.2.1
6.4.0
2 changes: 1 addition & 1 deletion cc/.bazelversion
Original file line number Diff line number Diff line change
@@ -1 +1 @@
6.2.1
6.4.0
2 changes: 1 addition & 1 deletion cc/algorithms/algorithm.h
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ class Algorithm {
// algorithm used. The summary proto cannot be empty.
virtual absl::Status Merge(const Summary& summary) = 0;

// Returns an estimate for the currrent memory consumption of the algorithm in
// Returns an estimate for the current memory consumption of the algorithm in
// bytes. Intended to be used for distribution frameworks to prevent
// out-of-memory errors.
virtual int64_t MemoryUsed() = 0;
Expand Down
1 change: 1 addition & 0 deletions cc/algorithms/bounded-mean.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

#include <algorithm>
#include <cmath>
#include <cstdint>
#include <memory>
#include <type_traits>
#include <utility>
Expand Down
2 changes: 2 additions & 0 deletions cc/algorithms/internal/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ cc_test(
deps = [
":bounded-mean-ci",
"//algorithms:numerical-mechanisms",
"//base/testing:proto_matchers",
"//base/testing:status_matchers",
"@com_google_absl//absl/log:check",
"@com_google_absl//absl/status:statusor",
"@com_google_differential_privacy//proto:confidence_interval_cc_proto",
Expand Down
10 changes: 10 additions & 0 deletions cc/algorithms/internal/bounded-mean-ci.cc
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include "algorithms/internal/bounded-mean-ci.h"

#include <algorithm>
#include <cmath>
#include <limits>

#include "algorithms/numerical-mechanisms.h"
Expand Down Expand Up @@ -100,8 +101,17 @@ NoiseConfidenceIntervalForFixedNumAndDenom(
//
// This implementation uses a brute force search for confidenceLevelNum that
// minimizes the size of the confidence interval of bounded mean.
//
// In case one of the input parameters is not finite, this function will return
// a default-constructed ConfidenceInterval with no values set.
ConfidenceInterval BoundedMeanConfidenceInterval(
const BoundedMeanConfidenceIntervalParams &params) {
if (!std::isfinite(params.confidence_level) ||
!std::isfinite(params.noised_sum) || !std::isfinite(params.lower_bound) ||
!std::isfinite(params.upper_bound) ||
!std::isfinite(params.noised_count)) {
return ConfidenceInterval();
}
NumericalMechanism::NoiseConfidenceIntervalResult tightest_ci;
double tightest_ci_size = std::numeric_limits<double>::max();
for (int i = 1; i < kNumStepsOptMeanConfidenceInterval; ++i) {
Expand Down
16 changes: 16 additions & 0 deletions cc/algorithms/internal/bounded-mean-ci_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,12 @@
#include "algorithms/internal/bounded-mean-ci.h"

#include <cmath>
#include <limits>
#include <memory>
#include <utility>

#include "base/testing/proto_matchers.h"
#include "base/testing/status_matchers.h"
#include "gmock/gmock.h"
#include "gtest/gtest.h"
#include "absl/log/check.h"
Expand All @@ -35,6 +38,7 @@ using ::testing::_;
using ::testing::AtLeast;
using ::testing::DoubleEq;
using ::testing::DoubleNear;
using ::differential_privacy::base::testing::EqualsProto;
using ::testing::Gt;
using ::testing::Lt;
using ::testing::StrictMock;
Expand Down Expand Up @@ -246,6 +250,18 @@ TEST(BoundedMeanCiTest,
EXPECT_GT(ci_fewer_units.upper_bound(), ci_more_units.upper_bound());
}

TEST(BoundedMeanCiTest, InfiniteNoisedParamsReturnsDefaultCi) {
BoundedMeanConfidenceIntervalParams params;
params.lower_bound = -1.0;
params.upper_bound = 1.0;
params.noised_sum = std::numeric_limits<double>::infinity();
params.noised_count = std::numeric_limits<double>::infinity();
params.sum_mechanism = nullptr;
params.count_mechanism = nullptr;

EXPECT_THAT(BoundedMeanConfidenceInterval(params), EqualsProto(""));
}

} // namespace
} // namespace internal
} // namespace differential_privacy
11 changes: 0 additions & 11 deletions cc/algorithms/internal/count-tree_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -144,17 +144,6 @@ TEST(CountTreeTest, MisatchMergeFails) {
StatusIs(absl::StatusCode::kInternal, HasSubstr("Branching")));
}

TEST(CountTreeTest, MemoryUsed) {
CountTree empty(3, 5);
CountTree single(3, 5);
CountTree twice(3, 5);
single.IncrementNode(1);
twice.IncrementNode(9);
twice.IncrementNode(9);
EXPECT_GT(single.MemoryUsed(), empty.MemoryUsed());
EXPECT_EQ(twice.MemoryUsed(), single.MemoryUsed());
}

TEST(CountTreeTest, ClearNodes) {
CountTree test1(3, 5);
test1.IncrementNode(1);
Expand Down
14 changes: 7 additions & 7 deletions cc/cc_differential_privacy_deps.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ def cc_differential_privacy_deps():
# Abseil
http_archive(
name = "com_google_absl",
url = "https://github.com/abseil/abseil-cpp/archive/refs/tags/20230125.3.tar.gz",
sha256 = "5366d7e7fa7ba0d915014d387b66d0d002c03236448e1ba9ef98122c13b35c36",
strip_prefix = "abseil-cpp-20230125.3",
url = "https://github.com/abseil/abseil-cpp/archive/refs/tags/20230802.1.tar.gz",
sha256 = "987ce98f02eefbaf930d6e38ab16aa05737234d7afbab2d5c4ea7adbe50c28ed",
strip_prefix = "abseil-cpp-20230802.1",
)

# Common bazel rules. Also required for Abseil.
Expand Down Expand Up @@ -69,11 +69,11 @@ def cc_differential_privacy_deps():
# BoringSSL for cryptographic PRNG
http_archive(
name = "boringssl",
# Commit date: 2023-03-17
# Commit date: 2023-10-26
# Note for updating: we need to use a commit from the `master-with-bazel` branch.
url = "https://github.com/google/boringssl/archive/e0648e015f039ef88801ff0cf84dcb5944b8b5ab.tar.gz",
sha256 = "b9ba36d3c309cfee56df70da8e8700f9ac65d4c0460f78bf8a4e580300b7f59d",
strip_prefix = "boringssl-e0648e015f039ef88801ff0cf84dcb5944b8b5ab",
url = "https://github.com/google/boringssl/archive/add3674f646bcc3dfa828f308454fb3b37919512.tar.gz",
sha256 = "f8b81f1741667e4a5aa9f0cc3e873875f7f832b3b141b8ee3a5d5863f992b8ba",
strip_prefix = "boringssl-add3674f646bcc3dfa828f308454fb3b37919512",
)

# Supports `./configure && make` style packages to become dependencies.
Expand Down
2 changes: 1 addition & 1 deletion cc/postgres/.bazelversion
Original file line number Diff line number Diff line change
@@ -1 +1 @@
6.2.1
6.4.0
9 changes: 2 additions & 7 deletions cc/proto/util.h
Original file line number Diff line number Diff line change
Expand Up @@ -132,13 +132,8 @@ void AddToOutput(Output* output, const T& value,
const ConfidenceInterval& noise_confidence_interval) {
Output_Element* element = output->add_elements();
SetValue(element->mutable_value(), value);
// Use the copy constructor here since operator= (or CopyFrom) would use an
// uninitialized value, perhaps as ConfidenceInterval is a proto3 message
// inside a proto2 message.
ConfidenceInterval* ci_copy =
new ConfidenceInterval(noise_confidence_interval);
// Transfers ownership of ci_copy to element.
element->set_allocated_noise_confidence_interval(ci_copy);
element->mutable_noise_confidence_interval()->CopyFrom(
noise_confidence_interval);
}

} // namespace differential_privacy
Expand Down
2 changes: 1 addition & 1 deletion examples/cc/.bazelversion
Original file line number Diff line number Diff line change
@@ -1 +1 @@
6.2.1
6.4.0
2 changes: 1 addition & 1 deletion examples/go/.bazelversion
Original file line number Diff line number Diff line change
@@ -1 +1 @@
6.2.1
6.4.0
2 changes: 1 addition & 1 deletion examples/java/.bazelversion
Original file line number Diff line number Diff line change
@@ -1 +1 @@
5.3.2
6.4.0
2 changes: 1 addition & 1 deletion go/.bazelversion
Original file line number Diff line number Diff line change
@@ -1 +1 @@
6.2.1
6.4.0
2 changes: 1 addition & 1 deletion java/.bazelversion
Original file line number Diff line number Diff line change
@@ -1 +1 @@
6.2.1
6.4.0
Loading

0 comments on commit 53b4c6a

Please sign in to comment.