Skip to content

Commit

Permalink
Merge branch 'dev-hetero' of github.com:iflytek/iflearner into main
Browse files Browse the repository at this point in the history
  • Loading branch information
xs233 committed Oct 17, 2022
2 parents 3cdc852 + fef5154 commit fac9cbe
Show file tree
Hide file tree
Showing 52 changed files with 4,044 additions and 1 deletion.
Empty file.
29 changes: 29 additions & 0 deletions examples/mpc/quickstart_piss/client_service.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Copyright 2022 iFLYTEK. All Rights Reserved.
# #
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
# #
# http://www.apache.org/licenses/LICENSE-2.0
# #
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ==============================================================================

from importlib import import_module
from iflearner.business.mpc.piss.piss_client_controller import PissClientServicesController
from iflearner.business.mpc.piss.argument import parser


if __name__ == "__main__":
args = parser.parse_args()
print(args)
controller = PissClientServicesController(args)
controller.run()




4 changes: 4 additions & 0 deletions examples/mpc/quickstart_piss/piss_data_test.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
ID,Age,Money,Height,Credit_value
10001,18,6.1,1.88,98.6
10002,19,-99.25,1.76,87
10003,20,8.6,1.68,99.5
65 changes: 65 additions & 0 deletions examples/mpc/quickstart_piss/quickstart_piss.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
# Copyright 2022 iFLYTEK. All Rights Reserved.
# #
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
# #
# http://www.apache.org/licenses/LICENSE-2.0
# #
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ==============================================================================
import argparse
import json
from importlib import import_module
from typing import Any, Dict, Union

from iflearner.business.mpc.piss.piss_client_controller import PissClientController
from iflearner.business.mpc.piss.argument import parser

if __name__ == "__main__":

parser = argparse.ArgumentParser()

parser.add_argument(
"--data",
default='examples/mpc/quickstart_piss/piss_data_test.csv',
type=str,
help="path of data")

parser.add_argument(
"--param",
default={'10001':'Age', '10002':'Money'},
type=json.loads,
help="encryption param"
)
parser.add_argument(
"--server",
default="127.0.0.1:45551",
type=str,
help="address of client service"
)
parser.add_argument(
"--name",
default="client_querty",
type=str,
help="querty client name"
)

parser.add_argument(
"--cert",
default=None,
type=str,
help="path of server SSL cert"
"""use secure channel to connect to server if not none"""
)

args = parser.parse_args()
print(args)
controller = PissClientController(args)
#controller.init_data()
controller.start_querty()
print(controller.get_secrets_sum())
4 changes: 4 additions & 0 deletions examples/mpc/quickstart_piss/server.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
from iflearner.business.mpc.piss.piss_aggregate_server import main

if __name__ == "__main__":
main()
24 changes: 24 additions & 0 deletions iflearner/business/hetero/builder/builders.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Copyright 2022 iFLYTEK. All Rights Reserved.
# #
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
# #
# http://www.apache.org/licenses/LICENSE-2.0
# #
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ==============================================================================

from typing import Dict
from iflearner.business.hetero.model.base_model import BaseModel
from iflearner.business.hetero.builder.demo_builder import DemoBuilder
from iflearner.business.hetero.builder.lr_builder import LRBuilder

Builders: Dict[str, BaseModel] = {
"demo": DemoBuilder(),
"logistic_regression": LRBuilder(),
}
59 changes: 59 additions & 0 deletions iflearner/business/hetero/builder/demo_builder.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
# Copyright 2022 iFLYTEK. All Rights Reserved.
# #
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
# #
# http://www.apache.org/licenses/LICENSE-2.0
# #
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ==============================================================================

from iflearner.business.hetero.model.role import Role
from iflearner.business.hetero.model.base_model import BaseModel
from iflearner.business.hetero.model.demo import demo_guest, demo_host, demo_arbiter

from iflearner.business.hetero.builder.model_builder import ModelBuilder


class DemoBuilder(ModelBuilder):

def create_role_model_instance(self, role: str) -> BaseModel:
"""Create a model instance base on specific role.
Args:
role (str): The role name.
Returns:
BaseModel: Return the base class.
"""
if role == Role.guest:
return demo_guest.DemoGuest()
elif role == Role.host:
return demo_host.DemoHost()
elif role == Role.arbiter:
return demo_arbiter.DemoArbiter()

raise Exception(f"{role} is not existed.")

def get_role_model_flow_file(self, role: str) -> str:
"""Get model flow file by role name.
Args:
role (str): The role name.
Returns:
str: Return the filename.
"""
if role == Role.guest:
return "demo_guest_flow.yaml"
elif role == Role.host:
return "demo_host_flow.yaml"
elif role == Role.arbiter:
return "demo_arbiter_flow.yaml"

raise Exception(f"{role} is not existed.")
59 changes: 59 additions & 0 deletions iflearner/business/hetero/builder/lr_builder.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
# Copyright 2022 iFLYTEK. All Rights Reserved.
# #
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
# #
# http://www.apache.org/licenses/LICENSE-2.0
# #
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ==============================================================================

from iflearner.business.hetero.model.role import Role, Guest, Host, Arbiter
from iflearner.business.hetero.model.base_model import BaseModel
from iflearner.business.hetero.model.logistic_regression import lr_guest, lr_host, lr_arbiter

from iflearner.business.hetero.builder.model_builder import ModelBuilder


class LRBuilder(ModelBuilder):

def create_role_model_instance(self, role: Role) -> BaseModel:
"""Create a model instance base on specific role.
Args:
role (Role): The role name.
Returns:
BaseModel: Return the base class.
"""
if isinstance(role, Guest):
return lr_guest.LRGuest()
elif isinstance(role, Host):
return lr_host.LRHost()
elif isinstance(role, Arbiter):
return lr_arbiter.LRArbiter()

raise Exception(f"{role} is not existed.")

def get_role_model_flow_file(self, role: Role) -> str:
"""Get model flow file by role name.
Args:
role (Role): The role name.
Returns:
str: Return the filename.
"""
if isinstance(role, Guest):
return "lr_guest_flow.yaml"
elif isinstance(role, Host):
return "lr_host_flow.yaml"
elif isinstance(role, Arbiter):
return "lr_arbiter_flow.yaml"

raise Exception(f"{role} is not existed.")
47 changes: 47 additions & 0 deletions iflearner/business/hetero/builder/model_builder.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# Copyright 2022 iFLYTEK. All Rights Reserved.
# #
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
# #
# http://www.apache.org/licenses/LICENSE-2.0
# #
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ==============================================================================

from abc import ABC, abstractmethod
from iflearner.business.hetero.model.role import Role
from iflearner.business.hetero.model.base_model import BaseModel


class ModelBuilder(ABC):
"""Build a model instance base on the role you specify.
"""

@abstractmethod
def create_role_model_instance(self, role: Role) -> BaseModel:
"""Create a model instance base on specific role.
Args:
role (Role): The role name.
Returns:
BaseModel: Return the base class.
"""
pass

@abstractmethod
def get_role_model_flow_file(self, role: Role) -> str:
"""Get model flow file by role name.
Args:
role (Role): The role name.
Returns:
str: Return the filename.
"""
pass
Loading

0 comments on commit fac9cbe

Please sign in to comment.