pipeline-column-expand.py 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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 ColumnExpand
  19. from pipeline.component import DataTransform
  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. guest_train_data = {"name": "breast_hetero_guest", "namespace": f"experiment{namespace}"}
  30. # initialize pipeline
  31. pipeline = PipeLine()
  32. # set job initiator
  33. pipeline.set_initiator(role="guest", party_id=guest).set_roles(guest=guest)
  34. # define Reader components to read in data
  35. reader_0 = Reader(name="reader_0")
  36. # configure Reader for guest
  37. reader_0.get_party_instance(role="guest", party_id=guest).component_param(table=guest_train_data)
  38. # define ColumnExpand components
  39. column_expand_0 = ColumnExpand(name="column_expand_0")
  40. column_expand_0.get_party_instance(
  41. role="guest", party_id=guest).component_param(
  42. need_run=True, method="manual", append_header=[
  43. "x_0", "x_1", "x_2", "x_3"], fill_value=[
  44. 0, 0.2, 0.5, 1])
  45. # define DataTransform components
  46. data_transform_0 = DataTransform(name="data_transform_0") # start component numbering at 0
  47. # get DataTransform party instance of guest
  48. data_transform_0_guest_party_instance = data_transform_0.get_party_instance(role="guest", party_id=guest)
  49. # configure DataTransform for guest
  50. data_transform_0_guest_party_instance.component_param(with_label=True, output_format="dense")
  51. # add components to pipeline, in order of task execution
  52. pipeline.add_component(reader_0)
  53. pipeline.add_component(column_expand_0, data=Data(data=reader_0.output.data))
  54. pipeline.add_component(data_transform_0, data=Data(data=column_expand_0.output.data))
  55. # compile pipeline once finished adding modules, this step will form conf and dsl files for running job
  56. pipeline.compile()
  57. # fit model
  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()