Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions FHEDemo.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@
3226D94C2D38168D00595BBC /* TFHE.xcframework in Frameworks */ = {isa = PBXBuildFile; fileRef = 3226D94B2D38168D00595BBC /* TFHE.xcframework */; };
3226D9512D3816A500595BBC /* TFHE.xcframework in Frameworks */ = {isa = PBXBuildFile; fileRef = 3226D94B2D38168D00595BBC /* TFHE.xcframework */; };
322B62082D72210F009881A9 /* ConcreteMLExtensions.xcframework in Frameworks */ = {isa = PBXBuildFile; fileRef = 3226D94E2D38169A00595BBC /* ConcreteMLExtensions.xcframework */; };
322B62092D72210F009881A9 /* concrete_ml_extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3226D9532D3816DD00595BBC /* concrete_ml_extensions.swift */; };
322E72BB2CC9A636009B2530 /* Algorithms in Frameworks */ = {isa = PBXBuildFile; productRef = 322E72BA2CC9A636009B2530 /* Algorithms */; };
324F8E2A2CA43B2100F0BB11 /* QLHealthExtension.appex in Embed Foundation Extensions */ = {isa = PBXBuildFile; fileRef = 324F8E1D2CA43B2100F0BB11 /* QLHealthExtension.appex */; settings = {ATTRIBUTES = (RemoveHeadersOnCopy, ); }; };
32543D8D2D47EFA4007600B2 /* QuickLook.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 32543D8C2D47EFA4007600B2 /* QuickLook.framework */; };
32738D232D89D7870040C27A /* concrete_ml_extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3226D9532D3816DD00595BBC /* concrete_ml_extensions.swift */; };
32738D242D89D78C0040C27A /* ConcreteMLExtensions.xcframework in Frameworks */ = {isa = PBXBuildFile; fileRef = 3226D94E2D38169A00595BBC /* ConcreteMLExtensions.xcframework */; };
CE11756A2DD7363900B58C2A /* concrete_ml_extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = CE1175692DD7363900B58C2A /* concrete_ml_extensions.swift */; };
CE11756B2DD7363900B58C2A /* concrete_ml_extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = CE1175692DD7363900B58C2A /* concrete_ml_extensions.swift */; };
/* End PBXBuildFile section */

/* Begin PBXContainerItemProxy section */
Expand Down Expand Up @@ -56,13 +56,13 @@
322658952D6E20AD004BB59A /* QLAdsExtension.appex */ = {isa = PBXFileReference; explicitFileType = "wrapper.app-extension"; includeInIndex = 0; path = QLAdsExtension.appex; sourceTree = BUILT_PRODUCTS_DIR; };
3226D94B2D38168D00595BBC /* TFHE.xcframework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcframework; name = TFHE.xcframework; path = Frameworks/TFHE.xcframework; sourceTree = "<group>"; };
3226D94E2D38169A00595BBC /* ConcreteMLExtensions.xcframework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcframework; name = ConcreteMLExtensions.xcframework; path = Frameworks/ConcreteMLExtensions.xcframework; sourceTree = "<group>"; };
3226D9532D3816DD00595BBC /* concrete_ml_extensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = concrete_ml_extensions.swift; path = Frameworks/concrete_ml_extensions.swift; sourceTree = "<group>"; };
324F8E1D2CA43B2100F0BB11 /* QLHealthExtension.appex */ = {isa = PBXFileReference; explicitFileType = "wrapper.app-extension"; includeInIndex = 0; path = QLHealthExtension.appex; sourceTree = BUILT_PRODUCTS_DIR; };
32543D8C2D47EFA4007600B2 /* QuickLook.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = QuickLook.framework; path = System/Library/Frameworks/QuickLook.framework; sourceTree = SDKROOT; };
328F5CB32D009CA800D7B219 /* FHE Ads.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = "FHE Ads.app"; sourceTree = BUILT_PRODUCTS_DIR; };
32B258372C98693800538B23 /* ZAMA Data Vault.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = "ZAMA Data Vault.app"; sourceTree = BUILT_PRODUCTS_DIR; };
32B258512C9869A700538B23 /* README.md */ = {isa = PBXFileReference; lastKnownFileType = net.daringfireball.markdown; path = README.md; sourceTree = "<group>"; };
32C9CC202CA565A100AEDA32 /* FHE Health.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = "FHE Health.app"; sourceTree = BUILT_PRODUCTS_DIR; };
CE1175692DD7363900B58C2A /* concrete_ml_extensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = concrete_ml_extensions.swift; sourceTree = "<group>"; };
/* End PBXFileReference section */

/* Begin PBXFileSystemSynchronizedBuildFileExceptionSet section */
Expand Down Expand Up @@ -352,7 +352,7 @@
isa = PBXGroup;
children = (
32543D8C2D47EFA4007600B2 /* QuickLook.framework */,
3226D9532D3816DD00595BBC /* concrete_ml_extensions.swift */,
CE1175692DD7363900B58C2A /* concrete_ml_extensions.swift */,
3226D94E2D38169A00595BBC /* ConcreteMLExtensions.xcframework */,
3226D94B2D38168D00595BBC /* TFHE.xcframework */,
);
Expand Down Expand Up @@ -599,7 +599,7 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
322B62092D72210F009881A9 /* concrete_ml_extensions.swift in Sources */,
CE11756B2DD7363900B58C2A /* concrete_ml_extensions.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand All @@ -621,7 +621,7 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
32738D232D89D7870040C27A /* concrete_ml_extensions.swift in Sources */,
CE11756A2DD7363900B58C2A /* concrete_ml_extensions.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down
28 changes: 25 additions & 3 deletions HealthApp/SleepTab.swift
Original file line number Diff line number Diff line change
Expand Up @@ -200,9 +200,31 @@ extension SleepTab {
self.status = .progress("Uploading Encrypted Data…")
let taskID = try await uploadSample(data, uid: uid)

self.status = .progress("Analyzing sleep quality…")
self.resultURL = try await getServerResult(uid: uid, taskID: taskID, for: date)
self.status = nil
self.status = .progress("Task submitted to server…")
var lastStatus: String?

while true {
let statusResponse = try await Network.shared.getStatus(for: serverTask, id: taskID, uid: uid)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

where do you exit this while true loop ?


if statusResponse.status != lastStatus {
lastStatus = statusResponse.status
switch statusResponse.status {
case "started":
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just in case, add 'active'

self.status = .progress("Analyzing sleep quality…")
case "reserved", "queued":
self.status = .progress("Task is in queue")
case "pending", "failure", "revoked", "unknown", "error":
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In our design, we added the cancel_task endpoint, which returns the status revoked.
it's a manual cancellation initiated by the user and should not be considered an error.

throw TaskError.needToRetry
case "completed", "success":
self.resultURL = try await getServerResult(uid: uid, taskID: taskID, for: date)
self.status = nil
break
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does it exit the 'switch' or the 'while' loop ?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i m not familiar with swift, maybe 'return' is more suited

default: break
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe you should throw an error if we don't know the status of:

default:
throw TaskError.unexpectedStatus(statusResponse.status)

}
}

try await Task.sleep(for: .seconds(statusResponse.status == "queued" || statusResponse.status == "started" ? 5 : 10))
}
} catch {
self.status = .error(error.localizedDescription)
}
Expand Down
31 changes: 26 additions & 5 deletions HealthApp/WeightTab.swift
Original file line number Diff line number Diff line change
Expand Up @@ -149,11 +149,32 @@ extension WeightTab {

self.status = .progress("Uploading Encrypted Data…")
let taskID = try await uploadSample(samples.data, uid: uid)

self.status = .progress("Analyzing weight statistics…")
self.results = try await getServerResult(uid: uid, taskID: taskID)

self.status = nil

self.status = .progress("Task submitted to server…")
var lastStatus: String?

while true {
let statusResponse = try await Network.shared.getStatus(for: serverTask, id: taskID, uid: uid)

if statusResponse.status != lastStatus {
lastStatus = statusResponse.status
switch statusResponse.status {
case "started":
self.status = .progress("Analyzing weight statistics…")
case "reserved", "queued":
self.status = .progress("Task is in queue")
case "pending", "failure", "revoked", "unknown", "error":
throw TaskError.needToRetry
case "completed", "success":
self.results = try await getServerResult(uid: uid, taskID: taskID)
self.status = nil
break
default: break
}
}

try await Task.sleep(for: .seconds(statusResponse.status == "queued" || statusResponse.status == "started" ? 5 : 10))
}
} catch {
self.status = .error(error.localizedDescription)
}
Expand Down
4 changes: 2 additions & 2 deletions Shared/Helpers-Zama/Network.swift
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,14 @@ final class Network {
return obj.task_id
}

func getStatus(for task: ServerTask, id taskID: TaskID, uid: UID) async throws -> String {
func getStatus(for task: ServerTask, id taskID: TaskID, uid: UID) async throws -> StatusResponse {
let res = try await sendRequest(.GET(root: rootURL,
path: "/get_task_status",
json: ["task_name": task.rawValue,
"task_id": taskID,
"uid": uid]))
let obj = try JSONDecoder().decode(StatusResponse.self, from: res)
return obj.status
return obj
}

/// Returns:
Expand Down