secure-information-retrieval.py 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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 Reader
  19. from pipeline.component import DataTransform
  20. from pipeline.component import SecureInformationRetrieval
  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_host", "namespace": f"experiment_sid{namespace}"}
  31. host_train_data = {"name": "breast_hetero_guest", "namespace": f"experiment_sid{namespace}"}
  32. # initialize pipeline
  33. pipeline = PipeLine()
  34. # set job initiator
  35. pipeline.set_initiator(role="guest", party_id=guest)
  36. # set participants information
  37. pipeline.set_roles(guest=guest, host=host)
  38. # define Reader components to read in data
  39. reader_0 = Reader(name="reader_0")
  40. # configure Reader for guest
  41. reader_0.get_party_instance(role="guest", party_id=guest).component_param(table=guest_train_data)
  42. # configure Reader for host
  43. reader_0.get_party_instance(role="host", party_id=host).component_param(table=host_train_data)
  44. data_transform_0 = DataTransform(name="datatransform_0", with_match_id=True)
  45. data_transform_0.get_party_instance(
  46. role="guest", party_id=guest).component_param(
  47. with_label=False, output_format="dense")
  48. data_transform_0.get_party_instance(role="host", party_id=host).component_param(with_label=True)
  49. param = {
  50. "security_level": 0.5,
  51. "oblivious_transfer_protocol": "OT_Hauck",
  52. "commutative_encryption": "CommutativeEncryptionPohligHellman",
  53. "non_committing_encryption": "aes",
  54. "dh_params": {
  55. "key_length": 1024
  56. },
  57. "raw_retrieval": False,
  58. "target_cols": ["x0", "x3"]
  59. }
  60. secure_information_retrieval_0 = SecureInformationRetrieval(name="secure_information_retrieval_0", **param)
  61. # add components to pipeline, in order of task execution.
  62. pipeline.add_component(reader_0)
  63. pipeline.add_component(data_transform_0, data=Data(data=reader_0.output.data))
  64. pipeline.add_component(secure_information_retrieval_0, data=Data(data=data_transform_0.output.data))
  65. # compile pipeline once finished adding modules, this step will form conf and dsl files for running job
  66. pipeline.compile()
  67. # fit model
  68. pipeline.fit()
  69. if __name__ == "__main__":
  70. parser = argparse.ArgumentParser("PIPELINE DEMO")
  71. parser.add_argument("-config", type=str,
  72. help="config file")
  73. args = parser.parse_args()
  74. if args.config is not None:
  75. main(args.config)
  76. else:
  77. main()