Skip to content

Commit

Permalink
Merge pull request #5400 from FederatedAI/feature-2.0.0-rc_psi_exampl…
Browse files Browse the repository at this point in the history
…es_update

example: update psi pipeline example
  • Loading branch information
sagewe authored Dec 28, 2023
2 parents 5bc3098 + 3a404cc commit 1abd106
Show file tree
Hide file tree
Showing 3 changed files with 166 additions and 0 deletions.
56 changes: 56 additions & 0 deletions examples/pipeline/psi/psi_testsuite.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
data:
- file: examples/data/breast_hetero_guest.csv
meta:
delimiter: ","
dtype: float64
input_format: dense
label_type: int64
label_name: y
match_id_name: id
match_id_range: 0
tag_value_delimiter: ":"
tag_with_value: false
weight_type: float64
partitions: 4
head: true
extend_sid: true
table_name: breast_hetero_guest
namespace: experiment
role: guest_0
- file: examples/data/breast_hetero_host.csv
meta:
delimiter: ","
dtype: float64
input_format: dense
match_id_name: id
match_id_range: 0
tag_value_delimiter: ":"
tag_with_value: false
weight_type: float64
partitions: 4
head: true
extend_sid: true
table_name: breast_hetero_host
namespace: experiment
role: host_0
- file: examples/data/breast_hetero_host.csv
meta:
delimiter: ","
dtype: float64
input_format: dense
match_id_name: id
match_id_range: 0
tag_value_delimiter: ":"
tag_with_value: false
weight_type: float64
partitions: 4
head: true
extend_sid: true
table_name: breast_hetero_host
namespace: experiment
role: host_1
tasks:
psi:
script: test_psi.py
psi-multi-host:
script: test_psi_multi_host.py
55 changes: 55 additions & 0 deletions examples/pipeline/psi/test_psi.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
#
# 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, 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]

pipeline = FateFlowPipeline().set_parties(guest=guest, host=host)

reader_0 = Reader("reader_0")
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"
)
psi_0 = PSI("psi_0", input_data=reader_0.outputs["output_data"])
pipeline.add_tasks([reader_0, psi_0])

pipeline.compile()
pipeline.fit()


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)
55 changes: 55 additions & 0 deletions examples/pipeline/psi/test_psi_multi_host.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
#
# 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, 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:2]

pipeline = FateFlowPipeline().set_parties(guest=guest, host=host)

reader_0 = Reader("reader_0")
reader_0.guest.task_parameters(
namespace=f"experiment{namespace}",
name="breast_hetero_guest"
)
reader_0.hosts[[0, 1]].task_parameters(
namespace=f"experiment{namespace}",
name="breast_hetero_host"
)
psi_0 = PSI("psi_0", input_data=reader_0.outputs["output_data"])
pipeline.add_tasks([reader_0, psi_0])

pipeline.compile()
pipeline.fit()


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)

0 comments on commit 1abd106

Please sign in to comment.