Skip to content

Commit

Permalink
[pep8] format
Browse files Browse the repository at this point in the history
Signed-off-by: weiwee <[email protected]>
  • Loading branch information
sagewe committed Dec 2, 2021
1 parent 01498c6 commit 48bf5ae
Show file tree
Hide file tree
Showing 701 changed files with 18,950 additions and 13,059 deletions.
13 changes: 1 addition & 12 deletions .flake8
Original file line number Diff line number Diff line change
@@ -1,18 +1,7 @@
[flake8]
select = B,C,E,F,P,T4,W,B9
max-line-length = 120
# C408 ignored because we like the dict keyword argument syntax
# E501 is not flexible enough, we're using B950 instead
ignore =
E203,E305,E402,E501,E721,E741,F405,F821,F841,F999,W503,W504,C408,E302,W291,E303,
# shebang has extra meaning in fbcode lints, so I think it's not worth trying
# to line this up with executable bit
EXE001,
# these ignores are from flake8-bugbear; please fix!
B007,B008,
# these ignores are from flake8-comprehensions; please fix!
C400,C401,C402,C403,C404,C405,C407,C411,C413,C414,C415
optional-ascii-coding = True
E402
exclude =
./.git,
./fateflow,
Expand Down
2 changes: 1 addition & 1 deletion doc/mkdocs/hook.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ def sub(match):
if url.endswith(".git"):
url = url[:-4]
GITHUB_REPO = f"{url}/tree/{sha}"
except:
except BaseException:
GITHUB_REPO = "https://github.com/FederatedAI/FATE/tree/master"

_DIR_URL_REGEX = re.compile(
Expand Down
2 changes: 1 addition & 1 deletion examples/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@
# 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.
# limitations under the License.
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ def main(config="../../config.yaml", param="./xgb_config_binary.yaml", namespace
guest = parties.guest[0]
host = parties.host[0]


# data sets
guest_train_data = {"name": param['data_guest_train'], "namespace": f"experiment{namespace}"}
host_train_data = {"name": param['data_host_train'], "namespace": f"experiment{namespace}"}
Expand Down
2 changes: 1 addition & 1 deletion examples/benchmark_quality/hetero_fast_sbt/gbdt-binary.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def main(config="../../config.yaml", param="./gbdt_config_binary.yaml"):

try:
auc_score = roc_auc_score(y, y_prob)
except:
except BaseException:
print(f"no auc score available")
return

Expand Down
2 changes: 1 addition & 1 deletion examples/benchmark_quality/hetero_fast_sbt/gbdt-multi.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def main(config="../../config.yaml", param="./gbdt_config_multi.yaml"):

try:
auc_score = roc_auc_score(y, y_pred)
except:
except BaseException:
print(f"no auc score available")

acc = accuracy_score(y, y_pred)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ def main(config="../../config.yaml", param="./linr_config.yaml", namespace=""):
data_transform_0_guest_party_instance = data_transform_0.get_party_instance(role='guest', party_id=guest)
# configure DataTransform for guest
data_transform_0_guest_party_instance.component_param(with_label=True, output_format="dense",
label_name=param["label_name"], label_type="float")
label_name=param["label_name"], label_type="float")
# get and configure DataTransform party instance of host
data_transform_0.get_party_instance(role='host', party_id=host).component_param(with_label=False)

Expand Down Expand Up @@ -97,7 +97,7 @@ def main(config="../../config.yaml", param="./linr_config.yaml", namespace=""):
pipeline.add_component(data_transform_0, data=Data(data=reader_0.output.data))
pipeline.add_component(intersection_0, data=Data(data=data_transform_0.output.data))
pipeline.add_component(hetero_linr_0, data=Data(train_data=intersection_0.output.data))
pipeline.add_component(hetero_linr_1,data=Data(test_data=intersection_0.output.data),
pipeline.add_component(hetero_linr_1, data=Data(test_data=intersection_0.output.data),
model=Model(hetero_linr_0.output.model))
pipeline.add_component(evaluation_0, data=Data(data=hetero_linr_0.output.data))

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,9 @@ def main(config="../../config.yaml", param="./linr_config.yaml"):
r2 = r2_score(y, y_pred)
explained_var = explained_variance_score(y, y_pred)
metric_summary = {"r2_score": r2,
"mean_squared_error": mse,
"root_mean_squared_error": rmse,
"explained_variance": explained_var}
"mean_squared_error": mse,
"root_mean_squared_error": rmse,
"explained_variance": explained_var}
data_summary = {}
return data_summary, metric_summary

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ def main(config="../../config.yaml", param="./lr_config.yaml", namespace=""):
"max_iter": param["max_iter"],
"alpha": param["alpha"],
"learning_rate": param["learning_rate"],
"optimizer": param["optimizer"], # use sgd
"optimizer": param["optimizer"], # use sgd
"batch_size": param["batch_size"],
"early_stop": "diff",
"tol": 1e-4,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ def main(config="../../config.yaml", param="./vehicle_sshe_lr_config.yaml", name
"max_iter": param["max_iter"],
"alpha": param["alpha"],
"learning_rate": param["learning_rate"],
"optimizer": param["optimizer"], # use sgd
"optimizer": param["optimizer"], # use sgd
"batch_size": param["batch_size"],
"early_stop": "diff",
"init_param": {
Expand Down
3 changes: 1 addition & 2 deletions examples/benchmark_quality/hetero_lr/sklearn-lr-binary.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ def main(config="../../config.yaml", param="./vechile_config.yaml"):
y_prob = lm_fit.predict_proba(x_test)[:, 1]
try:
auc_score = roc_auc_score(y_test, y_prob)
except:
except BaseException:
print(f"no auc score available")
return
recall = recall_score(y_test, y_pred, average="macro")
Expand All @@ -89,4 +89,3 @@ def main(config="../../config.yaml", param="./vechile_config.yaml"):
help="config file for params")
args = parser.parse_args()
main(param=args.param)

38 changes: 29 additions & 9 deletions examples/benchmark_quality/hetero_nn/local-hetero_nn.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,37 @@

def build(param, shape1, shape2):
input1 = tf.keras.layers.Input(shape=(shape1,))
x1 = tf.keras.layers.Dense(units=param["bottom_layer_units"], activation='tanh',
kernel_initializer=keras.initializers.RandomUniform(minval=-1, maxval=1, seed=123))(input1)
x1 = tf.keras.layers.Dense(
units=param["bottom_layer_units"],
activation='tanh',
kernel_initializer=keras.initializers.RandomUniform(
minval=-1,
maxval=1,
seed=123))(input1)
input2 = tf.keras.layers.Input(shape=(shape2,))
x2 = tf.keras.layers.Dense(units=param["bottom_layer_units"], activation='tanh',
kernel_initializer=keras.initializers.RandomUniform(minval=-1, maxval=1, seed=123))(input2)
x2 = tf.keras.layers.Dense(
units=param["bottom_layer_units"],
activation='tanh',
kernel_initializer=keras.initializers.RandomUniform(
minval=-1,
maxval=1,
seed=123))(input2)

concat = tf.keras.layers.Concatenate(axis=-1)([x1, x2])
out1 = tf.keras.layers.Dense(units=param["interactive_layer_units"], activation='relu',
kernel_initializer=keras.initializers.RandomUniform(minval=-1, maxval=1, seed=123))(concat)
out2 = tf.keras.layers.Dense(units=param["top_layer_units"], activation=param["top_act"],
kernel_initializer=keras.initializers.RandomUniform(minval=-1, maxval=1, seed=123))(out1)
out1 = tf.keras.layers.Dense(
units=param["interactive_layer_units"],
activation='relu',
kernel_initializer=keras.initializers.RandomUniform(
minval=-1,
maxval=1,
seed=123))(concat)
out2 = tf.keras.layers.Dense(
units=param["top_layer_units"],
activation=param["top_act"],
kernel_initializer=keras.initializers.RandomUniform(
minval=-1,
maxval=1,
seed=123))(out1)
model = tf.keras.models.Model(inputs=[input1, input2], outputs=out2)
opt = getattr(optimizers, param["opt"])(lr=param["learning_rate"])
model.compile(optimizer=opt, loss=param["loss"])
Expand Down Expand Up @@ -74,7 +94,7 @@ def main(config="../../config.yaml", param="./hetero_nn_breast_config.yaml"):
acc = metrics.accuracy_score(y_true=labels, y_pred=predict_y)
eval_result["accuracy"] = acc

print (eval_result)
print(eval_result)
data_summary = {}
return data_summary, eval_result

Expand Down
2 changes: 1 addition & 1 deletion examples/benchmark_quality/hetero_sbt/fate-sbt.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
from federatedml.evaluation.metrics import regression_metric, classification_metric
from fate_test.utils import extract_data, parse_summary_result


def parse_summary_result(rs_dict):
for model_key in rs_dict:
rs_content = rs_dict[model_key]
Expand Down Expand Up @@ -141,7 +142,6 @@ def main(config="../../config.yaml", param="./xgb_config_binary.yaml", namespace
return data_summary, metric_summary



if __name__ == "__main__":
parser = argparse.ArgumentParser("BENCHMARK-QUALITY PIPELINE JOB")
parser.add_argument("-config", type=str,
Expand Down
2 changes: 1 addition & 1 deletion examples/benchmark_quality/hetero_sbt/gbdt-binary.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def main(config="../../config.yaml", param="./gbdt_config_binary.yaml"):

try:
auc_score = roc_auc_score(y, y_prob)
except:
except BaseException:
print(f"no auc score available")
return

Expand Down
2 changes: 1 addition & 1 deletion examples/benchmark_quality/hetero_sbt/gbdt-multi.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def main(config="../../config.yaml", param="./gbdt_config_multi.yaml"):

try:
auc_score = roc_auc_score(y, y_pred)
except:
except BaseException:
print(f"no auc score available")

acc = accuracy_score(y, y_pred)
Expand Down
1 change: 1 addition & 0 deletions examples/benchmark_quality/homo_lr/pipeline-lr-binary.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
from fate_test.utils import extract_data, parse_summary_result
from federatedml.evaluation.metrics import classification_metric


def main(config="../../config.yaml", param="./breast_lr_config.yaml", namespace=""):
# obtain config
if isinstance(config, str):
Expand Down
1 change: 0 additions & 1 deletion examples/benchmark_quality/homo_lr/sklearn-lr-binary.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ def main(config="../../config.yaml", param="./lr_config.yaml"):
# x_test = df_test.drop(label_name, axis=1)
x_test, y_test = x_train, y_train


# lm = LogisticRegression(max_iter=20)
lm = SGDClassifier(loss="log", **config_param)
lm_fit = lm.fit(x_train, y_train)
Expand Down
2 changes: 1 addition & 1 deletion examples/benchmark_quality/homo_sbt/gbdt-binary.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def main(config="../../config.yaml", param="./gbdt_config_binary.yaml"):

try:
auc_score = roc_auc_score(y_guest, y_prob)
except:
except BaseException:
print(f"no auc score available")
return

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ def main(config="../../config.yaml", namespace=""):
host = parties.host[0]
arbiter = parties.arbiter[0]

guest_train_data_0 = {"name":"breast_hetero_guest", "namespace": "experiment"}
guest_train_data_1 = {"name":"breast_hetero_guest", "namespace": "experiment"}
guest_train_data_0 = {"name": "breast_hetero_guest", "namespace": "experiment"}
guest_train_data_1 = {"name": "breast_hetero_guest", "namespace": "experiment"}
guest_test_data_0 = {"name": "breast_hetero_guest", "namespace": "experiment"}
guest_test_data_1 = {"name": "breast_hetero_guest", "namespace": "experiment"}
host_train_data_0 = {"name": "breast_hetero_host_tag_value", "namespace": "experiment"}
Expand Down Expand Up @@ -89,7 +89,7 @@ def main(config="../../config.yaml", namespace=""):
"delimitor": ";",
"output_format": "dense"
}

# define DataIO components
dataio_0 = DataIO(name="dataio_0") # start component numbering at 0
dataio_1 = DataIO(name="dataio_1") # start component numbering at 1
Expand Down Expand Up @@ -141,8 +141,8 @@ def main(config="../../config.yaml", namespace=""):
hetero_feature_selection_0 = HeteroFeatureSelection(**param)
hetero_feature_selection_1 = HeteroFeatureSelection(name='hetero_feature_selection_1')
param = {
"name":"hetero_scale_0",
"method":"standard_scale"
"name": "hetero_scale_0",
"method": "standard_scale"
}
hetero_scale_0 = FeatureScale(**param)
hetero_scale_1 = FeatureScale(name='hetero_scale_1')
Expand All @@ -153,7 +153,6 @@ def main(config="../../config.yaml", namespace=""):
"max_iter": 5
}


hetero_lr_0 = HeteroLR(name='hetero_lr_0', **param)
evaluation_0 = Evaluation(name='evaluation_0')
# add components to pipeline, in order of task execution
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ def main(config="../../config.yaml", namespace=""):
pipeline.add_component(hetero_secureboost_0, data=Data(train_data=hetero_feature_selection_0.output.data,
validate_data=hetero_feature_selection_1.output.data))
pipeline.add_component(hetero_secureboost_1, data=Data(test_data=hetero_feature_selection_2.output.data),
model=Model(hetero_secureboost_0.output.model))
model=Model(hetero_secureboost_0.output.model))

pipeline.add_component(evaluation_0,
data=Data(data=[hetero_secureboost_0.output.data, hetero_secureboost_1.output.data]))
Expand Down
2 changes: 1 addition & 1 deletion examples/min_test_task/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@
# 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.
# limitations under the License.
2 changes: 1 addition & 1 deletion examples/min_test_task/config/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@
# 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.
# limitations under the License.
3 changes: 1 addition & 2 deletions examples/min_test_task/run_task.py
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ def _check_cpn_status(job_id):

time_print("Current task status: {}".format(task_status))
return task_status
except:
except BaseException:
return None

def _deploy_model(self):
Expand Down Expand Up @@ -469,4 +469,3 @@ def _check_status(self, job_id):
if add_sbt:
task = TrainSBTTask(file_type, guest_id, host_id)
task.run()

9 changes: 5 additions & 4 deletions examples/pipeline/column_expand/pipeline-column-expand.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,11 @@ def main(config="../../config.yaml", namespace=""):

# define ColumnExpand components
column_expand_0 = ColumnExpand(name="column_expand_0")
column_expand_0.get_party_instance(role="guest", party_id=guest).component_param(need_run=True,
method="manual",
append_header=["x_0", "x_1", "x_2", "x_3"],
fill_value=[0, 0.2, 0.5, 1])
column_expand_0.get_party_instance(
role="guest", party_id=guest).component_param(
need_run=True, method="manual", append_header=[
"x_0", "x_1", "x_2", "x_3"], fill_value=[
0, 0.2, 0.5, 1])
# define DataTransform components
data_transform_0 = DataTransform(name="data_transform_0") # start component numbering at 0
# get DataTransform party instance of guest
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,13 @@ def main(config="../../config.yaml", namespace=""):
reader_0.get_party_instance(role='host', party_id=host).component_param(table=host_train_data)

data_transform_0 = DataTransform(name="data_transform_0")
data_transform_0.get_party_instance(role='guest', party_id=guest).component_param(with_label=True, label_name="motor_speed",
label_type="float", output_format="dense")
data_transform_0.get_party_instance(
role='guest',
party_id=guest).component_param(
with_label=True,
label_name="motor_speed",
label_type="float",
output_format="dense")
data_transform_0.get_party_instance(role='host', party_id=host).component_param(with_label=False)

intersection_0 = Intersection(name="intersection_0")
Expand Down
9 changes: 7 additions & 2 deletions examples/pipeline/data_split/pipeline-hetero-data-split.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,13 @@ def main(config="../../config.yaml", namespace=""):
reader_0.get_party_instance(role='host', party_id=host).component_param(table=host_train_data)

data_transform_0 = DataTransform(name="data_transform_0")
data_transform_0.get_party_instance(role='guest', party_id=guest).component_param(with_label=True, label_name="motor_speed",
label_type="float", output_format="dense")
data_transform_0.get_party_instance(
role='guest',
party_id=guest).component_param(
with_label=True,
label_name="motor_speed",
label_type="float",
output_format="dense")
data_transform_0.get_party_instance(role='host', party_id=host).component_param(with_label=False)

intersection_0 = Intersection(name="intersection_0")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ def main(config="../../config.yaml", namespace=""):
guest = parties.guest[0]
host = parties.host[0]


guest_train_data = {"name": "breast_homo_guest", "namespace": f"experiment{namespace}"}
host_train_data = {"name": "breast_homo_host", "namespace": f"experiment{namespace}"}

Expand All @@ -45,8 +44,13 @@ def main(config="../../config.yaml", namespace=""):

data_transform_0 = DataTransform(name="data_transform_0")

data_transform_0.get_party_instance(role='guest', party_id=guest).component_param(with_label=True, output_format="dense",
label_name="y", label_type="int")
data_transform_0.get_party_instance(
role='guest',
party_id=guest).component_param(
with_label=True,
output_format="dense",
label_name="y",
label_type="int")
data_transform_0.get_party_instance(role='host', party_id=host).component_param(with_label=True)

homo_data_split_0 = HomoDataSplit(name="homo_data_split_0", stratified=True, validate_size=0.2)
Expand Down
Loading

0 comments on commit 48bf5ae

Please sign in to comment.