Skip to content

Commit

Permalink
T138861426: [Bootcamp][PCF][BE] Migrate the DotproductGame to use the…
Browse files Browse the repository at this point in the history
… new API that accepts metric collector. (facebookresearch#1967)

Summary:
Pull Request resolved: facebookresearch#1967

X-link: facebookresearch/fbpcf#453

As titled.

Differential Revision: D41640581

fbshipit-source-id: cffd6f4df6aebc681e8f52774db2a4934b2f620c
  • Loading branch information
slaxman1978 authored and facebook-github-bot committed Dec 1, 2022
1 parent 7070de6 commit feb8297
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 7 deletions.
4 changes: 3 additions & 1 deletion fbpcs/emp_games/dotproduct/DotproductApp.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,9 @@ class DotproductApp {
->create();

DotproductGame<schedulerId> game(
std::move(scheduler), std::move(communicationAgentFactory_));
std::move(scheduler),
std::move(communicationAgentFactory_),
metricCollector_);

XLOG(INFO) << "Start Reading input file ";
auto inputTuple = readCSVInput(inputFilePath_, labelWidth_, numFeatures_);
Expand Down
9 changes: 7 additions & 2 deletions fbpcs/emp_games/dotproduct/DotproductGame.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

#include "folly/logging/xlog.h"

#include <fbpcf/util/MetricCollector.h>
#include "fbpcf/frontend/mpcGame.h"
#include "fbpcs/emp_games/common/Debug.h"
#include "fbpcs/emp_games/common/Util.h"
Expand All @@ -23,9 +24,11 @@ class DotproductGame : public fbpcf::frontend::MpcGame<schedulerId> {
std::unique_ptr<fbpcf::scheduler::IScheduler> scheduler,
std::shared_ptr<
fbpcf::engine::communication::IPartyCommunicationAgentFactory>
communicationAgentFactory)
communicationAgentFactory,
std::shared_ptr<fbpcf::util::MetricCollector> metricCollector)
: fbpcf::frontend::MpcGame<schedulerId>(std::move(scheduler)),
communicationAgentFactory_(communicationAgentFactory) {}
communicationAgentFactory_(communicationAgentFactory),
metricCollector_{metricCollector} {}

std::vector<double> computeDotProduct(
const int myRole,
Expand All @@ -44,6 +47,8 @@ class DotproductGame : public fbpcf::frontend::MpcGame<schedulerId> {
std::shared_ptr<fbpcf::engine::communication::IPartyCommunicationAgentFactory>
communicationAgentFactory_;

std::shared_ptr<fbpcf::util::MetricCollector> metricCollector_;

std::vector<fbpcf::frontend::Bit<true, schedulerId, true>>
createSecretLabelShare(const std::vector<std::vector<bool>>& labelValues);

Expand Down
15 changes: 11 additions & 4 deletions fbpcs/emp_games/dotproduct/test/DotproductGameTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,12 @@ class MockDotProductGame : public DotproductGame<schedulerId> {
std::unique_ptr<fbpcf::scheduler::IScheduler> scheduler,
std::shared_ptr<
fbpcf::engine::communication::IPartyCommunicationAgentFactory>
communicationAgentFactory)
communicationAgentFactory,
std::shared_ptr<fbpcf::util::MetricCollector> metricCollector)
: DotproductGame<schedulerId>(
std::move(scheduler),
std::move(communicationAgentFactory)) {}
std::move(communicationAgentFactory),
std::move(metricCollector)) {}

MOCK_METHOD(
std::vector<double>,
Expand All @@ -55,8 +57,11 @@ std::vector<bool> runORLabelsGame(
fbpcf::SchedulerCreator schedulerCreator,
std::vector<std::vector<bool>> labels) {
auto scheduler = schedulerCreator(PARTY, *factory);
auto metricCollector =
std::make_shared<fbpcf::util::MetricCollector>("dotproduct_test");

DotproductGame<schedulerId> game(std::move(scheduler), std::move(factory));
DotproductGame<schedulerId> game(
std::move(scheduler), std::move(factory), metricCollector);

// Create label secret shares
auto labelShare = game.createSecretLabelShare(labels);
Expand Down Expand Up @@ -84,9 +89,11 @@ std::vector<double> runGame(
std::vector<double> dpNoise) {
auto scheduler = schedulerCreator(PARTY, *factory);

auto metricCollector =
std::make_shared<fbpcf::util::MetricCollector>("dotproduct_test");
// create a mock Dotproduct Game
MockDotProductGame<schedulerId> mockGame(
std::move(scheduler), std::move(factory));
std::move(scheduler), std::move(factory), metricCollector);

// mock the dpNoise generation in DotproductGame
ON_CALL(mockGame, generateDpNoise(numFeatures, delta, eps, addDpNoise))
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[0,0,0,0,0,0,0,0.001448442,0,0,0.06863192,0.14435472,0.033341374,0,0.12865546,0.020235294,0.14462507,0,0.17825273,0,0,0,0.46016255,0,0,0.128087239,0.4376182,0.000390805,0.033707865,0.13740458,0,0.000504521,0.07516815,0.03580519,1,0,0.46016255,0.050997782,0.46016258,0,0.002447232,0,0.8,0,0,0.042172838,0.505038259,0,1,0.1516517]

0 comments on commit feb8297

Please sign in to comment.