Skip to content

Commit

Permalink
added differential privacy parameters, sensitivity & privacy budget, …
Browse files Browse the repository at this point in the history
…to smpc cluster payload
  • Loading branch information
apmariglis committed Sep 19, 2023
1 parent 27c0666 commit f5042e1
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 13 deletions.
16 changes: 10 additions & 6 deletions exareme2/controller/algorithm_execution_engine_smpc_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,11 @@
from exareme2.node_tasks_DTOs import TableInfo
from exareme2.smpc_cluster_comm_helpers import SMPCComputationError
from exareme2.smpc_cluster_comm_helpers import trigger_smpc
from exareme2.smpc_cluster_comm_helpers import create_payload
from exareme2.smpc_DTOs import SMPCRequestType
from exareme2.smpc_DTOs import SMPCResponse
from exareme2.smpc_DTOs import SMPCResponseStatus
from exareme2.smpc_DTOs import DifferentialPrivacyParams


def get_smpc_job_id(
Expand Down Expand Up @@ -59,12 +61,13 @@ def load_data_to_smpc_clients(
)


def trigger_smpc_operation(
def _trigger_smpc_operation(
logger: Logger,
context_id: str,
command_id: int,
op_type: SMPCRequestType,
smpc_op_clients: List[str],
dp_params: DifferentialPrivacyParams = None,
) -> bool:
trigger_smpc(
logger=logger,
Expand All @@ -74,8 +77,9 @@ def trigger_smpc_operation(
command_id=command_id,
operation=op_type,
),
computation_type=op_type,
clients=smpc_op_clients,
payload=create_payload(
computation_type=op_type, clients=smpc_op_clients, dp_params=dp_params
),
) if smpc_op_clients else None

return True if smpc_op_clients else False
Expand All @@ -92,13 +96,13 @@ def trigger_smpc_operations(
min_op_smpc_clients,
max_op_smpc_clients,
) = smpc_clients_per_op
sum_op = trigger_smpc_operation(
sum_op = _trigger_smpc_operation(
logger, context_id, command_id, SMPCRequestType.SUM, sum_op_smpc_clients
)
min_op = trigger_smpc_operation(
min_op = _trigger_smpc_operation(
logger, context_id, command_id, SMPCRequestType.MIN, min_op_smpc_clients
)
max_op = trigger_smpc_operation(
max_op = _trigger_smpc_operation(
logger, context_id, command_id, SMPCRequestType.MAX, max_op_smpc_clients
)
return sum_op, min_op, max_op
Expand Down
10 changes: 8 additions & 2 deletions exareme2/controller/smpc_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
from exareme2.smpc_DTOs import SMPCRequestType
from exareme2.smpc_DTOs import SMPCResponse
from exareme2.smpc_DTOs import SMPCResponseStatus
from exareme2.smpc_cluster_comm_helpers import create_payload
from exareme2.smpc_DTOs import DifferentialPrivacyParams


def get_smpc_job_id(
Expand Down Expand Up @@ -65,6 +67,7 @@ def trigger_smpc_operation(
command_id: int,
op_type: SMPCRequestType,
smpc_op_clients: List[str],
dp_params: DifferentialPrivacyParams = None,
) -> bool:
trigger_smpc(
logger=logger,
Expand All @@ -74,8 +77,11 @@ def trigger_smpc_operation(
command_id=command_id,
operation=op_type,
),
computation_type=op_type,
clients=smpc_op_clients,
payload=create_payload(
computation_type=op_type,
clients=smpc_op_clients,
dp_params=dp_params,
),
) if smpc_op_clients else None

return True if smpc_op_clients else False
Expand Down
8 changes: 8 additions & 0 deletions exareme2/smpc_DTOs.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import enum
from typing import List
from typing import Optional

from pydantic import BaseModel

Expand Down Expand Up @@ -30,6 +31,13 @@ def __str__(self):
class SMPCRequestData(BaseModel):
computationType: SMPCRequestType
clients: List[str]
c: Optional[float] # Differential Privacy - sensitivity
e: Optional[float] # Differential Privacy - privacy budget


class DifferentialPrivacyParams(BaseModel):
sensitivity: float
privacy_budget: float


class SMPCResponse(BaseModel):
Expand Down
46 changes: 41 additions & 5 deletions exareme2/smpc_cluster_comm_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

from exareme2.smpc_DTOs import SMPCRequestData
from exareme2.smpc_DTOs import SMPCRequestType
from exareme2.smpc_DTOs import DifferentialPrivacyParams

ADD_DATASET_ENDPOINT = "/api/update-dataset/"
TRIGGER_COMPUTATION_ENDPOINT = "/api/secure-aggregation/job-id/"
Expand Down Expand Up @@ -53,18 +54,16 @@ def trigger_smpc(
logger: Logger,
coordinator_address: str,
jobid: str,
computation_type: SMPCRequestType,
clients: List[str],
payload: SMPCRequestData,
):
request_url = coordinator_address + TRIGGER_COMPUTATION_ENDPOINT + jobid
request_headers = {"Content-type": "application/json", "Accept": "text/plain"}
data = SMPCRequestData(computationType=computation_type, clients=clients).json()
logger.info(f"Starting SMPC with {jobid=}...")
logger.debug(f"{request_url=}")
logger.debug(f"{data=}")
logger.debug(f"{payload=}")
response = requests.post(
url=request_url,
data=data,
data=payload,
headers=request_headers,
)
if response.status_code != 200:
Expand All @@ -73,6 +72,43 @@ def trigger_smpc(
)


def create_payload(
computation_type: SMPCRequestType,
clients: List[str],
dp_params: DifferentialPrivacyParams = None,
) -> SMPCRequestData:
if dp_params:
return SMPCRequestData(
computationType=computation_type,
clients=clients,
c=dp_params.sensitivity,
e=dp_params.privacy_budget,
).json()
else:
return SMPCRequestData(computationType=computation_type, clients=clients).json()


def trigger_dp(
logger: Logger,
coordinator_address: str,
jobid: str,
computation_type: SMPCRequestType,
clients: List[str],
):
# http://{{coordinator}}:{{coordinator-port}}/api/secure-aggregation/job-id/testKey13

# {
# "computationType": "sum",
# "returnUrl": "http://localhost:4100",
# "clients": ["ZuellingPharma"],
# "dp": {
# "c": 1,
# "e": 1
# }
# }
pass


def validate_smpc_usage(use_smpc: bool, smpc_enabled: bool, smpc_optional: bool):
"""
Validates if smpc can be used or if it must be used based on the configs.
Expand Down

0 comments on commit f5042e1

Please sign in to comment.