1 /* 2 * Copyright (C) 2023 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package com.android.federatedcompute.services.training.util; 18 19 import android.federatedcompute.common.ExampleConsumption; 20 21 import com.google.intelligence.fcp.client.FLRunnerResult; 22 import com.google.intelligence.fcp.client.FLRunnerResult.ContributionResult; 23 import com.google.ondevicepersonalization.federatedcompute.proto.ReportResultRequest.Result; 24 25 import java.util.ArrayList; 26 27 /** The result of federated computation. */ 28 public class ComputationResult { 29 private String mOutputCheckpointFile = ""; 30 private FLRunnerResult mFlRunnerResult = null; 31 private ArrayList<ExampleConsumption> mExampleConsumptionList = null; 32 ComputationResult( String outputCheckpointFile, FLRunnerResult flRunnerResult, ArrayList<ExampleConsumption> exampleConsumptionList)33 public ComputationResult( 34 String outputCheckpointFile, 35 FLRunnerResult flRunnerResult, 36 ArrayList<ExampleConsumption> exampleConsumptionList) { 37 this.mOutputCheckpointFile = outputCheckpointFile; 38 this.mFlRunnerResult = flRunnerResult; 39 this.mExampleConsumptionList = exampleConsumptionList; 40 } 41 getExampleConsumptionList()42 public ArrayList<ExampleConsumption> getExampleConsumptionList() { 43 return mExampleConsumptionList; 44 } 45 getOutputCheckpointFile()46 public String getOutputCheckpointFile() { 47 return mOutputCheckpointFile; 48 } 49 getFlRunnerResult()50 public FLRunnerResult getFlRunnerResult() { 51 return mFlRunnerResult; 52 } 53 isResultSuccess()54 public boolean isResultSuccess() { 55 return mFlRunnerResult.getContributionResult() == ContributionResult.SUCCESS; 56 } 57 58 /** Convert {@link ContributionResult} to {@link Result}. */ convertToResult()59 public Result convertToResult() { 60 if (mFlRunnerResult.getContributionResult() == ContributionResult.SUCCESS) { 61 return Result.COMPLETED; 62 } 63 if (mFlRunnerResult.getErrorStatus() == FLRunnerResult.ErrorStatus.NOT_ELIGIBLE) { 64 return Result.NOT_ELIGIBLE; 65 } 66 return Result.FAILED; 67 } 68 } 69