#
#  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
import os
import sys

cur_path = os.path.realpath(__file__)
for i in range(4):
    cur_path = os.path.dirname(cur_path)
print(f'fate_path: {cur_path}')
sys.path.append(cur_path)

from examples.pipeline.hetero_logistic_regression import common_tools

from pipeline.utils.tools import load_job_config
from pipeline.runtime.entity import JobParameters


def main(config="../../config.yaml", namespace=""):
    # obtain config
    if isinstance(config, str):
        config = load_job_config(config)
    backend = config.backend
    work_mode = config.work_mode

    lr_param = {
        "name": "hetero_lr_0",
        "penalty": "L2",
        "optimizer": "sqn",
        "tol": 0.0001,
        "alpha": 1e-05,
        "max_iter": 10,
        "early_stop": "diff",
        "batch_size": 5000,
        "learning_rate": 0.15,
        "decay": 0.3,
        "decay_sqrt": True,
        "init_param": {
            "init_method": "zeros"
        },
        "sqn_param": {
            "update_interval_L": 3,
            "memory_M": 5,
            "sample_size": 5000,
            "random_seed": None
        },
        "cv_param": {
            "n_splits": 3,
            "shuffle": False,
            "random_seed": 103,
            "need_cv": False
        }
    }

    pipeline = common_tools.make_normal_dsl(config, namespace, lr_param, is_ovr=True)
    # fit model
    pipeline.fit(backend=backend, work_mode=work_mode)
    # query component summary
    common_tools.prettify(pipeline.get_component("hetero_lr_0").get_summary())


if __name__ == "__main__":
    parser = argparse.ArgumentParser("PIPELINE DEMO")
    parser.add_argument("-config", type=str,
                        help="config file")
    args = parser.parse_args()
    if args.config is not None:
        main(args.config)
    else:
        main()

@@ -1995,20 +1995,38 @@
     
-pipeline.fit
+job_parameters = JobParameters
 (bac
@@ -2060,16 +2060,49 @@
 k_mode)%0A
+    pipeline.fit(job_parameters)%0A
     # qu

edit pipeline examples pipeline-hetero-lr-ovr-sqn