pipeline-feldman-verifiable-sum.py 3.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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 FeldmanVerifiableSum
  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. hosts = parties.host
  30. guest_train_data = {"name": "breast_homo_test", "namespace": f"experiment{namespace}"}
  31. host_train_data = {"name": "breast_homo_test", "namespace": f"experiment{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=hosts)
  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=hosts).component_param(table=host_train_data)
  44. data_transform_0 = DataTransform(name="data_transform_0")
  45. # get and configure DataTransform party instance of guest
  46. data_transform_0.get_party_instance(
  47. role="guest", party_id=guest).component_param(
  48. with_label=False, output_format="dense")
  49. # get and configure DataTransform party instance of host
  50. data_transform_0.get_party_instance(role="host", party_id=hosts).component_param(with_label=False)
  51. # define FeldmanVerifiableSum components
  52. feldmanverifiablesum_0 = FeldmanVerifiableSum(name="feldmanverifiablesum_0")
  53. feldmanverifiablesum_0.get_party_instance(role="guest", party_id=guest).component_param(sum_cols=[1, 2, 3], q_n=6)
  54. feldmanverifiablesum_0.get_party_instance(role="host", party_id=hosts).component_param(sum_cols=[1, 2, 3], q_n=6)
  55. # add components to pipeline, in order of task execution.
  56. pipeline.add_component(reader_0)
  57. pipeline.add_component(data_transform_0, data=Data(data=reader_0.output.data))
  58. pipeline.add_component(feldmanverifiablesum_0, data=Data(data=data_transform_0.output.data))
  59. # compile pipeline once finished adding modules, this step will form conf and dsl files for running job
  60. pipeline.compile()
  61. # fit model
  62. pipeline.fit()
  63. if __name__ == "__main__":
  64. parser = argparse.ArgumentParser("PIPELINE DEMO")
  65. parser.add_argument("-config", type=str,
  66. help="config file")
  67. args = parser.parse_args()
  68. if args.config is not None:
  69. main(args.config)
  70. else:
  71. main()