def visit(path, key, value): """Check whether a parameter is of a complex type. If not, return it unchanged. Otherwise, 1) create a hash for its value; 2) save a complex type lookup entry linking `key`, `value`, and the hash for `value`; and 3) return the hashed value with `key`, instead of the original complex-typed `value` Parameters ---------- path: Tuple The path of keys that leads to `key` key: Str The parameter name value: * The value of the parameter `key` Returns ------- Tuple of (`key`, value), in which value is either unchanged or a hash for the original `value`""" if isinstance(value, BaseKerasCallback): return (key, keras_callback_to_dict(value)) if isinstance(value, Sentinel): return (key, value.sentinel) elif callable(value) or isinstance(value, pd.DataFrame): hashed_value = make_hash_sha256(value) if isinstance(value, pd.DataFrame): dataframe_hashes.setdefault(hashed_value, []).append(key) try: self.add_complex_type_lookup_entry(path, key, value, hashed_value) except FileNotFoundError: os.makedirs(self.key_attribute_lookup_dir, exist_ok=False) self.add_complex_type_lookup_entry(path, key, value, hashed_value) return (key, hashed_value) return (key, value)
def _visit(path, key, value): """If `value` is `BaseKerasCallback`, return dict representation. Else default_visit""" if isinstance(value, BaseKerasCallback): return (key, keras_callback_to_dict(value)) if isinstance(value, BaseKerasInitializer): return (key, keras_initializer_to_dict(value)) return (key, value)
def visit(path, key, value): """Check whether a parameter is of a complex type. If not, return it unchanged. Otherwise, 1) create a hash for its value; 2) save a complex type lookup entry linking `key`, `value`, and the hash for `value`; and 3) return the hashed value with `key`, instead of the original complex-typed `value` Parameters ---------- path: Tuple The path of keys that leads to `key` key: Str The parameter name value: * The value of the parameter `key` Returns ------- Tuple of (`key`, value), in which value is either unchanged or a hash for the original `value`""" if isinstance(value, BaseKerasCallback): return (key, keras_callback_to_dict(value)) if isinstance(value, BaseKerasInitializer): return (key, keras_initializer_to_dict(value)) if isinstance(value, Sentinel): return (key, value.sentinel) # from hyperparameter_hunter.feature_engineering import FeatureEngineer, EngineerStep # if isinstance(value, EngineerStep): # return (key, value.get_key_data()) # if isinstance(value, FeatureEngineer): # return (key, value.get_key_data()) elif callable(value) or isinstance(value, pd.DataFrame): # TODO: Check here if callable, and using a `Trace`d model/model_initializer # TODO: If so, pass extra kwargs to below `make_hash_sha256`, which are eventually given to `hash_callable` # TODO: Notably, `ignore_source_lines=True` should be included # FLAG: Also, look into adding package version number to hashed attributes hashed_value = make_hash_sha256(value) if isinstance(value, pd.DataFrame): dataframe_hashes.setdefault(hashed_value, []).append(key) if self.tested_keys_dir is not None: # Key-making not blacklisted self.add_complex_type_lookup_entry(path, key, value, hashed_value) return (key, hashed_value) return (key, value)
def visit(path, key, value): """Check whether a parameter is of a complex type. If not, return it unchanged. Otherwise, 1) create a hash for its value; 2) save a complex type lookup entry linking `key`, `value`, and the hash for `value`; and 3) return the hashed value with `key`, instead of the original complex-typed `value` Parameters ---------- path: Tuple The path of keys that leads to `key` key: Str The parameter name value: * The value of the parameter `key` Returns ------- Tuple of (`key`, value), in which value is either unchanged or a hash for the original `value`""" if isinstance(value, BaseKerasCallback): return (key, keras_callback_to_dict(value)) if isinstance(value, BaseKerasInitializer): return (key, keras_initializer_to_dict(value)) if isinstance(value, Sentinel): return (key, value.sentinel) elif callable(value) or isinstance(value, pd.DataFrame): # FLAG: Look into adding package version number to hashed attributes hashed_value = make_hash_sha256(value) if isinstance(value, pd.DataFrame): dataframe_hashes.setdefault(hashed_value, []).append(key) if self.tested_keys_dir is not None: # Key-making not blacklisted self.add_complex_type_lookup_entry(path, key, value, hashed_value) return (key, hashed_value) return (key, value)