-
Notifications
You must be signed in to change notification settings - Fork 1.6k
/
Copy pathtest_scale_standard.py
108 lines (89 loc) · 3.92 KB
/
test_scale_standard.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
#
# Copyright 2019 The FATE Authors. 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
from fate_client.pipeline import FateFlowPipeline
from fate_client.pipeline.components.fate import PSI, FeatureScale, Reader
from fate_client.pipeline.utils import test_utils
def main(config="../config.yaml", namespace=""):
if isinstance(config, str):
config = test_utils.load_job_config(config)
parties = config.parties
guest = parties.guest[0]
host = parties.host[0]
arbiter = parties.arbiter[0]
pipeline = FateFlowPipeline().set_parties(guest=guest, host=host, arbiter=arbiter)
if config.task_cores:
pipeline.conf.set("task_cores", config.task_cores)
if config.timeout:
pipeline.conf.set("timeout", config.timeout)
reader_0 = Reader("reader_0", runtime_parties=dict(guest=guest, host=host))
reader_0.guest.task_parameters(
namespace=f"experiment{namespace}",
name="breast_hetero_guest"
)
reader_0.hosts[0].task_parameters(
namespace=f"experiment{namespace}",
name="breast_hetero_host"
)
reader_1 = Reader("reader_1", runtime_parties=dict(guest=guest, host=host))
reader_1.guest.task_parameters(
namespace=f"experiment{namespace}",
name="breast_hetero_guest"
)
reader_1.hosts[0].task_parameters(
namespace=f"experiment{namespace}",
name="breast_hetero_host"
)
psi_0 = PSI("psi_0", input_data=reader_0.outputs["output_data"])
psi_1 = PSI("psi_1", input_data=reader_1.outputs["output_data"])
feature_scale_0 = FeatureScale("feature_scale_0",
method="standard",
train_data=psi_0.outputs["output_data"])
feature_scale_1 = FeatureScale("feature_scale_1",
test_data=psi_1.outputs["output_data"],
input_model=feature_scale_0.outputs["output_model"])
pipeline.add_tasks([reader_0, reader_1, psi_0, psi_1, feature_scale_0, feature_scale_1])
# pipeline.add_task(hetero_feature_binning_0)
pipeline.compile()
print(pipeline.get_dag())
pipeline.fit()
print(pipeline.get_task_info("feature_scale_0").get_output_model())
# print(pipeline.get_task_info("feature_scale_1").get_output_model())
pipeline.deploy([psi_0, feature_scale_0])
predict_pipeline = FateFlowPipeline()
reader_2 = Reader("reader_2", runtime_parties=dict(guest=guest, host=host))
reader_2.guest.task_parameters(
namespace=f"experiment{namespace}",
name="breast_hetero_guest"
)
reader_2.hosts[0].task_parameters(
namespace=f"experiment{namespace}",
name="breast_hetero_host"
)
deployed_pipeline = pipeline.get_deployed_pipeline()
deployed_pipeline.psi_0.input_data = reader_2.outputs["output_data"]
predict_pipeline.add_tasks([reader_2, deployed_pipeline])
predict_pipeline.compile()
# print("\n\n\n")
# print(predict_pipeline.compile().get_dag())
predict_pipeline.predict()
if __name__ == "__main__":
parser = argparse.ArgumentParser("PIPELINE DEMO")
parser.add_argument("--config", type=str, default="../config.yaml",
help="config file")
parser.add_argument("--namespace", type=str, default="",
help="namespace for data stored in FATE")
args = parser.parse_args()
main(config=args.config, namespace=args.namespace)