Code Duplication    Length = 22-23 lines in 2 locations

hyperactive/memory/memory_helper.py 2 locations

@@ 55-77 (lines=23) @@
52
        print("Model data not found in memory")
53
54
55
def merge_model_IDs(model1, model2):
56
    # do checks if search space has same dim
57
58
    with open(meta_path + "model_connections.json") as f:
59
        data = json.load(f)
60
61
    model1_hash = _get_model_hash(model1)
62
    model2_hash = _get_model_hash(model2)
63
64
    if model1_hash in data:
65
        key_model = model1_hash
66
        value_model = model2_hash
67
        data = _connect_key2value(data, key_model, value_model)
68
    elif model2_hash in data:
69
        key_model = model2_hash
70
        value_model = model1_hash
71
        data = _connect_key2value(data, key_model, value_model)
72
    else:
73
        data[model1_hash] = [model2_hash]
74
        print("IDs successfully connected")
75
76
    with open(meta_path + "model_connections.json", "w") as f:
77
        json.dump(data, f, indent=4)
78
79
80
def _connect_key2value(data, key_model, value_model):
@@ 103-124 (lines=22) @@
100
    return data
101
102
103
def split_model_IDs(model1, model2):
104
    # TODO: do checks if search space has same dim
105
106
    with open(meta_path + "model_connections.json") as f:
107
        data = json.load(f)
108
109
    model1_hash = _get_model_hash(model1)
110
    model2_hash = _get_model_hash(model2)
111
112
    if model1_hash in data:
113
        key_model = model1_hash
114
        value_model = model2_hash
115
        data = _split_key_value(data, key_model, value_model)
116
    elif model2_hash in data:
117
        key_model = model2_hash
118
        value_model = model1_hash
119
        data = _split_key_value(data, key_model, value_model)
120
    else:
121
        print("IDs of models are not connected")
122
123
    with open(meta_path + "model_connections.json", "w") as f:
124
        json.dump(data, f, indent=4)
125
126
127
def _get_file_path(model, X, y):