Go updates, C++ build timeout resolution, Python overflow fix. Go DP: - Update Go to 1.18 and Go tools for the Bazel build. C++ DP: - Omit long tests in GitHub CI to fix build timeout. Python DP: - Fix an overflow issue. Change-Id: Iefd12be42c12094d5deef3da11f4b15d07556dbb GitOrigin-RevId: c9871e8bed9b96713eda811b19347deb88b90494
diff --git a/.github/workflows/bazel.yml b/.github/workflows/bazel.yml index 5622e42..b882092 100644 --- a/.github/workflows/bazel.yml +++ b/.github/workflows/bazel.yml
@@ -19,9 +19,9 @@ - name: Build C++ Workspace working-directory: cc run: bazelisk build ... - - name: Test C++ Workspace (without eternal tests) + - name: Test C++ Workspace (without long and eternal tests) working-directory: cc - run: bazelisk test --test_timeout_filters=-eternal ... + run: bazelisk test --test_timeout_filters=-long,-eternal ... - name: Build C++ Examples working-directory: examples/cc run: bazelisk build ... @@ -45,9 +45,9 @@ - name: Build Java Workspace working-directory: java run: bazelisk build ... - - name: Test Java Workspace (without eternal tests) + - name: Test Java Workspace (without long and eternal tests) working-directory: java - run: bazelisk test --test_timeout_filters=-eternal ... + run: bazelisk test --test_timeout_filters=-long,-eternal ... - name: Build Java Examples working-directory: examples/java run: bazelisk build ...
diff --git a/go/WORKSPACE b/go/WORKSPACE index 433bc0c..265ebd0 100644 --- a/go/WORKSPACE +++ b/go/WORKSPACE
@@ -20,10 +20,19 @@ http_archive( name = "io_bazel_rules_go", - sha256 = "d6b2513456fe2229811da7eb67a444be7785f5323c6708b38d851d2b51e54d83", + sha256 = "099a9fb96a376ccbbb7d291ed4ecbdfd42f6bc822ab77ae6f1b5cb9e914e94fa", urls = [ - "https://mirror.bazel.build/github.com/bazelbuild/rules_go/releases/download/v0.30.0/rules_go-v0.30.0.zip", - "https://github.com/bazelbuild/rules_go/releases/download/v0.30.0/rules_go-v0.30.0.zip", + "https://mirror.bazel.build/github.com/bazelbuild/rules_go/releases/download/v0.35.0/rules_go-v0.35.0.zip", + "https://github.com/bazelbuild/rules_go/releases/download/v0.35.0/rules_go-v0.35.0.zip", + ], +) + +http_archive( + name = "bazel_gazelle", + sha256 = "efbbba6ac1a4fd342d5122cbdfdb82aeb2cf2862e35022c752eaddffada7c3f3", + urls = [ + "https://mirror.bazel.build/github.com/bazelbuild/bazel-gazelle/releases/download/v0.27.0/bazel-gazelle-v0.27.0.tar.gz", + "https://github.com/bazelbuild/bazel-gazelle/releases/download/v0.27.0/bazel-gazelle-v0.27.0.tar.gz", ], ) @@ -31,22 +40,15 @@ go_rules_dependencies() -go_register_toolchains(version = "1.16.7") - -http_archive( - name = "bazel_gazelle", - sha256 = "de69a09dc70417580aabf20a28619bb3ef60d038470c7cf8442fafcf627c21cb", - urls = [ - "https://mirror.bazel.build/github.com/bazelbuild/bazel-gazelle/releases/download/v0.24.0/bazel-gazelle-v0.24.0.tar.gz", - "https://github.com/bazelbuild/bazel-gazelle/releases/download/v0.24.0/bazel-gazelle-v0.24.0.tar.gz", - ], -) - -load("@bazel_gazelle//:deps.bzl", "gazelle_dependencies") - -gazelle_dependencies() +go_register_toolchains(version = "1.18.3") # Load Go DP library dependencies. load(":go_differential_privacy_deps.bzl", "go_differential_privacy_deps") +# gazelle:repository_macro go_differential_privacy_deps.bzl%go_differential_privacy_deps go_differential_privacy_deps() + +# Gazelle dependencies must be added last. +load("@bazel_gazelle//:deps.bzl", "gazelle_dependencies") + +gazelle_dependencies()
diff --git a/go/go.mod b/go/go.mod index 5c6ee89..6d22fe8 100644 --- a/go/go.mod +++ b/go/go.mod
@@ -1,10 +1,15 @@ module github.com/google/differential-privacy/go/v2 -go 1.16 +go 1.18 require ( github.com/golang/glog v1.0.0 github.com/google/go-cmp v0.5.6 github.com/grd/stat v0.0.0-20130623202159-138af3fd5012 gonum.org/v1/gonum v0.8.2 -) \ No newline at end of file +) + +require ( + golang.org/x/exp v0.0.0-20190125153040-c74c464bbbf2 // indirect + golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 // indirect +)
diff --git a/privacy-on-beam/WORKSPACE b/privacy-on-beam/WORKSPACE index 5f5f148..8c7e654 100644 --- a/privacy-on-beam/WORKSPACE +++ b/privacy-on-beam/WORKSPACE
@@ -20,10 +20,19 @@ http_archive( name = "io_bazel_rules_go", - sha256 = "8e968b5fcea1d2d64071872b12737bbb5514524ee5f0a4f54f5920266c261acb", + sha256 = "099a9fb96a376ccbbb7d291ed4ecbdfd42f6bc822ab77ae6f1b5cb9e914e94fa", urls = [ - "https://mirror.bazel.build/github.com/bazelbuild/rules_go/releases/download/v0.28.0/rules_go-v0.28.0.zip", - "https://github.com/bazelbuild/rules_go/releases/download/v0.28.0/rules_go-v0.28.0.zip", + "https://mirror.bazel.build/github.com/bazelbuild/rules_go/releases/download/v0.35.0/rules_go-v0.35.0.zip", + "https://github.com/bazelbuild/rules_go/releases/download/v0.35.0/rules_go-v0.35.0.zip", + ], +) + +http_archive( + name = "bazel_gazelle", + sha256 = "efbbba6ac1a4fd342d5122cbdfdb82aeb2cf2862e35022c752eaddffada7c3f3", + urls = [ + "https://mirror.bazel.build/github.com/bazelbuild/bazel-gazelle/releases/download/v0.27.0/bazel-gazelle-v0.27.0.tar.gz", + "https://github.com/bazelbuild/bazel-gazelle/releases/download/v0.27.0/bazel-gazelle-v0.27.0.tar.gz", ], ) @@ -31,21 +40,7 @@ go_rules_dependencies() -go_register_toolchains(version = "1.16.7") - -# Updating this to v0.24.0 breaks due to Apache Beam dependency, meaning we also cannot update io_bazel_rule_go: https://github.com/bazelbuild/bazel-gazelle/tree/v0.24.0#id5 -http_archive( - name = "bazel_gazelle", - sha256 = "62ca106be173579c0a167deb23358fdfe71ffa1e4cfdddf5582af26520f1c66f", - urls = [ - "https://mirror.bazel.build/github.com/bazelbuild/bazel-gazelle/releases/download/v0.23.0/bazel-gazelle-v0.23.0.tar.gz", - "https://github.com/bazelbuild/bazel-gazelle/releases/download/v0.23.0/bazel-gazelle-v0.23.0.tar.gz", - ], -) - -load("@bazel_gazelle//:deps.bzl", "gazelle_dependencies") - -gazelle_dependencies() +go_register_toolchains(version = "1.18.3") local_repository( name = "com_google_differential_privacy", @@ -68,6 +63,7 @@ # Load Privacy on Beam dependencies. load(":privacy_on_beam_deps.bzl", "privacy_on_beam_deps") +# gazelle:repository_macro privacy_on_beam_deps.bzl%privacy_on_beam_deps privacy_on_beam_deps() # Load Go DP library dependencies. @@ -76,3 +72,8 @@ go_differential_privacy_deps() protobuf_deps() + +# Gazelle dependencies must be added last. +load("@bazel_gazelle//:deps.bzl", "gazelle_dependencies") + +gazelle_dependencies()
diff --git a/privacy-on-beam/go.mod b/privacy-on-beam/go.mod index e0e7c07..a60da75 100644 --- a/privacy-on-beam/go.mod +++ b/privacy-on-beam/go.mod
@@ -1,6 +1,6 @@ module github.com/google/differential-privacy/privacy-on-beam/v2 -go 1.16 +go 1.18 require ( github.com/apache/beam/sdks/v2 v2.36.0 @@ -8,6 +8,25 @@ github.com/google/differential-privacy/go/v2 v2.0.0-pre github.com/google/go-cmp v0.5.6 gonum.org/v1/plot v0.10.0 - google.golang.org/grpc v1.40.0 // indirect google.golang.org/protobuf v1.27.1 -) \ No newline at end of file +) + +require ( + github.com/ajstarks/svgo v0.0.0-20210923152817-c3b6e2f0c527 // indirect + github.com/fogleman/gg v1.3.0 // indirect + github.com/go-fonts/liberation v0.2.0 // indirect + github.com/go-latex/latex v0.0.0-20210823091927-c0d11ff05a81 // indirect + github.com/go-pdf/fpdf v0.5.0 // indirect + github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0 // indirect + github.com/golang/protobuf v1.5.2 // indirect + github.com/google/uuid v1.3.0 // indirect + golang.org/x/exp v0.0.0-20200224162631-6cc2880d07d6 // indirect + golang.org/x/image v0.0.0-20210628002857-a66eb6448b8d // indirect + golang.org/x/net v0.0.0-20210423184538-5f58ad60dda6 // indirect + golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c // indirect + golang.org/x/text v0.3.6 // indirect + golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 // indirect + gonum.org/v1/gonum v0.9.3 // indirect + google.golang.org/genproto v0.0.0-20210728212813-7823e685a01f // indirect + google.golang.org/grpc v1.40.0 // indirect +)
diff --git a/python/dp_accounting/pld/common.py b/python/dp_accounting/pld/common.py index ec53b18..249327e 100644 --- a/python/dp_accounting/pld/common.py +++ b/python/dp_accounting/pld/common.py
@@ -321,11 +321,33 @@ min_val * num_times + min_val_convolution) +def _log_add(a: float, b: float) -> float: + """Returns log(exp(a) + exp(b)).""" + mn, mx = min(a, b), max(a, b) + return mx + np.log1p(np.exp(mn - mx)) + + +def _log_sub(a: float, b: float) -> float: + """Returns log(exp(a) - exp(b)).""" + if b >= a: + raise ValueError(f'a must be greater than b. Got a={a} and b={b}.') + return a + np.log1p(-np.exp(b - a)) + + def log_a_times_exp_b_plus_c(a: float, b: float, c: float) -> float: - """Computes log(a * exp(b) + c) for a > 0.""" - try: - return math.log(a * math.exp(b) + c) - except OverflowError: - # This can occur when b is very large, in which case, the answer can be - # estimated by b + log(a). - return b + math.log(a) + """Computes log(a * exp(b) + c).""" + if a == 0: + return np.log(c) + if a < 0: + if c <= 0: + raise ValueError(f'a exp(b) + c must be positive: {a}, {b}, {c}.') + return _log_sub(np.log(c), np.log(-a) + b) + if b == 0: + return np.log(a + c) + d = b + np.log(a) + if c == 0: + return d + elif c < 0: + return _log_sub(d, np.log(-c)) + else: + return _log_add(d, np.log(c))