pipeline-intersect-dh-exact-cardinality.py 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. #
  2. # Copyright 2019 The FATE Authors. All Rights Reserved.
  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. import argparse
  17. from pipeline.backend.pipeline import PipeLine
  18. from pipeline.component import DataTransform
  19. from pipeline.component import Intersection
  20. from pipeline.component import Reader
  21. from pipeline.interface import Data
  22. from pipeline.utils.tools import load_job_config
  23. def main(config="../../config.yaml", namespace=""):
  24. # obtain config
  25. if isinstance(config, str):
  26. config = load_job_config(config)
  27. parties = config.parties
  28. guest = parties.guest[0]
  29. host = parties.host[0]
  30. guest_train_data = {"name": "breast_hetero_guest", "namespace": f"experiment{namespace}"}
  31. host_train_data = {"name": "breast_hetero_host", "namespace": f"experiment{namespace}"}
  32. pipeline = PipeLine().set_initiator(role='guest', party_id=guest).set_roles(guest=guest, host=host)
  33. reader_0 = Reader(name="reader_0")
  34. reader_0.get_party_instance(role='guest', party_id=guest).component_param(table=guest_train_data)
  35. reader_0.get_party_instance(role='host', party_id=host).component_param(table=host_train_data)
  36. data_transform_0 = DataTransform(name="data_transform_0")
  37. data_transform_0.get_party_instance(
  38. role='guest', party_id=guest).component_param(
  39. with_label=False, output_format="dense")
  40. data_transform_0.get_party_instance(
  41. role='host', party_id=host).component_param(
  42. with_label=False, output_format="dense")
  43. param = {
  44. "cardinality_method": "dh",
  45. "cardinality_only": True,
  46. "sync_cardinality": True,
  47. "dh_params": {
  48. "hash_method": "sha256",
  49. "salt": "12345",
  50. "key_length": 1024
  51. }
  52. }
  53. intersect_0 = Intersection(name="intersect_0", **param)
  54. pipeline.add_component(reader_0)
  55. pipeline.add_component(data_transform_0, data=Data(data=reader_0.output.data))
  56. pipeline.add_component(intersect_0, data=Data(data=data_transform_0.output.data))
  57. pipeline.compile()
  58. pipeline.fit()
  59. if __name__ == "__main__":
  60. parser = argparse.ArgumentParser("PIPELINE DEMO")
  61. parser.add_argument("-config", type=str,
  62. help="config file")
  63. args = parser.parse_args()
  64. if args.config is not None:
  65. main(args.config)
  66. else:
  67. main()