Skip to content

Commit

Permalink
Update PrivacyQueryMapper for ACDP composition
Browse files Browse the repository at this point in the history
  • Loading branch information
iverson52000 committed Aug 15, 2023
1 parent d1f5d00 commit e0037b4
Show file tree
Hide file tree
Showing 3 changed files with 395 additions and 104 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,27 +17,33 @@ import org.wfanet.measurement.api.v2alpha.MeasurementSpec
import org.wfanet.measurement.api.v2alpha.MeasurementSpec.MeasurementTypeCase
import org.wfanet.measurement.api.v2alpha.RequisitionSpec
import org.wfanet.measurement.common.toRange
import org.wfanet.measurement.eventdataprovider.noiser.DpParams
import org.wfanet.measurement.eventdataprovider.privacybudgetmanagement.AcdpParamsConverter
import org.wfanet.measurement.eventdataprovider.privacybudgetmanagement.AcdpQuery
import org.wfanet.measurement.eventdataprovider.privacybudgetmanagement.DpCharge
import org.wfanet.measurement.eventdataprovider.privacybudgetmanagement.DpQuery
import org.wfanet.measurement.eventdataprovider.privacybudgetmanagement.EventGroupSpec
import org.wfanet.measurement.eventdataprovider.privacybudgetmanagement.LandscapeMask
import org.wfanet.measurement.eventdataprovider.privacybudgetmanagement.Reference

object PrivacyQueryMapper {

private const val SENSITIVITY = 1.0

/**
* Constructs a pbm specific [DpQuery] from given proto messages.
*
* @param reference representing the reference key and if the charge is a refund.
* @param measurementSpec The measurementSpec protobuf that is associated with the query. The VID
* sampling interval is obtained from from this.
* sampling interval is obtained from this.
* @param eventSpecs event specs from the Requisition. The date range and demo groups are obtained
* from this.
* @throws
* org.wfanet.measurement.eventdataprovider.privacybudgetmanagement.PrivacyBudgetManagerException
* if an error occurs in handling this request. Possible exceptions could include running out of
* privacy budget or a failure to commit the transaction to the database.
*/
fun getPrivacyQuery(
fun getDpQuery(
reference: Reference,
measurementSpec: MeasurementSpec,
eventSpecs: Iterable<RequisitionSpec.EventGroupEntry.Value>
Expand All @@ -56,21 +62,6 @@ object PrivacyQueryMapper {
measurementSpec.reachAndFrequency.reachPrivacyParams.delta.toFloat() +
measurementSpec.reachAndFrequency.frequencyPrivacyParams.delta.toFloat()
)
// TODO(@uakyol): After the privacy budget accounting is switched to using the Gaussian
// mechanism, replace the above lines with the following. This will further improve the
// efficiency of privacy budget usage for reach and frequency queries.
//
// {
//
// chargeList.add(PrivacyCharge(
// measurementSpec.reachAndFrequency.reachPrivacyParams.epsilon.toFloat(),
// measurementSpec.reachAndFrequency.reachPrivacyParams.delta.toFloat()))
//
// chargeList.add(PrivacyCharge(
// measurementSpec.reachAndFrequency.frequencyPrivacyParams.epsilon.toFloat(),
// measurementSpec.reachAndFrequency.frequencyPrivacyParams.delta.toFloat()))
// }

MeasurementTypeCase.IMPRESSION ->
DpCharge(
measurementSpec.impression.privacyParams.epsilon.toFloat(),
Expand All @@ -90,7 +81,115 @@ object PrivacyQueryMapper {
measurementSpec.vidSamplingInterval.start,
measurementSpec.vidSamplingInterval.width
),
dpCharge
dpCharge,
)
}

fun getMpcAcdpQuery(
reference: Reference,
measurementSpec: MeasurementSpec,
eventSpecs: Iterable<RequisitionSpec.EventGroupEntry.Value>,
contributorCount: Int,
): AcdpQuery {
val acdpCharge =
when (measurementSpec.measurementTypeCase) {
MeasurementTypeCase.REACH -> {
AcdpParamsConverter.getMpcAcdpCharge(
DpParams(
measurementSpec.reach.privacyParams.epsilon,
measurementSpec.reach.privacyParams.delta
),
contributorCount,
)
}
MeasurementTypeCase.REACH_AND_FREQUENCY -> {
val dpParams =
DpParams(
measurementSpec.reachAndFrequency.reachPrivacyParams.epsilon +
measurementSpec.reachAndFrequency.frequencyPrivacyParams.epsilon,
measurementSpec.reachAndFrequency.reachPrivacyParams.delta +
measurementSpec.reachAndFrequency.frequencyPrivacyParams.delta
)

AcdpParamsConverter.getMpcAcdpCharge(
dpParams,
contributorCount,
)
}
else ->
throw IllegalArgumentException(
"Measurement type ${measurementSpec.measurementTypeCase} is not supported in getMpcAcdpQuery()"
)
}

return AcdpQuery(
reference,
LandscapeMask(
eventSpecs.map { EventGroupSpec(it.filter.expression, it.collectionInterval.toRange()) },
measurementSpec.vidSamplingInterval.start,
measurementSpec.vidSamplingInterval.width
),
acdpCharge
)
}

fun getDirectAcdpQuery(
reference: Reference,
measurementSpec: MeasurementSpec,
eventSpecs: Iterable<RequisitionSpec.EventGroupEntry.Value>,
): AcdpQuery {
val acdpCharge =
when (measurementSpec.measurementTypeCase) {
MeasurementTypeCase.REACH -> {
AcdpParamsConverter.getDirectAcdpCharge(
DpParams(
measurementSpec.reach.privacyParams.epsilon,
measurementSpec.reach.privacyParams.delta
),
SENSITIVITY,
)
}
MeasurementTypeCase.REACH_AND_FREQUENCY -> {
val dpParams =
DpParams(
measurementSpec.reachAndFrequency.reachPrivacyParams.epsilon +
measurementSpec.reachAndFrequency.frequencyPrivacyParams.epsilon,
measurementSpec.reachAndFrequency.reachPrivacyParams.delta +
measurementSpec.reachAndFrequency.frequencyPrivacyParams.delta
)

AcdpParamsConverter.getDirectAcdpCharge(
dpParams,
SENSITIVITY,
)
}
MeasurementTypeCase.IMPRESSION ->
AcdpParamsConverter.getDirectAcdpCharge(
DpParams(
measurementSpec.impression.privacyParams.epsilon,
measurementSpec.impression.privacyParams.delta
),
SENSITIVITY,
)
MeasurementTypeCase.DURATION ->
AcdpParamsConverter.getDirectAcdpCharge(
DpParams(
measurementSpec.duration.privacyParams.epsilon,
measurementSpec.duration.privacyParams.delta
),
SENSITIVITY,
)
else -> throw IllegalArgumentException("Measurement type not supported")
}

return AcdpQuery(
reference,
LandscapeMask(
eventSpecs.map { EventGroupSpec(it.filter.expression, it.collectionInterval.toRange()) },
measurementSpec.vidSamplingInterval.start,
measurementSpec.vidSamplingInterval.width
),
acdpCharge,
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ import org.wfanet.measurement.eventdataprovider.privacybudgetmanagement.PrivacyB
import org.wfanet.measurement.eventdataprovider.privacybudgetmanagement.PrivacyBudgetManagerException
import org.wfanet.measurement.eventdataprovider.privacybudgetmanagement.PrivacyBudgetManagerExceptionType
import org.wfanet.measurement.eventdataprovider.privacybudgetmanagement.Reference
import org.wfanet.measurement.eventdataprovider.privacybudgetmanagement.api.v2alpha.PrivacyQueryMapper.getPrivacyQuery
import org.wfanet.measurement.eventdataprovider.privacybudgetmanagement.api.v2alpha.PrivacyQueryMapper.getDpQuery
import org.wfanet.measurement.loadtest.config.TestIdentifiers.SIMULATOR_EVENT_GROUP_REFERENCE_ID_PREFIX
import org.wfanet.measurement.loadtest.config.VidSampling

Expand Down Expand Up @@ -673,7 +673,7 @@ class EdpSimulator(
) {
try {
privacyBudgetManager.chargePrivacyBudget(
getPrivacyQuery(
getDpQuery(
Reference(measurementConsumerName, requisitionName, false),
measurementSpec,
eventSpecs
Expand Down
Loading

0 comments on commit e0037b4

Please sign in to comment.